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 48713fe  PropertyStore refactoring.
48713fe is described below

commit 48713feeb0c6686862b2c3cb0141b57b7c012fdb
Author: JamesBognar <james.bog...@salesforce.com>
AuthorDate: Sun Feb 7 17:31:57 2021 -0500

    PropertyStore refactoring.
---
 .../main/java/org/apache/juneau/BeanContext.java    |  2 +-
 .../main/java/org/apache/juneau/PropertyStore.java  | 21 ++++-----------------
 .../org/apache/juneau/html/HtmlDocSerializer.java   | 18 +++++++++---------
 .../org/apache/juneau/rest/client/RestClient.java   |  4 ++--
 .../java/org/apache/juneau/rest/RestContext.java    |  6 +++---
 .../apache/juneau/rest/RestOperationContext.java    |  6 +++---
 6 files changed, 22 insertions(+), 35 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 c6af320..dbac558 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
@@ -2139,7 +2139,7 @@ public class BeanContext extends Context implements 
MetaProvider {
 
                List<String> l1 = new LinkedList<>();
                List<String> l2 = new LinkedList<>();
-               for (String s : ps.getArray(BEAN_notBeanPackages, String.class, 
DEFAULT_NOTBEAN_PACKAGES)) {
+               for (String s : ps.getArray(BEAN_notBeanPackages, 
String.class).orElse(DEFAULT_NOTBEAN_PACKAGES)) {
                        if (s.endsWith(".*"))
                                l2.add(s.substring(0, s.length()-2));
                        else
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 ccc4333..ac324cd 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
@@ -405,7 +405,7 @@ public final class PropertyStore {
         *
         * @param key The property name.
         * @param type The class type of the property.
-        * @return The property value, or the default value if it doesn't exist.
+        * @return The property value, never <jk>null</jk>.
         */
        public <T> Optional<Class<? extends T>> getClass(String key, Class<T> 
type) {
                Property p = findProperty(key);
@@ -417,24 +417,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, or an empty array if it doesn't exist.
-        */
-       public <T> T[] getArray(String key, Class<T> eType) {
-               Property p = findProperty(key);
-               return (T[]) (p == null ? Array.newInstance(eType, 0) : 
p.asArray(eType));
-       }
-
-       /**
-        * Returns the array property value 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.
-        * @return The property value, or an empty array if it doesn't exist.
+        * @return The property value, never <jk>null</jk>.
         */
-       public <T> T[] getArray(String key, Class<T> eType, T[] def) {
+       public <T> Optional<T[]> getArray(String key, Class<T> eType) {
                Property p = findProperty(key);
-               return p == null ? def : p.asArray(eType);
+               return Optional.ofNullable(p == null ? null : p.asArray(eType));
        }
 
        /**
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
index fa796fd..ff56aa8 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
@@ -763,17 +763,17 @@ public class HtmlDocSerializer extends 
HtmlStrippedDocSerializer {
         */
        public HtmlDocSerializer(PropertyStore ps, String produces, String 
accept) {
                super(ps, produces, accept);
-               style = ps.getArray(HTMLDOC_style, String.class);
-               stylesheet = ps.getArray(HTMLDOC_stylesheet, String.class);
-               script = ps.getArray(HTMLDOC_script, String.class);
-               head = ps.getArray(HTMLDOC_head, String.class);
-               header = ps.getArray(HTMLDOC_header, String.class);
-               nav = ps.getArray(HTMLDOC_nav, String.class);
-               aside = ps.getArray(HTMLDOC_aside, String.class);
+               style = ps.getArray(HTMLDOC_style, String.class).orElse(new 
String[0]);
+               stylesheet = ps.getArray(HTMLDOC_stylesheet, 
String.class).orElse(new String[0]);
+               script = ps.getArray(HTMLDOC_script, String.class).orElse(new 
String[0]);
+               head = ps.getArray(HTMLDOC_head, String.class).orElse(new 
String[0]);
+               header = ps.getArray(HTMLDOC_header, String.class).orElse(new 
String[0]);
+               nav = ps.getArray(HTMLDOC_nav, String.class).orElse(new 
String[0]);
+               aside = ps.getArray(HTMLDOC_aside, String.class).orElse(new 
String[0]);
                asideFloat = ps.get(HTMLDOC_asideFloat, 
AsideFloat.class).orElse(AsideFloat.RIGHT);
-               footer = ps.getArray(HTMLDOC_footer, String.class);
+               footer = ps.getArray(HTMLDOC_footer, String.class).orElse(new 
String[0]);
                nowrap = ps.getBoolean(HTMLDOC_nowrap).orElse(false);
-               navlinks = ps.getArray(HTMLDOC_navlinks, String.class);
+               navlinks = ps.getArray(HTMLDOC_navlinks, 
String.class).orElse(new String[0]);
                noResultsMessage = 
ps.getString(HTMLDOC_noResultsMessage).orElse("<p>no results</p>");
                template = ps.getInstance(HTMLDOC_template, 
HtmlDocTemplate.class, BasicHtmlDocTemplate.class);
 
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 a76085d..cea95a3 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
@@ -2053,7 +2053,7 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
                this.logRequestsPredicate = 
ps.getInstance(RESTCLIENT_logRequestsPredicate, BiPredicate.class, 
LOG_REQUESTS_PREDICATE_DEFAULT);
 
                SerializerGroupBuilder sgb = SerializerGroup.create();
-               for (Object o : ps.getArray(RESTCLIENT_serializers, 
Object.class)) {
+               for (Object o : ps.getArray(RESTCLIENT_serializers, 
Object.class).orElse(new Object[0])) {
                        if (o instanceof Serializer) {
                                sgb.append((Serializer)o);  // Don't apply 
PropertyStore.
                        } else if (o instanceof Class) {
@@ -2068,7 +2068,7 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
                this.serializers = sgb.build();
 
                ParserGroupBuilder pgb = ParserGroup.create();
-               for (Object o : ps.getArray(RESTCLIENT_parsers, Object.class)) {
+               for (Object o : ps.getArray(RESTCLIENT_parsers, 
Object.class).orElse(new Object[0])) {
                        if (o instanceof Parser) {
                                pgb.append((Parser)o);  // Don't apply 
PropertyStore.
                        } else if (o instanceof Class) {
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 be96e8c..b160329 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
@@ -4246,7 +4246,7 @@ public class RestContext extends BeanContext {
         */
        protected SerializerGroupBuilder createSerializerGroupBuilder(Object 
resource, PropertyStore properties, BeanFactory beanFactory) throws Exception {
 
-               Object[] x = properties.getArray(REST_serializers, 
Object.class);
+               Object[] x = properties.getArray(REST_serializers, 
Object.class).orElse(null);
 
                if (x == null)
                        x = 
beanFactory.getBean(Serializer[].class).orElse(null);
@@ -4341,7 +4341,7 @@ public class RestContext extends BeanContext {
         */
        protected ParserGroupBuilder createParserGroupBuilder(Object resource, 
PropertyStore properties, BeanFactory beanFactory) throws Exception {
 
-               Object[] x = properties.getArray(REST_parsers, Object.class);
+               Object[] x = properties.getArray(REST_parsers, 
Object.class).orElse(null);
 
                if (x == null)
                        x = beanFactory.getBean(Parser[].class).orElse(null);
@@ -5576,7 +5576,7 @@ public class RestContext extends BeanContext {
                        .implClass(properties.getClass(REST_restChildrenClass, 
RestChildren.class).orElse(null));
 
                // Initialize our child resources.
-               for (Object o : properties.getArray(REST_children, 
Object.class)) {
+               for (Object o : properties.getArray(REST_children, 
Object.class).orElse(new Object[0])) {
                        String path = null;
 
                        if (o instanceof RestChild) {
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 135ee8f..0e41e05 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
@@ -1103,7 +1103,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
                SerializerGroup g = 
beanFactory.getBean(SerializerGroup.class).orElse(null);
 
                if (g == null) {
-                       Object[] x = ps.getArray(REST_serializers, 
Object.class);
+                       Object[] x = ps.getArray(REST_serializers, 
Object.class).orElse(null);
 
                        if (x == null)
                                x = 
beanFactory.getBean(Serializer[].class).orElse(null);
@@ -1164,7 +1164,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
                ParserGroup g = 
beanFactory.getBean(ParserGroup.class).orElse(null);
 
                if (g == null) {
-                       Object[] x = ps.getArray(REST_parsers, Object.class);
+                       Object[] x = ps.getArray(REST_parsers, 
Object.class).orElse(null);
 
                        if (x == null)
                                x = 
beanFactory.getBean(Parser[].class).orElse(null);
@@ -1322,7 +1322,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
                UrlPathMatcherList x = UrlPathMatcherList.create();
                boolean dotAll = 
properties.getBoolean("RestOperationContext.dotAll.b").orElse(false);
 
-               for (String p : properties.getArray(RESTOP_path, String.class)) 
{
+               for (String p : properties.getArray(RESTOP_path, 
String.class).orElse(new String[0])) {
                        if (dotAll && ! p.endsWith("/*"))
                                p += "/*";
                        x.add(UrlPathMatcher.of(p));

Reply via email to