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>A mutable triple consisting of three {@code Object} elements.</p>
021 *
022 * <p>Not #ThreadSafe#</p>
023 *
024 * @param <L> the left element type
025 * @param <M> the middle element type
026 * @param <R> the right element type
027 *
028 * @since 3.2
029 */
030public class MutableTriple<L, M, R> extends Triple<L, M, R> {
031
032    /** Serialization version */
033    private static final long serialVersionUID = 1L;
034
035    /** Left object */
036    public L left;
037    /** Middle object */
038    public M middle;
039    /** Right object */
040    public R right;
041
042    /**
043     * <p>Obtains an mutable triple of three objects inferring the generic types.</p>
044     *
045     * <p>This factory allows the triple to be created using inference to
046     * obtain the generic types.</p>
047     *
048     * @param <L> the left element type
049     * @param <M> the middle element type
050     * @param <R> the right element type
051     * @param left  the left element, may be null
052     * @param middle  the middle element, may be null
053     * @param right  the right element, may be null
054     * @return a triple formed from the three parameters, not null
055     */
056    public static <L, M, R> MutableTriple<L, M, R> of(final L left, final M middle, final R right) {
057        return new MutableTriple<>(left, middle, right);
058    }
059
060    /**
061     * Create a new triple instance of three nulls.
062     */
063    public MutableTriple() {
064        super();
065    }
066
067    /**
068     * Create a new triple instance.
069     *
070     * @param left  the left value, may be null
071     * @param middle  the middle value, may be null
072     * @param right  the right value, may be null
073     */
074    public MutableTriple(final L left, final M middle, final R right) {
075        super();
076        this.left = left;
077        this.middle = middle;
078        this.right = right;
079    }
080
081    //-----------------------------------------------------------------------
082    /**
083     * {@inheritDoc}
084     */
085    @Override
086    public L getLeft() {
087        return left;
088    }
089
090    /**
091     * Sets the left element of the triple.
092     *
093     * @param left  the new value of the left element, may be null
094     */
095    public void setLeft(final L left) {
096        this.left = left;
097    }
098
099    /**
100     * {@inheritDoc}
101     */
102    @Override
103    public M getMiddle() {
104        return middle;
105    }
106
107    /**
108     * Sets the middle element of the triple.
109     *
110     * @param middle  the new value of the middle element, may be null
111     */
112    public void setMiddle(final M middle) {
113        this.middle = middle;
114    }
115
116    /**
117     * {@inheritDoc}
118     */
119    @Override
120    public R getRight() {
121        return right;
122    }
123
124    /**
125     * Sets the right element of the triple.
126     *
127     * @param right  the new value of the right element, may be null
128     */
129    public void setRight(final R right) {
130        this.right = right;
131    }
132}
133