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 78387a6  Clean up builders.
78387a6 is described below

commit 78387a6ab039df9620e6f89dfc7f1a896b0a4098
Author: JamesBognar <[email protected]>
AuthorDate: Sun Aug 8 08:34:21 2021 -0400

    Clean up builders.
---
 .../java/org/apache/juneau/ContextBuilder.java     | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextBuilder.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextBuilder.java
index ed2ea08..66905a6 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextBuilder.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ContextBuilder.java
@@ -870,6 +870,10 @@ public abstract class ContextBuilder {
                return this;
        }
 
+       
//-----------------------------------------------------------------------------------------------------------------
+       // Helper methods.
+       
//-----------------------------------------------------------------------------------------------------------------
+
        /**
         * Looks up a default value from the environment.
         *
@@ -914,6 +918,47 @@ public abstract class ContextBuilder {
                return name2;
        }
 
+       /**
+        * Creates a list from an array of objects.
+        *
+        * @param objects The objects to create a list from.
+        * @return A new list not backed by the array.
+        */
+       @SuppressWarnings("unchecked")
+       protected <T> List<T> list(T...objects) {
+               return new ArrayList<>(Arrays.asList(objects));
+       }
+
+       /**
+        * Appends to an existing list.
+        *
+        * @param list The list to append to.
+        * @param objects The objects to append.
+        * @return The same list, or a new list if the list was <jk>null</jk>.
+        */
+       @SuppressWarnings("unchecked")
+       protected <T> List<T> append(List<T> list, T...objects) {
+               if (list == null)
+                       return list(objects);
+               list.addAll(Arrays.asList(objects));
+               return list;
+       }
+
+       /**
+        * Prepends to an existing list.
+        *
+        * @param list The list to prepend to.
+        * @param objects The objects to prepend.
+        * @return The same list, or a new list if the list was <jk>null</jk>.
+        */
+       @SuppressWarnings("unchecked")
+       protected <T> List<T> prepend(List<T> list, T...objects) {
+               if (list == null)
+                       return list(objects);
+               list.addAll(0, Arrays.asList(objects));
+               return list;
+       }
+
        // <FluentSetters>
 
        // </FluentSetters>

Reply via email to