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 KeyAware<K> & DataObject, K extends Key<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 KeyedBuilder<T, K> builder() {
45 return new KeyedBuilder<>(this);
49 protected boolean fastNonEqual(final InstanceIdentifier<?> other) {
50 final KeyedInstanceIdentifier<?, ?> kii = (KeyedInstanceIdentifier<?, ?>) other;
53 * We could do an equals() here, but that may actually be expensive.
54 * equals() in superclass falls back to a full compare, which will
55 * end up running that equals anyway, so do not bother here.
57 return key == null != (kii.key == null);
61 private Object writeReplace() throws ObjectStreamException {
62 return new KeyedInstanceIdentifierV2<>(this);