@Override public Renderer setIjData(Map<String, ?> ijData) { this.ijData = (ijData == null) ? null : new SoyMapData(ijData); return this; }
@Override public Map<String, SoyData> asMap() { SoyMapData combinedMapData = new SoyMapData(); addMapDataHelper(combinedMapData, "", baseData.asMap()); addMapDataHelper(combinedMapData, "", super.asMap()); return Collections.unmodifiableMap(combinedMapData.asMap()); }
/** * Merge two SoyMapData resources. If the two maps to merge contain duplicate key names, source * s2 will overwrite s1. * @param s1 1st resource map. * @param s2 2nd resource map. * @return A new SoyMapData object containing data from both source. */ public static SoyMapData mergeSoyMapData(SoyMapData s1, SoyMapData s2) { Preconditions.checkNotNull(s1); Preconditions.checkNotNull(s2); SoyMapData merged = new SoyMapData(); for (String key: s1.getKeys()) { merged.putSingle(key, s1.getSingle(key)); } for (String key: s2.getKeys()) { merged.putSingle(key, s2.getSingle(key)); } return merged; }
@Override public boolean hasItem(SoyValue key) { return getSingle(getStringKey(key)) != null; }
/** * Constructor that directly takes the keys/values as parameters. * @param data The initial data, with alternating keys/values. */ public SoyMapData(Object... data) { this(); put(data); }
public <K, V> SoyMapData convertToSoyMapData(Map<K, V> map) { SoyMapData soyMapData = new SoyMapData(); for (Map.Entry<K, V> entry : map.entrySet()) { String key = entry.getKey().toString(); Object value = entry.getValue(); Object soyValue = convertObject(value); soyMapData.put(key, soyValue); } return soyMapData; }
@Override public boolean hasField(String name) { return getSingle(name) != null; }
/** * Private helper for {@code asMap()} to add a sublist to the combined map data. * @param combinedMapData The combined map data that we're building. * @param keyPrefix The key prefix for this sublist. * @param list The list of data to add. */ private static void addListDataHelper( SoyMapData combinedMapData, String keyPrefix, List<SoyData> list) { for (int i = 0; i < list.size(); ++i) { SoyData el = list.get(i); if (el instanceof SoyMapData) { addMapDataHelper(combinedMapData, keyPrefix + i + ".", ((SoyMapData) el).asMap()); } else if (el instanceof SoyListData) { addListDataHelper(combinedMapData, keyPrefix + i + ".", ((SoyListData) el).asList()); } else { combinedMapData.put(keyPrefix + i, el); } } }
@Override @Nonnull public Map<String, ? extends SoyValueProvider> asJavaStringMap() { return asMap(); }
@Override public SoyData compute(List<SoyData> args) { SoyData arg0 = args.get(0); SoyData arg1 = args.get(1); Preconditions.checkArgument(arg0 instanceof SoyMapData, "First argument to augmentMap() function is not SoyMapData."); Preconditions.checkArgument(arg1 instanceof SoyMapData, "Second argument to augmentMap() function is not SoyMapData."); AugmentedSoyMapData augmentedMap = new AugmentedSoyMapData((SoyMapData) arg0); SoyMapData additionalMap = (SoyMapData) arg1; for (String key : additionalMap.getKeys()) { augmentedMap.putSingle(key, additionalMap.getSingle(key)); } return augmentedMap; }
if (!node.isPassingData()) { callData = new SoyMapData(); } else if (node.numChildren() == 0) { callData.putSingle( child.getKey(), eval(((CallParamValueNode) child).getValueExprUnion().getExpr())); callData.putSingle(child.getKey(), renderedBlock);
@Override public int getItemCnt() { return getKeys().size(); }
@Override public void put(String keyStr, SoyData value) { if (keyStr.indexOf('.') >= 0) { throw new SoyDataException( "Attempted to put multi-part key string into AugmentedSoyMapData. Please ensure that" + " all of your 'param' commands only use top-level keys."); } super.putSingle(keyStr, value); }
@Override public SoyValue getItem(SoyValue key) { return getSingle(getStringKey(key)); }
/** * Constructor that directly takes the keys/values as parameters. * * @param data The initial data, with alternating keys/values. */ public SoyMapData(Object... data) { this(); put(data); }
/** * Private helper for {@code asMap()} to add a map (or submap) to the combined map data. * @param combinedMapData The combined map data that we're building. * @param keyPrefix The key prefix if adding a submap (or empty string if adding one of the * top-level maps: the base data or the augmented data). * @param map The map of data to add. */ private static void addMapDataHelper( SoyMapData combinedMapData, String keyPrefix, Map<String, SoyData> map) { for (Map.Entry<String, SoyData> entry : map.entrySet()) { String key = entry.getKey(); SoyData value = entry.getValue(); if (value instanceof SoyMapData) { addMapDataHelper(combinedMapData, keyPrefix + key + ".", ((SoyMapData) value).asMap()); } else if (value instanceof SoyListData) { addListDataHelper(combinedMapData, keyPrefix + key + ".", ((SoyListData) value).asList()); } else { combinedMapData.put(keyPrefix + key, value); } } }
@Override @Nonnull public Map<String, ? extends SoyValue> asResolvedJavaStringMap() { return asMap(); }
@Override public int size() { return getKeys().size(); }
@Override public Renderer setData(Map<String, ?> data) { this.data = (data == null) ? null : new SoyMapData(data); return this; }