@ParametersAreNonnullByDefault public final class DictImpl extends SoyAbstractValue implements SoyDict, SoyMap
legacy_object_map<K,V>, a
Soy map map<K, V>, or a Soy record [field1: type1, ...] at runtime.
This class exists because the Java rendering APIs do not have enough structure. When a user
requests a template to be rendered with a Map as part of its data (either
regular data or injected data), it is generally not
possible to determine whether the java.util.Map is meant to represent a legacy object
map, a map, or a record. (Data can be passed transitively down a template call chain, so
inspecting the immediate callee's signature is not sufficient.)
This class implements all three interfaces (SoyLegacyObjectMap, SoyMap, and SoyRecord respectively). It would be easy to allow a DictImpl
instance to behave as one type (say, a legacy object map) and then another (say, a map) at
different points during a single rendering. But this would break Soy's cross-platform
compatibility. In JavaScript, legacy object maps and maps have different calling conventions
(plain JS objects and ES6 Maps, respectively). Indexing into a plain JS object as though it were
an ES6 Map is a runtime error. Soy's Java runtime must preserve this behavior.
DictImpl.RuntimeType exists to provide this non-compatibility. DictImpl instances begin life in
an DictImpl.RuntimeType.UNKNOWN state. If a SoyMap method is first invoked on it, it transitions
to the DictImpl.RuntimeType.MAP state, and later invocations of SoyMap or SoyRecord methods cause
runtime errors. Likewise, if a SoyMap or SoyRecord method is first invoked on the DictImpl
instance, it transitions to the DictImpl.RuntimeType.LEGACY_OBJECT_MAP_OR_RECORD state, and later
invocations of SoyMap methods cause runtime errors.
every legacy_object_map to map and delete legacy_object_map. This will
require changing every plain JS object passed in to Soy to be an ES6 Map with the same entries.
It should not require any changes to Java renderers: every java.util.Map becomes a DictImpl
instance that can act as a map. After the migration, Java renderers that want to take
advantage of nonstring keys must wrap their java.util.Maps in SoyValueConverter.markAsSoyMap(java.util.Map<?, ?>).
Important: Do not use outside of Soy code (treat as superpackage-private).
| Modifier and Type | Class and Description |
|---|---|
static class |
DictImpl.RuntimeType
Represents the runtime type of this DictImpl.
|
| Modifier and Type | Method and Description |
|---|---|
Map<? extends SoyValue,? extends SoyValueProvider> |
asJavaMap()
Gets a Java map of all items in this SoyMap, where mappings are value to value provider.
|
Map<String,? extends SoyValueProvider> |
asJavaStringMap()
Gets a Java map of all items in this SoyDict, where mappings are string to value provider.
|
Map<String,? extends SoyValue> |
asResolvedJavaStringMap()
Gets a Java map of all items in this SoyDict, where mappings are string to value.
|
boolean |
coerceToBoolean()
Coerces this value into a boolean.
|
String |
coerceToString()
Coerces this value into a string.
|
boolean |
containsKey(SoyValue key)
Checks whether this SoyMap has an item with the given key.
|
boolean |
equals(Object other)
Compares this value against another for equality in the sense of the '==' operator of Soy.
|
static DictImpl |
forProviderMap(Map<String,? extends SoyValueProvider> providerMap,
DictImpl.RuntimeType mapType)
Creates a SoyDict implementation for a particular underlying provider map.
|
SoyValue |
get(SoyValue key)
Gets an item value of this SoyMap.
|
SoyValue |
getField(String name)
Gets a field value of this SoyRecord.
|
SoyValueProvider |
getFieldProvider(String name)
Gets a provider of a field value of this SoyRecord.
|
SoyValue |
getItem(SoyValue key)
Gets an item value of this SoyMap.
|
int |
getItemCnt()
Gets the number of items in this SoyMap.
|
Iterable<? extends SoyValue> |
getItemKeys()
Gets an iterable over all item keys in this SoyMap.
|
SoyValueProvider |
getItemProvider(SoyValue key)
Gets a provider of an item value of this SoyMap.
|
SoyValueProvider |
getProvider(SoyValue key)
Gets a provider of an item value of this SoyMap.
|
boolean |
hasField(String name)
Checks whether this SoyRecord has a field of the given name.
|
int |
hashCode() |
boolean |
hasItem(SoyValue key)
Checks whether this SoyMap has an item with the given key.
|
Iterable<? extends SoyValue> |
keys()
Gets an iterable over all item keys in this SoyMap.
|
void |
render(LoggingAdvisingAppendable appendable)
Renders this value to the given appendable.
|
int |
size()
Gets the number of items in this SoyMap.
|
String |
toString() |
booleanValue, floatValue, integerValue, longValue, numberValue, render, renderAndResolve, resolve, status, stringValueclone, finalize, getClass, notify, notifyAll, wait, wait, waitbooleanValue, floatValue, integerValue, longValue, numberValue, render, stringValuerenderAndResolve, resolve, statuspublic static DictImpl forProviderMap(Map<String,? extends SoyValueProvider> providerMap, DictImpl.RuntimeType mapType)
The map may be mutable, but will not be mutated by the DictImpl.
public final boolean hasField(String name)
SoyRecordpublic final SoyValue getField(String name)
SoyRecordpublic final SoyValueProvider getFieldProvider(String name)
SoyRecordgetFieldProvider in interface SoyRecordname - The field name to get.public final int getItemCnt()
SoyLegacyObjectMapgetItemCnt in interface SoyLegacyObjectMappublic int size()
SoyMap@Nonnull public final Iterable<? extends SoyValue> getItemKeys()
SoyLegacyObjectMapImportant: Iteration order is undefined.
getItemKeys in interface SoyLegacyObjectMap@Nonnull public Iterable<? extends SoyValue> keys()
SoyMapImportant: Iteration order is undefined.
public final boolean hasItem(SoyValue key)
SoyLegacyObjectMaphasItem in interface SoyLegacyObjectMapkey - The item key to check.public boolean containsKey(SoyValue key)
SoyMapcontainsKey in interface SoyMapkey - The item key to check.public final SoyValue getItem(SoyValue key)
SoyLegacyObjectMapgetItem in interface SoyLegacyObjectMapkey - The item key to get.public SoyValue get(SoyValue key)
SoyMappublic final SoyValueProvider getItemProvider(SoyValue key)
SoyLegacyObjectMapgetItemProvider in interface SoyLegacyObjectMapkey - The item key to get.public SoyValueProvider getProvider(SoyValue key)
SoyMapgetProvider in interface SoyMapkey - The item key to get.@Nonnull public final Map<String,? extends SoyValueProvider> asJavaStringMap()
SoyDictasJavaStringMap in interface SoyDict@Nonnull public final Map<String,? extends SoyValue> asResolvedJavaStringMap()
SoyDictasResolvedJavaStringMap in interface SoyDict@Nonnull public Map<? extends SoyValue,? extends SoyValueProvider> asJavaMap()
SoyMappublic final boolean coerceToBoolean()
SoyValuecoerceToBoolean in interface SoyValuepublic final String coerceToString()
SoyValuecoerceToString in interface SoyValuepublic void render(LoggingAdvisingAppendable appendable) throws IOException
SoyValueThis should behave identically to appendable.append(coerceToString()) but is
provided separately to allow more incremental approaches.
render in interface SoyValueappendable - The appendable to render to.IOExceptionpublic final boolean equals(Object other)
SoyValueequals in interface SoyValueequals in class SoyAbstractValueother - The other value to compare against.