summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
committerbjculkin <bjculkin@mix.wvu.edu>2018-02-12 22:45:04 -0500
commitdf94066e3af02ff02d5ab4d033a3d603f743234c (patch)
tree168a1edaf58d386c175ffb601e9d4da8e13d31e2 /base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
parentae51c587c53f7ca311e556e3cbd0c5566d6c2843 (diff)
Formatting pass
Diffstat (limited to 'base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java')
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java65
1 files changed, 32 insertions, 33 deletions
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
index ccfaffb..0eddebe 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
@@ -24,7 +24,7 @@ import bjc.utils.funcutils.StringUtils;
* @author EVE
*
* @param <T>
- * The type of items in the sequence.
+ * The type of items in the sequence.
*/
public class SequenceDelimiter<T> {
/*
@@ -63,10 +63,9 @@ public class SequenceDelimiter<T> {
* </pre>
*
* @param chars
- * The parameters on how to mark certain portions of the
- * tree.
+ * The parameters on how to mark certain portions of the tree.
* @param seq
- * The sequence to delimit.
+ * The sequence to delimit.
*
* @return The sequence as a tree that matches its group structure. Each
* node in the tree is either a data node, a subgroup node, or a
@@ -89,14 +88,14 @@ public class SequenceDelimiter<T> {
* recursive tree.
*
* @throws DelimiterException
- * Thrown if something went wrong during sequence
- * delimitation.
+ * Thrown if something went wrong during sequence delimitation.
*
*/
public ITree<T> delimitSequence(final SequenceCharacteristics<T> chars,
@SuppressWarnings("unchecked") final T... seq) throws DelimiterException {
- if (initialGroup == null) throw new NullPointerException("Initial group must be specified.");
- else if (chars == null) throw new NullPointerException("Sequence characteristics must not be null");
+ if(initialGroup == null)
+ throw new NullPointerException("Initial group must be specified.");
+ else if(chars == null) throw new NullPointerException("Sequence characteristics must not be null");
/*
* The stack of opened and not yet closed groups.
@@ -128,7 +127,7 @@ public class SequenceDelimiter<T> {
/*
* Process each member of the sequence.
*/
- for (int i = 0; i < seq.length; i++) {
+ for(int i = 0; i < seq.length; i++) {
final T tok = seq[i];
/*
@@ -137,14 +136,14 @@ public class SequenceDelimiter<T> {
final IPair<T, T[]> possibleOpenPar = groupStack.top().doesOpen(tok);
T possibleOpen = possibleOpenPar.getLeft();
- if (possibleOpen == null) {
+ if(possibleOpen == null) {
/*
* Handle nested openers.
*
* Local openers take priority over nested ones
* if they overlap.
*/
- if (allowedDelimiters.top().containsKey(tok)) {
+ if(allowedDelimiters.top().containsKey(tok)) {
possibleOpen = allowedDelimiters.top().get(tok).iterator().next();
}
}
@@ -152,7 +151,7 @@ public class SequenceDelimiter<T> {
/*
* If we have an opening delimiter, handle it.
*/
- if (possibleOpen != null) {
+ if(possibleOpen != null) {
final DelimiterGroup<T> group = groups.get(possibleOpen);
/*
@@ -163,10 +162,10 @@ public class SequenceDelimiter<T> {
* top-level of this group, as well as nested
* exclusions from all enclosing groups.
*/
- if (isForbidden(groupStack, forbiddenDelimiters, possibleOpen)) {
+ if(isForbidden(groupStack, forbiddenDelimiters, possibleOpen)) {
T forbiddenBy;
- if (whoForbid.containsKey(tok)) {
+ if(whoForbid.containsKey(tok)) {
forbiddenBy = whoForbid.get(tok);
} else {
forbiddenBy = groupStack.top().getName();
@@ -188,7 +187,7 @@ public class SequenceDelimiter<T> {
/*
* Handle 'forgetful' groups that reset nesting
*/
- if (open.isForgetful()) {
+ if(open.isForgetful()) {
allowedDelimiters.push(HashMultimap.create());
forbiddenDelimiters.push(HashMultiset.create());
}
@@ -197,7 +196,7 @@ public class SequenceDelimiter<T> {
* Add the nested opens from this group.
*/
final Multimap<T, T> currentAllowed = allowedDelimiters.top();
- for (final Entry<T, T> opener : open.getNestingOpeners().entrySet()) {
+ for(final Entry<T, T> opener : open.getNestingOpeners().entrySet()) {
currentAllowed.put(opener.getKey(), opener.getValue());
}
@@ -205,12 +204,12 @@ public class SequenceDelimiter<T> {
* Add the nested exclusions from this group
*/
final Multiset<T> currentForbidden = forbiddenDelimiters.top();
- for (final T exclusion : open.getNestingExclusions()) {
+ for(final T exclusion : open.getNestingExclusions()) {
currentForbidden.add(exclusion);
whoForbid.put(exclusion, possibleOpen);
}
- } else if (!groupStack.empty() && groupStack.top().isClosing(tok)) {
+ } else if(!groupStack.empty() && groupStack.top().isClosing(tok)) {
/*
* Close the group.
*/
@@ -222,7 +221,7 @@ public class SequenceDelimiter<T> {
* Remove nested exclusions from this group.
*/
final Multiset<T> currentForbidden = forbiddenDelimiters.top();
- for (final T excludedGroup : closed.getNestingExclusions()) {
+ for(final T excludedGroup : closed.getNestingExclusions()) {
currentForbidden.remove(excludedGroup);
whoForbid.remove(excludedGroup);
@@ -232,18 +231,18 @@ public class SequenceDelimiter<T> {
* Remove the nested opens from this group.
*/
final Multimap<T, T> currentAllowed = allowedDelimiters.top();
- for (final Entry<T, T> closer : closed.getNestingOpeners().entrySet()) {
+ for(final Entry<T, T> closer : closed.getNestingOpeners().entrySet()) {
currentAllowed.remove(closer.getKey(), closer.getValue());
}
/*
* Handle 'forgetful' groups that reset nesting.
*/
- if (closed.isForgetful()) {
+ if(closed.isForgetful()) {
allowedDelimiters.drop();
forbiddenDelimiters.drop();
}
- } else if (!groupStack.empty() && groupStack.top().marksSubgroup(tok)) {
+ } else if(!groupStack.empty() && groupStack.top().marksSubgroup(tok)) {
/*
* Mark a subgroup.
*/
@@ -259,7 +258,7 @@ public class SequenceDelimiter<T> {
/*
* Error if not all groups were closed.
*/
- if (groupStack.size() > 1) {
+ if(groupStack.size() > 1) {
final DelimiterGroup<T>.OpenGroup group = groupStack.top();
final StringBuilder msgBuilder = new StringBuilder();
@@ -294,7 +293,7 @@ public class SequenceDelimiter<T> {
/*
* Check if a delimiter is locally forbidden.
*/
- if (groupStack.empty()) {
+ if(groupStack.empty()) {
localForbid = false;
} else {
localForbid = groupStack.top().excludes(groupName);
@@ -307,10 +306,10 @@ public class SequenceDelimiter<T> {
* Add a delimiter group.
*
* @param group
- * The delimiter group.
+ * The delimiter group.
*/
public void addGroup(final DelimiterGroup<T> group) {
- if (group == null) throw new NullPointerException("Group must not be null");
+ if(group == null) throw new NullPointerException("Group must not be null");
groups.put(group.groupName, group);
}
@@ -319,11 +318,11 @@ public class SequenceDelimiter<T> {
* Creates and adds a delimiter group using the provided settings.
*
* @param openers
- * The tokens that open this group
+ * The tokens that open this group
* @param groupName
- * The name of the group
+ * The name of the group
* @param closers
- * The tokens that close this group
+ * The tokens that close this group
*/
public void addGroup(final T[] openers, final T groupName, @SuppressWarnings("unchecked") final T... closers) {
final DelimiterGroup<T> group = new DelimiterGroup<>(groupName);
@@ -332,7 +331,7 @@ public class SequenceDelimiter<T> {
addGroup(group);
- for (final T open : openers) {
+ for(final T open : openers) {
group.addOpener(open, groupName);
}
}
@@ -343,13 +342,13 @@ public class SequenceDelimiter<T> {
builder.append("SequenceDelimiter [");
- if (groups != null) {
+ if(groups != null) {
builder.append("groups=");
builder.append(groups);
builder.append(",");
}
- if (initialGroup != null) {
+ if(initialGroup != null) {
builder.append("initialGroup=");
builder.append(initialGroup);
}
@@ -363,7 +362,7 @@ public class SequenceDelimiter<T> {
* Set the initial group of this delimiter.
*
* @param initialGroup
- * The initial group of this delimiter.
+ * The initial group of this delimiter.
*/
public void setInitialGroup(final DelimiterGroup<T> initialGroup) {
this.initialGroup = initialGroup;