You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2022/02/08 15:44:21 UTC
[juneau] branch master updated: Remove Mutable class.
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 78106fb Remove Mutable class.
78106fb is described below
commit 78106fb05965b798f9e56da71efd6b0557551c5e
Author: JamesBognar <ja...@salesforce.com>
AuthorDate: Tue Feb 8 10:44:01 2022 -0500
Remove Mutable class.
---
.../org/apache/juneau/internal/ObjectUtils.java | 8 +-
.../main/java/org/apache/juneau/utils/Mutable.java | 136 ---------------------
.../06.jrc.ResponseStatus.html | 4 +-
.../apache/juneau/rest/client/ResponseHeader.java | 25 ++--
.../apache/juneau/rest/client/RestResponse.java | 19 ++-
.../org/apache/juneau/http/BasicHeader_Test.java | 8 +-
.../client/RestClient_Response_Headers_Test.java | 9 +-
.../rest/client/RestClient_Response_Test.java | 8 +-
8 files changed, 39 insertions(+), 178 deletions(-)
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
index 35fd9df..b0c1d2a 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
@@ -17,9 +17,9 @@ import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
+import org.apache.juneau.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.reflect.*;
-import org.apache.juneau.utils.*;
/**
* Various generic object utility methods.
@@ -161,7 +161,7 @@ public class ObjectUtils {
}
/**
- * If the specified object is a {@link Supplier} or {@link Mutable}, returns the inner value, otherwise the same value.
+ * If the specified object is a {@link Supplier} or {@link Value}, returns the inner value, otherwise the same value.
*
* @param o The object to unwrap.
* @return The unwrapped object.
@@ -169,8 +169,8 @@ public class ObjectUtils {
public static Object unwrap(Object o) {
while (o instanceof Supplier)
o = ((Supplier<?>)o).get();
- while (o instanceof Mutable)
- o = ((Mutable<?>)o).get();
+ while (o instanceof Value)
+ o = ((Value<?>)o).get();
return o;
}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/Mutable.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/Mutable.java
deleted file mode 100644
index 566b4c4..0000000
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/Mutable.java
+++ /dev/null
@@ -1,136 +0,0 @@
-// ***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
-// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
-// * with the License. You may obtain a copy of the License at *
-// * *
-// * http://www.apache.org/licenses/LICENSE-2.0 *
-// * *
-// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
-// * specific language governing permissions and limitations under the License. *
-// ***************************************************************************************************************************
-package org.apache.juneau.utils;
-
-import java.util.*;
-
-/**
- * Represents a settable object.
- *
- * Typically passed as method parameters to provide by-reference support.
- *
- * <p class='bjava'>
- * Mutable<String> <jv>map</jv> = Mutable.<jsm>create</jsm>(String.<jk>class</jk>);
- * <jsm>callSomeMethodThatSetsValue</jsm>(<jv>map</jv>);
- * String <jv>vlaue</jv> = <jv>map</jv>.get();
- * </p>
- *
- * <ul class='notes'>
- * <li class='note'>This object can be used as hashmap keys.
- * </ul>
- *
- * <ul class='spaced-list'>
- * <li class='warn'>This class is not thread safe.
- * </ul>
- *
- * <ul class='seealso'>
- * <li class='extlink'>{@source}
- * </ul>
- *
- * @param <T> The inner object type.
- */
-@Deprecated
-public class Mutable<T> {
-
- private T value;
-
- /**
- * Creates an empty mutable.
- *
- * @param <T> The inner object type.
- * @param c The inner object type.
- * @return The new mutable object.
- */
- public static <T> Mutable<T> create(Class<T> c) {
- return new Mutable<>();
- }
-
- /**
- * Creates an empty mutable.
- *
- * @param <T> The inner object type.
- * @return The new mutable object.
- */
- public static <T> Mutable<T> create() {
- return new Mutable<>();
- }
-
- /**
- * Creates a mutable initialized with the specified object.
- *
- * @param <T> The inner object type.
- * @param t The inner object.
- * @return The new mutable object.
- */
- public static <T> Mutable<T> of(T t) {
- return new Mutable<>(t);
- }
-
- /**
- * Creates an empty mutable.
- */
- public Mutable() {}
-
- /**
- * Creates a mutable initialized with the specified object.
- *
- * @param t The inner object.
- */
- public Mutable(T t) {
- this.value = t;
- }
-
- /**
- * Returns the inner object.
- *
- * @return The inner object, or <jk>null</jk> if empty.
- */
- public T get() {
- return value;
- }
-
- /**
- * Sets the inner object.
- *
- * @param t The inner object.
- * @return This object.
- */
- public Mutable<T> set(T t) {
- this.value = t;
- return this;
- }
-
- /**
- * Returns <jk>true</jk> if inner object is set.
- *
- * @return <jk>true</jk> if inner object is set.
- */
- public boolean isSet() {
- return value != null;
- }
-
- @Override /* Object */
- public boolean equals(Object o) {
- return Objects.equals(o, value);
- }
-
- @Override /* Object */
- public int hashCode() {
- return value == null ? 0 : value.hashCode();
- }
-
- @Override /* Object */
- public String toString() {
- return value == null ? "null" : value.toString();
- }
-}
diff --git a/juneau-doc/docs/Topics/10.juneau-rest-client/06.jrc.ResponseStatus.html b/juneau-doc/docs/Topics/10.juneau-rest-client/06.jrc.ResponseStatus.html
index aa67405..c1d1eda 100644
--- a/juneau-doc/docs/Topics/10.juneau-rest-client/06.jrc.ResponseStatus.html
+++ b/juneau-doc/docs/Topics/10.juneau-rest-client/06.jrc.ResponseStatus.html
@@ -43,8 +43,8 @@
<h5 class='figure'>Example:</h5>
<p class='bjava'>
| <jc>// Interested in multiple values.</jc>
- | Mutable<Integer> <jv>statusCode</jv> = Mutable.<jsm>create</jsm>();
- | Mutable<String> <jv>reasonPhrase</jv> = Mutable.<jsm>create</jsm>();
+ | Value<Integer> <jv>statusCode</jv> = Value.<jsm>empty</jsm>();
+ | Value<String> <jv>reasonPhrase</jv> = Value.<jsm>empty</jsm>();
|
| <jv>client</jv>.get(<jsf>URI</jsf>).complete().getStatusCode(<jv>statusCode</jv>).getReasonPhrase(<jv>reasonPhrase</jv>);
| System.<jsf>err</jsf>.println(<js>"statusCode="</js>+<jv>statusCode</jv>.get()+<js>", reasonPhrase="</js>+<jv>reasonPhrase</jv>.get());
diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java
index 20fff04..fa3008b 100644
--- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java
+++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java
@@ -30,7 +30,6 @@ import org.apache.juneau.oapi.*;
import org.apache.juneau.parser.ParseException;
import org.apache.juneau.reflect.*;
import org.apache.juneau.rest.client.assertion.*;
-import org.apache.juneau.utils.*;
/**
* Represents a single header on an HTTP response.
@@ -334,11 +333,11 @@ public class ResponseHeader implements Header {
/**
* Same as {@link #asString()} but sets the value in a mutable for fluent calls.
*
- * @param m The mutable to set the header value in.
+ * @param value The mutable to set the header value in.
* @return This object.
*/
- public RestResponse asString(Mutable<String> m) {
- m.set(orElse(null));
+ public RestResponse asString(Value<String> value) {
+ value.set(orElse(null));
return response;
}
@@ -364,7 +363,7 @@ public class ResponseHeader implements Header {
* <p>
* See {@doc jm.ComplexDataTypes Complex Data Types} for information on defining complex generic types of {@link Map Maps} and {@link Collection Collections}.
*
- * @param m The mutable to set the parsed header value in.
+ * @param value The mutable to set the parsed header value in.
* @param <T> The type to convert to.
* @param type The type to convert to.
* @param args The type parameters.
@@ -372,8 +371,8 @@ public class ResponseHeader implements Header {
* @throws RestCallException If value could not be parsed.
*/
@SuppressWarnings("unchecked")
- public <T> RestResponse asType(Mutable<T> m, Type type, Type...args) throws RestCallException {
- m.set((T)asType(type, args).orElse(null));
+ public <T> RestResponse asType(Value<T> value, Type type, Type...args) throws RestCallException {
+ value.set((T)asType(type, args).orElse(null));
return response;
}
@@ -392,14 +391,14 @@ public class ResponseHeader implements Header {
/**
* Same as {@link #asType(Class)} but sets the value in a mutable for fluent calls.
*
- * @param m The mutable to set the parsed header value in.
+ * @param value The mutable to set the parsed header value in.
* @param <T> The type to convert to.
* @param type The type to convert to.
* @return This object.
* @throws RestCallException If value could not be parsed.
*/
- public <T> RestResponse asType(Mutable<T> m, Class<T> type) throws RestCallException {
- m.set(asType(type).orElse(null));
+ public <T> RestResponse asType(Value<T> value, Class<T> type) throws RestCallException {
+ value.set(asType(type).orElse(null));
return response;
}
@@ -422,14 +421,14 @@ public class ResponseHeader implements Header {
/**
* Same as {@link #asType(ClassMeta)} but sets the value in a mutable for fluent calls.
*
- * @param m The mutable to set the parsed header value in.
+ * @param value The mutable to set the parsed header value in.
* @param <T> The type to convert to.
* @param type The type to convert to.
* @return This object.
* @throws RestCallException If value could not be parsed.
*/
- public <T> RestResponse asType(Mutable<T> m, ClassMeta<T> type) throws RestCallException {
- m.set(asType(type).orElse(null));
+ public <T> RestResponse asType(Value<T> value, ClassMeta<T> type) throws RestCallException {
+ value.set(asType(type).orElse(null));
return response;
}
diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java
index 7146a77..72ba6ea 100644
--- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java
+++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java
@@ -32,7 +32,6 @@ import org.apache.juneau.http.header.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.httppart.bean.*;
import org.apache.juneau.internal.*;
-import org.apache.juneau.utils.*;
/**
* Represents a response from a remote REST resource.
@@ -109,11 +108,11 @@ public class RestResponse implements HttpResponse {
/**
* Same as {@link #getStatusLine()} but sets the value in a mutable for fluent calls.
*
- * @param m The mutable to set the status line in.
+ * @param value The mutable to set the status line in.
* @return This object.
*/
- public RestResponse getStatusLine(Mutable<StatusLine> m) {
- m.set(getStatusLine());
+ public RestResponse getStatusLine(Value<StatusLine> value) {
+ value.set(getStatusLine());
return this;
}
@@ -131,11 +130,11 @@ public class RestResponse implements HttpResponse {
/**
* Same as {@link #getStatusCode()} but sets the value in a mutable for fluent calls.
*
- * @param m The mutable to set the status code in.
+ * @param value The mutable to set the status code in.
* @return This object.
*/
- public RestResponse getStatusCode(Mutable<Integer> m) {
- m.set(getStatusCode());
+ public RestResponse getStatusCode(Value<Integer> value) {
+ value.set(getStatusCode());
return this;
}
@@ -153,11 +152,11 @@ public class RestResponse implements HttpResponse {
/**
* Same as {@link #getReasonPhrase()} but sets the value in a mutable for fluent calls.
*
- * @param m The mutable to set the status line reason phrase in.
+ * @param value The mutable to set the status line reason phrase in.
* @return This object.
*/
- public RestResponse getReasonPhrase(Mutable<String> m) {
- m.set(getReasonPhrase());
+ public RestResponse getReasonPhrase(Value<String> value) {
+ value.set(getReasonPhrase());
return this;
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/http/BasicHeader_Test.java b/juneau-utest/src/test/java/org/apache/juneau/http/BasicHeader_Test.java
index 37c6b07..80788dd 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/http/BasicHeader_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/http/BasicHeader_Test.java
@@ -20,8 +20,8 @@ import static org.junit.runners.MethodSorters.*;
import java.util.function.*;
import org.apache.http.*;
+import org.apache.juneau.*;
import org.apache.juneau.http.header.*;
-import org.apache.juneau.utils.*;
import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
@@ -73,7 +73,7 @@ public class BasicHeader_Test {
@Test
public void a08_getElements() {
- Mutable<Integer> m = Mutable.of(1);
+ Value<Integer> m = Value.of(1);
Header h1 = header("X1","1");
Header h2 = header("X2",()->m);
Header h3 = header("X3",null);
@@ -89,11 +89,11 @@ public class BasicHeader_Test {
x = h2.getElements();
assertEquals(1, x.length);
- assertEquals("1", x[0].getName());
+ assertEquals("Value(1)", x[0].getName());
m.set(2);
x = h2.getElements();
assertEquals(1, x.length);
- assertEquals("2", x[0].getName());
+ assertEquals("Value(2)", x[0].getName());
x = h3.getElements();
assertEquals(0, x.length);
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java
index a5382b9..f46efd7 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java
@@ -30,7 +30,6 @@ import org.apache.juneau.http.header.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.mock.*;
import org.apache.juneau.rest.servlet.*;
-import org.apache.juneau.utils.*;
import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
@@ -88,7 +87,7 @@ public class RestClient_Response_Headers_Test {
String s = checkFooClient().build().get("/echo").header("Foo","bar").run().getHeader("Foo").asString().orElse(null);
assertEquals("bar", s);
- Mutable<String> m = Mutable.create();
+ Value<String> m = Value.empty();
checkFooClient().build().get("/echo").header("Foo","bar").run().getHeader("Foo").asString(m);
assertEquals("bar", m.get());
@@ -109,14 +108,14 @@ public class RestClient_Response_Headers_Test {
Integer i = checkFooClient().build().get("/echo").header("Foo","123").run().getHeader("Foo").asType(Integer.class).orElse(null);
assertEquals(123, i.intValue());
- Mutable<Integer> m1 = Mutable.create();
+ Value<Integer> m1 = Value.empty();
checkFooClient().build().get("/echo").header("Foo","123").run().getHeader("Foo").asType(m1,Integer.class);
assertEquals(123, m1.get().intValue());
List<Integer> l = (List<Integer>) checkFooClient().build().get("/echo").header("Foo","1,2").run().getHeader("Foo").asType(LinkedList.class,Integer.class).get();
assertObject(l).asJson().is("[1,2]");
- Mutable<Integer> m2 = Mutable.create();
+ Value<Integer> m2 = Value.empty();
checkFooClient().build().get("/echo").header("Foo","1,2").run().getHeader("Foo").asType(m2,LinkedList.class,Integer.class);
ClassMeta<LinkedList<Integer>> cm1 = BeanContext.DEFAULT.getClassMeta(LinkedList.class, Integer.class);
@@ -125,7 +124,7 @@ public class RestClient_Response_Headers_Test {
l = checkFooClient().build().get("/echo").header("Foo","1,2").run().getHeader("Foo").asType(cm1).get();
assertObject(l).asJson().is("[1,2]");
- Mutable<LinkedList<Integer>> m3 = Mutable.create();
+ Value<LinkedList<Integer>> m3 = Value.empty();
checkFooClient().build().get("/echo").header("Foo","1,2").run().getHeader("Foo").asType(m3,cm1);
assertObject(m3.get()).asJson().is("[1,2]");
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Test.java
index fca2284..d582fc2 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Test.java
@@ -27,12 +27,12 @@ import org.apache.http.Header;
import org.apache.http.entity.*;
import org.apache.http.message.*;
import org.apache.http.params.*;
+import org.apache.juneau.*;
import org.apache.juneau.http.annotation.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.mock.*;
import org.apache.juneau.rest.servlet.*;
-import org.apache.juneau.utils.*;
import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
@@ -78,7 +78,7 @@ public class RestClient_Response_Test {
@Test
public void a02_getStatusLine_Mutable() throws RestCallException {
- Mutable<StatusLine> m = Mutable.create();
+ Value<StatusLine> m = Value.empty();
client().build().get("/bean").run().getStatusLine(m);
assertEquals(200,m.get().getStatusCode());
}
@@ -90,7 +90,7 @@ public class RestClient_Response_Test {
@Test
public void a04_getStatusCode_Mutable() throws RestCallException {
- Mutable<Integer> m = Mutable.create();
+ Value<Integer> m = Value.empty();
client().build().get("/bean").run().getStatusCode(m);
assertEquals(200,m.get().intValue());
}
@@ -102,7 +102,7 @@ public class RestClient_Response_Test {
@Test
public void a06_getReasonPhrase_Mutable() throws RestCallException {
- Mutable<String> m = Mutable.create();
+ Value<String> m = Value.empty();
client().build().get("/bean").run().getReasonPhrase(m);
assertNull(m.get());
}