1 /* 2 * Copyright (C) 2015 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 package dagger.producers.monitoring; 17 18 import dagger.producers.Produces; 19 20 import static com.google.common.base.Preconditions.checkNotNull; 21 22 /** A token that represents an individual {@linkplain Produces producer method}. */ 23 public final class ProducerToken { 24 private final Class<?> classToken; 25 26 private ProducerToken(Class<?> classToken) { 27 this.classToken = classToken; 28 } 29 30 /** 31 * Creates a token for a class token that represents the generated factory for a producer method. 32 * 33 * <p><b>Do not use this!</b> This is intended to be called by generated code only, and its 34 * signature may change at any time. 35 */ 36 public static ProducerToken create(Class<?> classToken) { 37 return new ProducerToken(checkNotNull(classToken)); 38 } 39 40 /** Two tokens are equal if they represent the same method. */ 41 @Override 42 public boolean equals(Object o) { 43 if (o == this) { 44 return true; 45 } else if (o instanceof ProducerToken) { 46 ProducerToken that = (ProducerToken) o; 47 return this.classToken.equals(that.classToken); 48 } else { 49 return false; 50 } 51 } 52 53 /** Returns an appropriate hash code to match {@link #equals). */ 54 @Override 55 public int hashCode() { 56 return classToken.hashCode(); 57 } 58 59 /** Returns a representation of the method. */ 60 @Override 61 public String toString() { 62 return classToken.toString(); 63 } 64 } 65