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