1 /* 2 * Copyright (C) 2016 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.signapk; 18 19 /** 20 * Pair of two elements. 21 */ 22 public final class Pair<A, B> { 23 private final A mFirst; 24 private final B mSecond; 25 Pair(A first, B second)26 private Pair(A first, B second) { 27 mFirst = first; 28 mSecond = second; 29 } 30 create(A first, B second)31 public static <A, B> Pair<A, B> create(A first, B second) { 32 return new Pair<A, B>(first, second); 33 } 34 getFirst()35 public A getFirst() { 36 return mFirst; 37 } 38 getSecond()39 public B getSecond() { 40 return mSecond; 41 } 42 43 @Override hashCode()44 public int hashCode() { 45 final int prime = 31; 46 int result = 1; 47 result = prime * result + ((mFirst == null) ? 0 : mFirst.hashCode()); 48 result = prime * result + ((mSecond == null) ? 0 : mSecond.hashCode()); 49 return result; 50 } 51 52 @Override equals(Object obj)53 public boolean equals(Object obj) { 54 if (this == obj) { 55 return true; 56 } 57 if (obj == null) { 58 return false; 59 } 60 if (getClass() != obj.getClass()) { 61 return false; 62 } 63 @SuppressWarnings("rawtypes") 64 Pair other = (Pair) obj; 65 if (mFirst == null) { 66 if (other.mFirst != null) { 67 return false; 68 } 69 } else if (!mFirst.equals(other.mFirst)) { 70 return false; 71 } 72 if (mSecond == null) { 73 if (other.mSecond != null) { 74 return false; 75 } 76 } else if (!mSecond.equals(other.mSecond)) { 77 return false; 78 } 79 return true; 80 } 81 } 82