Fix more potentially-static methods 47/72647/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jun 2018 10:57:21 +0000 (12:57 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jun 2018 12:05:21 +0000 (14:05 +0200)
All these methods can easily be static, make it so. Also do not
access attributes/augmentations multiple times.

Change-Id: I784ce35ce9d6e9f86e51514c98d6432db9a0f4ff
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/mvpn/src/main/java/org/opendaylight/protocol/bgp/mvpn/impl/nlri/AbstractMvpnNlri.java
bgp/mvpn/src/test/java/org/opendaylight/protocol/bgp/mvpn/impl/attributes/PEDistinguisherLabelsAttributeHandlerTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AdjRibInWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/StrictBGPPeerRegistry.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BGPClusterSingletonService.java

index 3a2b09c4ff58e573a172fc9f144f3ab136a1467e..7e8c8631470a87c84b2fd6b8c93d3ddeb84fbd0d 100644 (file)
@@ -52,7 +52,7 @@ abstract class AbstractMvpnNlri<T extends MvpnChoice> implements MvpnSerializer<
     protected abstract ByteBuf serializeBody(T mvpn);
 
 
-    final MulticastSourceRdGrouping parseRDMulticastSource(final ByteBuf buffer) {
+    static final MulticastSourceRdGrouping parseRDMulticastSource(final ByteBuf buffer) {
         final SPmsiADBuilder builder = new SPmsiADBuilder();
         builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(buffer));
         final IpAddress address = IpAddressUtil.addressForByteBuf(buffer);
@@ -60,7 +60,7 @@ abstract class AbstractMvpnNlri<T extends MvpnChoice> implements MvpnSerializer<
         return builder.build();
     }
 
-    final void serializeRDMulticastSource(final MulticastSourceRdGrouping route, final ByteBuf output) {
+    static final void serializeRDMulticastSource(final MulticastSourceRdGrouping route, final ByteBuf output) {
         RouteDistinguisherUtil.serializeRouteDistinquisher(route.getRouteDistinguisher(), output);
         output.writeBytes(IpAddressUtil.bytesFor(route.getMulticastSource()));
     }
index e72f062c9272f78d4b67901f2c958ebfce19d817..8831a686cd9053d1fe07c293b8ac8aaafb7960a2 100644 (file)
@@ -72,8 +72,8 @@ public final class PEDistinguisherLabelsAttributeHandlerTest {
         assertEquals(expected, actualAttr);
     }
 
-    private Attributes buildPEDistinguisherLabelsAttributAttribute() {
-        final List<PeDistinguisherLabelAttribute> peAtt = new ArrayList<>();
+    private static Attributes buildPEDistinguisherLabelsAttributAttribute() {
+        final List<PeDistinguisherLabelAttribute> peAtt = new ArrayList<>(2);
 
         peAtt.add(new PeDistinguisherLabelAttributeBuilder()
                 .setPeAddress(new IpAddress(new Ipv4Address("127.0.0.1")))
index 9b2738fd4b2ef5cff12bcd09b4ae5c860e6cd04b..a954e99ac6237de85fe8f61ce949f73a8e8bf158 100644 (file)
@@ -172,9 +172,10 @@ final class AdjRibInWriter {
     /**
      * Create new table instances, potentially creating their empty entries
      */
-    private ImmutableMap<TablesKey, TableContext> createNewTableInstances(final YangInstanceIdentifier newPeerPath,
-            final RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes,
-            final Map<TablesKey, SendReceive> addPathTablesType, final DOMDataWriteTransaction tx) {
+    private static ImmutableMap<TablesKey, TableContext> createNewTableInstances(
+            final YangInstanceIdentifier newPeerPath, final RIBSupportContextRegistry registry,
+            final Set<TablesKey> tableTypes, final Map<TablesKey, SendReceive> addPathTablesType,
+            final DOMDataWriteTransaction tx) {
 
         final Builder<TablesKey, TableContext> tb = ImmutableMap.builder();
         for (final TablesKey tableKey : tableTypes) {
@@ -208,7 +209,7 @@ final class AdjRibInWriter {
         tb.put(tableKey, ctx);
     }
 
-    private void installAdjRibsOutTables(final YangInstanceIdentifier newPeerPath, final RIBSupportContext rs,
+    private static void installAdjRibsOutTables(final YangInstanceIdentifier newPeerPath, final RIBSupportContext rs,
             final NodeIdentifierWithPredicates instanceIdentifierKey, final TablesKey tableKey,
             final SendReceive sendReceive, final DOMDataWriteTransaction tx) {
         final NodeIdentifierWithPredicates supTablesKey = RibSupportUtils.toYangKey(SupportedTables.QNAME, tableKey);
index 7da3f6f3357baa8fa0e95730f6aab6df17ed0eac..614e2dba2f297174bacbf863a0d24e0cd130c506 100644 (file)
@@ -114,7 +114,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
         this.reg = requireNonNull(this.databroker).registerDataTreeChangeListener(treeId, this);
     }
 
-    private Map<TablesKey, LongAdder> buildPrefixesTables(final Set<TablesKey> tables) {
+    private static Map<TablesKey, LongAdder> buildPrefixesTables(final Set<TablesKey> tables) {
         final ImmutableMap.Builder<TablesKey, LongAdder> b = ImmutableMap.builder();
         tables.forEach(table -> b.put(table, new LongAdder()));
         return b.build();
index 206c161d1e8dade16f621ee005da1bff621323e9..477cd616847f7c2905894b2fa761627905e63195 100644 (file)
@@ -44,6 +44,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.OptionalCapabilities;
@@ -95,12 +96,9 @@ public final class StrictBGPPeerRegistry implements BGPPeerRegistry {
         }
     }
 
-    private IpAddress getFullIp(final IpAddress ip) {
-        requireNonNull(ip);
-        if (ip.getIpv6Address() != null) {
-            return new IpAddress(Ipv6Util.getFullForm(ip.getIpv6Address()));
-        }
-        return ip;
+    private static IpAddress getFullIp(final IpAddress ip) {
+        final Ipv6Address addr = ip.getIpv6Address();
+        return addr == null ? ip : new IpAddress(Ipv6Util.getFullForm(addr));
     }
 
     @Override
index deedf6b0ef214ac4ecd305a7319ce1a88d2d899d..ef65402305a8f2d52992c364e7483c5eccbdbaa3 100644 (file)
@@ -276,11 +276,12 @@ public final class BGPClusterSingletonService implements ClusterSingletonService
         LOG.debug("Peer instance created {}", bgpPeer);
     }
 
-    private String getPeerGroupName(final Config config) {
-        if (config != null && config.getAugmentation(NeighborPeerGroupConfig.class) != null) {
-            return config.getAugmentation(NeighborPeerGroupConfig.class).getPeerGroup();
+    private static String getPeerGroupName(final Config config) {
+        if (config == null) {
+            return null;
         }
-        return null;
+        final NeighborPeerGroupConfig aug = config.getAugmentation(NeighborPeerGroupConfig.class);
+        return aug == null ? null : aug.getPeerGroup();
     }
 
     private synchronized void onNeighborUpdated(final PeerBean bgpPeer, final Neighbor neighbor) {
@@ -293,7 +294,7 @@ public final class BGPClusterSingletonService implements ClusterSingletonService
         LOG.debug("Peer instance updated {}", bgpPeer);
     }
 
-    private void closePeer(final PeerBean bgpPeer) {
+    private static void closePeer(final PeerBean bgpPeer) {
         if (bgpPeer != null) {
             try {
                 bgpPeer.closeServiceInstance().get();