Ensure immutability of constants Collection
Change-Id: I9b26282ccabaef5e4ac81fb626abfa6e537d9333
diff --git a/utils/misc/src/main/java/org/onlab/packet/MPLS.java b/utils/misc/src/main/java/org/onlab/packet/MPLS.java
index f6ca734..3a6f71d 100644
--- a/utils/misc/src/main/java/org/onlab/packet/MPLS.java
+++ b/utils/misc/src/main/java/org/onlab/packet/MPLS.java
@@ -16,9 +16,10 @@
package org.onlab.packet;
import java.nio.ByteBuffer;
-import java.util.HashMap;
import java.util.Map;
+import com.google.common.collect.ImmutableMap;
+
import static com.google.common.base.MoreObjects.toStringHelper;
import static org.onlab.packet.PacketUtils.checkInput;
@@ -30,13 +31,12 @@
public static final byte PROTOCOL_IPV4 = 0x1;
public static final byte PROTOCOL_MPLS = 0x6;
- static Map<Byte, Deserializer<? extends IPacket>> protocolDeserializerMap
- = new HashMap<>();
-
- static {
- protocolDeserializerMap.put(PROTOCOL_IPV4, IPv4.deserializer());
- protocolDeserializerMap.put(PROTOCOL_MPLS, MPLS.deserializer());
- }
+ // mutable for Testing
+ static Map<Byte, Deserializer<? extends IPacket>> protocolDeserializerMap =
+ ImmutableMap.<Byte, Deserializer<? extends IPacket>>builder()
+ .put(PROTOCOL_IPV4, IPv4.deserializer())
+ .put(PROTOCOL_MPLS, MPLS.deserializer())
+ .build();
protected int label; //20bits
protected byte bos; //1bit