001/** 002 * 003 * Copyright 2020-2024 Florian Schmaus. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack.util; 018 019public final class Pair<F, S> { 020 021 private final F first; 022 private final S second; 023 024 private Pair(F first, S second) { 025 this.first = first; 026 this.second = second; 027 } 028 029 public static <F, S> Pair<F, S> create(F first, S second) { 030 return new Pair<>(first, second); 031 } 032 033 @SuppressWarnings("ReturnValueIgnored") 034 public static <F, S> Pair<F, S> createAndInitHashCode(F first, S second) { 035 Pair<F, S> pair = new Pair<>(first, second); 036 pair.hashCode(); 037 return pair; 038 } 039 040 public F getFirst() { 041 return first; 042 } 043 044 public S getSecond() { 045 return second; 046 } 047 048 private final HashCode.Cache hashCodeCache = new HashCode.Cache(); 049 050 @Override 051 public int hashCode() { 052 return hashCodeCache.getHashCode(c -> 053 c.append(first) 054 .append(second) 055 ); 056 } 057 058 @Override 059 public boolean equals(Object object) { 060 return EqualsUtil.equals(this, object, (e, o) -> 061 e.append(first, o.first) 062 .append(second, o.second) 063 ); 064 } 065}