summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java')
-rw-r--r--base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java75
1 files changed, 42 insertions, 33 deletions
diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java b/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
index e068b46..384572d 100644
--- a/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
+++ b/base/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java
@@ -5,18 +5,19 @@ import java.util.function.Consumer;
import java.util.function.Function;
/**
- * A string tokenizer that exposes a functional interface
+ * A string tokenizer that exposes a functional interface.
*
* @author ben
- *
*/
public class FunctionalStringTokenizer {
/**
* Create a new tokenizer from the specified string.
*
* @param strang
- * The string to create a tokenizer from.
- * @return A new tokenizer that splits the provided string on spaces.
+ * The string to create a tokenizer from.
+ *
+ * @return
+ * A new tokenizer that splits the provided string on spaces.
*/
public static FunctionalStringTokenizer fromString(final String strang) {
if (strang == null) throw new NullPointerException("String to tokenize must be non-null");
@@ -24,16 +25,14 @@ public class FunctionalStringTokenizer {
return new FunctionalStringTokenizer(new StringTokenizer(strang, " "));
}
- /*
- * The string tokenizer being driven
- */
+ /* The string tokenizer being driven */
private final StringTokenizer input;
/**
- * Create a functional string tokenizer from a given string
+ * Create a functional string tokenizer from a given string.
*
* @param inp
- * The string to tokenize
+ * The string to tokenize.
*/
public FunctionalStringTokenizer(final String inp) {
if (inp == null) throw new NullPointerException("String to tokenize must be non-null");
@@ -43,26 +42,29 @@ public class FunctionalStringTokenizer {
/**
* Create a functional string tokenizer from a given string and set of
- * separators
+ * separators.
*
* @param input
- * The string to tokenize
+ * The string to tokenize.
+ *
* @param seperators
- * The set of separating tokens to use for splitting
+ * The set of separating tokens to use for splitting.
*/
public FunctionalStringTokenizer(final String input, final String seperators) {
- if (input == null)
+ if (input == null) {
throw new NullPointerException("String to tokenize must not be null");
- else if (seperators == null) throw new NullPointerException("Tokens to split on must not be null");
+ } else if (seperators == null) {
+ throw new NullPointerException("Tokens to split on must not be null");
+ }
this.input = new StringTokenizer(input, seperators);
}
/**
- * Create a functional string tokenizer from a non-functional one
+ * Create a functional string tokenizer from a non-functional one.
*
* @param toWrap
- * The non-functional string tokenizer to wrap
+ * The non-functional string tokenizer to wrap.
*/
public FunctionalStringTokenizer(final StringTokenizer toWrap) {
if (toWrap == null) throw new NullPointerException("Wrapped tokenizer must not be null");
@@ -71,10 +73,10 @@ public class FunctionalStringTokenizer {
}
/**
- * Execute a provided action for each of the remaining tokens
+ * Execute a provided action for each of the remaining tokens.
*
* @param action
- * The action to execute for each token
+ * The action to execute for each token.
*/
public void forEachToken(final Consumer<String> action) {
if (action == null) throw new NullPointerException("Action must not be null");
@@ -85,18 +87,20 @@ public class FunctionalStringTokenizer {
}
/**
- * Get the string tokenizer encapsulated by this tokenizer
+ * Get the string tokenizer encapsulated by this tokenizer.
*
- * @return The encapsulated tokenizer
+ * @return
+ * The encapsulated tokenizer.
*/
public StringTokenizer getInternal() {
return input;
}
/**
- * Check if this tokenizer has more tokens
+ * Check if this tokenizer has more tokens.
*
- * @return Whether or not this tokenizer has more tokens
+ * @return
+ * Whether or not this tokenizer has more tokens.
*/
public boolean hasMoreTokens() {
return input.hasMoreTokens();
@@ -105,22 +109,25 @@ public class FunctionalStringTokenizer {
/**
* Return the next token from the tokenizer.
*
- * Returns null if no more tokens are available
- *
- * @return The next token from the tokenizer
+ * @return
+ * The next token from the tokenizer, or null if no more tokens are
+ * available.
*/
public String nextToken() {
- if (input.hasMoreTokens()) // Return the next available token
+ if (input.hasMoreTokens()) {
+ /* Return the next available token. */
return input.nextToken();
+ }
- // Return no token
+ /* Return no token. */
return null;
}
/**
- * Convert this tokenizer into a list of strings
+ * Convert this tokenizer into a list of strings.
*
- * @return This tokenizer, converted into a list of strings
+ * @return
+ * This tokenizer, converted into a list of strings.
*/
public IList<String> toList() {
return toList((final String element) -> element);
@@ -131,18 +138,20 @@ public class FunctionalStringTokenizer {
* the input from this tokenizer.
*
* @param <E>
- * The type of the converted tokens
+ * The type of the converted tokens.
*
* @param transformer
- * The function to use to convert tokens.
- * @return A list containing all of the converted tokens.
+ * The function to use to convert tokens.
+ *
+ * @return
+ * A list containing all of the converted tokens.
*/
public <E> IList<E> toList(final Function<String, E> transformer) {
if (transformer == null) throw new NullPointerException("Transformer must not be null");
final IList<E> returned = new FunctionalList<>();
- // Add each token to the list after transforming it
+ /* Add each token to the list after transforming it. */
forEachToken(token -> {
final E transformedToken = transformer.apply(token);