use of android.filterfw.io.GraphIOException in project android_frameworks_base by ResurrectionRemix.
the class FilterGraphEffect method createGraph.
private void createGraph(String graphString) {
GraphReader reader = new TextGraphReader();
try {
mGraph = reader.readGraphString(graphString);
} catch (GraphIOException e) {
throw new RuntimeException("Could not setup effect", e);
}
if (mGraph == null) {
throw new RuntimeException("Could not setup effect");
}
mRunner = new SyncRunner(getFilterContext(), mGraph, mSchedulerClass);
}
use of android.filterfw.io.GraphIOException in project android_frameworks_base by DirtyUnicorns.
the class Filter method initWithAssignmentString.
public final void initWithAssignmentString(String assignments) {
try {
KeyValueMap valueMap = new TextGraphReader().readKeyValueAssignments(assignments);
initWithValueMap(valueMap);
} catch (GraphIOException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
use of android.filterfw.io.GraphIOException in project android_frameworks_base by DirtyUnicorns.
the class TextGraphReader method readKeyValueAssignments.
private KeyValueMap readKeyValueAssignments(PatternScanner scanner, Pattern endPattern) throws GraphIOException {
// Our parser is a state-machine, and these are our states
final int STATE_IDENTIFIER = 0;
final int STATE_EQUALS = 1;
final int STATE_VALUE = 2;
final int STATE_POST_VALUE = 3;
final Pattern equalsPattern = Pattern.compile("=");
final Pattern semicolonPattern = Pattern.compile(";");
final Pattern wordPattern = Pattern.compile("[a-zA-Z]+[a-zA-Z0-9]*");
final Pattern stringPattern = Pattern.compile("'[^']*'|\\\"[^\\\"]*\\\"");
final Pattern intPattern = Pattern.compile("[0-9]+");
final Pattern floatPattern = Pattern.compile("[0-9]*\\.[0-9]+f?");
final Pattern referencePattern = Pattern.compile("\\$[a-zA-Z]+[a-zA-Z0-9]");
final Pattern booleanPattern = Pattern.compile("true|false");
int state = STATE_IDENTIFIER;
KeyValueMap newVals = new KeyValueMap();
String curKey = null;
String curValue = null;
while (!scanner.atEnd() && !(endPattern != null && scanner.peek(endPattern))) {
switch(state) {
case STATE_IDENTIFIER:
curKey = scanner.eat(wordPattern, "<identifier>");
state = STATE_EQUALS;
break;
case STATE_EQUALS:
scanner.eat(equalsPattern, "=");
state = STATE_VALUE;
break;
case STATE_VALUE:
if ((curValue = scanner.tryEat(stringPattern)) != null) {
newVals.put(curKey, curValue.substring(1, curValue.length() - 1));
} else if ((curValue = scanner.tryEat(referencePattern)) != null) {
String refName = curValue.substring(1, curValue.length());
Object referencedObject = mBoundReferences != null ? mBoundReferences.get(refName) : null;
if (referencedObject == null) {
throw new GraphIOException("Unknown object reference to '" + refName + "'!");
}
newVals.put(curKey, referencedObject);
} else if ((curValue = scanner.tryEat(booleanPattern)) != null) {
newVals.put(curKey, Boolean.parseBoolean(curValue));
} else if ((curValue = scanner.tryEat(floatPattern)) != null) {
newVals.put(curKey, Float.parseFloat(curValue));
} else if ((curValue = scanner.tryEat(intPattern)) != null) {
newVals.put(curKey, Integer.parseInt(curValue));
} else {
throw new GraphIOException(scanner.unexpectedTokenMessage("<value>"));
}
state = STATE_POST_VALUE;
break;
case STATE_POST_VALUE:
scanner.eat(semicolonPattern, ";");
state = STATE_IDENTIFIER;
break;
}
}
// Make sure end is expected
if (state != STATE_IDENTIFIER && state != STATE_POST_VALUE) {
throw new GraphIOException("Unexpected end of assignments on line " + scanner.lineNo() + "!");
}
return newVals;
}
use of android.filterfw.io.GraphIOException in project android_frameworks_base by DirtyUnicorns.
the class FilterGraphEffect method createGraph.
private void createGraph(String graphString) {
GraphReader reader = new TextGraphReader();
try {
mGraph = reader.readGraphString(graphString);
} catch (GraphIOException e) {
throw new RuntimeException("Could not setup effect", e);
}
if (mGraph == null) {
throw new RuntimeException("Could not setup effect");
}
mRunner = new SyncRunner(getFilterContext(), mGraph, mSchedulerClass);
}
use of android.filterfw.io.GraphIOException in project android_frameworks_base by crdroidandroid.
the class FilterGraphEffect method createGraph.
private void createGraph(String graphString) {
GraphReader reader = new TextGraphReader();
try {
mGraph = reader.readGraphString(graphString);
} catch (GraphIOException e) {
throw new RuntimeException("Could not setup effect", e);
}
if (mGraph == null) {
throw new RuntimeException("Could not setup effect");
}
mRunner = new SyncRunner(getFilterContext(), mGraph, mSchedulerClass);
}
Aggregations