001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Martin Pernollet 018 */ 019 020package org.nuxeo.ecm.platform.groups.audit.service.acl; 021 022import java.io.Serializable; 023 024/** 025 * Class Pair. Represents a mathematical pair of objects (a, b). 026 */ 027public class Pair<X, Y> implements Serializable { 028 private static final long serialVersionUID = 4246736946032440512L; 029 030 /** 031 * a in the pair (a, b) 032 */ 033 public final X a; 034 035 /** 036 * b in the pair (a, b) 037 */ 038 public final Y b; 039 040 /** 041 * Construct a Pair(a, b) 042 * 043 * @param a a in the pair (a, b) 044 * @param b b in the pair (a, b) 045 */ 046 public Pair(X a, Y b) { 047 this.a = a; 048 this.b = b; 049 } 050 051 @Override 052 public int hashCode() { 053 final int prime = 31; 054 int result = 1; 055 result = prime * result + ((a == null) ? 0 : a.hashCode()); 056 result = prime * result + ((b == null) ? 0 : b.hashCode()); 057 return result; 058 } 059 060 @Override 061 public boolean equals(Object obj) { 062 if (this == obj) 063 return true; 064 if (obj == null) 065 return false; 066 if (getClass() != obj.getClass()) 067 return false; 068 @SuppressWarnings("rawtypes") 069 Pair other = (Pair) obj; 070 if (a == null) { 071 if (other.a != null) 072 return false; 073 } else if (!a.equals(other.a)) 074 return false; 075 if (b == null) { 076 if (other.b != null) 077 return false; 078 } else if (!b.equals(other.b)) 079 return false; 080 return true; 081 } 082 083 public static <M, N> Pair<M, N> of(M x, N y) { 084 return new Pair<M, N>(x, y); 085 } 086}