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 a68d304 PropertyStore refactoring.
a68d304 is described below
commit a68d30421289bd88df217525d729486f8c9d66e8
Author: JamesBognar <[email protected]>
AuthorDate: Sun Feb 7 18:57:05 2021 -0500
PropertyStore refactoring.
---
.../main/java/org/apache/juneau/BeanContext.java | 4 ++--
.../main/java/org/apache/juneau/PropertyStore.java | 27 ++++++----------------
.../org/apache/juneau/rest/client/RestClient.java | 7 +++---
.../apache/juneau/rest/mock/MockRestClient.java | 3 ++-
.../java/org/apache/juneau/rest/RestContext.java | 6 ++---
.../apache/juneau/rest/RestOperationContext.java | 4 ++--
6 files changed, 20 insertions(+), 31 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
index 4d0d754..ba63e90 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
@@ -2084,7 +2084,7 @@ public class BeanContext extends Context implements
MetaProvider {
ps = ps.subset(new String[]{"Context","BeanContext"});
ReflectionMapBuilder<Annotation> rmb =
ReflectionMap.create(Annotation.class);
- for (Annotation a : ps.getList(BEAN_annotations,
Annotation.class)) {
+ for (Annotation a : ps.getList(BEAN_annotations,
Annotation.class).orElse(emptyList())) {
try {
ClassInfo ci = ClassInfo.of(a.getClass());
@@ -2149,7 +2149,7 @@ public class BeanContext extends Context implements
MetaProvider {
notBeanPackagePrefixes = l2.toArray(new String[l2.size()]);
LinkedList<PojoSwap<?,?>> lpf = new LinkedList<>();
- for (Object o : ps.getList(BEAN_swaps, Object.class)) {
+ for (Object o : ps.getList(BEAN_swaps,
Object.class).orElse(emptyList())) {
if (o instanceof Class) {
ClassInfo ci = ClassInfo.of((Class<?>)o);
if (ci.isChildOf(PojoSwap.class))
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
index 5fa0d69..a694ea4 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
@@ -440,7 +440,7 @@ public final class PropertyStore {
*
* @param key The property name.
* @param eType The class type of the elements in the property.
- * @return The property value as an unmodifiable <c>LinkedHashSet</c>,
or never <jk>null</jk>.
+ * @return The property value as an unmodifiable <c>LinkedHashSet</c>,
never <jk>null</jk>.
*/
public <T> Optional<Set<T>> getSet(String key, Class<T> eType) {
Property p = findProperty(key);
@@ -452,24 +452,11 @@ public final class PropertyStore {
*
* @param key The property name.
* @param eType The class type of the elements in the property.
- * @return The property value as an unmodifiable <c>ArrayList</c>, or
an empty list if it doesn't exist.
+ * @return The property value as an unmodifiable <c>ArrayList</c>,
never <jk>null</jk>.
*/
- public <T> List<T> getList(String key, Class<T> eType) {
+ public <T> Optional<List<T>> getList(String key, Class<T> eType) {
Property p = findProperty(key);
- return p == null ? Collections.EMPTY_LIST : p.asList(eType);
- }
-
- /**
- * Returns the list property with the specified name.
- *
- * @param key The property name.
- * @param eType The class type of the elements in the property.
- * @param def The default value if the property doesn't exist or is
empty.
- * @return The property value as an unmodifiable <c>ArrayList</c>, or
the default value if it doesn't exist or is empty.
- */
- public <T> List<T> getList(String key, Class<T> eType, List<T> def) {
- List<T> l = getList(key, eType);
- return (l.isEmpty() ? def : l);
+ return Optional.ofNullable(p == null ? null : p.asList(eType));
}
/**
@@ -477,11 +464,11 @@ public final class PropertyStore {
*
* @param key The property name.
* @param eType The class type of the elements in the property.
- * @return The property value as an unmodifiable <c>LinkedHashMap</c>,
or an empty map if it doesn't exist.
+ * @return The property value as an unmodifiable <c>LinkedHashMap</c>,
never <jk>null</jk>.
*/
- public <T> Map<String,T> getMap(String key, Class<T> eType) {
+ public <T> Optional<Map<String,T>> getMap(String key, Class<T> eType) {
Property p = findProperty(key);
- return p == null ? Collections.EMPTY_MAP : p.asMap(eType);
+ return Optional.ofNullable(p == null ? null : p.asMap(eType));
}
/**
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index cea95a3..fc11a4e 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -19,6 +19,7 @@ import static org.apache.juneau.http.HttpMethod.*;
import static java.util.logging.Level.*;
import static org.apache.juneau.internal.StateMachineState.*;
import static java.lang.Character.*;
+import static java.util.Collections.*;
import java.io.*;
import java.lang.reflect.*;
@@ -2094,7 +2095,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
HttpPartSerializerSession partSerializerSession =
partSerializer.createPartSession(null);
this.headers = HeaderSupplier.create();
- for (Object o : ps.getList(RESTCLIENT_headers, Object.class)) {
+ for (Object o : ps.getList(RESTCLIENT_headers,
Object.class).orElse(emptyList())) {
o = buildBuilders(o, partSerializerSession);
if (o instanceof HeaderSupplier)
headers.add((HeaderSupplier)o);
@@ -2103,7 +2104,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
}
this.query = NameValuePairSupplier.create();
- for (Object o : ps.getList(RESTCLIENT_query, Object.class)) {
+ for (Object o : ps.getList(RESTCLIENT_query,
Object.class).orElse(emptyList())) {
o = buildBuilders(o, partSerializerSession);
if (o instanceof NameValuePairSupplier)
query.add((NameValuePairSupplier)o);
@@ -2112,7 +2113,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
}
this.formData = NameValuePairSupplier.create();
- for (Object o : ps.getList(RESTCLIENT_formData, Object.class)) {
+ for (Object o : ps.getList(RESTCLIENT_formData,
Object.class).orElse(emptyList())) {
o = buildBuilders(o, partSerializerSession);
if (o instanceof NameValuePairSupplier)
formData.add((NameValuePairSupplier)o);
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
index a4c57c6..bb18e91 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
@@ -15,6 +15,7 @@ package org.apache.juneau.rest.mock;
import static org.apache.juneau.internal.StringUtils.*;
import static org.apache.juneau.rest.util.RestUtils.*;
import static org.apache.juneau.Enablement.*;
+import static java.util.Collections.*;
import java.io.*;
import java.net.*;
@@ -259,7 +260,7 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
this.restObject = restBeanCtx.getResource();
this.contextPath =
ps.getString(MOCKRESTCLIENT_contextPath).orElse("");
this.servletPath =
ps.getString(MOCKRESTCLIENT_servletPath).orElse("");
- this.pathVars = ps.getMap(MOCKRESTCLIENT_pathVars,
String.class);
+ this.pathVars = ps.getMap(MOCKRESTCLIENT_pathVars,
String.class).orElse(emptyMap());
HttpClientConnectionManager ccm =
getHttpClientConnectionManager();
if (ccm instanceof MockHttpClientConnectionManager)
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index b160329..83ef20a 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -3542,8 +3542,8 @@ public class RestContext extends BeanContext {
debugEnablement = createDebugEnablement(r, ps, bf);
- consumes = ps.getList(REST_consumes, MediaType.class,
parsers.getSupportedMediaTypes());
- produces = ps.getList(REST_produces, MediaType.class,
serializers.getSupportedMediaTypes());
+ consumes = ps.getList(REST_consumes,
MediaType.class).orElse(parsers.getSupportedMediaTypes());
+ produces = ps.getList(REST_produces,
MediaType.class).orElse(serializers.getSupportedMediaTypes());
fullPath = (builder.parentContext == null ? "" :
(builder.parentContext.fullPath + '/')) + builder.getPath();
path = builder.getPath();
@@ -4527,7 +4527,7 @@ public class RestContext extends BeanContext {
RestOperationParamList x = RestOperationParamList.create();
- for (Class<?> c : properties.getList(REST_restOperationParams,
Class.class, AList.create()))
+ for (Class<?> c : properties.getList(REST_restOperationParams,
Class.class).orElse(emptyList()))
x.append((Class<? extends RestOperationParam>)c);
x.append(
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
index e21e1cb..0126d2d 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
@@ -777,8 +777,8 @@ public class RestOperationContext extends BeanContext
implements Comparable<Rest
jsonSchemaGenerator = createJsonSchemaGenerator(r, bf,
ps);
bf.addBean(JsonSchemaGenerator.class,
jsonSchemaGenerator);
- supportedAcceptTypes = ps.getList(REST_produces,
MediaType.class, serializers.getSupportedMediaTypes());
- supportedContentTypes = ps.getList(REST_consumes,
MediaType.class, parsers.getSupportedMediaTypes());
+ supportedAcceptTypes = ps.getList(REST_produces,
MediaType.class).orElse(serializers.getSupportedMediaTypes());
+ supportedContentTypes = ps.getList(REST_consumes,
MediaType.class).orElse(parsers.getSupportedMediaTypes());
defaultRequestHeaders = createDefaultRequestHeaders(r,
ps, bf, method, context).asArray();
defaultResponseHeaders =
createDefaultResponseHeaders(r, ps, bf, method, context).asArray();