2 * Copyright (c) 2016 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.util;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.yangtools.concepts.Identifier;
16 * Utility {@link Identifier} backed by a {@link String}.
19 public final class StringIdentifier implements Identifier, Comparable<StringIdentifier> {
20 private static final long serialVersionUID = 1L;
21 private final String string;
23 public StringIdentifier(final String string) {
24 this.string = Preconditions.checkNotNull(string);
27 public String getString() {
32 public int hashCode() {
33 return string.hashCode();
37 public boolean equals(final Object o) {
38 return this == o || (o instanceof StringIdentifier && string.equals(((StringIdentifier)o).string));
42 public String toString() {
43 return MoreObjects.toStringHelper(StringIdentifier.class).add("string", string).toString();
47 public int compareTo(final StringIdentifier o) {
48 return string.compareTo(o.string);