BUG-592: Migrate users to new build() method
[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 public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K extends Identifier<T>> extends InstanceIdentifier<T> {
11     private final K key;
12
13     KeyedInstanceIdentifier(final Class<T> type, final Iterable<PathArgument> pathArguments, final boolean wildcarded, final int hash, final K key) {
14         super(type, pathArguments, wildcarded, hash);
15         this.key = key;
16     }
17
18     public final K getKey() {
19         return key;
20     }
21
22     @Override
23     public final InstanceIdentifierBuilder<T> builder() {
24         return new InstanceIdentifierBuilderImpl<T>(new InstanceIdentifier.IdentifiableItem<T, K>(getTargetType(), key), getPathArguments(), hashCode(), isWildcarded());
25     }
26
27     @Override
28     protected boolean fastNonEqual(final InstanceIdentifier<?> other) {
29         final KeyedInstanceIdentifier<?, ?> kii = (KeyedInstanceIdentifier<?, ?>) other;
30
31         /*
32          * We could do an equals() here, but that may actually be expensive.
33          * equals() in superclass falls back to a full compare, which will
34          * end up running that equals anyway, so do not bother here.
35          */
36         return (key == null) != (kii.key == null);
37     }
38 }