Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 org.onosproject.yangutils.translator.tojava; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | |
| 21 | import com.google.common.base.MoreObjects; |
| 22 | |
| 23 | /** |
| 24 | * Maintains the information about individual imports in the generated file. |
| 25 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 26 | public class ImportInfo implements Comparable { |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Package location where the imported class/interface is defined. |
| 30 | */ |
| 31 | private String pkgInfo; |
| 32 | |
| 33 | /** |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 34 | * Class/interface being referenced. |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 35 | */ |
| 36 | private String classInfo; |
| 37 | |
| 38 | /** |
| 39 | * Default constructor. |
| 40 | */ |
| 41 | public ImportInfo() { |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Get the imported package info. |
| 46 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 47 | * @return the imported package info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 48 | */ |
| 49 | public String getPkgInfo() { |
| 50 | return pkgInfo; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Set the imported package info. |
| 55 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 56 | * @param pkgInfo the imported package info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 57 | */ |
| 58 | public void setPkgInfo(String pkgInfo) { |
| 59 | this.pkgInfo = pkgInfo; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get the imported class/interface info. |
| 64 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 65 | * @return the imported class/interface info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 66 | */ |
| 67 | public String getClassInfo() { |
| 68 | return classInfo; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Set the imported class/interface info. |
| 73 | * |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 74 | * @param classInfo the imported class/interface info |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 75 | */ |
| 76 | public void setClassInfo(String classInfo) { |
| 77 | this.classInfo = classInfo; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public int hashCode() { |
| 82 | return Objects.hash(pkgInfo, classInfo); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public boolean equals(Object obj) { |
| 87 | if (this == obj) { |
| 88 | return true; |
| 89 | } |
| 90 | if (obj instanceof ImportInfo) { |
| 91 | ImportInfo other = (ImportInfo) obj; |
| 92 | return Objects.equals(pkgInfo, other.pkgInfo) && |
| 93 | Objects.equals(classInfo, other.classInfo); |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * check if the import info matches. |
| 100 | * |
| 101 | * @param importInfo matched import |
| 102 | * @return if equal or not |
| 103 | */ |
| 104 | public boolean exactMatch(ImportInfo importInfo) { |
| 105 | return equals(importInfo) |
| 106 | && Objects.equals(pkgInfo, importInfo.getPkgInfo()) |
| 107 | && Objects.equals(classInfo, importInfo.getClassInfo()); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public String toString() { |
| 112 | return MoreObjects.toStringHelper(getClass()) |
| 113 | .add("pkgInfo", pkgInfo) |
| 114 | .add("classInfo", classInfo).toString(); |
| 115 | } |
| 116 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 117 | /** |
| 118 | * Check that there is no 2 objects with the same class name. |
| 119 | * |
| 120 | * @param o compared import info. |
| 121 | */ |
| 122 | @Override |
| 123 | public int compareTo(Object o) { |
| 124 | ImportInfo other; |
| 125 | if (o instanceof ImportInfo) { |
| 126 | other = (ImportInfo) o; |
| 127 | } else { |
| 128 | return -1; |
| 129 | } |
| 130 | return getClassInfo().compareTo(other.getClassInfo()); |
| 131 | } |
| 132 | |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 133 | } |