001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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.apache.commons.lang3.tuple; 018 019/** 020 * <p>An immutable triple consisting of three {@code Object} elements.</p> 021 * 022 * <p>Although the implementation is immutable, there is no restriction on the objects 023 * that may be stored. If mutable objects are stored in the triple, then the triple 024 * itself effectively becomes mutable. The class is also {@code final}, so a subclass 025 * can not add undesirable behaviour.</p> 026 * 027 * <p>#ThreadSafe# if all three objects are thread-safe</p> 028 * 029 * @param <L> the left element type 030 * @param <M> the middle element type 031 * @param <R> the right element type 032 * 033 * @version $Id: ImmutableTriple.java 1592817 2014-05-06 17:57:38Z britter $ 034 * @since 3.2 035 */ 036public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> { 037 038 /** Serialization version */ 039 private static final long serialVersionUID = 1L; 040 041 /** Left object */ 042 public final L left; 043 /** Middle object */ 044 public final M middle; 045 /** Right object */ 046 public final R right; 047 048 /** 049 * <p>Obtains an immutable triple of from three objects inferring the generic types.</p> 050 * 051 * <p>This factory allows the triple to be created using inference to 052 * obtain the generic types.</p> 053 * 054 * @param <L> the left element type 055 * @param <M> the middle element type 056 * @param <R> the right element type 057 * @param left the left element, may be null 058 * @param middle the middle element, may be null 059 * @param right the right element, may be null 060 * @return a triple formed from the three parameters, not null 061 */ 062 public static <L, M, R> ImmutableTriple<L, M, R> of(final L left, final M middle, final R right) { 063 return new ImmutableTriple<L, M, R>(left, middle, right); 064 } 065 066 /** 067 * Create a new triple instance. 068 * 069 * @param left the left value, may be null 070 * @param middle the middle value, may be null 071 * @param right the right value, may be null 072 */ 073 public ImmutableTriple(final L left, final M middle, final R right) { 074 super(); 075 this.left = left; 076 this.middle = middle; 077 this.right = right; 078 } 079 080 //----------------------------------------------------------------------- 081 /** 082 * {@inheritDoc} 083 */ 084 @Override 085 public L getLeft() { 086 return left; 087 } 088 089 /** 090 * {@inheritDoc} 091 */ 092 @Override 093 public M getMiddle() { 094 return middle; 095 } 096 097 /** 098 * {@inheritDoc} 099 */ 100 @Override 101 public R getRight() { 102 return right; 103 } 104} 105