System.out.print(prompt);
try {
- final String userInput = br.readLine();
-
- return userInput;
+ return br.readLine();
} catch (final IOException ioe) {
ioe.printStackTrace();
}
public abstract class Parameter<T, I extends Parameter> {
- public String description;
+ public final String description;
public final ArrayList<String> arguments = new ArrayList<>();
- ArgumentCount argumentCount;
+ final ArgumentCount argumentCount;
private final ArrayList<String> aliases = new ArrayList<>();
/**
* Indicates that at least one argument is mandatory for this parameter.
// save aliases
Collections.addAll(aliases, aliasArray);
- return (I)this;
+ return (I) this;
}
/**
@SuppressWarnings("unchecked")
public I setMandatory() {
mandatory = true;
- return (I)this;
+ return (I) this;
}
/**
package eu.svjatoslav.commons.data;
-/**
- * Read individual bits from the input stream.
- */
import java.io.IOException;
import java.io.InputStream;
+/**
+ * Read individual bits from the input stream.
+ */
public class BitInputStream {
private final InputStream inputStream;
package eu.svjatoslav.commons.data;
-/**
- * Write individual bits to the output stream.
- */
import java.io.IOException;
import java.io.OutputStream;
+/**
+ * Write individual bits to the output stream.
+ */
public class BitOutputStream {
private final OutputStream outputStream;
try {
final String requestPath = new URL(requestUrl).getPath();
- @SuppressWarnings("unchecked")
- final NI match = (NI) rootNavigationItem.getMatchingNavigationItem(requestPath);
+ @SuppressWarnings("unchecked") final NI match = (NI) rootNavigationItem.getMatchingNavigationItem(requestPath);
if (match != null)
return match;
return true;
}
- public enum TerminationStrategy {
- PRESERVE,
- DROP
- }
-
- public boolean hasEndSequence(){
+ public boolean hasEndSequence() {
return endSequence != null;
}
", termination=" + termination +
'}';
}
+
+ public enum TerminationStrategy {
+ PRESERVE,
+ DROP
+ }
}
public class Tokenizer {
- final Stack<Integer> tokenIndexes = new Stack<>();
+ private final Stack<Integer> tokenIndexes = new Stack<>();
private final List<Terminator> terminators = new ArrayList<>();
private String source;
private int currentIndex = 0;
- int cachedTerminatorIndex = -1;
- Terminator cachedTerminator;
+ private int cachedTerminatorIndex = -1;
+ private Terminator cachedTerminator;
public Tokenizer(final String source) {
this.source = source;
}
- public Tokenizer(){}
+ public Tokenizer() {
+ }
- public Tokenizer setSource(String source){
+ public Tokenizer setSource(String source) {
this.source = source;
currentIndex = 0;
tokenIndexes.clear();
}
-
public TokenizerMatch getNextToken() throws InvalidSyntaxException {
tokenIndexes.push(currentIndex);
StringBuilder tokenAccumulator = new StringBuilder();
- while (true){
+ while (true) {
- if (currentIndex >= source.length()){ // reached end of input
+ if (currentIndex >= source.length()) { // reached end of input
if (hasAccumulatedToken(tokenAccumulator))
return new TokenizerMatch(tokenAccumulator.toString(), null, null);
else
if (terminator.termination == PRESERVE)
return buildPreservedToken(tokenAccumulator, terminator);
- else if (terminator.termination == DROP){
+ else if (terminator.termination == DROP) {
skipUntilTerminatorEnd(terminator);
if (hasAccumulatedToken(tokenAccumulator))
return getOrFindTokenTerminator() == null;
}
- public boolean hasMoreTokens(){
+ public boolean hasMoreTokens() {
return currentIndex < source.length();
}
return result;
}
- public boolean peekIsOneOf(String ... possibilities) throws InvalidSyntaxException {
+ public boolean peekIsOneOf(String... possibilities) throws InvalidSyntaxException {
String nextToken = peekNextToken().token;
return Stream.of(possibilities).anyMatch(possibility -> possibility.equals(nextToken));
}
- public void peekExpectNoneOf(String ... possibilities) throws InvalidSyntaxException {
+ public void peekExpectNoneOf(String... possibilities) throws InvalidSyntaxException {
if (peekIsOneOf(possibilities))
throw new InvalidSyntaxException("Not expected \"" + peekNextToken().token + "\" here.");
}
-
+
public void unreadToken() {
currentIndex = tokenIndexes.pop();
}
// define allowed parameters
final StringParameter helpParameter = parser.add(new StringParameter("Show help screen")
- .addAliases("--help", "-h").setMandatory());
+ .addAliases("--help", "-h").setMandatory());
final StringParameter compileParameter = parser.add(new StringParameter("Compile code"))
.addAliases("--compile", "-c");
public class TerminatorTest {
@Test
- public void testMatches(){
+ public void testMatches() {
Terminator terminator = new Terminator(
"/*", "*/", Terminator.TerminationStrategy.PRESERVE);
import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.DROP;
import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.PRESERVE;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.*;
public class TokenizerTest {
Tokenizer tokenizer = new Tokenizer("\"hello\" /** comment **/ (( is a N'2015-03-18 09:48:54.360' test")
.addTerminator(" ", DROP)
.addTerminator("(", PRESERVE)
- .addTerminator("\"", "\"" , PRESERVE)
- .addTerminator("N'", "'" , PRESERVE)
- .addTerminator("/*", "*/" , DROP)
- ;
+ .addTerminator("\"", "\"", PRESERVE)
+ .addTerminator("N'", "'", PRESERVE)
+ .addTerminator("/*", "*/", DROP);
assertTokenEquals("\"", "hello", tokenizer);
assertTokenEquals("(", null, tokenizer);
else
System.out.println("T: \"" + nextToken.token + "\", R: \"" + nextToken.reminder + "\"");
}
-
+
}
\ No newline at end of file