summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/funcdata/FunctionalStringTokenizer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bjc/funcdata/FunctionalStringTokenizer.java')
-rw-r--r--src/main/java/bjc/funcdata/FunctionalStringTokenizer.java47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/main/java/bjc/funcdata/FunctionalStringTokenizer.java b/src/main/java/bjc/funcdata/FunctionalStringTokenizer.java
index 7b7c2f2..856c153 100644
--- a/src/main/java/bjc/funcdata/FunctionalStringTokenizer.java
+++ b/src/main/java/bjc/funcdata/FunctionalStringTokenizer.java
@@ -14,12 +14,13 @@ public class FunctionalStringTokenizer {
* Create a new tokenizer from the specified string.
*
* @param strang
- * The string to create a tokenizer from.
+ * 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");
+ if (strang == null)
+ throw new NullPointerException("String to tokenize must be non-null");
return new FunctionalStringTokenizer(new StringTokenizer(strang, " "));
}
@@ -31,10 +32,11 @@ public class FunctionalStringTokenizer {
* 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");
+ if (inp == null)
+ throw new NullPointerException("String to tokenize must be non-null");
this.input = new StringTokenizer(inp);
}
@@ -44,15 +46,15 @@ public class FunctionalStringTokenizer {
* 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) {
+ } else if (seperators == null) {
throw new NullPointerException("Tokens to split on must not be null");
}
@@ -63,10 +65,11 @@ public class FunctionalStringTokenizer {
* 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");
+ if (toWrap == null)
+ throw new NullPointerException("Wrapped tokenizer must not be null");
this.input = toWrap;
}
@@ -75,12 +78,13 @@ public class FunctionalStringTokenizer {
* 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");
+ if (action == null)
+ throw new NullPointerException("Action must not be null");
- while(input.hasMoreTokens()) {
+ while (input.hasMoreTokens()) {
action.accept(input.nextToken());
}
}
@@ -106,11 +110,11 @@ public class FunctionalStringTokenizer {
/**
* Return the next token from the tokenizer.
*
- * @return The next token from the tokenizer, or null if no more tokens
- * are available.
+ * @return The next token from the tokenizer, or null if no more tokens are
+ * available.
*/
public String nextToken() {
- if(input.hasMoreTokens()) {
+ if (input.hasMoreTokens()) {
/* Return the next available token. */
return input.nextToken();
}
@@ -129,19 +133,20 @@ public class FunctionalStringTokenizer {
}
/**
- * Convert the contents of this tokenizer into a list. Consumes all of
- * the input from this tokenizer.
+ * Convert the contents of this tokenizer into a list. Consumes all of 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.
+ * 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");
+ if (transformer == null)
+ throw new NullPointerException("Transformer must not be null");
final IList<E> returned = new FunctionalList<>();