View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.lang3.tuple;
18  
19  /**
20   * <p>A mutable triple consisting of three {@code Object} elements.</p>
21   *
22   * <p>Not #ThreadSafe#</p>
23   *
24   * @param <L> the left element type
25   * @param <M> the middle element type
26   * @param <R> the right element type
27   *
28   * @version $Id: MutableTriple.java 1552635 2013-12-20 13:02:03Z britter $
29   * @since 3.2
30   */
31  public class MutableTriple<L, M, R> extends Triple<L, M, R> {
32  
33      /** Serialization version */
34      private static final long serialVersionUID = 1L;
35  
36      /** Left object */
37      public L left;
38      /** Middle object */
39      public M middle;
40      /** Right object */
41      public R right;
42  
43      /**
44       * <p>Obtains an mutable triple of three objects inferring the generic types.</p>
45       *
46       * <p>This factory allows the triple to be created using inference to
47       * obtain the generic types.</p>
48       *
49       * @param <L> the left element type
50       * @param <M> the middle element type
51       * @param <R> the right element type
52       * @param left  the left element, may be null
53       * @param middle  the middle element, may be null
54       * @param right  the right element, may be null
55       * @return a triple formed from the three parameters, not null
56       */
57      public static <L, M, R> MutableTriple<L, M, R> of(final L left, final M middle, final R right) {
58          return new MutableTriple<L, M, R>(left, middle, right);
59      }
60  
61      /**
62       * Create a new triple instance of three nulls.
63       */
64      public MutableTriple() {
65          super();
66      }
67  
68      /**
69       * Create a new triple instance.
70       *
71       * @param left  the left value, may be null
72       * @param middle  the middle value, may be null
73       * @param right  the right value, may be null
74       */
75      public MutableTriple(final L left, final M middle, final R right) {
76          super();
77          this.left = left;
78          this.middle = middle;
79          this.right = right;
80      }
81  
82      //-----------------------------------------------------------------------
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      public L getLeft() {
88          return left;
89      }
90  
91      /**
92       * Sets the left element of the triple.
93       *
94       * @param left  the new value of the left element, may be null
95       */
96      public void setLeft(final L left) {
97          this.left = left;
98      }
99  
100     /**
101      * {@inheritDoc}
102      */
103     @Override
104     public M getMiddle() {
105         return middle;
106     }
107 
108     /**
109      * Sets the middle element of the triple.
110      *
111      * @param middle  the new value of the middle element, may be null
112      */
113     public void setMiddle(final M middle) {
114         this.middle = middle;
115     }
116 
117     /**
118      * {@inheritDoc}
119      */
120     @Override
121     public R getRight() {
122         return right;
123     }
124 
125     /**
126      * Sets the right element of the triple.
127      *
128      * @param right  the new value of the right element, may be null
129      */
130     public void setRight(final R right) {
131         this.right = right;
132     }
133 }
134