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 } 090 091 /** 092 * Create a new triple instance. 093 * 094 * @param left the left value, may be null 095 * @param middle the middle value, may be null 096 * @param right the right value, may be null 097 */ 098 public MutableTriple(final L left, final M middle, final R right) { 099 this.left = left; 100 this.middle = middle; 101 this.right = right; 102 } 103 104 //----------------------------------------------------------------------- 105 /** 106 * {@inheritDoc} 107 */ 108 @Override 109 public L getLeft() { 110 return left; 111 } 112 113 /** 114 * {@inheritDoc} 115 */ 116 @Override 117 public M getMiddle() { 118 return middle; 119 } 120 121 /** 122 * {@inheritDoc} 123 */ 124 @Override 125 public R getRight() { 126 return right; 127 } 128 129 /** 130 * Sets the left element of the triple. 131 * 132 * @param left the new value of the left element, may be null 133 */ 134 public void setLeft(final L left) { 135 this.left = left; 136 } 137 138 /** 139 * Sets the middle element of the triple. 140 * 141 * @param middle the new value of the middle element, may be null 142 */ 143 public void setMiddle(final M middle) { 144 this.middle = middle; 145 } 146 147 /** 148 * Sets the right element of the triple. 149 * 150 * @param right the new value of the right element, may be null 151 */ 152 public void setRight(final R right) { 153 this.right = right; 154 } 155} 156