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 /** 033 * The empty array singleton. 034 * <p> 035 * Consider using {@link #emptyArray()} to avoid generics warnings. 036 * </p> 037 * 038 * @since 3.10. 039 */ 040 public static final MutableTriple<?, ?, ?>[] EMPTY_ARRAY = new MutableTriple[0]; 041 042 /** Serialization version */ 043 private static final long serialVersionUID = 1L; 044 045 /** 046 * Returns the empty array singleton that can be assigned without compiler warning. 047 * 048 * @param <L> the left element type 049 * @param <M> the middle element type 050 * @param <R> the right element type 051 * @return the empty array singleton that can be assigned without compiler warning. 052 * 053 * @since 3.10. 054 */ 055 @SuppressWarnings("unchecked") 056 public static <L, M, R> MutableTriple<L, M, R>[] emptyArray() { 057 return (MutableTriple<L, M, R>[]) EMPTY_ARRAY; 058 } 059 060 /** 061 * <p>Obtains a mutable triple of three objects inferring the generic types.</p> 062 * 063 * <p>This factory allows the triple to be created using inference to 064 * obtain the generic types.</p> 065 * 066 * @param <L> the left element type 067 * @param <M> the middle element type 068 * @param <R> the right element type 069 * @param left the left element, may be null 070 * @param middle the middle element, may be null 071 * @param right the right element, may be null 072 * @return a triple formed from the three parameters, not null 073 */ 074 public static <L, M, R> MutableTriple<L, M, R> of(final L left, final M middle, final R right) { 075 return new MutableTriple<>(left, middle, right); 076 } 077 /** Left object */ 078 public L left; 079 /** Middle object */ 080 public M middle; 081 082 /** Right object */ 083 public R right; 084 085 /** 086 * Create a new triple instance of three nulls. 087 */ 088 public MutableTriple() { 089 super(); 090 } 091 092 /** 093 * Create a new triple instance. 094 * 095 * @param left the left value, may be null 096 * @param middle the middle value, may be null 097 * @param right the right value, may be null 098 */ 099 public MutableTriple(final L left, final M middle, final R right) { 100 super(); 101 this.left = left; 102 this.middle = middle; 103 this.right = right; 104 } 105 106 //----------------------------------------------------------------------- 107 /** 108 * {@inheritDoc} 109 */ 110 @Override 111 public L getLeft() { 112 return left; 113 } 114 115 /** 116 * {@inheritDoc} 117 */ 118 @Override 119 public M getMiddle() { 120 return middle; 121 } 122 123 /** 124 * {@inheritDoc} 125 */ 126 @Override 127 public R getRight() { 128 return right; 129 } 130 131 /** 132 * Sets the left element of the triple. 133 * 134 * @param left the new value of the left element, may be null 135 */ 136 public void setLeft(final L left) { 137 this.left = left; 138 } 139 140 /** 141 * Sets the middle element of the triple. 142 * 143 * @param middle the new value of the middle element, may be null 144 */ 145 public void setMiddle(final M middle) { 146 this.middle = middle; 147 } 148 149 /** 150 * Sets the right element of the triple. 151 * 152 * @param right the new value of the right element, may be null 153 */ 154 public void setRight(final R right) { 155 this.right = right; 156 } 157} 158