001/* 002 * nimbus-jose-jwt 003 * 004 * Copyright 2012-2021, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.jose.util; 019 020 021import net.jcip.annotations.Immutable; 022 023 024/** 025 * A pair of two objects. 026 * 027 * <p>This class is immutable. 028 * 029 * @param <L> the left object type. 030 * @param <R> the right object type 031 * @author Alexander Martynov 032 * @version 2021-09-30 033 */ 034@Immutable 035public class Pair<L, R> { 036 037 038 private final L left; 039 040 041 private final R right; 042 043 044 protected Pair(final L left, final R right) { 045 this.left = left; 046 this.right = right; 047 } 048 049 050 /** 051 * Creates a new pair of two objects. 052 * 053 * @param left The left object, {@code null} if not specified. 054 * @param right The right object, {@code null} if not specified. 055 * 056 * @return The pair. 057 */ 058 public static <L, R> Pair<L, R> of(final L left, final R right) { 059 return new Pair<>(left, right); 060 } 061 062 063 /** 064 * Returns the left object of this pair. 065 * 066 * @return The left object, {@code null} if not specified. 067 */ 068 public L getLeft() { 069 return left; 070 } 071 072 073 /** 074 * Returns the right object of this pair. 075 * 076 * @return The right object, {@code null} if not specified. 077 */ 078 public R getRight() { 079 return right; 080 } 081}