*/
package org.opendaylight.protocol.bgp.parser;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.io.Serializable;
-import java.util.Map;
-
+import java.util.Arrays;
/**
* Possible errors from implemented RFCs and drafts. Each error consists of error code and error subcode
public static final String MANDATORY_ATTR_MISSING_MSG = "Well known mandatory attribute missing: ";
- private static final Map<BGPErrorIdentifier, BGPError> VALUE_MAP;
-
- static {
- VALUE_MAP = Maps.newHashMap();
- for (final BGPError enumItem : BGPError.values()) {
- VALUE_MAP.put(enumItem.getErrorIdentifier(), enumItem);
- }
- }
+ private static final ImmutableMap<BGPErrorIdentifier, BGPError> VALUE_MAP = Maps.uniqueIndex(
+ Arrays.asList(values()), BGPError::getErrorIdentifier);
private final BGPErrorIdentifier errorId;
public static BGPError forValue(final int code, final int subcode) {
final BGPError e = VALUE_MAP.get(new BGPErrorIdentifier((short) code, (short) subcode));
- Preconditions.checkArgument(e != null, "BGP Error code %s and subcode %s not recognized.",
- code, subcode);
+ checkArgument(e != null, "BGP Error code %s and subcode %s not recognized.", code, subcode);
return e;
}