/** * Precondition: The specified key string is the path to a SoyMapData object. Gets the SoyMapData * at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The SoyMapData at the specified key string, or null if no data is stored there. */ public SoyMapData getMapData(String keyStr) { return (SoyMapData) get(keyStr); }
/** * Removes the data at the specified key string. * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. */ public void remove(String keyStr) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData soyData = collectionData.getSingle(keys.get(i)); if (soyData == null || !(soyData instanceof CollectionData)) { return; } collectionData = (CollectionData) soyData; } collectionData.removeSingle(keys.get(numKeys - 1)); }
/** * Gets the data at the specified key string. * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The data at the specified key string, or null if there's no data at the location. */ public SoyData get(String keyStr) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData soyData = collectionData.getSingle(keys.get(i)); if (soyData == null || !(soyData instanceof CollectionData)) { return null; } collectionData = (CollectionData) soyData; } return collectionData.getSingle(keys.get(numKeys - 1)); }
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, SoyData value) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData nextSoyData = collectionData.getSingle(keys.get(i)); if (nextSoyData != null && !(nextSoyData instanceof CollectionData)) { throw new SoyDataException("Failed to evaluate key string \"" + keyStr + "\" for put()."); } CollectionData nextCollectionData = (CollectionData) nextSoyData; if (nextCollectionData == null) { // Create the SoyData object that will be bound to keys.get(i). We need to check the first // part of keys[i+1] to know whether to create a SoyMapData or SoyListData (checking the // first char is sufficient). nextCollectionData = (Character.isDigit(keys.get(i + 1).charAt(0))) ? new SoyListData() : new SoyMapData(); collectionData.putSingle(keys.get(i), nextCollectionData); } collectionData = nextCollectionData; } collectionData.putSingle(keys.get(numKeys - 1), ensureValidValue(value)); }
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, String value) { put(keyStr, StringData.forValue(value)); }
public static SoyData $$getDataSingle(SoyData collectionData, String key) { SoyData value = ((CollectionData) collectionData).getSingle(key); return (value != null) ? value : UndefinedData.INSTANCE; }
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, SoyData value) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData nextSoyData = collectionData.getSingle(keys.get(i)); if (nextSoyData != null && !(nextSoyData instanceof CollectionData)) { throw new SoyDataException("Failed to evaluate key string \"" + keyStr + "\" for put()."); } CollectionData nextCollectionData = (CollectionData) nextSoyData; if (nextCollectionData == null) { // Create the SoyData object that will be bound to keys.get(i). We need to check the first // part of keys[i+1] to know whether to create a SoyMapData or SoyListData (checking the // first char is sufficient). nextCollectionData = (Character.isDigit(keys.get(i + 1).charAt(0))) ? new SoyListData() : new SoyMapData(); collectionData.putSingle(keys.get(i), nextCollectionData); } collectionData = nextCollectionData; } collectionData.putSingle(keys.get(numKeys - 1), ensureValidValue(value)); }
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, int value) { put(keyStr, IntegerData.forValue(value)); }
/** * Gets the data at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The data at the specified key string, or null if there's no data at the location. */ public SoyData get(String keyStr) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData soyData = collectionData.getSingle(keys.get(i)); if (!(soyData instanceof CollectionData)) { return null; } collectionData = (CollectionData) soyData; } return collectionData.getSingle(keys.get(numKeys - 1)); }
value = ((CollectionData) value).getSingle(key); } else { if (! (value instanceof SoyListData)) {
/** * Puts data into this data tree at the specified key string. * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, SoyData value) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData nextSoyData = collectionData.getSingle(keys.get(i)); if (nextSoyData != null && !(nextSoyData instanceof CollectionData)) { throw new SoyDataException( "Failed to evaluate key string \"" + keyStr + "\" for put()."); } CollectionData nextCollectionData = (CollectionData) nextSoyData; if (nextCollectionData == null) { // Create the SoyData object that will be bound to keys.get(i). We need to check the first // part of keys[i+1] to know whether to create a SoyMapData or SoyListData (checking the // first char is sufficient). nextCollectionData = (Character.isDigit(keys.get(i + 1).charAt(0))) ? new SoyListData() : new SoyMapData(); collectionData.putSingle(keys.get(i), nextCollectionData); } collectionData = nextCollectionData; } collectionData.putSingle(keys.get(numKeys - 1), ensureValidValue(value)); }
/** * Removes the data at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. */ public void remove(String keyStr) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData soyData = collectionData.getSingle(keys.get(i)); if (!(soyData instanceof CollectionData)) { return; } collectionData = (CollectionData) soyData; } collectionData.removeSingle(keys.get(numKeys - 1)); }
/** * Precondition: The specified key string is the path to a SoyListData object. Gets the * SoyListData at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The SoyListData at the specified key string, or null if no data is stored there. */ public SoyListData getListData(String keyStr) { return (SoyListData) get(keyStr); }
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, double value) { put(keyStr, FloatData.forValue(value)); }
/** * Gets the data at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The data at the specified key string, or null if there's no data at the location. */ public SoyData get(String keyStr) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData soyData = collectionData.getSingle(keys.get(i)); if (!(soyData instanceof CollectionData)) { return null; } collectionData = (CollectionData) soyData; } return collectionData.getSingle(keys.get(numKeys - 1)); }
/** * Removes the data at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. */ public void remove(String keyStr) { List<String> keys = split(keyStr, '.'); int numKeys = keys.size(); CollectionData collectionData = this; for (int i = 0; i <= numKeys - 2; ++i) { SoyData soyData = collectionData.getSingle(keys.get(i)); if (!(soyData instanceof CollectionData)) { return; } collectionData = (CollectionData) soyData; } collectionData.removeSingle(keys.get(numKeys - 1)); }
/** * Precondition: The specified key string is the path to a SoyMapData object. Gets the SoyMapData * at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The SoyMapData at the specified key string, or null if no data is stored there. */ public SoyMapData getMapData(String keyStr) { return (SoyMapData) get(keyStr); }
/** * Puts data into this data tree at the specified key string. * * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, long value) { put(keyStr, IntegerData.forValue(value)); }
/** * Precondition: The specified key string is the path to a SoyMapData object. * Gets the SoyMapData at the specified key string. * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @return The SoyMapData at the specified key string, or null if no data is stored there. */ public SoyMapData getMapData(String keyStr) { return (SoyMapData) get(keyStr); }
/** * Puts data into this data tree at the specified key string. * @param keyStr One or more map keys and/or list indices (separated by '.' if multiple parts). * Indicates the path to the location within this data tree. * @param value The data to put at the specified location. */ public void put(String keyStr, double value) { put(keyStr, FloatData.forValue(value)); }