Home | History | Annotate | Download | only in test
      1 /*
      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 
     17 package android.test;
     18 
     19 import com.google.android.collect.Sets;
     20 
     21 import java.util.Collections;
     22 import 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.
     27  *
     28  * {@hide} Not needed for 1.0 SDK.
     29  */
     30 @Deprecated
     31 public 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 }
     81