dd140ca410156d028175243dbd66fba67e339794
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / PathArgumentTypes.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.stream;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableMap;
13 import java.util.Map;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15
16 final class PathArgumentTypes {
17     public static final byte AUGMENTATION_IDENTIFIER = 1;
18     public static final byte NODE_IDENTIFIER = 2;
19     public static final byte NODE_IDENTIFIER_WITH_VALUE = 3;
20     public static final byte NODE_IDENTIFIER_WITH_PREDICATES = 4;
21
22     private PathArgumentTypes() {
23         throw new UnsupportedOperationException("Utility class");
24     }
25
26     private static final Map<Class<?>, Byte> CLASS_TO_ENUM_MAP =
27             ImmutableMap.<Class<?>, Byte>builder().
28                 put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER).
29                 put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER).
30                 put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES).
31                 put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build();
32
33     public static byte getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument) {
34         final Byte type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass());
35         Preconditions.checkArgument(type != null, "Unknown type of PathArgument = %s", pathArgument);
36         return type;
37     }
38
39 }