• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 com.android.class2nonsdklist;
18 
19 import java.util.Objects;
20 
21 class PackageAndClassName{
22     public String packageName;
23     public String className;
24 
PackageAndClassName(String packageName, String className)25     private PackageAndClassName(String packageName, String className) {
26         this.packageName = packageName;
27         this.className = className;
28     }
29 
30     /**
31      * Given a potentially fully qualified class name, split it into package and class.
32      *
33      * @param fullyQualifiedClassName potentially fully qualified class name.
34      * @return A pair of strings, containing the package name (or empty if not specified) and
35      * the
36      * class name (or empty if string is empty).
37      */
splitClassName(String fullyQualifiedClassName)38     public static PackageAndClassName splitClassName(String fullyQualifiedClassName) {
39         int lastDotIdx = fullyQualifiedClassName.lastIndexOf('.');
40         if (lastDotIdx == -1) {
41             return new PackageAndClassName("", fullyQualifiedClassName);
42         }
43         String packageName = fullyQualifiedClassName.substring(0, lastDotIdx);
44         String className = fullyQualifiedClassName.substring(lastDotIdx + 1);
45         return new PackageAndClassName(packageName, className);
46     }
47 
48     @Override
equals(Object obj)49     public boolean equals(Object obj) {
50         if (!(obj instanceof PackageAndClassName)) {
51             return false;
52         }
53         PackageAndClassName other = (PackageAndClassName) obj;
54         return Objects.equals(packageName, other.packageName) && Objects.equals(className,
55                 other.className);
56     }
57 
58     @Override
toString()59     public String toString() {
60         return packageName + "." + className;
61     }
62 
63     @Override
hashCode()64     public int hashCode() {
65         return Objects.hash(packageName, className);
66     }
67 }
68