summaryrefslogtreecommitdiff
path: root/JPratt/src/main/java/bjc/pratt/TokenStream.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:49:54 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2017-04-10 16:49:54 -0400
commit56f07e9a3aaa873fe385d224f088f048dbafa8f7 (patch)
tree64fae78f95fd1c233689ecf3dda2e2b645bb8d33 /JPratt/src/main/java/bjc/pratt/TokenStream.java
parent251419e1f0ab8eb04d21287b708b06a552f4c58a (diff)
Cleanup
Diffstat (limited to 'JPratt/src/main/java/bjc/pratt/TokenStream.java')
-rw-r--r--JPratt/src/main/java/bjc/pratt/TokenStream.java39
1 files changed, 20 insertions, 19 deletions
diff --git a/JPratt/src/main/java/bjc/pratt/TokenStream.java b/JPratt/src/main/java/bjc/pratt/TokenStream.java
index e377352..7390e5f 100644
--- a/JPratt/src/main/java/bjc/pratt/TokenStream.java
+++ b/JPratt/src/main/java/bjc/pratt/TokenStream.java
@@ -1,27 +1,28 @@
package bjc.pratt;
-import bjc.utils.funcutils.StringUtils;
-import bjc.utils.parserutils.ParserException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import bjc.utils.funcutils.StringUtils;
+import bjc.utils.parserutils.ParserException;
+
/**
* A stream of tokens.
- *
+ *
* @author EVE
*
* @param <K>
* The key type of the token.
- *
+ *
* @param <V>
* The value type of the token.
*/
public abstract class TokenStream<K, V> implements Iterator<Token<K, V>> {
/**
* The exception thrown when an expectation fails.
- *
+ *
* @author EVE
*
*/
@@ -30,18 +31,18 @@ public abstract class TokenStream<K, V> implements Iterator<Token<K, V>> {
/**
* Create a new exception with the specified message.
- *
+ *
* @param msg
* The message of the exception.
*/
- public ExpectationException(String msg) {
+ public ExpectationException(final String msg) {
super(msg);
}
}
/**
* Get the current token.
- *
+ *
* @return The current token.
*/
public abstract Token<K, V> current();
@@ -55,18 +56,18 @@ public abstract class TokenStream<K, V> implements Iterator<Token<K, V>> {
/**
* Utility method for checking that the next token is one of a specific
* set of types, and then consuming it.
- *
+ *
* @param expectedKeys
* The expected values
- *
+ *
* @throws ExpectationException
* If the token is not one of the expected types.
*/
- public void expect(Set<K> expectedKeys) throws ExpectationException {
- K curKey = current().getKey();
+ public void expect(final Set<K> expectedKeys) throws ExpectationException {
+ final K curKey = current().getKey();
if (!expectedKeys.contains(curKey)) {
- String expectedList = StringUtils.toEnglishList(expectedKeys.toArray(), false);
+ final String expectedList = StringUtils.toEnglishList(expectedKeys.toArray(), false);
throw new ExpectationException("One of '" + expectedList + "' was expected, not " + curKey);
}
@@ -77,27 +78,27 @@ public abstract class TokenStream<K, V> implements Iterator<Token<K, V>> {
/**
* Utility method for checking that the next token is one of a specific
* set of types, and then consuming it.
- *
+ *
* @param expectedKeys
* The expected values
- *
+ *
* @throws ExpectationException
* If the token is not one of the expected types.
*/
@SafeVarargs
- public final void expect(K... expectedKeys) throws ExpectationException {
+ public final void expect(final K... expectedKeys) throws ExpectationException {
expect(new HashSet<>(Arrays.asList(expectedKeys)));
}
/**
* Check whether the head token is a certain type.
- *
+ *
* @param val
* The type to check for.
- *
+ *
* @return Whether or not the head token is of that type.
*/
- public boolean headIs(K val) {
+ public boolean headIs(final K val) {
return current().getKey().equals(val);
}
}