Skip to content

Commit

Permalink
refactorings, javadoc additions and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Mar 8, 2024
1 parent d335157 commit 41f7bf6
Show file tree
Hide file tree
Showing 40 changed files with 104 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.sql.Driver;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Objects;
import java.util.Properties;
import java.util.logging.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* A log buffer class intended to provide a buffer for log messages to display in GUI applications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,59 @@
import java.time.Instant;
import java.time.format.DateTimeFormatter;

/**
* The LogEntry interface represents a log entry with various properties such as message, logger name, time, level, marker, and throwable.
*/
public interface LogEntry {
/**
* Retrieves the message of the log entry.
*
* @return The message of the log entry.
*/
String message();

/**
* Returns the name of the logger associated with the log entry.
*
* @return The name of the logger.
*/
String loggerName();

/**
* Returns the time when the logging event was created as an Instant object.
*
* @return the creation time of the logging event as an Instant object
*/
Instant time();

/**
* Returns the log level of the LogEntry.
*
* @return the log level of the LogEntry
*/
LogLevel level();

/**
* Returns the marker associated with this log entry.
*
* @return the marker
*/
String marker();

/**
* Returns the throwable object associated with this LogEntry.
*
* @return the throwable object associated with this LogEntry, or null if no throwable is present
*/
Throwable throwable();

/**
* Formats the log entry with the given prefix and suffix.
*
* @param prefix the prefix to prepend to the formatted entry
* @param suffix the suffix to append to the formatted entry
* @return the formatted log entry as a string
*/
default String format(String prefix, String suffix) {
StringBuilder sb = new StringBuilder(100);
sb.append(prefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.dua3.utility.data.Color;
import com.dua3.utility.io.AnsiCode;

/**
* Enumeration representing different log levels.
*/
public enum LogLevel {
TRACE(AnsiCode.fg(Color.DARKGRAY), AnsiCode.reset()),
DEBUG(AnsiCode.fg(Color.BLACK), AnsiCode.reset()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public final class LogEntrySlf4j implements LogEntry {
private String formattedMessage;
private final Throwable throwable;

/**
* Creates a new instance of LogEntrySlf4j.
*
* @param loggerName the name of the logger
* @param level the log level of the log entry
* @param marker the marker associated with the log entry (nullable)
* @param messageFormatter the supplier used to format the log message
* @param throwable the throwable associated with the log entry (nullable)
*/
public LogEntrySlf4j(String loggerName, Level level, @Nullable Marker marker, Supplier<String> messageFormatter,
@Nullable Throwable throwable) {
this.loggerName = loggerName;
Expand Down
12 changes: 12 additions & 0 deletions utility-swing/src/main/java/com/dua3/utility/swing/FileInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,22 @@ public String getText() {

/**
* Enum for file selection modes.
* <p>
* The file selection mode determines whether the user can select only files,
* only directories, or both files and directories when browsing for a file.
*/
public enum SelectionMode {
/**
* The SELECT_FILE constant indicates that only files should be selectable.
*/
SELECT_FILE(JFileChooser.FILES_ONLY),
/**
* The SELECT_DIRECTORY constant indicates that only directories should be selectable.
*/
SELECT_DIRECTORY(JFileChooser.DIRECTORIES_ONLY),
/**
* The SELECT_DIRECTORY constant indicates that both files and directories should be selectable.
*/
SELECT_FILE_OR_DIRECTORY(JFileChooser.FILES_AND_DIRECTORIES);

private final int fileSelectionMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Objects;

/**
* A class that represents an image using the Swing BufferedImage API.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.dua3.utility.concurrent;

import java.util.Objects;

/**
* Interface for progress tracking.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Predicate;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;

/**
* A peekable Iterator implementation.
Expand Down
1 change: 0 additions & 1 deletion utility/src/main/java/com/dua3/utility/io/CsvReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down
1 change: 0 additions & 1 deletion utility/src/main/java/com/dua3/utility/io/CsvWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;

/**
* A class that writes data in CSV format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -44,9 +43,9 @@ public LineOutputStream(Consumer<String> processor) {
private void flushLine() {
synchronized (lock) {
// remove line end
if (count>0 && buf[count-1]=='\n') {
if (count > 0 && buf[count - 1] == '\n') {
count--;
if (count>0 && buf[count-1]=='\r') {
if (count > 0 && buf[count - 1] == '\r') {
count--;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
import java.util.function.Function;
import java.util.regex.Pattern;

/**
* The PredefinedDateTimeFormat class defines a set of predefined date and time formats.
* Each format represents a specific style and pattern for formatting dates and times.
*/
public enum PredefinedDateTimeFormat {
/**
* The default format to use for the current locale.
*/
LOCALE_DEFAULT("locale dependent", PredefinedDateTimeFormat::formatDateTimeFromLocale, PredefinedDateTimeFormat::formatDateFromLocale, PredefinedDateTimeFormat::formatTimeFromLocale),

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package com.dua3.utility.io;

import java.lang.ref.SoftReference;
import java.util.Objects;
import java.util.function.Supplier;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dua3.utility.lang;

import java.util.Objects;
import java.util.function.Function;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Vector2f current() {
* <strong>NOTE:</strong> This implicitly starts a new path.
*
* @param v the vertex that marks the start of the new path
* @return this PathBuilder2f instance
*/
public PathBuilder2f moveTo(Vector2f v) {
if (open) {
Expand All @@ -95,6 +96,16 @@ public PathBuilder2f lineTo(Vector2f v) {
return this;
}

/**
* Adds an arc segment to the path, defined by the endpoint, radii, angle, and arc flags.
*
* @param ep the endpoint of the arc segment
* @param r the radii of the arc segment
* @param angle the angle of the arc segment in degrees
* @param largeArc if true, the arc should be greater than or equal to 180 degrees, otherwise less than 180 degrees
* @param sweep if true, the arc should be drawn in a "clockwise" direction, otherwise in a "counterclockwise" direction
* @return this PathBuilder2f instance
*/
public PathBuilder2f arcTo(Vector2f ep, Vector2f r, float angle, boolean largeArc, boolean sweep) {
LangUtil.check(open, "no current path");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Formatter;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down
1 change: 0 additions & 1 deletion utility/src/main/java/com/dua3/utility/options/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dua3.cabe.annotations.Nullable;

import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dua3.utility.text;

import java.util.Objects;
import java.util.function.Consumer;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private static void copyAttributes(Iterable<? extends Map.Entry<String, Object>>
String attribute = entry.getKey();
Object value = entry.getValue();
if (Objects.equals(Style.FONT, attribute)) {
// special handling if FONT is set: as FONT overrides all other font related attributes,
// once FONT is set it will override all subsequent font related changes until a new FONT
// special handling if FONT is set: as FONT overrides all other font-related attributes,
// once FONT is set, it will override all later font-related changes until a new FONT
// is encountered. so filter out FONT and instead set the individual attributes.
RichTextConverter.putFontProperties(destinationAttributes, (Font) value);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dua3.utility.text;

import java.util.Objects;
import java.util.function.Consumer;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.SortedMap;
import java.util.TreeMap;

Expand Down Expand Up @@ -190,7 +189,7 @@ public void ensureCapacity(int minimumCapacity) {
/**
* Returns the length (character count).
*
* @return the length of the sequence of characters
* @return the length of the character sequence
*/
public int length() {
return buffer.length();
Expand Down Expand Up @@ -245,6 +244,7 @@ void appendRun(Run run) {
*
* @param name attribute name
* @param value attribute value
* @return this RichTextBuilder instance
*/
public RichTextBuilder push(String name, Object value) {
Object previousValue = split().put(name, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dua3.utility.text;

import java.util.Objects;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down
4 changes: 2 additions & 2 deletions utility/src/main/java/com/dua3/utility/text/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean equals(@Nullable Run other, BiPredicate<? super TextAttributes, ?
}

/**
* Get position of end of Run.
* Get the end position of this Run.
*
* @return end of Run
*/
Expand All @@ -96,7 +96,7 @@ public int getEnd() {
}

/**
* Get position of start of Run.
* Get the start position this Run.
*
* @return start of Run
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import com.dua3.cabe.annotations.Nullable;

import java.util.Objects;

public class SharableString implements CharSequence {

private final String base;
Expand Down
1 change: 0 additions & 1 deletion utility/src/main/java/com/dua3/utility/xml/XmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.regex.Pattern;
Expand Down
Loading

0 comments on commit 41f7bf6

Please sign in to comment.