Skip to content

Commit

Permalink
javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Aug 22, 2023
1 parent 3faa9ce commit 4da5be7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@ public class ProgressView<T> implements ProgressTracker<T> {
private final Function<T, ProgressIndicator> createProgressIndicator;
private final Map<T, TaskRecord> tasks = Collections.synchronizedMap(new LinkedHashMap<>());

/**
* Constructs a new ProgressView object.
*
* @param createProgressIndicator a function that creates a ProgressIndicator based on a given task type T.
* The function must not return null.
*/
public ProgressView(Function<T, ProgressIndicator> createProgressIndicator) {
this.createProgressIndicator = Objects.requireNonNull(createProgressIndicator);
}

/**
* Adds multiple tasks to the ProgressView.
*
* @param tasks the tasks to be added to the ProgressView. The tasks must be of type T.
*/
@SafeVarargs
public final void addTasks(T... tasks) {
for (T task : tasks) {
Expand Down
47 changes: 41 additions & 6 deletions utility/src/main/java/com/dua3/utility/data/FileTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Represents a node in a file tree.
* @param <T> the type of the node
*/
@SuppressWarnings("unchecked")
public class FileTreeNode<T extends FileTreeNode<T>> implements TreeNode<T> {

private final T parent;
private final Path path;
private final boolean lazy;
private final List<Consumer<T>> listeners = new ArrayList<>();
private final List<Consumer<T>> refreshListeners = new ArrayList<>();
private List<T> children;

protected FileTreeNode(@Nullable T parent, Path path, boolean lazy) {
Expand Down Expand Up @@ -65,10 +69,15 @@ public Collection<T> children() {
return Collections.unmodifiableList(children);
}

/**
* Refreshes the FileTree by invoking the refresh listeners of all its children.
*
* @throws UncheckedIOException if an error occurs while refreshing the FileTree
*/
public void refresh() {
try {
this.children = new ArrayList<>(collectChildren());
listeners.forEach(lst -> lst.accept((T) this));
refreshListeners.forEach(lst -> lst.accept((T) this));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -99,6 +108,11 @@ public T parent() {
return parent;
}

/**
* Returns the file path associated with the FileTree.
*
* @return the file path associated with the FileTree
*/
public Path getFilePath() {
return path;
}
Expand All @@ -118,20 +132,41 @@ public int hashCode() {
return path.hashCode();
}

/**
* Returns a boolean value indicating if the lazy loading mode is enabled or not.
*
* @return true if the lazy loading mode is enabled, false otherwise
*/
public boolean isLazy() {
return lazy;
}

/**
* Returns a boolean value indicating whether this node is a leaf node.
*
* @return {@code true} if this node is a leaf, {@code false} otherwise
*/
public boolean isLeaf() {
return children().isEmpty();
}

public void addRefreshListener(Consumer<T> listener) {
listeners.add(Objects.requireNonNull(listener));
/**
* Adds a refresh listener to be notified when the FileTree is refreshed.
*
* @param refreshListener the refresh listener to be added
* @throws NullPointerException if the refreshListener is null
*/
public void addRefreshListener(Consumer<T> refreshListener) {
refreshListeners.add(Objects.requireNonNull(refreshListener));
}

public void removeRefreshListener(Consumer<T> listener) {
listeners.remove(listener);
/**
* Removes the specified refresh listener from the list of refresh listeners.
*
* @param refreshListener the refresh listener to be removed
*/
public void removeRefreshListener(Consumer<T> refreshListener) {
refreshListeners.remove(refreshListener);
}

}
16 changes: 16 additions & 0 deletions utility/src/main/java/com/dua3/utility/io/LineOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@
* An OutputStream implementation that splits the input into lines and passes these on to a processor.
*/
public class LineOutputStream extends OutputStream {
/**
* The initial size of the buffer.
* <p>
* This constant represents the initial size (in bytes) of a buffer. It is used to allocate memory for storing data
* when initializing a buffer.
*/
public static final int INITIAL_BUFFER_SIZE = 128;
/**
* Maximum buffer size constant.
*
* This constant represents the maximum size (in bytes) that a buffer can have.
*/
public static final int MAX_BUFFER_SIZE = 1024;

private final Object lock = new Object();
private final Consumer<String> processor;
private byte[] buf;
private int count;

/**
* Creates a new LineOutputStream.
*
* @param processor the consumer function to process each line of output.
*/
public LineOutputStream(Consumer<String> processor) {
this.buf = new byte[INITIAL_BUFFER_SIZE];
this.count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ private static DateTimeFormatter formatFromLocale(Locale locale) {
return DateTimeFormatter.ofPattern(formatPattern, locale);
}

/**
* Get a DateTimeFormatter based on the specified locale.
*
* @param locale the locale to use
* @return the DateTimeFormatter for the specified locale
*/
public DateTimeFormatter getFormatter(Locale locale) {
return factory.apply(locale);
}
Expand Down

0 comments on commit 4da5be7

Please sign in to comment.