/** * Creates a SoyList from a Java Iterable. * * <p>Values are converted into Soy types lazily and only once. * * @param items The collection of Java values * @return A new SoyList initialized from the given Java Collection. */ private SoyList newListFromIterable(Iterable<?> items) { // Create a list backed by a Java list which has eagerly converted each value into a lazy // value provider. Specifically, the list iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableList.Builder<SoyValueProvider> builder = ImmutableList.builder(); for (Object item : items) { builder.add(convertLazy(item)); } return ListImpl.forProviderList(builder.build()); }
/** * Creates a Soy map from a Java map. While this is O(n) in the map's shallow size, the Java * values are converted into Soy values lazily and only once. The keys are converted eagerly. */ private SoyMap newSoyMapFromJavaMap(Map<?, ?> javaMap) { Map<SoyValue, SoyValueProvider> map = Maps.newHashMapWithExpectedSize(javaMap.size()); for (Map.Entry<?, ?> entry : javaMap.entrySet()) { map.put(convert(entry.getKey()).resolve(), convertLazy(entry.getValue())); } return SoyMapImpl.forProviderMap(map); }
/** * Creates a SoyList from a Java Iterable. * * <p>Values are converted into Soy types lazily and only once. * * @param items The collection of Java values * @return A new SoyList initialized from the given Java Collection. */ private SoyList newListFromIterable(Iterable<?> items) { // Create a list backed by a Java list which has eagerly converted each value into a lazy // value provider. Specifically, the list iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableList.Builder<SoyValueProvider> builder = ImmutableList.builder(); for (Object item : items) { builder.add(convertLazy(item)); } return ListImpl.forProviderList(builder.build()); }
/** * Creates a Soy map from a Java map. While this is O(n) in the map's shallow size, the Java * values are converted into Soy values lazily and only once. The keys are converted eagerly. */ private SoyMap newSoyMapFromJavaMap(Map<?, ?> javaMap) { ImmutableMap.Builder<SoyValue, SoyValueProvider> builder = ImmutableMap.builder(); for (Map.Entry<?, ?> entry : javaMap.entrySet()) { builder.put(convert(entry.getKey()).resolve(), convertLazy(entry.getValue())); } return SoyMapImpl.forProviderMap(builder.build()); }
/** * Creates a Soy dictionary from a Java string map. While this is O(n) in the map's shallow size, * the Java values are converted into Soy values lazily and only once. */ public SoyDict newDictFromMap(Map<String, ?> javaStringMap) { // Create a dictionary backed by a map which has eagerly converted each value into a lazy // value provider. Specifically, the map iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableMap.Builder<String, SoyValueProvider> builder = ImmutableMap.builder(); for (Map.Entry<String, ?> entry : javaStringMap.entrySet()) { builder.put(entry.getKey(), convertLazy(entry.getValue())); } return DictImpl.forProviderMap( builder.build(), // This Java map could represent a Soy legacy_object_map, a Soy map, or a Soy record. // We don't know which until one of the SoyMap, SoyLegacyObjectMap, or SoyRecord methods // is invoked on it. RuntimeMapTypeTracker.Type.UNKNOWN); }
/** * Creates a Soy dictionary from a Java string map. While this is O(n) in the map's shallow size, * the Java values are converted into Soy values lazily and only once. */ public SoyDict newDictFromMap(Map<String, ?> javaStringMap) { // Create a dictionary backed by a map which has eagerly converted each value into a lazy // value provider. Specifically, the map iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableMap.Builder<String, SoyValueProvider> builder = ImmutableMap.builder(); for (Map.Entry<String, ?> entry : javaStringMap.entrySet()) { builder.put(entry.getKey(), convertLazy(entry.getValue())); } return DictImpl.forProviderMap( builder.build(), // This Java map could represent a Soy legacy_object_map, a Soy map, or a Soy record. // We don't know which until one of the SoyMap, SoyLegacyObjectMap, or SoyRecord methods // is invoked on it. RuntimeType.UNKNOWN); }