2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.binding;
10 import java.io.ObjectStreamException;
11 import java.io.Serial;
12 import org.eclipse.jdt.annotation.NonNull;
15 * An {@link InstanceIdentifier}, which has a list key attached at its last path element.
17 * @param <T> Target data type
18 * @param <K> Target key type
20 public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K extends Identifier<T>>
21 extends InstanceIdentifier<T> {
23 private static final long serialVersionUID = 2L;
27 KeyedInstanceIdentifier(final Class<@NonNull T> type, final Iterable<PathArgument> pathArguments,
28 final boolean wildcarded, final int hash, final K key) {
29 super(type, pathArguments, wildcarded, hash);
34 * Return the key attached to this identifier. This method is equivalent to calling
35 * {@link InstanceIdentifier#keyOf(InstanceIdentifier)}.
37 * @return Key associated with this instance identifier.
39 public final K getKey() {
44 public final InstanceIdentifierBuilder<T> builder() {
45 return new InstanceIdentifierBuilderImpl<>(IdentifiableItem.of(getTargetType(), key), pathArguments,
46 hashCode(), isWildcarded());
50 protected boolean fastNonEqual(final InstanceIdentifier<?> other) {
51 final KeyedInstanceIdentifier<?, ?> kii = (KeyedInstanceIdentifier<?, ?>) other;
54 * We could do an equals() here, but that may actually be expensive.
55 * equals() in superclass falls back to a full compare, which will
56 * end up running that equals anyway, so do not bother here.
58 return key == null != (kii.key == null);
62 private Object writeReplace() throws ObjectStreamException {
63 return new KeyedInstanceIdentifierV2<>(this);