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 * @since 3.2
034 */
035public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
036
037    /** Serialization version */
038    private static final long serialVersionUID = 1L;
039
040    /** Left object */
041    public final L left;
042    /** Middle object */
043    public final M middle;
044    /** Right object */
045    public final R right;
046
047    /**
048     * <p>Obtains an immutable triple of from three objects inferring the generic types.</p>
049     * 
050     * <p>This factory allows the triple to be created using inference to
051     * obtain the generic types.</p>
052     * 
053     * @param <L> the left element type
054     * @param <M> the middle element type
055     * @param <R> the right element type
056     * @param left  the left element, may be null
057     * @param middle  the middle element, may be null
058     * @param right  the right element, may be null
059     * @return a triple formed from the three parameters, not null
060     */
061    public static <L, M, R> ImmutableTriple<L, M, R> of(final L left, final M middle, final R right) {
062        return new ImmutableTriple<L, M, R>(left, middle, right);
063    }
064
065    /**
066     * Create a new triple instance.
067     *
068     * @param left  the left value, may be null
069     * @param middle the middle value, may be null
070     * @param right  the right value, may be null
071     */
072    public ImmutableTriple(final L left, final M middle, final R right) {
073        super();
074        this.left = left;
075        this.middle = middle;
076        this.right = right;
077    }
078
079    //-----------------------------------------------------------------------
080    /**
081     * {@inheritDoc}
082     */
083    @Override
084    public L getLeft() {
085        return left;
086    }
087
088    /**
089     * {@inheritDoc}
090     */
091    @Override
092    public M getMiddle() {
093        return middle;
094    }
095
096    /**
097     * {@inheritDoc}
098     */
099    @Override
100    public R getRight() {
101        return right;
102    }
103}
104