
org.mvel.util.CollectionParser Maven / Gradle / Ivy
The newest version!
/**
* MVEL (The MVFLEX Expression Language)
*
* Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.mvel.util;
import static org.mvel.util.ParseTools.balancedCapture;
import static org.mvel.util.PropertyTools.createStringTrimmed;
import static org.mvel.util.PropertyTools.isIdentifierPart;
import static org.mvel.util.ParseTools.isWhitespace;
import static org.mvel.util.ParseTools.subCompileExpression;
import static java.lang.System.arraycopy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* This is the inline collection sub-parser. It produces a skeleton model of the collection which is in turn translated
* into a sequenced AST to produce the collection efficiently at runtime, and passed off to one of the JIT's if
* configured.
*
* @author Christopher Brock
*/
public class CollectionParser {
private char[] property;
private int cursor;
private int length;
private int start;
private int type;
public static final int LIST = 0;
public static final int ARRAY = 1;
public static final int MAP = 2;
private static final Object[] EMPTY_ARRAY = new Object[0];
public CollectionParser() {
}
public CollectionParser(int type) {
this.type = type;
}
public Object parseCollection(char[] property, boolean subcompile) {
this.cursor = 0;
if ((this.length = (this.property = property).length) > 0)
while (length > 0 && isWhitespace(property[length - 1]))
length--;
return parseCollection(subcompile);
}
private Object parseCollection(boolean subcompile) {
if (length == 0) {
if (type == LIST) return new ArrayList();
else return EMPTY_ARRAY;
}
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy