blob: 1ab7c7faeca4772e5bb160104caa4857c0c25291 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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 android.test;
18
19import com.google.android.collect.Sets;
20
21import java.util.Collections;
22import java.util.Set;
23
24/**
25 * The Package object doesn't allow you to iterate over the contained
26 * classes and subpackages of that package. This is a version that does.
Stephan Linznerd46a7d02016-01-22 15:49:47 -080027 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028 * {@hide} Not needed for 1.0 SDK.
29 */
Stephan Linznerd46a7d02016-01-22 15:49:47 -080030@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031public class ClassPathPackageInfo {
32
33 private final ClassPathPackageInfoSource source;
34 private final String packageName;
35 private final Set<String> subpackageNames;
36 private final Set<Class<?>> topLevelClasses;
37
38 ClassPathPackageInfo(ClassPathPackageInfoSource source, String packageName,
39 Set<String> subpackageNames, Set<Class<?>> topLevelClasses) {
40 this.source = source;
41 this.packageName = packageName;
42 this.subpackageNames = Collections.unmodifiableSet(subpackageNames);
43 this.topLevelClasses = Collections.unmodifiableSet(topLevelClasses);
44 }
45
46 public Set<ClassPathPackageInfo> getSubpackages() {
47 Set<ClassPathPackageInfo> info = Sets.newHashSet();
48 for (String name : subpackageNames) {
49 info.add(source.getPackageInfo(name));
50 }
51 return info;
52 }
53
54 public Set<Class<?>> getTopLevelClassesRecursive() {
55 Set<Class<?>> set = Sets.newHashSet();
56 addTopLevelClassesTo(set);
57 return set;
58 }
59
60 private void addTopLevelClassesTo(Set<Class<?>> set) {
61 set.addAll(topLevelClasses);
62 for (ClassPathPackageInfo info : getSubpackages()) {
63 info.addTopLevelClassesTo(set);
64 }
65 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (obj instanceof ClassPathPackageInfo) {
70 ClassPathPackageInfo that = (ClassPathPackageInfo) obj;
71 return (this.packageName).equals(that.packageName);
72 }
73 return false;
74 }
75
76 @Override
77 public int hashCode() {
78 return packageName.hashCode();
79 }
80}