Introduce top-level pom file.
[mdsal.git] / yang / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / KeyedInstanceIdentifier.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.yangtools.yang.binding;
9
10 /**
11  * An {@link InstanceIdentifier}, which has a list key attached at its last path
12  * element.
13  *
14  * @param <T> Target data type
15  * @param <K> Target key type
16  */
17 public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K extends Identifier<T>> extends InstanceIdentifier<T> {
18     private static final long serialVersionUID = 1L;
19     private final K key;
20
21     KeyedInstanceIdentifier(final Class<T> type, final Iterable<PathArgument> pathArguments, final boolean wildcarded, final int hash, final K key) {
22         super(type, pathArguments, wildcarded, hash);
23         this.key = key;
24     }
25
26     /**
27      * Return the key attached to this identifier. This method is equivalent to
28      * calling {@link InstanceIdentifier#keyOf(InstanceIdentifier)}.
29      *
30      * @return Key associated with this instance identifier.
31      */
32     public final K getKey() {
33         return key;
34     }
35
36     @Override
37     public final InstanceIdentifierBuilder<T> builder() {
38         return new InstanceIdentifierBuilderImpl<T>(new InstanceIdentifier.IdentifiableItem<T, K>(getTargetType(), key), pathArguments, hashCode(), isWildcarded());
39     }
40
41     @Override
42     protected boolean fastNonEqual(final InstanceIdentifier<?> other) {
43         final KeyedInstanceIdentifier<?, ?> kii = (KeyedInstanceIdentifier<?, ?>) other;
44
45         /*
46          * We could do an equals() here, but that may actually be expensive.
47          * equals() in superclass falls back to a full compare, which will
48          * end up running that equals anyway, so do not bother here.
49          */
50         return (key == null) != (kii.key == null);
51     }
52 }