Code example for Deque

Methods: getFirstpoppush

0
        parse(','); 
        return token;
    } 
 
    private State state() { 
        return states.getFirst();
    } 
 
    private void parse(char c) {
        char real = c;
        switch (c) {
            case ',': 
            case '\n': 
                switch (state()) { 
                    case EXPRESSION:
                    case ARRAY:
                    case STRING:
                    case OBJECT:
                        value += c;
                        break; 
                    default: 
                        states.push(State.KEY);
                        value = value.trim();
                        key = key.trim();
                        if ("".equals(key)) {
                            return; 
                        } 
                        String name = key.replaceAll("^['\"]|['\"]$", "");
                        String cleanValue = value.replaceAll("^['\"]|['\"]$", "");
 
                        if ("".equals(cleanValue) && quote == ' ') {
                            token.addBooleanAttribute(name, Boolean.TRUE);
                        } else if (value.matches("^\"[^\"]*\"$") || value.matches("^'[^']*'$")) {
                            token.addAttribute(name, cleanValue);
                        } else { 
                            token.addExpressionAttribute(name, value);
                        } 
                        key = "";
                        value = "";
                        quote = ' ';
                        break; 
                } 
                break; 
            case '=': 
                parseAssign(real);
                break; 
            case '(': 
                parseExpressionStart(c);
                break; 
            case ')': 
                parseExpressionEnd(c);
                break; 
            case '{': 
                parseObjectStart(c);
                break; 
            case '}': 
                parseObjectEnd(c);
                break; 
            case '[': 
                parseArrayStart(c);
                break; 
            case ']': 
                parseArrayEnd(c);
                break; 
            case '"': 
            case '\'': 
                parseQuotes(c);
                break; 
            default: 
                parseDefaults(c);
                break; 
        } 
    } 
 
    private void parseAssign(char real) {
        switch (state()) { 
            case KEY_CHAR:
                key += real;
                break; 
            case VALUE:
            case EXPRESSION:
            case ARRAY:
            case STRING:
            case OBJECT:
                value += real;
                break; 
            default: 
                states.push(State.VALUE);
                break; 
        } 
    } 
 
    private void parseExpressionStart(char c) {
        if (state() == State.VALUE || state() == State.EXPRESSION) {
            states.push(State.EXPRESSION);
        } 
        value += c;
    } 
 
    private void parseExpressionEnd(char c) {
        if (state() == State.VALUE || state() == State.EXPRESSION) {
            states.pop();
        } 
        value += c;
    } 
 
    private void parseObjectStart(char c) {
        if (state() == State.VALUE) {
            states.push(State.OBJECT);
        } 
        value += c;
    } 
 
    private void parseObjectEnd(char c) {
        if (state() == State.OBJECT) {
            states.pop();
        } 
        value += c;
    } 
 
    private void parseArrayStart(char c) {
        if (state() == State.VALUE) {
            states.push(State.ARRAY);
        } 
        value += c;
    } 
 
    private void parseArrayEnd(char c) {
        if (state() == State.ARRAY) {
            states.pop();
        } 
        value += c;
    } 
 
    private void parseQuotes(char c) {
        switch (state()) { 
            case KEY:
                states.push(State.KEY_CHAR);
                break; 
            case KEY_CHAR:
                states.pop();
                break; 
            case STRING:
                if (c == quote) {
                    states.pop();
                } 
                value += c;
                break; 
            default: 
                states.push(State.STRING);
                value += c;
                quote = c;
                break; 
        } 
    }