Fix CS warnings in sal-clustering-commons and enable enforcement
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / serialization / PathArgumentType.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
10
11 import com.google.common.collect.ImmutableMap;
12 import java.util.Map;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14
15 public enum PathArgumentType {
16     AUGMENTATION_IDENTIFIER,
17     NODE_IDENTIFIER,
18     NODE_IDENTIFIER_WITH_VALUE,
19     NODE_IDENTIFIER_WITH_PREDICATES;
20
21     private static Map<Class<?>, PathArgumentType> CLASS_TO_ENUM_MAP =
22             ImmutableMap.<Class<?>, PathArgumentType>builder()
23                 .put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER)
24                 .put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER)
25                 .put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES)
26                 .put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build();
27
28     public static int getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument) {
29
30         PathArgumentType type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass());
31         if (type == null) {
32             throw new IllegalArgumentException("Unknown type of PathArgument = " + pathArgument);
33         }
34
35         return type.ordinal();
36     }
37 }