Search in sources :

Example 36 with KeyValueMap

use of android.filterfw.core.KeyValueMap in project platform_frameworks_base by android.

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;
}
Also used : Pattern(java.util.regex.Pattern) KeyValueMap(android.filterfw.core.KeyValueMap) String(java.lang.String) GraphIOException(android.filterfw.io.GraphIOException)

Example 37 with KeyValueMap

use of android.filterfw.core.KeyValueMap in project platform_frameworks_base by android.

the class TextGraphReader method reset.

private void reset() {
    mCurrentGraph = null;
    mCurrentFilter = null;
    mCommands.clear();
    mBoundReferences = new KeyValueMap();
    mSettings = new KeyValueMap();
    mFactory = new FilterFactory();
}
Also used : KeyValueMap(android.filterfw.core.KeyValueMap) FilterFactory(android.filterfw.core.FilterFactory)

Example 38 with KeyValueMap

use of android.filterfw.core.KeyValueMap in project platform_frameworks_base by android.

the class Filter method init.

public final void init() throws ProtocolException {
    KeyValueMap valueMap = new KeyValueMap();
    initWithValueMap(valueMap);
}
Also used : KeyValueMap(android.filterfw.core.KeyValueMap)

Example 39 with KeyValueMap

use of android.filterfw.core.KeyValueMap in project platform_frameworks_base by android.

the class Filter method initWithAssignmentList.

public final void initWithAssignmentList(Object... keyValues) {
    KeyValueMap valueMap = new KeyValueMap();
    valueMap.setKeyValues(keyValues);
    initWithValueMap(valueMap);
}
Also used : KeyValueMap(android.filterfw.core.KeyValueMap)

Example 40 with KeyValueMap

use of android.filterfw.core.KeyValueMap in project android_frameworks_base by AOSPA.

the class FrameFormat method mutableCopy.

public MutableFrameFormat mutableCopy() {
    MutableFrameFormat result = new MutableFrameFormat();
    result.setBaseType(getBaseType());
    result.setTarget(getTarget());
    result.setBytesPerSample(getBytesPerSample());
    result.setDimensions(getDimensions());
    result.setObjectClass(getObjectClass());
    result.mMetaData = mMetaData == null ? null : (KeyValueMap) mMetaData.clone();
    return result;
}
Also used : KeyValueMap(android.filterfw.core.KeyValueMap) MutableFrameFormat(android.filterfw.core.MutableFrameFormat)

Aggregations

KeyValueMap (android.filterfw.core.KeyValueMap)48 GraphIOException (android.filterfw.io.GraphIOException)18 String (java.lang.String)12 Pattern (java.util.regex.Pattern)12 FilterFactory (android.filterfw.core.FilterFactory)6 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)6 PatternScanner (android.filterfw.io.PatternScanner)6 TextGraphReader (android.filterfw.io.TextGraphReader)6 FrameBranch (android.filterpacks.base.FrameBranch)6 Iterator (java.util.Iterator)6 LinkedList (java.util.LinkedList)6