001package com.fs.starfarer.api.util; 002 003 004/** 005 * Simple container class for a pair of items. Has valid hashCode() and equals() methods. 006 * 007 * A pair is equal to another pair if each of the item .equals() their counterpart. 008 * 009 * @author Alexander Mosolov 010 * 011 */ 012public class Pair<A, B> { 013 public A one; 014 public B two; 015 016 public Pair() {} 017 018 public Pair(A one, B two) { 019 super(); 020 this.one = one; 021 this.two = two; 022 } 023 024 @Override 025 public int hashCode() { 026 final int PRIME = 31; 027 int result = 1; 028 result = PRIME * result + ((one == null) ? 0 : one.hashCode()); 029 result = PRIME * result + ((two == null) ? 0 : two.hashCode()); 030 return result; 031 } 032 @SuppressWarnings("unchecked") 033 @Override 034 public boolean equals(Object obj) { 035 if (this == obj) 036 return true; 037 if (obj == null) 038 return false; 039 if (getClass() != obj.getClass()) 040 return false; 041 final Pair other = (Pair) obj; 042 if (one == null) { 043 if (other.one != null) 044 return false; 045 } else if (!one.equals(other.one)) 046 return false; 047 if (two == null) { 048 if (other.two != null) 049 return false; 050 } else if (!two.equals(other.two)) 051 return false; 052 return true; 053 } 054}