Skip to content

Commit

Permalink
small code and text fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Nov 10, 2023
1 parent e509e25 commit d6bae1c
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 72 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ Replace `${utility_version}` with the current version.

**As of version 12.0.0, logging changed from SLF4J to Log4J-API!**

You can use whatever logging implementation you want, for configuration refer to the Log4J documentation. You can also look at the swing samples that use a SwingLogPane and route all logging output regardless of source (Log4J, SLF4J, JUL) to the logging implementation.
You can use whatever logging implementation you want, for configuration refer to the Log4J documentation. You can also
look at the swing samples that use a SwingLogPane and route all logging output regardless of source (Log4J, SLF4J, JUL)
to the logging implementation.

### utility-logging

Expand Down Expand Up @@ -160,8 +162,8 @@ the parameter.
## Changes
- all internal logging is done through log4j-api instead of slf4j
- introduced util-logging-slf4j as sub project of util-logging. Note that util-logging is not intended as a production logging
replacement. It is intended to provide utilites to capture and display log data in an application window.
- introduced util-logging-slf4j as sub project of util-logging. Note that util-logging is not intended as a production
logging replacement. It is intended to provide utilites to capture and display log data in an application window.
### 12.0.0 (to be released)
Expand All @@ -170,7 +172,7 @@ the parameter.
### 11.1.3
- update log4j to 2.21.0 (according to release notes now fully JLink compatible)
- update log4j to 2.21.0 (according to release notes now fully JLink compatible)
### 11.1.2
Expand All @@ -181,7 +183,7 @@ the parameter.
### 11.1.0
- overload TextUtil.getMD5String(byte[])
- Value interface as an abstraction for observable values that is meant to be used in place of JavaFX ObservableValue or
- Value interface as an abstraction for observable values that is meant to be used in place of JavaFX ObservableValue or
Swing Properties in library code that is supposed not to have dependencies on either JavaFX or java.desktop
### 11.0.0
Expand Down Expand Up @@ -687,7 +689,7 @@ the parameter.
### Version 5.1.2
- added methods in LangUtil to resolve localised resources
- added methods in LangUtil to resolve localized resources
- minor cleanups
### Version 5.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ public void setZonedDateTime(String name, @Nullable ZonedDateTime value) throws
* @throws IllegalArgumentException if the parameter does not exist
* @see PreparedStatement#setTimestamp(int, java.sql.Timestamp, java.util.Calendar)
*/
@SuppressWarnings("UseOfObsoleteDateTimeApi")
public void setInstant(String name, @Nullable Instant value) throws SQLException {

if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public ConsoleHandler(PrintStream out, boolean colored) {
this.out = out;

if (colored) {
colorMap.put(LogLevel.TRACE, Pair.of(AnsiCode.fg(Color.DARKGRAY), AnsiCode.reset()+NEWLINE));
colorMap.put(LogLevel.DEBUG, Pair.of(AnsiCode.fg(Color.BLACK), AnsiCode.reset()+NEWLINE));
colorMap.put(LogLevel.INFO, Pair.of(AnsiCode.fg(Color.BLUE), AnsiCode.reset()+NEWLINE));
colorMap.put(LogLevel.WARN, Pair.of(AnsiCode.fg(Color.ORANGERED), AnsiCode.reset()+NEWLINE));
colorMap.put(LogLevel.ERROR, Pair.of(AnsiCode.fg(Color.DARKRED), AnsiCode.reset()+NEWLINE));
colorMap.put(LogLevel.TRACE, Pair.of(AnsiCode.fg(Color.DARKGRAY), AnsiCode.reset() + NEWLINE));
colorMap.put(LogLevel.DEBUG, Pair.of(AnsiCode.fg(Color.BLACK), AnsiCode.reset() + NEWLINE));
colorMap.put(LogLevel.INFO, Pair.of(AnsiCode.fg(Color.BLUE), AnsiCode.reset() + NEWLINE));
colorMap.put(LogLevel.WARN, Pair.of(AnsiCode.fg(Color.ORANGERED), AnsiCode.reset() + NEWLINE));
colorMap.put(LogLevel.ERROR, Pair.of(AnsiCode.fg(Color.DARKRED), AnsiCode.reset() + NEWLINE));
} else {
colorMap.put(LogLevel.TRACE, Pair.of("", NEWLINE));
colorMap.put(LogLevel.DEBUG, Pair.of("", NEWLINE));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.dua3.utility.logging;

import java.util.Collection;

/**
* This interface defines the contract for classes that dispatch log entries to registered handlers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public enum LogLevel {
this.escEnd = escEnd;
}

String escStart;
String escEnd;
final String escStart;
final String escEnd;

String colorize(String text, boolean colored) {
return colored ? escStart+text+escEnd : text;
return colored ? escStart + text + escEnd : text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class LogAppenderLog4j extends AbstractAppender implements LogEntryDispat
*/
protected LogAppenderLog4j(String name, @Nullable Filter filter, @Nullable Layout<? extends Serializable> layout,
final boolean ignoreExceptions) {
super(name, filter, layout, ignoreExceptions);
super(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY);
}

/**
Expand Down Expand Up @@ -88,16 +89,16 @@ public static LogAppenderLog4j createAppender(
@Override
public void append(LogEvent event) {
boolean cleanup = false;
for (WeakReference<LogEntryHandler> ref: handlers) {
for (WeakReference<LogEntryHandler> ref : handlers) {
LogEntryHandler handler = ref.get();
if (handler==null) {
if (handler == null) {
cleanup = true;
} else {
handler.handleEntry(new LogEntryLog4J(event));
}
}
if (cleanup) {
handlers.removeIf(ref -> ref.get()==null);
handlers.removeIf(ref -> ref.get() == null);
}
}

Expand All @@ -108,6 +109,6 @@ public void addLogEntryHandler(LogEntryHandler handler) {

@Override
public void removeLogEntryHandler(LogEntryHandler handler) {
handlers.removeIf(h -> h.get()==handler);
handlers.removeIf(h -> h.get() == handler);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package com.dua3.utility.logging.log4j;

import com.dua3.cabe.annotations.Nullable;
import com.dua3.utility.logging.LogEntry;
import com.dua3.utility.logging.LogLevel;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.ReusableMessage;
import org.apache.logging.log4j.spi.StandardLevel;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.Instant;
import java.time.InstantSource;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*/
public final class LogUtilLog4J {

private LogUtilLog4J() {}
private LogUtilLog4J() {
}

/**
* Creates a Dua3LogAppenderLog4j instance. NOTE: The appender is not started.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import org.slf4j.spi.LocationAwareLogger;

import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
public final class LogUtilSlf4j {
private static final Logger LOG = LogManager.getLogger(LogUtilSlf4j.class);

private LogUtilSlf4j() {}
private LogUtilSlf4j() {
}

/**
* Returns an Optional containing an instance of LoggerFactorySlf4j if the retrieved ILoggerFactory
Expand All @@ -23,7 +24,7 @@ private LogUtilSlf4j() {}
*/
public static Optional<LoggerFactorySlf4j> getLoggerFactory() {
ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
if (iLoggerFactory instanceof LoggerFactorySlf4j factory) {
if (iLoggerFactory instanceof LoggerFactorySlf4j factory) {
LOG.debug("ILoggerFactory of class {} found", factory.getClass());
return Optional.of(factory);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
Expand Down Expand Up @@ -120,6 +117,6 @@ public void addLogEntryHandler(LogEntryHandler handler) {

@Override
public void removeLogEntryHandler(LogEntryHandler handler) {
handlers.removeIf(h -> h.get()==handler);
handlers.removeIf(h -> h.get() == handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import com.dua3.cabe.annotations.Nullable;
import com.dua3.utility.logging.LogEntryHandler;
import com.dua3.utility.logging.LogLevel;
import org.slf4j.Marker;
import org.slf4j.event.Level;
import org.slf4j.helpers.AbstractLogger;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;

import java.lang.ref.WeakReference;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -50,16 +47,16 @@ protected String getFullyQualifiedCallerName() {
@Override
protected void handleNormalizedLoggingCall(Level level, @Nullable Marker marker, String messagePattern, @Nullable Object[] arguments, @Nullable Throwable throwable) {
boolean cleanup = false;
for (WeakReference<LogEntryHandler> ref: handlers) {
for (WeakReference<LogEntryHandler> ref : handlers) {
LogEntryHandler handler = ref.get();
if (handler==null) {
if (handler == null) {
cleanup = true;
} else {
handler.handleEntry(new LogEntrySlf4j(name, level, marker, () -> MessageFormatter.basicArrayFormat(messagePattern, arguments), throwable));
}
}
if (cleanup) {
handlers.removeIf(ref -> ref.get()==null);
handlers.removeIf(ref -> ref.get() == null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Arguments getArguments() {
/**
* Creates a new ArgumentsDialog with the specified owner, parser, and title.
* The dialog is displayed as a modal dialog and blocks input from other windows.
* The dialog contains an ArgumentsPanel with the specified parser and callback methods for when the dialog is closed or cancelled.
* The dialog contains an ArgumentsPanel with the specified parser and callback methods for when the dialog is closed or canceled.
*
* @param owner the owner Window of the dialog
* @param parser the ArgumentsParser used by the dialog to parse arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import java.util.function.Function;

/**
* ProgressView class represents a view of the progress of tasks.
* It implements the ProgressTracker interface.
* View of task progress.
* This class implements the {@link ProgressTracker} interface.
*
* @param <T> the type of tasks being tracked
* @param <T> the type of the tasks being tracked
*/
public class ProgressView<T> implements ProgressTracker<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface ReadOnlyValue<T> {
* - The new value of type T
* The change listener does not return a value.
*/
void addChangeListener(BiConsumer<? super T,? super T> listener);
void addChangeListener(BiConsumer<? super T, ? super T> listener);

/**
* Removes a change listener for the given method. The change listener will no longer be triggered
Expand All @@ -35,13 +35,13 @@ public interface ReadOnlyValue<T> {
* @param listener The change listener to be removed.
* The change listener is a BiConsumer that was previously added using the addChangeListener method.
*/
void removeChangeListener(BiConsumer<? super T,? super T> listener);
void removeChangeListener(BiConsumer<? super T, ? super T> listener);

/**
* Returns a collection of all the change listeners currently registered for this method.
*
* @return A collection of change listeners, each represented as a BiConsumer.
* The change listeners are used to listen for changes in the value of type T.
*/
Collection<BiConsumer<? super T,? super T>> getChangeListeners();
Collection<BiConsumer<? super T, ? super T>> getChangeListeners();
}
4 changes: 2 additions & 2 deletions utility/src/main/java/com/dua3/utility/data/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,8 @@ default HSVColor toHSVColor() {
/**
* Get CSS compatible string representation of this color.
* <p>
* Opaque colors are represented as 3 component hex strings, i. e. "#ff0000" for red.
* Colors using transparency are represented as 4 component hex strings in rrggbbaa format.
* Opaque colors are represented as three component hex strings, i. e. "#ff0000" for red.
* Colors using transparency are represented as four component hex strings in rrggbbaa format.
*
* @return this color as hex value (in rgb or rgba representation)
*/
Expand Down
4 changes: 2 additions & 2 deletions utility/src/main/java/com/dua3/utility/data/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public Image convert(Image img) {
Image create(int w, int h, int[] data);

/**
* Convert image to underlying implementation.
* Convert {@link Image} instance to underlying implementation.
*
* @param img the image
* @return implementation dependent image class
*/
I convert(Image img);

/**
* Convert image underlying implementation. to image.
* Convert image from underlying implementation to {@link Image} instance.
*
* @param img the implementation dependent image
* @return image
Expand Down
3 changes: 2 additions & 1 deletion utility/src/main/java/com/dua3/utility/lang/LangUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.dua3.utility.io.IoUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -659,7 +660,7 @@ public static String getLocaleSuffix(Locale locale) {
}

/**
* Get localised resource.
* Get localized resource.
* <p>
* This method follows the resource bundle lookup algorithm, starting to search from the most specific
* resource name towards the general one, returning the first found valid URL.
Expand Down
4 changes: 2 additions & 2 deletions utility/src/main/java/com/dua3/utility/math/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static double pow10(int i) {
* The number of places {@code n} may be negative, resulting in rounding taking place before the decimal point,
* i.e. {@code round(125, -1)=130}.
* <p>
* Examples rounding to 2 digits precision:
* Examples rounding to two digits precision:
* <ul>
* <li>0.123 -&gt; 0.12
* <li>12.3 -&gt; 12.3
Expand Down Expand Up @@ -371,7 +371,7 @@ public static double round(double x, int n) {
* <p>
* Round {@code x} to {@code p} digits of precision according to {@link java.math.RoundingMode#HALF_UP}.
* <p>
* Examples rounding to 2 digits precision:
* Examples rounding to two digits precision:
* <ul>
* <li>0.123 -&gt; 0.12
* <li>12.3 -&gt; 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
public final class BezierCurve2f extends AbstractCurve2f {
/**
* Name of this type of segment.
* Name of this segment type.
*/
public static final String NAME = "BEZIER";

Expand Down
Loading

0 comments on commit d6bae1c

Please sign in to comment.