2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.harmony.luni.lang.reflect;
19 import java.lang.reflect.Type;
20 import java.util.ArrayList;
21 import java.util.List;
23 public final class ListOfTypes {
24 public static final ListOfTypes EMPTY = new ListOfTypes(0);
26 private final ArrayList<Type> types;
27 private Type[] resolvedTypes;
29 ListOfTypes(int capacity) {
30 types = new ArrayList<Type>(capacity);
33 ListOfTypes(Type[] types) {
34 this.types = new ArrayList<Type>(types.length);
35 for (Type type : types) {
42 throw new NullPointerException("type == null");
51 public Type[] getResolvedTypes() {
52 Type[] result = resolvedTypes;
53 return result != null ? result : (resolvedTypes = resolveTypes(types));
56 private Type[] resolveTypes(List<Type> unresolved) {
57 Type[] result = new Type[unresolved.size()];
58 for (int i = 0; i < unresolved.size(); i++) {
59 Type type = unresolved.get(i);
61 result[i] = ((ImplForType) type).getResolvedType();
62 } catch (ClassCastException e) {
69 @Override public String toString() {
70 StringBuilder result = new StringBuilder();
71 for (int i = 0; i < types.size(); i++) {
75 result.append(types.get(i));
77 return result.toString();