1 /* 2 * Copyright (C) 2006 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.inject.name; 18 19 import static com.google.common.base.Preconditions.checkNotNull; 20 21 import com.google.inject.internal.Annotations; 22 import java.io.Serializable; 23 import java.lang.annotation.Annotation; 24 25 class NamedImpl implements Named, Serializable { 26 27 private final String value; 28 NamedImpl(String value)29 public NamedImpl(String value) { 30 this.value = checkNotNull(value, "name"); 31 } 32 33 @Override value()34 public String value() { 35 return this.value; 36 } 37 38 @Override hashCode()39 public int hashCode() { 40 // This is specified in java.lang.Annotation. 41 return (127 * "value".hashCode()) ^ value.hashCode(); 42 } 43 44 @Override equals(Object o)45 public boolean equals(Object o) { 46 if (!(o instanceof Named)) { 47 return false; 48 } 49 50 Named other = (Named) o; 51 return value.equals(other.value()); 52 } 53 54 @Override toString()55 public String toString() { 56 return "@" + Named.class.getName() + "(value=" + Annotations.memberValueString(value) + ")"; 57 } 58 59 @Override annotationType()60 public Class<? extends Annotation> annotationType() { 61 return Named.class; 62 } 63 64 private static final long serialVersionUID = 0; 65 } 66