blob: 2cf76afa1d948f92940d76fe288f1ddd52caaa22 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import java.util.Collections;
Paul Duffin8c5a24d2017-05-10 13:30:16 +010020import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import java.util.Set;
22
23/**
24 * The Package object doesn't allow you to iterate over the contained
25 * classes and subpackages of that package. This is a version that does.
Stephan Linznerb51617f2016-01-27 18:09:50 -080026 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027 * {@hide} Not needed for 1.0 SDK.
28 */
Stephan Linznerb51617f2016-01-27 18:09:50 -080029@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030public class ClassPathPackageInfo {
31
32 private final ClassPathPackageInfoSource source;
33 private final String packageName;
34 private final Set<String> subpackageNames;
35 private final Set<Class<?>> topLevelClasses;
36
37 ClassPathPackageInfo(ClassPathPackageInfoSource source, String packageName,
38 Set<String> subpackageNames, Set<Class<?>> topLevelClasses) {
39 this.source = source;
40 this.packageName = packageName;
41 this.subpackageNames = Collections.unmodifiableSet(subpackageNames);
42 this.topLevelClasses = Collections.unmodifiableSet(topLevelClasses);
43 }
44
45 public Set<ClassPathPackageInfo> getSubpackages() {
Paul Duffin8c5a24d2017-05-10 13:30:16 +010046 Set<ClassPathPackageInfo> info = new HashSet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 for (String name : subpackageNames) {
48 info.add(source.getPackageInfo(name));
49 }
50 return info;
51 }
52
53 public Set<Class<?>> getTopLevelClassesRecursive() {
Paul Duffin8c5a24d2017-05-10 13:30:16 +010054 Set<Class<?>> set = new HashSet<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 addTopLevelClassesTo(set);
56 return set;
57 }
58
59 private void addTopLevelClassesTo(Set<Class<?>> set) {
60 set.addAll(topLevelClasses);
61 for (ClassPathPackageInfo info : getSubpackages()) {
62 info.addTopLevelClassesTo(set);
63 }
64 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (obj instanceof ClassPathPackageInfo) {
69 ClassPathPackageInfo that = (ClassPathPackageInfo) obj;
70 return (this.packageName).equals(that.packageName);
71 }
72 return false;
73 }
74
75 @Override
76 public int hashCode() {
77 return packageName.hashCode();
78 }
79}