X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fdevice%2FSwitchFeaturesUtil.java;h=93932451fb5b113fd9d68c24ff16f92501284f84;hb=refs%2Fchanges%2F77%2F100077%2F17;hp=272b68f3d4402bdafe848e6fcecd8922abbbe909;hpb=e24d613b2b6f151c424750e062215baab60880f1;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/SwitchFeaturesUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/SwitchFeaturesUtil.java index 272b68f3d4..93932451fb 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/SwitchFeaturesUtil.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/SwitchFeaturesUtil.java @@ -10,55 +10,40 @@ package org.opendaylight.openflowplugin.impl.device; import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_0; import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_3; -import java.util.HashMap; import java.util.Map; import org.opendaylight.openflowplugin.api.openflow.md.core.sal.BuildSwitchFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yangtools.yang.common.Uint8; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class SwitchFeaturesUtil { - private static final Logger LOG = LoggerFactory.getLogger(SwitchFeaturesUtil.class); - private static SwitchFeaturesUtil instance = new SwitchFeaturesUtil(); - private final Map swFeaturesBuilders; + private static final Map SWITCH_FEATURES_BUILDERS = Map.of( + OFP_VERSION_1_0, BuildSwitchCapabilitiesOF10.getInstance(), + OFP_VERSION_1_3, BuildSwitchCapabilitiesOF13.getInstance()); private SwitchFeaturesUtil() { - swFeaturesBuilders = new HashMap<>(); - swFeaturesBuilders.put(OFP_VERSION_1_0, BuildSwitchCapabilitiesOF10.getInstance()); - swFeaturesBuilders.put(OFP_VERSION_1_3, BuildSwitchCapabilitiesOF13.getInstance()); - } - - /** - * Get singleton instance. - * - * @return instance - */ - public static SwitchFeaturesUtil getInstance() { - return instance; + // Hidden on purpose } /** * Returns the features of the switch. * * @param features - * {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput} + * {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput} * @return switch features */ - public SwitchFeatures buildSwitchFeatures(final GetFeaturesOutput features) { - if (swFeaturesBuilders.containsKey(features.getVersion().toJava())) { - LOG.debug("map contains version {}", features.getVersion()); - try { - return swFeaturesBuilders.get(features.getVersion().toJava()).build(features); - } catch (NullPointerException e) { - LOG.warn("error while building switch features: {}", e.getMessage()); - LOG.debug("error while building switch features.. ", e); - } - } else { - LOG.warn("unknown version: {}", features.getVersion()); + public static SwitchFeatures buildSwitchFeatures(final GetFeaturesOutput features) { + final var version = features.getVersion(); + final var builder = SWITCH_FEATURES_BUILDERS.get(version); + if (builder != null) { + LOG.debug("map contains version {}", version); + return builder.build(features); } + LOG.warn("unknown version: {}", version); return null; } }