• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 /*
3  * Copyright (C) 2010 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package tests.util;
18 /**
19  * Pair of typed values.
20  *
21  * <p>Pairs are obtained using {@link #of(Object, Object) of}.
22  *
23  * @param <F> type of the first value.
24  * @param <S> type of the second value.
25  * @hide This class is not part of the Android public SDK API
26  */
27 public class Pair<F, S> {
28     private final F mFirst;
29     private final S mSecond;
Pair(F first, S second)30     private Pair(F first, S second) {
31         mFirst = first;
32         mSecond = second;
33     }
34     /**
35      * Gets the pair consisting of the two provided values.
36      *
37      * @param first first value or {@code null}.
38      * @param second second value or {@code null}.
39      */
of(F first, S second)40     public static <F, S> Pair<F, S> of(F first, S second) {
41         return new Pair<F, S>(first, second);
42     }
43     /**
44      * Gets the first value from this pair.
45      *
46      * @return value or {@code null}.
47      */
getFirst()48     public F getFirst() {
49         return mFirst;
50     }
51     /**
52      * Gets the second value from this pair.
53      *
54      * @return value or {@code null}.
55      */
getSecond()56     public S getSecond() {
57         return mSecond;
58     }
59     @Override
toString()60     public String toString() {
61         return "Pair[" + mFirst + ", " + mSecond + "]";
62     }
63     @Override
hashCode()64     public int hashCode() {
65         final int prime = 31;
66         int result = 1;
67         result = prime * result + ((mFirst == null) ? 0 : mFirst.hashCode());
68         result = prime * result + ((mSecond == null) ? 0 : mSecond.hashCode());
69         return result;
70     }
71     @Override
equals(Object obj)72     public boolean equals(Object obj) {
73         if (this == obj) {
74             return true;
75         }
76         if (obj == null) {
77             return false;
78         }
79         if (!(obj instanceof Pair)) {
80             return false;
81         }
82         @SuppressWarnings("rawtypes")
83         Pair other = (Pair) obj;
84         if (mFirst == null) {
85             if (other.mFirst != null) {
86                 return false;
87             }
88         } else if (!mFirst.equals(other.mFirst)) {
89             return false;
90         }
91         if (mSecond == null) {
92             if (other.mSecond != null) {
93                 return false;
94             }
95         } else if (!mSecond.equals(other.mSecond)) {
96             return false;
97         }
98         return true;
99     }
100 }
101