TypeList.java revision 579d7739c53a2707ad711a2d2cae46d7d782f061
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
17package com.google.dexmaker;
18
19import com.android.dx.rop.type.StdTypeList;
20import java.util.Arrays;
21import java.util.Collections;
22import java.util.List;
23
24/**
25 * An immutable of types.
26 */
27final class TypeList {
28    final Type<?>[] types;
29    final StdTypeList ropTypes;
30
31    TypeList(Type<?>[] 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     */
42    public List<Type<?>> asList() {
43        return Collections.unmodifiableList(Arrays.asList(types));
44    }
45
46    @Override public boolean equals(Object o) {
47        return o instanceof TypeList && Arrays.equals(((TypeList) o).types, types);
48    }
49
50    @Override public int hashCode() {
51        return Arrays.hashCode(types);
52    }
53
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