Use new ClassLoaderUtils methods
[mdsal.git] / binding / 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 element.
12  *
13  * @param <T> Target data type
14  * @param <K> Target key type
15  */
16 public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K extends Identifier<T>>
17         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,
22         final int hash, final K key) {
23         super(type, pathArguments, wildcarded, hash);
24         this.key = key;
25     }
26
27     /**
28      * Return the key attached to this identifier. This method is equivalent to calling
29      * {@link InstanceIdentifier#keyOf(InstanceIdentifier)}.
30      *
31      * @return Key associated with this instance identifier.
32      */
33     public final K getKey() {
34         return key;
35     }
36
37     @Override
38     public final InstanceIdentifierBuilder<T> builder() {
39         return new InstanceIdentifierBuilderImpl<>(IdentifiableItem.of(getTargetType(), key), pathArguments,
40                 hashCode(), isWildcarded());
41     }
42
43     @Override
44     protected boolean fastNonEqual(final InstanceIdentifier<?> other) {
45         final KeyedInstanceIdentifier<?, ?> kii = (KeyedInstanceIdentifier<?, ?>) other;
46
47         /*
48          * We could do an equals() here, but that may actually be expensive.
49          * equals() in superclass falls back to a full compare, which will
50          * end up running that equals anyway, so do not bother here.
51          */
52         return key == null != (kii.key == null);
53     }
54 }