use of groovy.lang.SpreadMap in project groovy by apache.
the class InvokerHelper method spreadMap.
public static SpreadMap spreadMap(Object value) {
if (value instanceof Map) {
Object[] values = new Object[((Map) value).keySet().size() * 2];
int index = 0;
for (Object key : ((Map) value).keySet()) {
values[index++] = key;
values[index++] = ((Map) value).get(key);
}
return new SpreadMap(values);
}
throw new SpreadMapEvaluatingException("Cannot spread the map " + typeName(value) + ", value " + value);
}
use of groovy.lang.SpreadMap in project groovy by apache.
the class InvokerHelper method createMap.
public static Map createMap(Object[] values) {
Map answer = new LinkedHashMap(values.length / 2);
int i = 0;
while (i < values.length - 1) {
if ((values[i] instanceof SpreadMap) && (values[i + 1] instanceof Map)) {
Map smap = (Map) values[i + 1];
for (Object key : smap.keySet()) {
answer.put(key, smap.get(key));
}
i += 2;
} else {
answer.put(values[i++], values[i++]);
}
}
return answer;
}
Aggregations