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 39abff5  Collections usage optimizations
39abff5 is described below

commit 39abff5c50d0d7abfa908049a6dc4f4fc0f8b29b
Author: JamesBognar <[email protected]>
AuthorDate: Fri Mar 18 12:40:38 2022 -0400

    Collections usage optimizations
---
 .../org/apache/juneau/utils/ThrowingConsumer.java  | 47 +++++++++++++
 .../org/apache/juneau/rest/client/RestClient.java  | 30 +++------
 .../org/apache/juneau/rest/client/RestRequest.java | 74 ++++++++-------------
 .../juneau/rest/client/remote/RemoteMeta.java      |  3 -
 .../rest/client/remote/RemoteOperationMeta.java    | 77 ++++++++++++++--------
 .../apache/juneau/rest/mock/MockRestClient.java    |  7 +-
 .../juneau/rest/mock/MockServletRequest.java       | 17 +++--
 .../test/java/org/apache/juneau/BenchmarkTest.java | 35 ++++++----
 8 files changed, 168 insertions(+), 122 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ThrowingConsumer.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ThrowingConsumer.java
new file mode 100644
index 0000000..ba0e686
--- /dev/null
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ThrowingConsumer.java
@@ -0,0 +1,47 @@
+// 
***************************************************************************************************************************
+// * 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 static org.apache.juneau.internal.ThrowableUtils.*;
+
+import java.util.function.*;
+
+/**
+ * A subclass of {@link Consumer} that allows for thrown exceptions.
+ *
+ * <ul class='seealso'>
+ *     <li class='extlink'>{@source}
+ * </ul>
+ *
+ * @param <T> the type of the input to the consumer.
+ */
+@FunctionalInterface
+public interface ThrowingConsumer<T> extends Consumer<T> {
+
+       @Override
+       default void accept(T t) {
+               try {
+                       acceptThrows(t);
+               } catch (Exception e) {
+                       throw runtimeException(e);
+               }
+       }
+
+       /**
+        * The functional method to implement.
+        *
+        * @param t The type of the input to the consumer.
+        * @throws Exception
+        */
+       void acceptThrows(T t) throws Exception;
+}
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 beed99d..00b3c60 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
@@ -7440,8 +7440,7 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
                try {
                        RestRequest req = request(method, uri, 
isNotEmpty(content));
                        if (headers != null)
-                               for (Map.Entry<String,Object> e : 
JsonMap.ofJson(headers).entrySet())
-                                       req.header(stringHeader(e.getKey(), 
stringify(e.getValue())));
+                               JsonMap.ofJson(headers).forEach((k,v) -> 
req.header(stringHeader(k, stringify(v))));
                        if (isNotEmpty(content))
                                req.bodyString(content);
                        return req;
@@ -7740,30 +7739,21 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
                                        rc.parser(parser);
 
                                        rm.getHeaders().forEach(x -> 
rc.header(x));
-
-                                       for (RemoteOperationArg a : 
rom.getPathArgs())
-                                               rc.pathArg(a.getName(), 
args[a.getIndex()], a.getSchema(), a.getSerializer().orElse(partSerializer));
-
-                                       for (RemoteOperationArg a : 
rom.getQueryArgs())
-                                               rc.queryArg(a.getName(), 
args[a.getIndex()], a.getSchema(), a.getSerializer().orElse(partSerializer), 
a.isSkipIfEmpty());
-
-                                       for (RemoteOperationArg a : 
rom.getFormDataArgs())
-                                               rc.formDataArg(a.getName(), 
args[a.getIndex()], a.getSchema(), a.getSerializer().orElse(partSerializer), 
a.isSkipIfEmpty());
-
-                                       for (RemoteOperationArg a : 
rom.getHeaderArgs())
-                                               rc.headerArg(a.getName(), 
args[a.getIndex()], a.getSchema(), a.getSerializer().orElse(partSerializer), 
a.isSkipIfEmpty());
+                                       rom.forEachPathArg(a -> 
rc.pathArg(a.getName(), args[a.getIndex()], a.getSchema(), 
a.getSerializer().orElse(partSerializer)));
+                                       rom.forEachQueryArg(a -> 
rc.queryArg(a.getName(), args[a.getIndex()], a.getSchema(), 
a.getSerializer().orElse(partSerializer), a.isSkipIfEmpty()));
+                                       rom.forEachFormDataArg(a -> 
rc.formDataArg(a.getName(), args[a.getIndex()], a.getSchema(), 
a.getSerializer().orElse(partSerializer), a.isSkipIfEmpty()));
+                                       rom.forEachHeaderArg(a -> 
rc.headerArg(a.getName(), args[a.getIndex()], a.getSchema(), 
a.getSerializer().orElse(partSerializer), a.isSkipIfEmpty()));
 
                                        RemoteOperationArg ba = 
rom.getBodyArg();
                                        if (ba != null)
                                                rc.body(args[ba.getIndex()], 
ba.getSchema());
 
-                                       if (rom.getRequestArgs().length > 0) {
-                                               for (RemoteOperationBeanArg 
rmba : rom.getRequestArgs()) {
+                                       rom.forEachRequestArg(rmba -> {
                                                        RequestBeanMeta rbm = 
rmba.getMeta();
                                                        Object bean = 
args[rmba.getIndex()];
                                                        if (bean != null) {
                                                                for 
(RequestBeanPropertyMeta p : rbm.getProperties()) {
-                                                                       Object 
val = p.getGetter().invoke(bean);
+                                                                       Object 
val = safeSupplier(()->p.getGetter().invoke(bean));
                                                                        
HttpPartType pt = p.getPartType();
                                                                        String 
pn = p.getPartName();
                                                                        
HttpPartSchema schema = p.getSchema();
@@ -7781,8 +7771,7 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
                                                                        }
                                                                }
                                                        }
-                                               }
-                                       }
+                                       });
 
                                        RemoteOperationReturn ror = 
rom.getReturns();
                                        if (ror.isFuture()) {
@@ -7825,7 +7814,8 @@ public class RestClient extends BeanContextable 
implements HttpClient, Closeable
                try {
                        Object ret = null;
                        RestResponse res = null;
-                       
rc.rethrow(RuntimeException.class).rethrow(rom.getExceptions());
+                       rc.rethrow(RuntimeException.class);
+                       rom.forEachException(x -> rc.rethrow(x));
                        if (ror.getReturnValue() == RemoteReturn.NONE) {
                                res = rc.complete();
                        } else if (ror.getReturnValue() == RemoteReturn.STATUS) 
{
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java
index 5264782..cf0f432 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java
@@ -1311,8 +1311,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                if (! isBean(value))
                        throw runtimeException("Object passed into 
headersBean(Object) is not a bean.");
                HeaderList.Builder b = getHeaderDataBuilder();
-               for (Map.Entry<String,Object> e : toBeanMap(value, 
PropertyNamerDUCS.INSTANCE).entrySet())
-                       b.append(createHeader(e.getKey(), e.getValue()));
+               toBeanMap(value, PropertyNamerDUCS.INSTANCE).forEach((k,v) -> 
b.append(createHeader(k, v)));
                return this;
        }
 
@@ -1340,8 +1339,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                if (! isBean(value))
                        throw runtimeException("Object passed into 
queryDataBean(Object) is not a bean.");
                PartList.Builder b = getQueryDataBuilder();
-               for (Map.Entry<String,Object> e : toBeanMap(value).entrySet())
-                       b.append(createPart(QUERY, e.getKey(), e.getValue()));
+               toBeanMap(value).forEach((k,v) -> b.append(createPart(QUERY, k, 
v)));
                return this;
        }
 
@@ -1369,8 +1367,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                if (! isBean(value))
                        throw runtimeException("Object passed into 
formDataBean(Object) is not a bean.");
                PartList.Builder b = getFormDataBuilder();
-               for (Map.Entry<String,Object> e : toBeanMap(value).entrySet())
-                       b.append(createPart(FORMDATA, e.getKey(), 
e.getValue()));
+               toBeanMap(value).forEach((k,v) -> b.append(createPart(FORMDATA, 
k, v)));
                return this;
        }
 
@@ -1398,8 +1395,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                if (! isBean(value))
                        throw runtimeException("Object passed into 
pathDataBean(Object) is not a bean.");
                PartList.Builder b = getPathDataBuilder();
-               for (Map.Entry<String,Object> e : toBeanMap(value).entrySet())
-                       b.set(createPart(PATH, e.getKey(), e.getValue()));
+               toBeanMap(value).forEach((k,v) -> b.set(createPart(PATH, k, 
v)));
                return this;
        }
 
@@ -1546,9 +1542,8 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
         *                      {@link PartList} - Converted to a URL-encoded 
query.
         *      </ul>
         * @return This object.
-        * @throws RestCallException Invalid input.
         */
-       public RestRequest queryCustom(Object value) throws RestCallException {
+       public RestRequest queryCustom(Object value) {
                try {
                        String q = null;
                        if (value instanceof Reader)
@@ -1559,7 +1554,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                                q = stringify(value);  // Works for 
NameValuePairs.
                        uriBuilder.setCustomQuery(q);
                } catch (IOException e) {
-                       throw new RestCallException(null, e, "Could not read 
custom query.");
+                       throw runtimeException(e, "Could not read custom 
query.");
                }
                return this;
        }
@@ -1608,9 +1603,8 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
         *                      {@link PartList} - Converted to a URL-encoded 
FORM post.
         *      </ul>
         * @return This object.
-        * @throws RestCallException Invalid input.
         */
-       public RestRequest formDataCustom(Object value) throws 
RestCallException {
+       public RestRequest formDataCustom(Object value) {
                header(ContentType.APPLICATION_FORM_URLENCODED);
                body(value instanceof CharSequence ? new 
StringReader(value.toString()) : value);
                return this;
@@ -1620,7 +1614,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
        // Args
        
//------------------------------------------------------------------------------------------------------------------
 
-       RestRequest headerArg(String name, Object value, HttpPartSchema schema, 
HttpPartSerializer serializer, boolean skipIfEmpty) throws RestCallException {
+       RestRequest headerArg(String name, Object value, HttpPartSchema schema, 
HttpPartSerializer serializer, boolean skipIfEmpty) {
                boolean isMulti = isEmpty(name) || "*".equals(name) || value 
instanceof HeaderList || isHeaderArray(value);
 
                if (! isMulti) {
@@ -1636,19 +1630,16 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                } else if (value instanceof HeaderList) {
                        ((HeaderList)value).forEach(x->l.add(x));
                } else if (value instanceof Collection) {
-                       for (Object o : (Collection<?>)value)
-                               l.add(HttpHeaders.cast(o));
+                       ((Collection<?>)value).forEach(x -> 
l.add(HttpHeaders.cast(x)));
                } else if (value != null && value.getClass().isArray()) {
                        for (int i = 0; i < Array.getLength(value); i++)
                                l.add(HttpHeaders.cast(Array.get(value, i)));
                } else if (value instanceof Map) {
-                       for (Map.Entry<Object,Object> e : 
toMap(value).entrySet())
-                               l.add(createHeader(stringify(e.getKey()), 
e.getValue(), serializer, schema, skipIfEmpty));
+                       toMap(value).forEach((k,v) -> 
l.add(createHeader(stringify(k), v, serializer, schema, skipIfEmpty)));
                } else if (isBean(value)) {
-                       for (Map.Entry<String,Object> e : 
toBeanMap(value).entrySet())
-                               l.add(createHeader(e.getKey(), e.getValue(), 
serializer, schema, skipIfEmpty));
+                       toBeanMap(value).forEach((k,v) -> l.add(createHeader(k, 
v, serializer, schema, skipIfEmpty)));
                } else if (value != null) {
-                       throw new RestCallException(null, null, "Invalid value 
type for header arg ''{0}'': {1}", name, className(value));
+                       throw runtimeException("Invalid value type for header 
arg ''{0}'': {1}", name, className(value));
                }
 
                if (skipIfEmpty)
@@ -1659,7 +1650,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                return this;
        }
 
-       RestRequest queryArg(String name, Object value, HttpPartSchema schema, 
HttpPartSerializer serializer, boolean skipIfEmpty) throws RestCallException {
+       RestRequest queryArg(String name, Object value, HttpPartSchema schema, 
HttpPartSerializer serializer, boolean skipIfEmpty) {
                boolean isMulti = isEmpty(name) || "*".equals(name) || value 
instanceof PartList || isNameValuePairArray(value);
 
                if (! isMulti) {
@@ -1675,17 +1666,14 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                } else if (value instanceof PartList) {
                        ((PartList)value).forEach(x->l.add(x));
                } else if (value instanceof Collection) {
-                       for (Object o : (Collection<?>)value)
-                               l.add(HttpParts.cast(o));
+                       ((Collection<?>)value).forEach(x -> 
l.add(HttpParts.cast(x)));
                } else if (value != null && value.getClass().isArray()) {
                        for (int i = 0; i < Array.getLength(value); i++)
                                l.add(HttpParts.cast(Array.get(value, i)));
                } else if (value instanceof Map) {
-                       for (Map.Entry<Object,Object> e : 
toMap(value).entrySet())
-                               l.add(createPart(stringify(e.getKey()), 
e.getValue(), QUERY, serializer, schema, skipIfEmpty));
+                       toMap(value).forEach((k,v) -> 
l.add(createPart(stringify(k), v, QUERY, serializer, schema, skipIfEmpty)));
                } else if (isBean(value)) {
-                       for (Map.Entry<String,Object> e : 
toBeanMap(value).entrySet())
-                               l.add(createPart(e.getKey(), e.getValue(), 
QUERY, serializer, schema, skipIfEmpty));
+                       toBeanMap(value).forEach((k,v) -> l.add(createPart(k, 
v, QUERY, serializer, schema, skipIfEmpty)));
                } else if (value != null) {
                        queryCustom(value);
                        return this;
@@ -1699,7 +1687,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                return this;
        }
 
-       RestRequest formDataArg(String name, Object value, HttpPartSchema 
schema, HttpPartSerializer serializer, boolean skipIfEmpty) throws 
RestCallException {
+       RestRequest formDataArg(String name, Object value, HttpPartSchema 
schema, HttpPartSerializer serializer, boolean skipIfEmpty) {
                boolean isMulti = isEmpty(name) || "*".equals(name) || value 
instanceof PartList || isNameValuePairArray(value);
 
                if (! isMulti) {
@@ -1715,17 +1703,14 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                } else if (value instanceof PartList) {
                        ((PartList)value).forEach(x->l.add(x));
                } else if (value instanceof Collection) {
-                       for (Object o : (Collection<?>)value)
-                               l.add(HttpParts.cast(o));
+                       ((Collection<?>)value).forEach(x -> 
l.add(HttpParts.cast(x)));
                } else if (value != null && value.getClass().isArray()) {
                        for (int i = 0; i < Array.getLength(value); i++)
                                l.add(HttpParts.cast(Array.get(value, i)));
                } else if (value instanceof Map) {
-                       for (Map.Entry<Object,Object> e : 
toMap(value).entrySet())
-                               l.add(createPart(stringify(e.getKey()), 
e.getValue(), FORMDATA, serializer, schema, skipIfEmpty));
+                       toMap(value).forEach((k,v) -> 
l.add(createPart(stringify(k), v, FORMDATA, serializer, schema, skipIfEmpty)));
                } else if (isBean(value)) {
-                       for (Map.Entry<String,Object> e : 
toBeanMap(value).entrySet())
-                               l.add(createPart(e.getKey(), e.getValue(), 
FORMDATA, serializer, schema, skipIfEmpty));
+                       toBeanMap(value).forEach((k,v) -> l.add(createPart(k, 
v, FORMDATA, serializer, schema, skipIfEmpty)));
                } else if (value != null) {
                        formDataCustom(value);
                        return this;
@@ -1739,7 +1724,7 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                return this;
        }
 
-       RestRequest pathArg(String name, Object value, HttpPartSchema schema, 
HttpPartSerializer serializer) throws RestCallException {
+       RestRequest pathArg(String name, Object value, HttpPartSchema schema, 
HttpPartSerializer serializer) {
                boolean isMulti = isEmpty(name) || "*".equals(name) || value 
instanceof PartList || isNameValuePairArray(value);
 
                if (! isMulti)
@@ -1752,19 +1737,16 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
                } else if (value instanceof PartList) {
                        ((PartList)value).forEach(x->l.add(x));
                } else if (value instanceof Collection) {
-                       for (Object o : (Collection<?>)value)
-                               l.add(HttpParts.cast(o));
+                       ((Collection<?>)value).forEach(x -> 
l.add(HttpParts.cast(x)));
                } else if (value != null && value.getClass().isArray()) {
                        for (int i = 0; i < Array.getLength(value); i++)
                                l.add(HttpParts.cast(Array.get(value, i)));
                } else if (value instanceof Map) {
-                       for (Map.Entry<Object,Object> e : 
toMap(value).entrySet())
-                               l.add(createPart(stringify(e.getKey()), 
e.getValue(), PATH, serializer, schema, false));
+                       toMap(value).forEach((k,v) -> 
l.add(createPart(stringify(k), v, PATH, serializer, schema, false)));
                } else if (isBean(value)) {
-                       for (Map.Entry<String,Object> e : 
toBeanMap(value).entrySet())
-                               l.add(createPart(e.getKey(), e.getValue(), 
PATH, serializer, schema, false));
+                       toBeanMap(value).forEach((k,v) -> l.add(createPart(k, 
v, PATH, serializer, schema, false)));
                } else if (value != null) {
-                       throw new RestCallException(null, null, "Invalid value 
type for path arg ''{0}'': {1}", name, className(value));
+                       throw runtimeException("Invalid value type for path arg 
''{0}'': {1}", name, className(value));
                }
 
                getPathDataBuilder().append(l);
@@ -1800,9 +1782,8 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
         *                      A {@link Supplier} of anything on this list.
         *      </ul>
         * @return This object.
-        * @throws RestCallException If a retry was attempted, but the entity 
was not repeatable.
         */
-       public RestRequest body(Object input) throws RestCallException {
+       public RestRequest body(Object input) {
                this.input = input;
                return this;
        }
@@ -1871,9 +1852,8 @@ public class RestRequest extends BeanSession implements 
HttpUriRequest, Configur
         *              <li>Only used if serializer is schema-aware (e.g. 
{@link OpenApiSerializer}).
         *      </ul>
         * @return This object.
-        * @throws RestCallException If a retry was attempted, but the entity 
was not repeatable.
         */
-       public RestRequest body(Object input, HttpPartSchema schema) throws 
RestCallException {
+       public RestRequest body(Object input, HttpPartSchema schema) {
                this.input = input;
                this.requestBodySchema = schema;
                return this;
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMeta.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMeta.java
index 94e2372..3d873e1 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMeta.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMeta.java
@@ -53,9 +53,6 @@ public class RemoteMeta {
 
                ClassInfo ci = ClassInfo.of(c);
                List<Remote> remotes = ci.getAnnotations(Remote.class);
-               for (Remote r : remotes)
-                       if (! r.path().isEmpty())
-                               path = trimSlashes(r.path());
 
                String versionHeader = "Client-Version", clientVersion = null;
                HeaderList.Builder headersBuilder = 
HeaderList.create().resolving();
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
index f33e7a1..067bb62 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteOperationMeta.java
@@ -18,6 +18,7 @@ import static org.apache.juneau.http.remote.RemoteUtils.*;
 
 import java.lang.reflect.*;
 import java.util.*;
+import java.util.function.*;
 
 import org.apache.juneau.*;
 import org.apache.juneau.http.annotation.*;
@@ -130,8 +131,8 @@ public class RemoteOperationMeta {
 
                        fullPath = path.indexOf("://") != -1 ? path : 
(parentPath.isEmpty() ? urlEncodePath(path) : (trimSlashes(parentPath) + '/' + 
urlEncodePath(path)));
 
-                       for (ParamInfo mpi : mi.getParams()) {
-                               RemoteOperationArg rma = 
RemoteOperationArg.create(mpi);
+                       mi.getParams().forEach(x -> {
+                               RemoteOperationArg rma = 
RemoteOperationArg.create(x);
                                if (rma != null) {
                                        HttpPartType pt = rma.getPartType();
                                        if (pt == HEADER)
@@ -145,11 +146,11 @@ public class RemoteOperationMeta {
                                        else
                                                bodyArg = rma;
                                }
-                               RequestBeanMeta rmba = 
RequestBeanMeta.create(mpi, AnnotationWorkList.create());
+                               RequestBeanMeta rmba = 
RequestBeanMeta.create(x, AnnotationWorkList.create());
                                if (rmba != null) {
-                                       requestArgs.add(new 
RemoteOperationBeanArg(mpi.getIndex(), rmba));
+                                       requestArgs.add(new 
RemoteOperationBeanArg(x.getIndex(), rmba));
                                }
-                       }
+                       });
                }
        }
 
@@ -172,48 +173,63 @@ public class RemoteOperationMeta {
        }
 
        /**
-        * Returns the {@link Path @Path} annotated arguments on this Java 
method.
+        * Performs an action on the {@link Path @Path} annotated arguments on 
this Java method.
         *
-        * @return A map of {@link Path#value() @Path(value)} names to 
zero-indexed argument indices.
+        * @param action The action to perform.
+        * @return This object.
         */
-       public RemoteOperationArg[] getPathArgs() {
-               return pathArgs;
+       public RemoteOperationMeta forEachPathArg(Consumer<RemoteOperationArg> 
action) {
+               for (RemoteOperationArg a : pathArgs)
+                       action.accept(a);
+               return this;
        }
 
        /**
-        * Returns the {@link Query @Query} annotated arguments on this Java 
method.
+        * Performs an action on the {@link Query @Query} annotated arguments 
on this Java method.
         *
-        * @return A map of {@link Query#value() @Query(value)} names to 
zero-indexed argument indices.
+        * @param action The action to perform.
+        * @return This object.
         */
-       public RemoteOperationArg[] getQueryArgs() {
-               return queryArgs;
+       public RemoteOperationMeta forEachQueryArg(Consumer<RemoteOperationArg> 
action) {
+               for (RemoteOperationArg a : queryArgs)
+                       action.accept(a);
+               return this;
        }
 
        /**
-        * Returns the {@link FormData @FormData} annotated arguments on this 
Java method.
+        * Performs an action on the {@link FormData @FormData} annotated 
arguments on this Java method.
         *
-        * @return A map of {@link FormData#value() @FormData(value)} names to 
zero-indexed argument indices.
+        * @param action The action to perform.
+        * @return This object.
         */
-       public RemoteOperationArg[] getFormDataArgs() {
-               return formDataArgs;
+       public RemoteOperationMeta 
forEachFormDataArg(Consumer<RemoteOperationArg> action) {
+               for (RemoteOperationArg a : formDataArgs)
+                       action.accept(a);
+               return this;
        }
 
        /**
-        * Returns the {@link Header @Header} annotated arguments on this Java 
method.
+        * Performs an action on the {@link Header @Header} annotated arguments 
on this Java method.
         *
-        * @return A map of {@link Header#value() @Header(value)} names to 
zero-indexed argument indices.
+        * @param action The action to perform.
+        * @return This object.
         */
-       public RemoteOperationArg[] getHeaderArgs() {
-               return headerArgs;
+       public RemoteOperationMeta 
forEachHeaderArg(Consumer<RemoteOperationArg> action) {
+               for (RemoteOperationArg a : headerArgs)
+                       action.accept(a);
+               return this;
        }
 
        /**
-        * Returns the {@link Request @Request} annotated arguments on this 
Java method.
+        * Performs an action on the {@link Request @Request} annotated 
arguments on this Java method.
         *
-        * @return A list of zero-indexed argument indices.
+        * @param action The action to perform.
+        * @return This object.
         */
-       public RemoteOperationBeanArg[] getRequestArgs() {
-               return requestArgs;
+       public RemoteOperationMeta 
forEachRequestArg(Consumer<RemoteOperationBeanArg> action) {
+               for (RemoteOperationBeanArg a : requestArgs)
+                       action.accept(a);
+               return this;
        }
 
        /**
@@ -235,11 +251,14 @@ public class RemoteOperationMeta {
        }
 
        /**
-        * Returns the exceptions thrown by this method.
+        * Performs an action on the exceptions thrown by this method.
         *
-        * @return The exceptions thrown by this method.  Never <jk>null</jk>.
+        * @param action The action to perform.
+        * @return This object.
         */
-       public Class<?>[] getExceptions() {
-               return exceptions;
+       public RemoteOperationMeta forEachException(Consumer<Class<?>> action) {
+               for (Class<?> e : exceptions)
+                       action.accept(e);
+               return this;
        }
 }
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 7fb981b..2cdd8fe 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
@@ -2286,9 +2286,10 @@ public class MockRestClient extends RestClient 
implements HttpClientConnection {
                        sres.set(res);
 
                        HttpResponse response = new BasicHttpResponse(new 
BasicStatusLine(HttpVersion.HTTP_1_1, res.getStatus(), res.getMessage()));
-                       for (Map.Entry<String,String[]> e : 
res.getHeaders().entrySet())
-                               for (String hv : e.getValue())
-                                       response.addHeader(e.getKey(), hv);
+                       res.getHeaders().forEach((k,v) -> {
+                               for (String hv : v)
+                                       response.addHeader(k, hv);
+                       });
 
                        return response;
                } catch (Exception e) {
diff --git 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
index 8c08308..1c0980b 100644
--- 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
+++ 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
@@ -764,11 +764,12 @@ public class MockServletRequest implements 
HttpServletRequest {
                                queryString = "";
                        else {
                                StringBuilder sb = new StringBuilder();
-                               for (Map.Entry<String,String[]> e : 
queryDataMap.entrySet())
-                                       if (e.getValue() == null)
-                                               sb.append(sb.length() == 0 ? "" 
: "&").append(urlEncode(e.getKey()));
-                                       else for (String v : e.getValue())
-                                               sb.append(sb.length() == 0 ? "" 
: "&").append(urlEncode(e.getKey())).append('=').append(urlEncode(v));
+                               queryDataMap.forEach((k,v) -> {
+                                       if (v == null)
+                                               sb.append(sb.length() == 0 ? "" 
: "&").append(urlEncode(k));
+                                       else for (String v2 : v)
+                                               sb.append(sb.length() == 0 ? "" 
: "&").append(urlEncode(k)).append('=').append(urlEncode(v2));
+                               });
                                queryString = sb.toString();
                        }
                }
@@ -989,10 +990,8 @@ public class MockServletRequest implements 
HttpServletRequest {
 
                if (req instanceof MockRestRequest) {
                        MockRestRequest mreq = (MockRestRequest)req;
-                       for (Map.Entry<String,Object> a : 
mreq.getAttributeMap().entrySet())
-                               attribute(a.getKey(), a.getValue());
-                       for (Map.Entry<String,RequestDispatcher> a : 
mreq.getRequestDispatcherMap().entrySet())
-                               requestDispatcher(a.getKey(), a.getValue());
+                       mreq.getAttributeMap().forEach((k,v) -> attribute(k, 
v));
+                       mreq.getRequestDispatcherMap().forEach((k,v) -> 
requestDispatcher(k, v));
                        if (mreq.getCharacterEncoding() != null)
                                characterEncoding(mreq.getCharacterEncoding());
                        if (mreq.getProtocol() != null)
diff --git a/juneau-utest/src/test/java/org/apache/juneau/BenchmarkTest.java 
b/juneau-utest/src/test/java/org/apache/juneau/BenchmarkTest.java
index 41fb6c9..f4ca938 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/BenchmarkTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/BenchmarkTest.java
@@ -12,11 +12,14 @@
 
//***************************************************************************************************************************
 package org.apache.juneau;
 
+import static org.junit.runners.MethodSorters.*;
+
 import java.util.*;
 import java.util.Map.*;
 import java.util.function.*;
 import java.util.stream.*;
 
+import org.apache.juneau.utils.*;
 import org.junit.*;
 import org.junit.rules.*;
 
@@ -24,6 +27,7 @@ import com.carrotsearch.junitbenchmarks.*;
 
 @BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds = 20)
 @Ignore
+@FixMethodOrder(NAME_ASCENDING)
 public class BenchmarkTest {
 
        @Rule
@@ -58,22 +62,31 @@ public class BenchmarkTest {
        private static final Consumer<Map<String,Integer>> map_iterator2 = x -> 
{for (Entry<String,Integer> i : x.entrySet()) result += i.getValue();};
        private static final Consumer<Map<String,Integer>> map_forEach1 = x -> 
x.values().forEach(y -> result += y);
        private static final Consumer<Map<String,Integer>> map_forEach2 = x -> 
x.forEach((k,v) -> result += v);
-
-//     @Test public void a01a_list_iterator() { list_iterator.accept(LIST); }
-//     @Test public void a01b_list_for() { list_for.accept(LIST); }
-//     @Test public void a01c_list_foreach() { list_foreach.accept(LIST); }
-//     @Test public void b01a_list_iterator() { list_iterator.accept(LIST); }
-//     @Test public void b01b_list_for() { list_for.accept(LIST); }
-//     @Test public void b01c_list_foreach() { list_foreach.accept(LIST); }
+       private static final ThrowingConsumer<List<Integer>> slist_iterator = x 
-> {for (Integer i : x) result += i;};
+       private static final ThrowingConsumer<List<Integer>> slist_for = x -> 
{for (int i = 0; i < x.size(); i++) result += x.get(i);};
+       private static final ThrowingConsumer<List<Integer>> slist_foreach = x 
-> x.forEach(y -> result += y);
+       private static final ThrowingConsumer<Map<String,Integer>> 
smap_iterator1 = x -> {for (Integer i : x.values()) result += i;};
+       private static final ThrowingConsumer<Map<String,Integer>> 
smap_iterator2 = x -> {for (Entry<String,Integer> i : x.entrySet()) result += 
i.getValue();};
+       private static final ThrowingConsumer<Map<String,Integer>> 
smap_forEach1 = x -> x.values().forEach(y -> result += y);
+       private static final ThrowingConsumer<Map<String,Integer>> 
smap_forEach2 = x -> x.forEach((k,v) -> result += v);
+
+       @Test public void a01a_list_iterator() { list_iterator.accept(LIST); }
+       @Test public void a01b_list_for() { list_for.accept(LIST); }
+       @Test public void a01c_list_foreach() { list_foreach.accept(LIST); }
 
        @Test public void a01a_map_iterator1_S() { map_iterator1.accept(MAP); }
        @Test public void a01b_map_iterator2_S() { map_iterator2.accept(MAP); }
        @Test public void a01c_map_forEach1_S() { map_forEach1.accept(MAP); }
        @Test public void a01d_map_forEach2_S() { map_forEach2.accept(MAP); }
-       @Test public void b01a_map_iterator1_S() { map_iterator1.accept(MAP); }
-       @Test public void b01b_map_iterator2_S() { map_iterator2.accept(MAP); }
-       @Test public void b01c_map_forEach1_S() { map_forEach1.accept(MAP); }
-       @Test public void b01d_map_forEach2_S() { map_forEach2.accept(MAP); }
+
+       @Test public void b01a_list_iterator() { slist_iterator.accept(LIST); }
+       @Test public void b01b_list_for() { slist_for.accept(LIST); }
+       @Test public void b01c_list_foreach() { slist_foreach.accept(LIST); }
+
+       @Test public void b01a_map_iterator1_S() { smap_iterator1.accept(MAP); }
+       @Test public void b01b_map_iterator2_S() { smap_iterator2.accept(MAP); }
+       @Test public void b01c_map_forEach1_S() { smap_forEach1.accept(MAP); }
+       @Test public void b01d_map_forEach2_S() { smap_forEach2.accept(MAP); }
 
        public static void main(String[] args) {
                int cap = 100000;

Reply via email to