public <V> SoyListData convertToSoyListData(Iterable<V> list) { SoyListData listData = new SoyListData(); for (Object o : list) { listData.add(convertObject(o)); } return listData; }
@Override @Nonnull public List<? extends SoyValue> asResolvedJavaList() { return asList(); }
/** * Adds a data value. * * @param value The data to add. */ public void add(SoyData value) { list.add(ensureValidValue(value)); }
@Override public boolean hasItem(SoyValue key) { int index = getIntegerIndex(key); return 0 <= index && index < length(); }
@Override public SoyValue getItem(SoyValue key) { return get(getIntegerIndex(key)); }
/** * Constructor that initializes this SoyListData from an existing list. * * @param data The initial data in an existing Iterable. */ public SoyListData(Iterable<?> data) { this(); add(data); }
@Override public SoyData compute(List<SoyData> args) { SoyData arg = args.get(0); if (! (arg instanceof SoyMapData)) { throw new IllegalArgumentException("Argument to keys() function is not SoyMapData."); } return new SoyListData(((SoyMapData) arg).getKeys()); }
/** * Precondition: The specified index contains a SoyMapData object. * Gets the SoyMapData at the given index. * @param index The index. * @return The SoyMapData at the given index, or null of the index is undefined. */ public SoyMapData getMapData(int index) { return (SoyMapData) get(index); }
/** * Important: Do not use outside of Soy code (treat as superpackage-private). * * <p>Puts data into this data object at the specified key. * * @param key An individual key. * @param value The data to put at the specified key. */ @Override public void putSingle(String key, SoyData value) { set(Integer.parseInt(key), value); }
@Override protected void visitForeachNode(ForeachNode node) { SoyData dataRefValue = eval(node.getExpr()); if (!(dataRefValue instanceof SoyListData)) { throw new RenderException( "In 'foreach' command " + node.toSourceString() + ", the data reference does not resolve to a SoyListData."); } SoyListData foreachList = (SoyListData) dataRefValue; if (foreachList.length() > 0) { // Case 1: Nonempty list. String varName = node.getVarName(); Map<String, SoyData> newEnvFrame = Maps.newHashMap(); // Note: No need to save firstIndex as it's always 0. newEnvFrame.put(varName + "__lastIndex", IntegerData.forValue(foreachList.length() - 1)); env.push(newEnvFrame); for (int i = 0; i < foreachList.length(); ++i) { newEnvFrame.put(varName + "__index", IntegerData.forValue(i)); newEnvFrame.put(varName, foreachList.get(i)); visitChildren((ForeachNonemptyNode) node.getChild(0)); } env.pop(); } else { // Case 2: Empty list. If the 'ifempty' node exists, visit it. if (node.numChildren() == 2) { visit(node.getChild(1)); } } }
@Override public int getItemCnt() { return length(); }
/** * Important: Do not use outside of Soy code (treat as superpackage-private). * * Removes the data at the specified key. * @param key An individual key. */ @Override public void removeSingle(String key) { remove(Integer.parseInt(key)); }
/** * Constructor that initializes this SoyListData from an existing list. * @param data The initial data in an existing Iterable. */ public SoyListData(Iterable<?> data) { this(); add(data); }
@Override protected SoyData visitListLiteralNode(ListLiteralNode node) { return new SoyListData(visitChildren(node)); }
/** * Precondition: The specified index contains a SoyMapData object. Gets the SoyMapData at the * given index. * * @param index The index. * @return The SoyMapData at the given index, or null of the index is undefined. */ public SoyMapData getMapData(int index) { return (SoyMapData) get(index); }
/** * Important: Do not use outside of Soy code (treat as superpackage-private). * * Puts data into this data object at the specified key. * @param key An individual key. * @param value The data to put at the specified key. */ @Override public void putSingle(String key, SoyData value) { set(Integer.parseInt(key), value); }
@Override public int getItemCnt() { return length(); }
@Override public boolean hasItem(SoyValue key) { int index = getIntegerIndex(key); return 0 <= index && index < length(); }
@Override public SoyValueProvider getItemProvider(SoyValue key) { return get(getIntegerIndex(key)); }
/** * Important: Do not use outside of Soy code (treat as superpackage-private). * * <p>Removes the data at the specified key. * * @param key An individual key. */ @Override public void removeSingle(String key) { remove(Integer.parseInt(key)); }