01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.lang.reflect.implementation;
19:
20: import java.lang.reflect.GenericArrayType;
21: import java.lang.reflect.Type;
22:
23: /**
24: * @author Serguei S. Zapreyev
25: * @version $Revision: 1.1.2.2 $
26: */
27: public final class GenericArrayTypeImpl implements GenericArrayType {
28: private final Type nextLayer;
29:
30: public GenericArrayTypeImpl(Type nextLayer) {
31: this .nextLayer = nextLayer;
32: }
33:
34: public boolean equals(Object other) {
35: //return super.equals(other);
36: if (!(other instanceof GenericArrayTypeImpl)) {
37: return false;
38: }
39: Type next = nextLayer;
40: Type next2 = ((GenericArrayTypeImpl) other).nextLayer;
41: while (next instanceof GenericArrayTypeImpl
42: && next2 instanceof GenericArrayTypeImpl) {
43: if (!next.equals(next2)) {
44: return false;
45: }
46: next = ((GenericArrayTypeImpl) next).nextLayer;
47: next2 = ((GenericArrayTypeImpl) next2).nextLayer;
48: }
49: if (next.getClass().isInstance(next2)) {
50: return next.equals(next2);
51: }
52: return false;
53: }
54:
55: public Type getGenericComponentType() {
56: return nextLayer;
57: }
58:
59: public int hashCode() {
60: //return super.hashCode();
61: int res = 0;
62: Type next = nextLayer;
63: while (next instanceof GenericArrayType) {
64: res += 1;
65: next = ((GenericArrayTypeImpl) next).nextLayer;
66: }
67: return res ^ next.hashCode();
68: }
69:
70: public String toString() {
71: // TODO: this body should be reimplemented effectively.
72: StringBuffer sb = new StringBuffer();
73: if (nextLayer instanceof GenericArrayType) {
74: sb.append(getGenericComponentType().toString());
75: } else {
76: if (nextLayer instanceof Class) {
77: sb.append(((Class) nextLayer).getName());
78: } else {
79: sb.append(nextLayer.toString());
80: }
81: }
82: sb.append("[]");
83: return sb.toString();
84: }
85: }
|