Use ImmutableMap collector in EnumStringCodec 21/90621/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 24 Jun 2020 10:05:52 +0000 (12:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 24 Jun 2020 10:05:52 +0000 (12:05 +0200)
Reduce the use of intermediate structures by using a direct
collector rather than collecting to a list and then performing
Maps.uniqueIndex().

Change-Id: I0d200211daa240076394af1d3e33ec4df26c146e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/EnumStringCodec.java

index 950acd12db49247753f460e3c88190b437ece493..4f05d2852936ce459266966aacfa75047aca26ee 100644 (file)
@@ -13,8 +13,6 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.Beta;
 import com.google.common.base.Functions;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import java.util.stream.Collectors;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.codec.EnumCodec;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
@@ -29,11 +27,10 @@ public final class EnumStringCodec extends TypeDefinitionAwareCodec<String, Enum
 
     private EnumStringCodec(final @NonNull EnumTypeDefinition typeDef) {
         super(typeDef, String.class);
-
-        values = Maps.uniqueIndex(typeDef.getValues().stream()
-            // Intern the String to get wide reuse
-            .map(pair -> pair.getName().intern())
-            .collect(Collectors.toList()), Functions.identity());
+        values = typeDef.getValues().stream()
+                // Intern the String to get wide reuse
+                .map(pair -> pair.getName().intern())
+                .collect(ImmutableMap.toImmutableMap(Functions.identity(), Functions.identity()));
     }
 
     public static EnumStringCodec from(final EnumTypeDefinition normalizedType) {