Skip to content

Commit 80b944a

Browse files
committed
org.apache.commons.lang3.mutable.Mutable now extends Supplier
1 parent a0d3cd1 commit 80b944a

20 files changed

+99
-36
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ The <action> type attribute can be add,update,fix,remove.
126126
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.JAVA_SECURITY_KERBEROS_REAL.</action>
127127
<action type="add" dev="ggregory" due-to="kommalapatiraviteja">Add ArrayFill.fill(boolean[], boolean) #1386.</action>
128128
<action type="add" dev="ggregory" due-to="Pankraz76, Gary Gregory">Add ObjectUtils.getIfNull(Object, Object) and deprecate defaultIfNull(Object, Object).</action>
129+
<action type="add" dev="ggregory" due-to="Gary Gregory">org.apache.commons.lang3.mutable.Mutable now extends Supplier.</action>
129130
<!-- UPDATE -->
130131
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 84 #1267, #1277, #1283, #1288, #1302, #1377.</action>
131132
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">[site] Bump org.codehaus.mojo:taglist-maven-plugin from 3.1.0 to 3.2.1 #1300.</action>

src/main/java/org/apache/commons/lang3/mutable/Mutable.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,49 @@
1717

1818
package org.apache.commons.lang3.mutable;
1919

20+
import java.util.function.Supplier;
21+
2022
/**
2123
* Provides mutable access to a value.
2224
* <p>
2325
* {@link Mutable} is used as a generic interface to the implementations in this package.
2426
* </p>
2527
* <p>
26-
* A typical use case would be to enable a primitive or string to be passed to a method and allow that method to
27-
* effectively change the value of the primitive/string. Another use case is to store a frequently changing primitive in
28-
* a collection (for example a total in a map) without needing to create new Integer/Long wrapper objects.
28+
* A typical use case would be to enable a primitive or string to be passed to a method and allow that method to effectively change the value of the
29+
* primitive/object. Another use case is to store a frequently changing primitive in a collection (for example a total in a map) without needing to create new
30+
* Integer/Long wrapper objects.
2931
* </p>
3032
*
31-
* @param <T> the type to set and get
33+
* @param <T> the type to wrap.
3234
* @since 2.1
3335
*/
34-
public interface Mutable<T> {
36+
public interface Mutable<T> extends Supplier<T> {
37+
38+
/**
39+
* Gets the value of this mutable.
40+
*
41+
* @return the stored value.
42+
* @since 3.18.0
43+
*/
44+
default T get() {
45+
return getValue();
46+
}
3547

3648
/**
3749
* Gets the value of this mutable.
3850
*
3951
* @return the stored value
52+
* @deprecated Use {@link #get()}.
4053
*/
54+
@Deprecated
4155
T getValue();
4256

4357
/**
4458
* Sets the value of this mutable.
4559
*
46-
* @param value
47-
* the value to store
48-
* @throws NullPointerException
49-
* if the object is null and null is invalid
50-
* @throws ClassCastException
51-
* if the type is invalid
60+
* @param value the value to store
61+
* @throws NullPointerException if the object is null and null is invalid.
62+
* @throws ClassCastException if the type is invalid.
5263
*/
5364
void setValue(T value);
54-
5565
}

src/main/java/org/apache/commons/lang3/mutable/MutableBoolean.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ public boolean equals(final Object obj) {
112112
/**
113113
* Gets the value as a Boolean instance.
114114
*
115-
* @return the value as a Boolean, never null
115+
* @return the value as a Boolean, never null.
116+
* @deprecated Use {@link #get()}.
116117
*/
118+
@SuppressWarnings("deprecation")
119+
@Deprecated
117120
@Override
118121
public Boolean getValue() {
119122
return Boolean.valueOf(this.value);

src/main/java/org/apache/commons/lang3/mutable/MutableByte.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ public byte getAndIncrement() {
260260
/**
261261
* Gets the value as a Byte instance.
262262
*
263-
* @return the value as a Byte, never null
263+
* @return the value as a Byte, never null.
264+
* @deprecated Use {@link #get()}.
264265
*/
266+
@SuppressWarnings("deprecation")
267+
@Deprecated
265268
@Override
266269
public Byte getValue() {
267270
return Byte.valueOf(this.value);

src/main/java/org/apache/commons/lang3/mutable/MutableDouble.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,11 @@ public double getAndIncrement() {
266266
/**
267267
* Gets the value as a Double instance.
268268
*
269-
* @return the value as a Double, never null
269+
* @return the value as a Double, never null.
270+
* @deprecated Use {@link #get()}.
270271
*/
272+
@SuppressWarnings("deprecation")
273+
@Deprecated
271274
@Override
272275
public Double getValue() {
273276
return Double.valueOf(this.value);

src/main/java/org/apache/commons/lang3/mutable/MutableFloat.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ public float getAndIncrement() {
268268
/**
269269
* Gets the value as a Float instance.
270270
*
271-
* @return the value as a Float, never null
271+
* @return the value as a Float, never null.
272+
* @deprecated Use {@link #get()}.
272273
*/
274+
@SuppressWarnings("deprecation")
275+
@Deprecated
273276
@Override
274277
public Float getValue() {
275278
return Float.valueOf(this.value);

src/main/java/org/apache/commons/lang3/mutable/MutableInt.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ public int getAndIncrement() {
255255
/**
256256
* Gets the value as a Integer instance.
257257
*
258-
* @return the value as a Integer, never null
258+
* @return the value as a Integer, never null.
259+
* @deprecated Use {@link #get()}.
259260
*/
261+
@SuppressWarnings("deprecation")
262+
@Deprecated
260263
@Override
261264
public Integer getValue() {
262265
return Integer.valueOf(this.value);

src/main/java/org/apache/commons/lang3/mutable/MutableLong.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ public long getAndIncrement() {
255255
/**
256256
* Gets the value as a Long instance.
257257
*
258-
* @return the value as a Long, never null
258+
* @return the value as a Long, never null.
259+
* @deprecated Use {@link #get()}.
259260
*/
261+
@SuppressWarnings("deprecation")
262+
@Deprecated
260263
@Override
261264
public Long getValue() {
262265
return Long.valueOf(this.value);

src/main/java/org/apache/commons/lang3/mutable/MutableObject.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public boolean equals(final Object obj) {
8787
* Gets the value.
8888
*
8989
* @return the value, may be null.
90+
* @deprecated Use {@link #get()}.
9091
*/
92+
@SuppressWarnings("deprecation")
93+
@Deprecated
9194
@Override
9295
public T getValue() {
9396
return this.value;

src/main/java/org/apache/commons/lang3/mutable/MutableShort.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,11 @@ public short getAndIncrement() {
249249
/**
250250
* Gets the value as a Short instance.
251251
*
252-
* @return the value as a Short, never null
252+
* @return the value as a Short, never null.
253+
* @deprecated Use {@link #get()}.
253254
*/
255+
@SuppressWarnings("deprecation")
256+
@Deprecated
254257
@Override
255258
public Short getValue() {
256259
return Short.valueOf(this.value);

0 commit comments

Comments
 (0)