From 3745263f280dd337f03c8e7b7e60dc5f6e290620 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 16 May 2015 18:18:40 +0200 Subject: [PATCH] Do not use InstanceIdentifier.builder() These instance identifiers are expected to be short-lived, so use the appropriate utility child() method instead. Change-Id: I23a6e6d33fec7b904794ac38ff153b4d46063858 Signed-off-by: Robert Varga --- .../InstanceIdentifierUtils.java | 53 ++++++++----------- .../learningswitch/PacketUtils.java | 15 +++--- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java index 10ee47ab63..07ebb46cd6 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java @@ -5,11 +5,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -22,11 +22,11 @@ public class InstanceIdentifierUtils { /** * Creates an Instance Identifier (path) for node with specified id - * + * * @param nodeId * @return */ - public static final InstanceIdentifier createNodePath(NodeId nodeId) { + public static final InstanceIdentifier createNodePath(final NodeId nodeId) { return InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(nodeId)) .build(); @@ -34,66 +34,59 @@ public class InstanceIdentifierUtils { /** * Shorten's node child path to node path. - * + * * @param nodeChild child of node, from which we want node path. * @return */ - public static final InstanceIdentifier getNodePath(InstanceIdentifier nodeChild) { + public static final InstanceIdentifier getNodePath(final InstanceIdentifier nodeChild) { return nodeChild.firstIdentifierOf(Node.class); } - - + + /** * Creates a table path by appending table specific location to node path - * + * * @param nodePath * @param tableKey * @return */ - public static final InstanceIdentifier createTablePath(InstanceIdentifier nodePath,TableKey tableKey) { - return InstanceIdentifier.builder(nodePath) - .augmentation(FlowCapableNode.class) - .child(Table.class, tableKey) - .build(); + public static final InstanceIdentifier
createTablePath(final InstanceIdentifier nodePath,final TableKey tableKey) { + return nodePath.augmentation(FlowCapableNode.class).child(Table.class, tableKey); } /** * Creates a path for particular flow, by appending flow-specific information * to table path. - * + * * @param tablePath * @param flowKey * @return path to flow */ - public static InstanceIdentifier createFlowPath(InstanceIdentifier
tablePath, FlowKey flowKey) { - return InstanceIdentifier.builder(tablePath) - .child(Flow.class, flowKey) - .build(); + public static InstanceIdentifier createFlowPath(final InstanceIdentifier
tablePath, final FlowKey flowKey) { + return tablePath.child(Flow.class, flowKey); } /** * Extract table id from table path. - * + * * @param tablePath * @return */ - public static Short getTableId(InstanceIdentifier
tablePath) { + public static Short getTableId(final InstanceIdentifier
tablePath) { return tablePath.firstKeyOf(Table.class, TableKey.class).getId(); } - + /** * Extracts NodeConnectorKey from node connector path. - * + * */ - public static NodeConnectorKey getNodeConnectorKey(InstanceIdentifier nodeConnectorPath) { + public static NodeConnectorKey getNodeConnectorKey(final InstanceIdentifier nodeConnectorPath) { return nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class); } - - + + // - public static final InstanceIdentifier createNodeConnectorPath(InstanceIdentifier nodeKey,NodeConnectorKey nodeConnectorKey) { - return InstanceIdentifier.builder(nodeKey) - .child(NodeConnector.class,nodeConnectorKey) - .build(); + public static final InstanceIdentifier createNodeConnectorPath(final InstanceIdentifier nodeKey,final NodeConnectorKey nodeConnectorKey) { + return nodeKey.child(NodeConnector.class,nodeConnectorKey); } } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/PacketUtils.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/PacketUtils.java index 776f139aeb..159e4e0e99 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/PacketUtils.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/PacketUtils.java @@ -66,7 +66,7 @@ public abstract class PacketUtils { * @param payload * @return destination MAC address */ - public static byte[] extractDstMac(byte[] payload) { + public static byte[] extractDstMac(final byte[] payload) { return Arrays.copyOfRange(payload, DST_MAC_START_POSITION, DST_MAC_END_POSITION); } @@ -74,7 +74,7 @@ public abstract class PacketUtils { * @param payload * @return source MAC address */ - public static byte[] extractSrcMac(byte[] payload) { + public static byte[] extractSrcMac(final byte[] payload) { return Arrays.copyOfRange(payload, SRC_MAC_START_POSITION, SRC_MAC_END_POSITION); } @@ -82,7 +82,7 @@ public abstract class PacketUtils { * @param payload * @return source MAC address */ - public static byte[] extractEtherType(byte[] payload) { + public static byte[] extractEtherType(final byte[] payload) { return Arrays.copyOfRange(payload, ETHER_TYPE_START_POSITION, ETHER_TYPE_END_POSITION); } @@ -91,7 +91,7 @@ public abstract class PacketUtils { * @return {@link MacAddress} wrapping string value, baked upon binary MAC * address */ - public static MacAddress rawMacToMac(byte[] rawMac) { + public static MacAddress rawMacToMac(final byte[] rawMac) { MacAddress mac = null; if (rawMac != null && rawMac.length == MAC_ADDRESS_SIZE) { StringBuilder sb = new StringBuilder(); @@ -109,11 +109,10 @@ public abstract class PacketUtils { * @param port * @return port wrapped into {@link NodeConnectorRef} */ - public static NodeConnectorRef createNodeConnRef(InstanceIdentifier nodeInstId, NodeKey nodeKey, String port) { - StringBuilder sBuild = new StringBuilder(nodeKey.getId().getValue()).append(":").append(port); + public static NodeConnectorRef createNodeConnRef(final InstanceIdentifier nodeInstId, final NodeKey nodeKey, final String port) { + StringBuilder sBuild = new StringBuilder(nodeKey.getId().getValue()).append(':').append(port); NodeConnectorKey nConKey = new NodeConnectorKey(new NodeConnectorId(sBuild.toString())); - InstanceIdentifier portPath = InstanceIdentifier.builder(nodeInstId) - .child(NodeConnector.class, nConKey).build(); + InstanceIdentifier portPath = nodeInstId.child(NodeConnector.class, nConKey); return new NodeConnectorRef(portPath); } } -- 2.36.6