• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.google.dexmaker;
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 
equals(Object o)46     @Override public boolean equals(Object o) {
47         return o instanceof TypeList && Arrays.equals(((TypeList) o).types, types);
48     }
49 
hashCode()50     @Override public int hashCode() {
51         return Arrays.hashCode(types);
52     }
53 
toString()54     @Override public String toString() {
55         StringBuilder result = new StringBuilder();
56         for (int i = 0; i < types.length; i++) {
57             if (i > 0) {
58                 result.append(", ");
59             }
60             result.append(types[i]);
61         }
62         return result.toString();
63     }
64 }
65