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 org.eclipse.jdt.annotation.NonNull;
14 * An {@link InstanceIdentifier}, which has a list key attached at its last path element.
16 * @param <T> Target data type
17 * @param <K> Target key type
19 public final class KeyedInstanceIdentifier<T extends KeyAware<K> & DataObject, K extends Key<T>>
20 extends InstanceIdentifier<T> {
22 private static final long serialVersionUID = 2L;
24 private final @NonNull KeyStep<K, T> lastStep;
26 KeyedInstanceIdentifier(final KeyStep<K, T> lastStep, final Iterable<DataObjectStep<?>> pathArguments,
27 final boolean wildcarded, final int hash) {
28 super(lastStep.type(), pathArguments, wildcarded, hash);
29 this.lastStep = lastStep;
32 @NonNull KeyStep<K, T> lastStep() {
37 * Return the key attached to this identifier. This method is equivalent to calling
38 * {@link InstanceIdentifier#keyOf(InstanceIdentifier)}.
40 * @return Key associated with this instance identifier.
42 public @NonNull K getKey() {
43 return lastStep.key();
47 public KeyedBuilder<T, K> builder() {
48 return new KeyedBuilder<>(this);
52 boolean keyEquals(final InstanceIdentifier<?> other) {
53 return getKey().equals(((KeyedInstanceIdentifier<?, ?>) other).getKey());
57 Object writeReplace() throws ObjectStreamException {
58 return new KIIv4<>(this);