1 /* 2 * Copyright (C) 2009 The Android Open Source Project 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 signature.model.impl; 18 19 import signature.model.ITypeReference; 20 import signature.model.IWildcardType; 21 22 import java.io.Serializable; 23 import java.util.List; 24 25 @SuppressWarnings("serial") 26 public class SigWildcardType implements IWildcardType, Serializable { 27 28 private ITypeReference lowerBound; 29 private List<ITypeReference> upperBounds; 30 31 public SigWildcardType(ITypeReference lowerBound, 32 List<ITypeReference> upperBounds) { 33 this.lowerBound = lowerBound; 34 this.upperBounds = upperBounds; 35 } 36 37 public ITypeReference getLowerBound() { 38 return lowerBound; 39 } 40 41 public List<ITypeReference> getUpperBounds() { 42 return upperBounds; 43 } 44 45 @Override 46 public int hashCode() { 47 return SigWildcardType.hashCode(this); 48 } 49 50 public static int hashCode(IWildcardType type) { 51 final int prime = 31; 52 int result = 1; 53 result = prime 54 + ((type.getLowerBound() == null) ? 0 : type.getLowerBound() 55 .hashCode()); 56 result = prime * result + type.getUpperBounds().hashCode(); 57 return result; 58 } 59 60 @Override 61 public boolean equals(Object obj) { 62 return SigWildcardType.equals(this, obj); 63 } 64 65 public static boolean equals(IWildcardType thiz, Object obj) { 66 if (thiz == obj) return true; 67 if (obj == null) return false; 68 if (!(obj instanceof IWildcardType)) return false; 69 IWildcardType that = (IWildcardType) obj; 70 if (thiz.getLowerBound() == null) { 71 if (that.getLowerBound() != null) return false; 72 } else if (!thiz.getLowerBound().equals(that.getLowerBound())) 73 return false; 74 if (!thiz.getUpperBounds().equals(that.getUpperBounds())) return false; 75 return true; 76 } 77 78 79 @Override 80 public String toString() { 81 return SigWildcardType.toString(this); 82 } 83 84 public static String toString(IWildcardType thiz) { 85 StringBuilder builder = new StringBuilder(); 86 builder.append("?"); 87 if (thiz.getLowerBound() != null) { 88 builder.append(" "); 89 builder.append(" super "); 90 builder.append(thiz.getLowerBound()); 91 } 92 if (!thiz.getUpperBounds().isEmpty()) { 93 builder.append(" extends "); 94 builder.append(thiz.getUpperBounds()); 95 } 96 return builder.toString(); 97 } 98 } 99