From b01a9090daf0b1515f1136f282e574ee7608eb69 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 16 Sep 2015 20:49:29 +0200 Subject: [PATCH] Use ImmutableSet/Map in YangValidationBundles These could easily be subverted, so make them proper constants. Also saves some memory and fixes some sonar warnings (about declarations being to a concrete class). Change-Id: I8f176ed7173b9b3eedce48b4e58131f00690ffc6 Signed-off-by: Robert Varga --- .../stmt/rfc6020/YangValidationBundles.java | 77 +++++++++---------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangValidationBundles.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangValidationBundles.java index b6b61c5209..4e70719be1 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangValidationBundles.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangValidationBundles.java @@ -7,58 +7,51 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.collect.ImmutableSet; +import java.util.Map; +import java.util.Set; import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping; import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition; public final class YangValidationBundles { + private YangValidationBundles() { + throw new UnsupportedOperationException("Utility class"); + } - public static final HashSet SUPPORTED_REFINE_SUBSTATEMENTS = new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.DEFAULT, - Rfc6020Mapping.DESCRIPTION, Rfc6020Mapping.REFERENCE, - Rfc6020Mapping.CONFIG, Rfc6020Mapping.MANDATORY, - Rfc6020Mapping.MUST, Rfc6020Mapping.PRESENCE, - Rfc6020Mapping.MIN_ELEMENTS, Rfc6020Mapping.MAX_ELEMENTS })); + public static final Set SUPPORTED_REFINE_SUBSTATEMENTS = ImmutableSet.of( + Rfc6020Mapping.DEFAULT, Rfc6020Mapping.DESCRIPTION, Rfc6020Mapping.REFERENCE, Rfc6020Mapping.CONFIG, + Rfc6020Mapping.MANDATORY, Rfc6020Mapping.MUST, Rfc6020Mapping.PRESENCE, Rfc6020Mapping.MIN_ELEMENTS, + Rfc6020Mapping.MAX_ELEMENTS); - public static final HashMap> SUPPORTED_REFINE_TARGETS = new HashMap<>(); + public static final Map> SUPPORTED_REFINE_TARGETS; static { - SUPPORTED_REFINE_TARGETS.put(Rfc6020Mapping.DEFAULT, new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.LEAF, Rfc6020Mapping.CHOICE }))); - SUPPORTED_REFINE_TARGETS.put(Rfc6020Mapping.MANDATORY, new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.LEAF, Rfc6020Mapping.CHOICE, Rfc6020Mapping.ANYXML }))); - SUPPORTED_REFINE_TARGETS.put(Rfc6020Mapping.PRESENCE, new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.CONTAINER }))); - SUPPORTED_REFINE_TARGETS.put(Rfc6020Mapping.MUST, new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.CONTAINER, - Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF, - Rfc6020Mapping.LEAF_LIST, Rfc6020Mapping.ANYXML, }))); - SUPPORTED_REFINE_TARGETS.put(Rfc6020Mapping.MIN_ELEMENTS, new HashSet<>( - Arrays.asList(new StatementDefinition[]{Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF_LIST}))); - SUPPORTED_REFINE_TARGETS.put(Rfc6020Mapping.MAX_ELEMENTS, new HashSet<>( - Arrays.asList(new StatementDefinition[]{Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF_LIST}))); + final Builder> b = ImmutableMap.builder(); + b.put(Rfc6020Mapping.DEFAULT, ImmutableSet.of(Rfc6020Mapping.LEAF, Rfc6020Mapping.CHOICE)); + b.put(Rfc6020Mapping.MANDATORY, ImmutableSet.of( + Rfc6020Mapping.LEAF, Rfc6020Mapping.CHOICE, Rfc6020Mapping.ANYXML)); + b.put(Rfc6020Mapping.PRESENCE, ImmutableSet.of(Rfc6020Mapping.CONTAINER)); + b.put(Rfc6020Mapping.MUST, ImmutableSet.of( + Rfc6020Mapping.CONTAINER, Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF, + Rfc6020Mapping.LEAF_LIST, Rfc6020Mapping.ANYXML)); + b.put(Rfc6020Mapping.MIN_ELEMENTS, ImmutableSet.of( + Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF_LIST)); + b.put(Rfc6020Mapping.MAX_ELEMENTS, ImmutableSet.of( + Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF_LIST)); + SUPPORTED_REFINE_TARGETS = b.build(); } - public static final HashSet SUPPORTED_AUGMENT_TARGETS = new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.CONTAINER, - Rfc6020Mapping.LIST, Rfc6020Mapping.CASE, - Rfc6020Mapping.INPUT, Rfc6020Mapping.OUTPUT, - Rfc6020Mapping.NOTIFICATION, Rfc6020Mapping.CHOICE, - Rfc6020Mapping.RPC })); - - public static final HashSet SUPPORTED_CASE_SHORTHANDS = new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.CONTAINER, - Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF, - Rfc6020Mapping.LEAF_LIST, Rfc6020Mapping.ANYXML, })); + public static final Set SUPPORTED_AUGMENT_TARGETS = ImmutableSet.of( + Rfc6020Mapping.CONTAINER, Rfc6020Mapping.LIST, Rfc6020Mapping.CASE, Rfc6020Mapping.INPUT, Rfc6020Mapping.OUTPUT, + Rfc6020Mapping.NOTIFICATION, Rfc6020Mapping.CHOICE, Rfc6020Mapping.RPC); - public static final HashSet SUPPORTED_DATA_NODES = new HashSet<>( - Arrays.asList(new StatementDefinition[] { Rfc6020Mapping.CONTAINER, - Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF, - Rfc6020Mapping.LEAF_LIST, Rfc6020Mapping.ANYXML, })); + public static final Set SUPPORTED_CASE_SHORTHANDS = ImmutableSet.of( + Rfc6020Mapping.CONTAINER, Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF, Rfc6020Mapping.LEAF_LIST, + Rfc6020Mapping.ANYXML); - private YangValidationBundles() { - throw new UnsupportedOperationException("Utility class"); - } + public static final Set SUPPORTED_DATA_NODES = ImmutableSet.of( + Rfc6020Mapping.CONTAINER, Rfc6020Mapping.LIST, Rfc6020Mapping.LEAF, Rfc6020Mapping.LEAF_LIST, + Rfc6020Mapping.ANYXML); } -- 2.36.6