1 /* 2 * Copyright (C) 2011 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 com.android.dx; 18 19 import com.android.dx.rop.type.StdTypeList; 20 import java.util.Arrays; 21 import java.util.Collections; 22 import java.util.List; 23 24 /** 25 * An immutable of types. 26 */ 27 final class TypeList { 28 final TypeId<?>[] types; 29 final StdTypeList ropTypes; 30 TypeList(TypeId<?>[] types)31 TypeList(TypeId<?>[] types) { 32 this.types = types.clone(); 33 this.ropTypes = new StdTypeList(types.length); 34 for (int i = 0; i < types.length; i++) { 35 ropTypes.set(i, types[i].ropType); 36 } 37 } 38 39 /** 40 * Returns an immutable list. 41 */ asList()42 public List<TypeId<?>> asList() { 43 return Collections.unmodifiableList(Arrays.asList(types)); 44 } 45 46 @Override equals(Object o)47 public boolean equals(Object o) { 48 return o instanceof TypeList && Arrays.equals(((TypeList) o).types, types); 49 } 50 51 @Override hashCode()52 public int hashCode() { 53 return Arrays.hashCode(types); 54 } 55 56 @Override toString()57 public String toString() { 58 StringBuilder result = new StringBuilder(); 59 for (int i = 0; i < types.length; i++) { 60 if (i > 0) { 61 result.append(", "); 62 } 63 result.append(types[i]); 64 } 65 return result.toString(); 66 } 67 } 68