Home | History | Annotate | Download | only in name
      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 java.io.Serializable;
     22 import java.lang.annotation.Annotation;
     23 
     24 class NamedImpl implements Named, Serializable {
     25 
     26   private final String value;
     27 
     28   public NamedImpl(String value) {
     29     this.value = checkNotNull(value, "name");
     30   }
     31 
     32   public String value() {
     33     return this.value;
     34   }
     35 
     36   public int hashCode() {
     37     // This is specified in java.lang.Annotation.
     38     return (127 * "value".hashCode()) ^ value.hashCode();
     39   }
     40 
     41   public boolean equals(Object o) {
     42     if (!(o instanceof Named)) {
     43       return false;
     44     }
     45 
     46     Named other = (Named) o;
     47     return value.equals(other.value());
     48   }
     49 
     50   public String toString() {
     51     return "@" + Named.class.getName() + "(value=" + value + ")";
     52   }
     53 
     54   public Class<? extends Annotation> annotationType() {
     55     return Named.class;
     56   }
     57 
     58   private static final long serialVersionUID = 0;
     59 }
     60