Debian Codegraph @

layoutlib-api/src/main/java/com/android/util/Pair.java

raw
1 /*
2 * Copyright (C) 2010 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.util;
18
19 /**
20 * A Pair class is simply a 2-tuple for use in this package. We might want to
21 * think about adding something like this to a more central utility place, or
22 * replace it by a common tuple class if one exists, or even rewrite the layout
23 * classes using this Pair by a more dedicated data structure (so we don't have
24 * to pass around generic signatures as is currently done, though at least the
25 * construction is helped a bit by the {@link #of} factory method.
26 *
27 * =================================================================================================
28 * WARNING
29 * This copy of the class is to be used only by layoutlib and is not to be changed, EVER.
30 * To use Pair outside of layoutlib, use com.android.utils.Pair, found in common.jar instead.
31 * =================================================================================================
32 *
33 * @param <S> The type of the first value
34 * @param <T> The type of the second value
35 *
36 * @deprecated This is used for backward compatibility with layoutlib-api. Use com.android.utils.Pair instead
37 */
38 @Deprecated
39 public class Pair<S,T> {
40 private final S mFirst;
41 private final T mSecond;
42
43 // Use {@link Pair#of} factory instead since it infers generic types
44 private Pair(S first, T second) {
45 this.mFirst = first;
46 this.mSecond = second;
47 }
48
49 /**
50 * Return the first item in the pair
51 *
52 * @return the first item in the pair
53 */
54 public S getFirst() {
55 return mFirst;
56 }
57
58 /**
59 * Return the second item in the pair
60 *
61 * @return the second item in the pair
62 */
63 public T getSecond() {
64 return mSecond;
65 }
66
67 /**
68 * Constructs a new pair of the given two objects, inferring generic types.
69 *
70 * @param first the first item to store in the pair
71 * @param second the second item to store in the pair
72 * @param <S> the type of the first item
73 * @param <T> the type of the second item
74 * @return a new pair wrapping the two items
75 */
76 public static <S,T> Pair<S,T> of(S first, T second) {
77 return new Pair<S,T>(first,second);
78 }
79
80 @Override
81 public String toString() {
82 return "Pair [first=" + mFirst + ", second=" + mSecond + "]";
83 }
84
85 @Override
86 public int hashCode() {
87 final int prime = 31;
88 int result = 1;
89 result = prime * result + ((mFirst == null) ? 0 : mFirst.hashCode());
90 result = prime * result + ((mSecond == null) ? 0 : mSecond.hashCode());
91 return result;
92 }
93
94 @SuppressWarnings("unchecked")
95 @Override
96 public boolean equals(Object obj) {
97 if (this == obj)
98 return true;
99 if (obj == null)
100 return false;
101 if (getClass() != obj.getClass())
102 return false;
103 Pair other = (Pair) obj;
104 if (mFirst == null) {
105 if (other.mFirst != null)
106 return false;
107 } else if (!mFirst.equals(other.mFirst))
108 return false;
109 if (mSecond == null) {
110 if (other.mSecond != null)
111 return false;
112 } else if (!mSecond.equals(other.mSecond))
113 return false;
114 return true;
115 }
116 }