2 * Copyright (c) 2017 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
9 package org.opendaylight.mdsal.binding2.spec.base;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
15 * An IdentifiableItem represents a object that is usually present in a collection and can be
16 * identified uniquely by a key. In YANG terms this would probably represent an item in a list.
18 * @param <I> An object that is identifiable by an identifier
19 * @param <T> The identifier of the object
22 public final class IdentifiableItem<I extends TreeNode, T> extends TreeArgument<I> {
23 private final Class<I> type;
26 public IdentifiableItem(final Class<I> type, final T key) {
27 this.type = Preconditions.checkNotNull(type);
28 this.key = Preconditions.checkNotNull(key, "Key may not be null.");
32 public Class<I> getType() {
41 public boolean equals(final Object obj) {
42 return super.equals(obj) && key.equals(((IdentifiableItem<?, ?>) obj).getKey());
46 public int hashCode() {
47 return super.hashCode() * 31 + key.hashCode();
51 public String toString() {
52 return type.getName() + "[key=" + key + "]";