diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java index 93f2dca..b7e3f30 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/FunctionalStringTokenizer.java @@ -6,22 +6,20 @@ import java.util.function.Function; /** * 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. */ public static FunctionalStringTokenizer fromString(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, " ")); } @@ -33,14 +31,12 @@ public class FunctionalStringTokenizer { /** * Create a functional string tokenizer from a given string - * + * * @param inp * The string to tokenize */ public FunctionalStringTokenizer(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); } @@ -48,55 +44,49 @@ public class FunctionalStringTokenizer { /** * Create a functional string tokenizer from a given string and set of * separators - * + * * @param input * The string to tokenize * @param seperators * The set of separating tokens to use for splitting */ public FunctionalStringTokenizer(String input, 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 - * + * * @param toWrap * The non-functional string tokenizer to wrap */ public FunctionalStringTokenizer(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; } /** * Execute a provided action for each of the remaining tokens - * + * * @param action * The action to execute for each token */ public void forEachToken(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()); } } /** * Get the string tokenizer encapsulated by this tokenizer - * + * * @return The encapsulated tokenizer */ public StringTokenizer getInternal() { @@ -105,7 +95,7 @@ public class FunctionalStringTokenizer { /** * Check if this tokenizer has more tokens - * + * * @return Whether or not this tokenizer has more tokens */ public boolean hasMoreTokens() { @@ -116,14 +106,12 @@ 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 */ 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 null; @@ -131,7 +119,7 @@ public class FunctionalStringTokenizer { /** * Convert this tokenizer into a list of strings - * + * * @return This tokenizer, converted into a list of strings */ public IList<String> toList() { @@ -141,18 +129,16 @@ public class FunctionalStringTokenizer { /** * 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 - * + * * @param transformer * The function to use to convert tokens. * @return A list containing all of the converted tokens. */ public <E> IList<E> toList(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"); IList<E> returned = new FunctionalList<>(); |
