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.binding.javav2.spec.base;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
16 * An IdentifiableItem represents a object that is usually present in a collection and can be
17 * identified uniquely by a key. In YANG terms this would probably represent an item in a list.
19 * @param <I> An object that is identifiable by an identifier
20 * @param <T> The identifier of the object
23 public final class IdentifiableItem<I extends TreeNode, T> extends TreeArgument<I> {
24 private final Class<I> type;
27 public IdentifiableItem(final Class<I> type, final T key) {
28 this.type = requireNonNull(type);
29 this.key = requireNonNull(key, "Key may not be null.");
33 public Class<I> getType() {
42 public boolean equals(final Object obj) {
43 return super.equals(obj) && key.equals(((IdentifiableItem<?, ?>) obj).getKey());
47 public int hashCode() {
48 return super.hashCode() * 31 + key.hashCode();
52 public String toString() {
53 return type.getName() + "[key=" + key + "]";