Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Nov 7, 2024
1 parent 5e4ed8e commit 6a68599
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.dua3.utility.text.TextUtil;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.jspecify.annotations.NonNull;

import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public ChoiceInputControl(ChoiceOption<T> option, Supplier<? extends @Nullable T
this.control = new ComboBox<>();
this.valueProperty = new SimpleObjectProperty<>();

control.valueProperty().addListener((v, o, n) -> valueProperty.setValue(n == null ? null : n.value()));
//noinspection NullableProblems - false positive
control.valueProperty().addListener((ObservableValue<? extends ChoiceOption.Choice<T>> v, ChoiceOption.@Nullable Choice<T> o, ChoiceOption.@Nullable Choice<T> n) -> valueProperty.setValue(n == null ? null : n.value()));
valueProperty.addListener((ObservableValue<? extends @Nullable T> v, @Nullable T o, @Nullable T n) -> {
if (n == null) {
control.getSelectionModel().clearSelection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public FileInput(
* @param existingOnly indicates whether only existing files or directories should be selectable
* @return a function that takes a Path and returns an Optional containing an error message if validation fails, or an empty Optional if validation succeeds
*/
public static Function<Path, Optional<String>> defaultValidate(FileDialogMode mode, boolean existingOnly) {
public static Function<@Nullable Path, Optional<String>> defaultValidate(FileDialogMode mode, boolean existingOnly) {
return p -> {
if (p == null) {
return Optional.of("Nothing selected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.dua3.utility.fx.controls;

import com.dua3.utility.data.Pair;
import com.dua3.utility.fx.FxUtil;
import com.dua3.utility.fx.PlatformHelper;
import javafx.beans.property.ObjectProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.scene.control.Control;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dua3.utility.fx.controls;

import javafx.beans.value.ObservableValue;
import org.jspecify.annotations.Nullable;
import javafx.application.Platform;
import javafx.event.Event;
Expand Down Expand Up @@ -71,7 +72,8 @@ public TableCellAutoCommit(StringConverter<T> converter) {
setGraphic(textField);
setContentDisplay(ContentDisplay.TEXT_ONLY);

itemProperty().addListener((observable, oldValue, newValue) -> {
//noinspection NullableProblems - false positive
itemProperty().addListener((ObservableValue<? extends T> observable, @Nullable T oldValue, @Nullable T newValue) -> {
if (newValue == null) {
setText(null);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.dua3.utility.fx.controls;

import org.jspecify.annotations.Nullable;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
Expand Down
4 changes: 2 additions & 2 deletions utility-fx/src/main/java/com/dua3/utility/fx/FxUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ public static void addMouseEventHandler(Node node, EventType<MouseEvent> eventTy
* @param newHandler the new event handler to be added
*/
private static void addHandler(
Supplier<? extends EventHandler<? super MouseEvent>> getHandler,
Consumer<EventHandler<? super MouseEvent>> setHandler,
Supplier<? extends @Nullable EventHandler<? super MouseEvent>> getHandler,
Consumer<@Nullable EventHandler<? super MouseEvent>> setHandler,
EventHandler<? super MouseEvent> newHandler) {
EventHandler<? super MouseEvent> currentHandler = getHandler.get();
if (currentHandler == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dua3.utility.data.Color;
import com.dua3.utility.data.Pair;
import com.dua3.utility.io.AnsiCode;
import org.jspecify.annotations.NonNull;

import java.io.PrintStream;
import java.util.EnumMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dua3.utility.logging;

import org.jspecify.annotations.Nullable;

/**
* Interface for a factory that provides an instance of the LogEntryDispatcher.
*/
Expand All @@ -11,5 +13,5 @@ public interface ILogEntryDispatcherFactory {
* NOTE: This method is called by the ServiceProvider and not intended to be called directly by user code.
* @return The global LogEntryDispatcher instance.
*/
LogEntryDispatcher getDispatcher();
@Nullable LogEntryDispatcher getDispatcher();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public abstract class SwingComponentsSampleLogBase extends JFrame {
private static final String TASK_INDETERMINATE_2 = "Another Indeterminate Task";
private static final int AVERAGE_SLEEP_MILLIS = 10;
private static final int LOG_BUFFER_SIZE = 1000;
private final org.slf4j.Logger SLF4J_LOGGER = LoggerFactory.getLogger("SLF4J." + getClass().getName());
private final java.util.logging.Logger JUL_LOGGER = java.util.logging.Logger.getLogger("JUL." + getClass().getName());
private final org.apache.logging.log4j.Logger LOG4J_LOGGER = org.apache.logging.log4j.LogManager.getLogger("LOG4J." + getClass().getName());
private final org.slf4j.Logger slf4JLogger = LoggerFactory.getLogger("SLF4J." + getClass().getName());
private final java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("JUL." + getClass().getName());
private final org.apache.logging.log4j.Logger log4JLogger = org.apache.logging.log4j.LogManager.getLogger("LOG4J." + getClass().getName());
private final AtomicInteger n = new AtomicInteger();
private volatile boolean done;

Expand Down Expand Up @@ -184,32 +184,32 @@ private void init() {
switch (implementation) {
case 0 -> {
switch (levelInt) {
case 0 -> SLF4J_LOGGER.trace(msg);
case 1 -> SLF4J_LOGGER.debug(msg);
case 2 -> SLF4J_LOGGER.info(msg);
case 3 -> SLF4J_LOGGER.warn(msg);
case 4 -> SLF4J_LOGGER.error(msg, generateThrowable(random));
case 0 -> slf4JLogger.trace(msg);
case 1 -> slf4JLogger.debug(msg);
case 2 -> slf4JLogger.info(msg);
case 3 -> slf4JLogger.warn(msg);
case 4 -> slf4JLogger.error(msg, generateThrowable(random));
default -> throw new IllegalStateException("integer out of range");
}
}
case 1 -> {
switch (levelInt) {
case 0 -> JUL_LOGGER.finest(msg);
case 1 -> JUL_LOGGER.finer(msg);
case 2 -> JUL_LOGGER.fine(msg);
case 3 -> JUL_LOGGER.info(msg);
case 4 -> JUL_LOGGER.warning(msg);
case 5 -> JUL_LOGGER.log(java.util.logging.Level.SEVERE, msg, generateThrowable(random));
case 0 -> julLogger.finest(msg);
case 1 -> julLogger.finer(msg);
case 2 -> julLogger.fine(msg);
case 3 -> julLogger.info(msg);
case 4 -> julLogger.warning(msg);
case 5 -> julLogger.log(java.util.logging.Level.SEVERE, msg, generateThrowable(random));
default -> throw new IllegalStateException("integer out of range");
}
}
case 2 -> {
switch (levelInt) {
case 0 -> LOG4J_LOGGER.trace(msg);
case 1 -> LOG4J_LOGGER.debug(msg);
case 2 -> LOG4J_LOGGER.info(msg);
case 3 -> LOG4J_LOGGER.warn(msg);
case 4 -> LOG4J_LOGGER.error(msg, generateThrowable(random));
case 0 -> log4JLogger.trace(msg);
case 1 -> log4JLogger.debug(msg);
case 2 -> log4JLogger.info(msg);
case 3 -> log4JLogger.warn(msg);
case 4 -> log4JLogger.error(msg, generateThrowable(random));
default -> throw new IllegalStateException("integer out of range");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dua3.utility.swing;

import com.dua3.utility.lang.LangUtil;
import org.jspecify.annotations.Nullable;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand All @@ -24,7 +23,6 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Function;
Expand Down
2 changes: 1 addition & 1 deletion utility/src/main/java/com/dua3/utility/data/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* A common interface for different color implementations.
*/
@SuppressWarnings({"Style"})
@SuppressWarnings("Style")
public interface Color {
/**
* Factor to apply when generating a brighter or darker version of a color.
Expand Down
2 changes: 0 additions & 2 deletions utility/src/main/java/com/dua3/utility/io/Codec.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.dua3.utility.io;

import org.jspecify.annotations.Nullable;

import java.io.DataInputStream;
import java.io.DataOutputStream;

Expand Down
1 change: 0 additions & 1 deletion utility/src/main/java/com/dua3/utility/io/Codecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.dua3.utility.lang.LangUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import java.io.DataInput;
Expand Down
2 changes: 0 additions & 2 deletions utility/src/main/java/com/dua3/utility/io/Decoder.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.dua3.utility.io;

import com.dua3.utility.lang.LangUtil;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import java.io.DataInputStream;
import java.io.IOException;
Expand Down
6 changes: 3 additions & 3 deletions utility/src/main/java/com/dua3/utility/lang/RingBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ public Object[] toArray() {

@Override
@SuppressWarnings("unchecked")
public <T> @Nullable T[] toArray(@Nullable T[] a) {
public <U> @Nullable U[] toArray(@Nullable U[] a) {
if (a.length < entries) {
a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), entries);
a = (U[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), entries);
}

// copy contents to array
Expand Down Expand Up @@ -307,7 +307,7 @@ public List<T> subList(int fromIndex, int toIndex) {
Objects.checkFromIndexSize(fromIndex, sz, len);

//noinspection NullableProblems - false positive; T is @Nullable
return new AbstractList<T>() {
return new AbstractList<>() {
@Override
public T get(int index) {
return RingBuffer.this.get(Objects.checkIndex(index, sz) + fromIndex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dua3.utility.options;

import com.dua3.utility.data.Pair;
import com.dua3.utility.lang.LangUtil;
import com.dua3.utility.text.TextUtil;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dua3.utility.options;

import com.dua3.utility.data.DataUtil;
import org.jspecify.annotations.Nullable;

import java.util.Collection;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void appendRun(Run run) {

// restore attributes
attributes = split();
for (Entry<String, Object> entry : backup.entrySet()) {
for (Entry<String, @Nullable Object> entry : backup.entrySet()) {
if (entry.getValue() == null) {
attributes.remove(entry.getKey());
} else {
Expand Down
1 change: 0 additions & 1 deletion utility/src/main/java/com/dua3/utility/text/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.dua3.utility.text;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import com.dua3.utility.data.Color;

Expand Down

0 comments on commit 6a68599

Please sign in to comment.