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 f06381d Collections usage optimizations
f06381d is described below
commit f06381dec620e6ff5e010fed67b34a273fd00379
Author: JamesBognar <[email protected]>
AuthorDate: Mon Mar 14 10:18:20 2022 -0400
Collections usage optimizations
---
.../java/org/apache/juneau/AnnotationWorkList.java | 3 +-
.../main/java/org/apache/juneau/BeanContext.java | 25 ++-
.../main/java/org/apache/juneau/BeanFilter.java | 32 ++--
.../src/main/java/org/apache/juneau/BeanMap.java | 37 +++--
.../src/main/java/org/apache/juneau/BeanMeta.java | 170 ++++++++++-----------
.../java/org/apache/juneau/BeanPropertyMeta.java | 94 ++++++------
.../main/java/org/apache/juneau/BeanRegistry.java | 27 ++--
.../main/java/org/apache/juneau/BeanSession.java | 43 +++---
.../org/apache/juneau/BeanTraverseSession.java | 12 +-
.../src/main/java/org/apache/juneau/ClassMeta.java | 34 ++---
.../src/main/java/org/apache/juneau/Context.java | 16 +-
.../java/org/apache/juneau/MarshalledFilter.java | 12 +-
.../src/main/java/org/apache/juneau/Value.java | 11 ++
.../apache/juneau/html/BasicHtmlDocTemplate.java | 1 -
.../org/apache/juneau/internal/ArrayUtils.java | 36 +----
.../org/apache/juneau/{ => internal}/Flag.java | 70 +++++++--
.../java/org/apache/juneau/internal/IntValue.java | 75 +++++++++
.../org/apache/juneau/reflect/ConstructorInfo.java | 1 -
.../org/apache/juneau/reflect/ExecutableInfo.java | 14 ++
.../org/apache/juneau/svl/VarResolverSession.java | 27 ++--
.../urlencoding/UrlEncodingSerializerSession.java | 65 ++++----
.../java/org/apache/juneau/utils/BeanDiff.java | 4 +-
.../java/org/apache/juneau/utils/ManifestFile.java | 7 +-
.../java/org/apache/juneau/utils/PojoQuery.java | 27 ++--
.../org/apache/juneau/utils/ReflectionMap.java | 41 +++--
.../java/org/apache/juneau/utils/SearchArgs.java | 12 +-
.../main/java/org/apache/juneau/xml/Namespace.java | 4 +-
.../java/org/apache/juneau/xml/XmlBeanMeta.java | 4 +-
.../apache/juneau/xml/XmlSerializerSession.java | 38 ++---
.../org/apache/juneau/utils/ArrayUtilsTest.java | 25 ---
.../org/apache/juneau/utils/ReflectionMapTest.java | 16 --
31 files changed, 503 insertions(+), 480 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationWorkList.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationWorkList.java
index 840e9e0..4a5941a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationWorkList.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/AnnotationWorkList.java
@@ -103,8 +103,7 @@ public class AnnotationWorkList extends
ArrayList<AnnotationWork> {
* @return This object.
*/
public AnnotationWorkList add(AnnotationList annotations) {
- for (AnnotationInfo<?> ai : annotations.sort())
- ai.getApplies(vrs, x -> add(ai, x));
+ annotations.sort().forEach(x -> x.getApplies(vrs, y -> add(x,
y)));
return this;
}
}
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 33048b3..e01161a 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
@@ -1064,8 +1064,7 @@ public class BeanContext extends Context {
*/
@FluentSetter
public Builder beanProperties(Map<String,Object> values) {
- for (Map.Entry<String,Object> e : values.entrySet())
-
annotations(BeanAnnotation.create(e.getKey()).p(stringify(e.getValue())).build());
+ values.forEach((k,v) ->
annotations(BeanAnnotation.create(k).p(stringify(v)).build()));
return this;
}
@@ -1234,8 +1233,7 @@ public class BeanContext extends Context {
*/
@FluentSetter
public Builder beanPropertiesExcludes(Map<String,Object>
values) {
- for (Map.Entry<String,Object> e : values.entrySet())
-
annotations(BeanAnnotation.create(e.getKey()).xp(stringify(e.getValue())).build());
+ values.forEach((k,v) ->
annotations(BeanAnnotation.create(k).xp(stringify(v)).build()));
return this;
}
@@ -1402,8 +1400,7 @@ public class BeanContext extends Context {
*/
@FluentSetter
public Builder beanPropertiesReadOnly(Map<String,Object>
values) {
- for (Map.Entry<String,Object> e : values.entrySet())
-
annotations(BeanAnnotation.create(e.getKey()).ro(stringify(e.getValue())).build());
+ values.forEach((k,v) ->
annotations(BeanAnnotation.create(k).ro(stringify(v)).build()));
return this;
}
@@ -1571,8 +1568,7 @@ public class BeanContext extends Context {
*/
@FluentSetter
public Builder beanPropertiesWriteOnly(Map<String,Object>
values) {
- for (Map.Entry<String,Object> e : values.entrySet())
-
annotations(BeanAnnotation.create(e.getKey()).wo(stringify(e.getValue())).build());
+ values.forEach((k,v) ->
annotations(BeanAnnotation.create(k).wo(stringify(v)).build()));
return this;
}
@@ -2372,8 +2368,7 @@ public class BeanContext extends Context {
*/
@FluentSetter
public Builder implClasses(Map<Class<?>,Class<?>> values) {
- for (Map.Entry<Class<?>,Class<?>> e : values.entrySet())
-
annotations(MarshalledAnnotation.create(e.getKey()).implClass(e.getValue()).build());
+ values.forEach((k,v) ->
annotations(MarshalledAnnotation.create(k).implClass(v).build()));
return this;
}
@@ -3584,11 +3579,11 @@ public class BeanContext extends Context {
}
LinkedList<ObjectSwap<?,?>> _swaps = new LinkedList<>();
- for (Object o : optional(swaps).orElse(emptyList())) {
- if (o instanceof ObjectSwap) {
- _swaps.add((ObjectSwap<?,?>)o);
+ swaps.forEach(x -> {
+ if (x instanceof ObjectSwap) {
+ _swaps.add((ObjectSwap<?,?>)x);
} else {
- ClassInfo ci = ClassInfo.of((Class<?>)o);
+ ClassInfo ci = ClassInfo.of((Class<?>)x);
if (ci.isChildOf(ObjectSwap.class))
_swaps.add(BeanCreator.of(ObjectSwap.class).type(ci).run());
else if (ci.isChildOf(Surrogate.class))
@@ -3596,7 +3591,7 @@ public class BeanContext extends Context {
else
throw runtimeException("Invalid class
{0} specified in BeanContext.swaps property. Must be a subclass of ObjectSwap
or Surrogate.", ci.inner());
}
- }
+ });
swapArray = _swaps.toArray(new ObjectSwap[_swaps.size()]);
cmCache = new ConcurrentHashMap<>();
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
index aefa4f6..5aaa555 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanFilter.java
@@ -95,22 +95,22 @@ public final class BeanFilter {
*/
public Builder applyAnnotations(List<Bean> annotations) {
- for (Bean b : annotations) {
- if (isNotEmpty(b.properties(), b.p()))
properties(b.properties(), b.p());
- if (b.sort()) sortProperties(true);
- if (b.findFluentSetters()) findFluentSetters();
- if (isNotEmpty(b.excludeProperties(), b.xp()))
excludeProperties(b.excludeProperties(), b.xp());
- if (isNotEmpty(b.readOnlyProperties(), b.ro()))
readOnlyProperties(b.readOnlyProperties(), b.ro());
- if (isNotEmpty(b.writeOnlyProperties(),
b.wo())) writeOnlyProperties(b.writeOnlyProperties(), b.wo());
- if (isNotEmpty(b.typeName()))
typeName(b.typeName());
- if (isNotVoid(b.propertyNamer()))
propertyNamer(b.propertyNamer());
- if (isNotVoid(b.interfaceClass()))
interfaceClass(b.interfaceClass());
- if (isNotVoid(b.stopClass()))
stopClass(b.stopClass());
- if (isNotVoid(b.interceptor()))
interceptor(b.interceptor());
- if (isNotVoid(b.implClass()))
implClass(b.implClass());
- if (isNotEmptyArray(b.dictionary()))
dictionary(b.dictionary());
- if (isNotEmpty(b.example()))
example(b.example());
- }
+ annotations.forEach(x -> {
+ if (isNotEmpty(x.properties(), x.p()))
properties(x.properties(), x.p());
+ if (x.sort()) sortProperties(true);
+ if (x.findFluentSetters()) findFluentSetters();
+ if (isNotEmpty(x.excludeProperties(), x.xp()))
excludeProperties(x.excludeProperties(), x.xp());
+ if (isNotEmpty(x.readOnlyProperties(), x.ro()))
readOnlyProperties(x.readOnlyProperties(), x.ro());
+ if (isNotEmpty(x.writeOnlyProperties(),
x.wo())) writeOnlyProperties(x.writeOnlyProperties(), x.wo());
+ if (isNotEmpty(x.typeName()))
typeName(x.typeName());
+ if (isNotVoid(x.propertyNamer()))
propertyNamer(x.propertyNamer());
+ if (isNotVoid(x.interfaceClass()))
interfaceClass(x.interfaceClass());
+ if (isNotVoid(x.stopClass()))
stopClass(x.stopClass());
+ if (isNotVoid(x.interceptor()))
interceptor(x.interceptor());
+ if (isNotVoid(x.implClass()))
implClass(x.implClass());
+ if (isNotEmptyArray(x.dictionary()))
dictionary(x.dictionary());
+ if (isNotEmpty(x.example()))
example(x.example());
+ });
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
index 2551603..0c3dcf1 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMap.java
@@ -140,16 +140,13 @@ public class BeanMap<T> extends
AbstractMap<String,Object> implements Delegate<T
// If we have any arrays that need to be constructed, do it now.
if (arrayPropertyCache != null) {
- for (Map.Entry<String,List<?>> e :
arrayPropertyCache.entrySet()) {
- String key = e.getKey();
- List<?> value = e.getValue();
- BeanPropertyMeta bpm = getPropertyMeta(key);
+ arrayPropertyCache.forEach((k,v) -> {
try {
- bpm.setArray(b, value);
+ getPropertyMeta(k).setArray(b, v);
} catch (Exception e1) {
throw runtimeException(e1);
}
- }
+ });
arrayPropertyCache = null;
}
@@ -160,11 +157,11 @@ public class BeanMap<T> extends
AbstractMap<String,Object> implements Delegate<T
pMeta.set(this, pMeta.getName(),
cm.getOptionalDefault());
}
// Do the same for hidden fields.
- for (BeanPropertyMeta pMeta :
this.meta.hiddenProperties.values()) {
- ClassMeta<?> cm = pMeta.getClassMeta();
- if (cm.isOptional() && pMeta.get(this, pMeta.getName())
== null)
- pMeta.set(this, pMeta.getName(),
cm.getOptionalDefault());
- }
+ this.meta.hiddenProperties.forEach((k,v) -> {
+ ClassMeta<?> cm = v.getClassMeta();
+ if (cm.isOptional() && v.get(this, v.getName()) == null)
+ v.set(this, v.getName(),
cm.getOptionalDefault());
+ });
return b;
}
@@ -193,8 +190,7 @@ public class BeanMap<T> extends AbstractMap<String,Object>
implements Delegate<T
args[i] = propertyCache.remove(props[i]);
try {
bean = c.<T>invoke(args);
- for (Map.Entry<String,Object> e :
propertyCache.entrySet())
- put(e.getKey(), e.getValue());
+ propertyCache.forEach((k,v) -> put(k, v));
propertyCache = null;
} catch (IllegalArgumentException e) {
throw new BeanRuntimeException(e,
meta.classMeta.innerClass, "IllegalArgumentException occurred on call to class
constructor ''{0}'' with argument types ''{1}''", c.getSimpleName(),
SimpleJsonSerializer.DEFAULT.toString(ClassUtils.getClasses(args)));
@@ -427,9 +423,10 @@ public class BeanMap<T> extends AbstractMap<String,Object>
implements Delegate<T
if (meta.dynaProperty == null)
return meta.properties.keySet();
Set<String> l = set();
- for (String p : meta.properties.keySet())
- if (! "*".equals(p))
- l.add(p);
+ meta.properties.forEach((k,v) -> {
+ if (! "*".equals(k))
+ l.add(k);
+ });
try {
l.addAll(meta.dynaProperty.getDynaMap(bean).keySet());
} catch (Exception e) {
@@ -534,10 +531,10 @@ public class BeanMap<T> extends
AbstractMap<String,Object> implements Delegate<T
// TODO - This is kind of inefficient.
Map<String,Object> dynaMap =
bpm.getDynaMap(bean);
if (dynaMap != null) {
- for (String pName :
dynaMap.keySet()) {
- Object val =
bpm.get(this, pName);
- actions.put(pName, new
BeanPropertyValue(bpm, pName, val, null));
- }
+ dynaMap.forEach((k,v) -> {
+ Object val =
bpm.get(this, k);
+ actions.put(k, new
BeanPropertyValue(bpm, k, val, null));
+ });
}
} catch (Exception e) {
e.printStackTrace();
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
index 31da94d..c01f2e9 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanMeta.java
@@ -13,6 +13,7 @@
package org.apache.juneau;
import static org.apache.juneau.internal.CollectionUtils.*;
+import static org.apache.juneau.internal.ConsumerUtils.*;
import static org.apache.juneau.internal.StringUtils.*;
import static org.apache.juneau.internal.ThrowableUtils.*;
import static org.apache.juneau.internal.ObjectUtils.*;
@@ -25,6 +26,7 @@ import java.util.*;
import java.util.function.*;
import org.apache.juneau.annotation.*;
+import org.apache.juneau.internal.*;
import org.apache.juneau.reflect.*;
/**
@@ -228,8 +230,30 @@ public class BeanMeta<T> {
return "Class is not serializable";
// Look for @Beanc constructor on public
constructors.
- for (ConstructorInfo x :
ci.getPublicConstructors()) {
- if (x.hasAnnotation(ctx, Beanc.class)) {
+ ci.forEachPublicConstructor(x ->
x.hasAnnotation(ctx, Beanc.class), x -> {
+ if (constructor != null)
+ throw new
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
+ constructor = x;
+ constructorArgs = new String[0];
+ ctx.forEachAnnotation(Beanc.class,
x.inner(), y -> ! y.properties().isEmpty(), z -> constructorArgs =
split(z.properties()));
+ if (!
x.hasNumParams(constructorArgs.length)) {
+ if (constructorArgs.length != 0)
+ throw new
BeanRuntimeException(c, "Number of properties defined in '@Beanc' annotation
does not match number of parameters in constructor.");
+ constructorArgs = new
String[x.getParamCount()];
+ IntValue i = IntValue.create();
+ x.forEachParam(null, pi -> {
+ String pn =
pi.getName();
+ if (pn == null)
+ throw new
BeanRuntimeException(c, "Could not find name for parameter #{0} of constructor
''{1}''", i, x.getFullName());
+
constructorArgs[i.getAndIncrement()] = pn;
+ });
+ }
+ constructor.setAccessible();
+ });
+
+ // Look for @Beanc on all other constructors.
+ if (constructor == null) {
+ ci.forEachDeclaredConstructor(x ->
x.hasAnnotation(ctx, Beanc.class), x -> {
if (constructor != null)
throw new
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
constructor = x;
@@ -239,42 +263,16 @@ public class BeanMeta<T> {
if
(constructorArgs.length != 0)
throw new
BeanRuntimeException(c, "Number of properties defined in '@Beanc' annotation
does not match number of parameters in constructor.");
constructorArgs = new
String[x.getParamCount()];
- int i = 0;
- for (ParamInfo pi :
x.getParams()) {
- String pn =
pi.getName();
+ IntValue i =
IntValue.create();
+ x.forEachParam(null, y
-> {
+ String pn =
y.getName();
if (pn == null)
throw
new BeanRuntimeException(c, "Could not find name for parameter #{0} of
constructor ''{1}''", i, x.getFullName());
-
constructorArgs[i++] = pn;
- }
+
constructorArgs[i.getAndIncrement()] = pn;
+ });
}
constructor.setAccessible();
- }
- }
-
- // Look for @Beanc on all other constructors.
- if (constructor == null) {
- for (ConstructorInfo x :
ci.getDeclaredConstructors()) {
- if (x.hasAnnotation(ctx,
Beanc.class)) {
- if (constructor != null)
- throw new
BeanRuntimeException(c, "Multiple instances of '@Beanc' found.");
- constructor = x;
- constructorArgs = new
String[0];
-
ctx.forEachAnnotation(Beanc.class, x.inner(), y -> ! y.properties().isEmpty(),
z -> constructorArgs = split(z.properties()));
- if (!
x.hasNumParams(constructorArgs.length)) {
- if
(constructorArgs.length != 0)
- throw
new BeanRuntimeException(c, "Number of properties defined in '@Beanc'
annotation does not match number of parameters in constructor.");
- constructorArgs
= new String[x.getParamCount()];
- int i = 0;
- for (ParamInfo
pi : x.getParams()) {
- String
pn = pi.getName();
- if (pn
== null)
-
throw new BeanRuntimeException(c, "Could not find name for parameter #{0} of
constructor ''{1}''", i, x.getFullName());
-
constructorArgs[i++] = pn;
- }
- }
-
constructor.setAccessible();
- }
- }
+ });
}
// If this is an interface, look for impl
classes defined in the context.
@@ -323,8 +321,7 @@ public class BeanMeta<T> {
// First populate the properties with those
specified in the bean annotation to
// ensure that ordering first.
- for (String name : fixedBeanProps)
- normalProps.put(name,
BeanPropertyMeta.builder(beanMeta, name));
+ fixedBeanProps.forEach(x -> normalProps.put(x,
BeanPropertyMeta.builder(beanMeta, x)));
if (ctx.isUseJavaBeanIntrospector()) {
BeanInfo bi = null;
@@ -343,25 +340,25 @@ public class BeanMeta<T> {
} else /* Use 'better' introspection */ {
- for (Field f : findBeanFields(ctx, c2,
stopClass, fVis)) {
- String name =
findPropertyName(f);
+ findBeanFields(ctx, c2, stopClass,
fVis).forEach(x -> {
+ String name =
findPropertyName(x);
if (name != null) {
if (!
normalProps.containsKey(name))
normalProps.put(name, BeanPropertyMeta.builder(beanMeta, name));
-
normalProps.get(name).setField(f);
+
normalProps.get(name).setField(x);
}
- }
+ });
List<BeanMethod> bms =
findBeanMethods(ctx, c2, stopClass, mVis, propertyNamer, fluentSetters);
// Iterate through all the getters.
- for (BeanMethod bm : bms) {
- String pn = bm.propertyName;
- Method m = bm.method;
+ bms.forEach(x -> {
+ String pn = x.propertyName;
+ Method m = x.method;
if (!
normalProps.containsKey(pn))
normalProps.put(pn, new
BeanPropertyMeta.Builder(beanMeta, pn));
BeanPropertyMeta.Builder bpm =
normalProps.get(pn);
- if (bm.methodType == GETTER) {
+ if (x.methodType == GETTER) {
// Two getters. Pick
the best.
if (bpm.getter != null)
{
@@ -373,24 +370,24 @@ public class BeanMeta<T> {
}
bpm.setGetter(m);
}
- }
+ });
// Now iterate through all the setters.
- for (BeanMethod bm : bms) {
- if (bm.methodType == SETTER) {
-
BeanPropertyMeta.Builder bpm = normalProps.get(bm.propertyName);
- if
(bm.matchesPropertyType(bpm))
-
bpm.setSetter(bm.method);
+ bms.forEach(x -> {
+ if (x.methodType == SETTER) {
+
BeanPropertyMeta.Builder bpm = normalProps.get(x.propertyName);
+ if
(x.matchesPropertyType(bpm))
+
bpm.setSetter(x.method);
}
- }
+ });
// Now iterate through all the
extraKeys.
- for (BeanMethod bm : bms) {
- if (bm.methodType == EXTRAKEYS)
{
-
BeanPropertyMeta.Builder bpm = normalProps.get(bm.propertyName);
-
bpm.setExtraKeys(bm.method);
+ bms.forEach(x -> {
+ if (x.methodType == EXTRAKEYS) {
+
BeanPropertyMeta.Builder bpm = normalProps.get(x.propertyName);
+
bpm.setExtraKeys(x.method);
}
- }
+ });
}
typeVarImpls = map();
@@ -422,9 +419,10 @@ public class BeanMeta<T> {
}
// Check for missing properties.
- for (String fp : fixedBeanProps)
- if (! normalProps.containsKey(fp))
- throw new
BeanRuntimeException(c, "The property ''{0}'' was defined on the
@Bean(properties=X) annotation of class ''{1}'' but was not found on the class
definition.", fp, ci.getSimpleName());
+ fixedBeanProps.forEach(x -> {
+ if (! normalProps.containsKey(x))
+ throw new
BeanRuntimeException(c, "The property ''{0}'' was defined on the
@Bean(properties=X) annotation of class ''{1}'' but was not found on the class
definition.", x, ci.getSimpleName());
+ });
// Mark constructor arg properties.
for (String fp : constructorArgs) {
@@ -447,12 +445,12 @@ public class BeanMeta<T> {
if (dictionaryName == null)
dictionaryName =
findDictionaryName(this.classMeta);
- for (Map.Entry<String,BeanPropertyMeta.Builder>
e : normalProps.entrySet()) {
- BeanPropertyMeta pMeta =
e.getValue().build();
+ normalProps.forEach((k,v) -> {
+ BeanPropertyMeta pMeta = v.build();
if (pMeta.isDyna())
dynaProperty = pMeta;
- properties.put(e.getKey(), pMeta);
- }
+ properties.put(k, pMeta);
+ });
// If a beanFilter is defined, look for
inclusion and exclusion lists.
if (beanFilter != null) {
@@ -465,32 +463,29 @@ public class BeanMeta<T> {
// Only include specified
properties if BeanFilter.includeKeys is specified.
// Note that the order must
match includeKeys.
Map<String,BeanPropertyMeta>
properties2 = map();
- for (String k : bfbpi) {
- if
(properties.containsKey(k))
-
properties2.put(k, properties.remove(k));
- }
+ bfbpi.forEach(x -> {
+ if
(properties.containsKey(x))
+
properties2.put(x, properties.remove(x));
+ });
hiddenProperties.putAll(properties);
properties = properties2;
}
if (bpx.isEmpty() && ! bfbpx.isEmpty())
{
- for (String k : bfbpx) {
- hiddenProperties.put(k,
properties.remove(k));
- }
+ bfbpx.forEach(x ->
hiddenProperties.put(x, properties.remove(x)));
}
}
if (! bpi.isEmpty()) {
Map<String,BeanPropertyMeta>
properties2 = map();
- for (String k : bpi) {
- if (properties.containsKey(k))
- properties2.put(k,
properties.remove(k));
- }
+ bpi.forEach(x -> {
+ if (properties.containsKey(x))
+ properties2.put(x,
properties.remove(x));
+ });
hiddenProperties.putAll(properties);
properties = properties2;
}
- for (String ep : bpx)
- hiddenProperties.put(ep,
properties.remove(ep));
+ bpx.forEach(x -> hiddenProperties.put(x,
properties.remove(x)));
if (pNames != null) {
Map<String,BeanPropertyMeta>
properties2 = map();
@@ -659,6 +654,7 @@ public class BeanMeta<T> {
static final List<BeanMethod> findBeanMethods(BeanContext ctx, Class<?>
c, Class<?> stopClass, Visibility v, PropertyNamer pn, boolean fluentSetters) {
List<BeanMethod> l = new LinkedList<>();
+ String TODO = "Make more efficient";
for (ClassInfo c2 : findClasses(c, stopClass)) {
for (MethodInfo m : c2.getDeclaredMethods()) {
if (m.isStatic() || m.isBridge() ||
m.getParamCount() > 2 || m.hasAnnotation(ctx, BeanIgnore.class))
@@ -824,7 +820,7 @@ public class BeanMeta<T> {
*/
public void forEachProperty(Predicate<BeanPropertyMeta> filter,
Consumer<BeanPropertyMeta> action) {
for (BeanPropertyMeta x : propertyArray)
- if (filter.test(x))
+ if (passes(filter, x))
action.accept(x);
}
@@ -837,7 +833,7 @@ public class BeanMeta<T> {
*/
public <T2> Optional<T2> firstProperty(Predicate<BeanPropertyMeta>
filter, Function<BeanPropertyMeta,T2> function) {
for (BeanPropertyMeta x : propertyArray)
- if (filter.test(x))
+ if (passes(filter, x))
return Optional.ofNullable(function.apply(x));
return Optional.empty();
}
@@ -979,17 +975,15 @@ public class BeanMeta<T> {
if (! n.isEmpty())
return last(n).value();
- String name = p.isEmpty() ? null : "";
- for (Beanp pp : p) {
- if (! pp.value().isEmpty())
- name = pp.value();
- if (! pp.name().isEmpty())
- name = pp.name();
- }
- if (name != null)
- return name;
+ Value<String> name = Value.of(p.isEmpty() ? null : "");
+ p.forEach(x -> {
+ if (! x.value().isEmpty())
+ name.set(x.value());
+ if (! x.name().isEmpty())
+ name.set(x.name());
+ });
- return null;
+ return name.orElse(null);
}
@Override /* Object */
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index 9f48c1d..ba22e10 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -190,15 +190,15 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
rawTypeMeta =
bc.resolveClassMeta(last(lp), innerField.getGenericType(), typeVarImpls);
isUri |= (rawTypeMeta.isUri());
}
- for (Beanp p : lp) {
- if (! p.properties().isEmpty())
- properties =
split(p.properties());
- addAll(bdClasses, p.dictionary());
- if (! p.ro().isEmpty())
- readOnly =
Boolean.valueOf(p.ro());
- if (! p.wo().isEmpty())
- writeOnly =
Boolean.valueOf(p.wo());
- }
+ lp.forEach(x -> {
+ if (! x.properties().isEmpty())
+ properties =
split(x.properties());
+ addAll(bdClasses, x.dictionary());
+ if (! x.ro().isEmpty())
+ readOnly =
Boolean.valueOf(x.ro());
+ if (! x.wo().isEmpty())
+ writeOnly =
Boolean.valueOf(x.wo());
+ });
bc.forEachAnnotation(Swap.class, innerField, x
-> true, x -> swap = getPropertySwap(x));
isUri |= bc.firstAnnotation(Uri.class,
innerField, x->true) != null;
}
@@ -209,15 +209,15 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
if (rawTypeMeta == null)
rawTypeMeta =
bc.resolveClassMeta(last(lp), getter.getGenericReturnType(), typeVarImpls);
isUri |= (rawTypeMeta.isUri() ||
bc.hasAnnotation(Uri.class, getter));
- for (Beanp p : lp) {
- if (properties != null && !
p.properties().isEmpty())
- properties =
split(p.properties());
- addAll(bdClasses, p.dictionary());
- if (! p.ro().isEmpty())
- readOnly =
Boolean.valueOf(p.ro());
- if (! p.wo().isEmpty())
- writeOnly =
Boolean.valueOf(p.wo());
- }
+ lp.forEach(x -> {
+ if (properties != null && !
x.properties().isEmpty())
+ properties =
split(x.properties());
+ addAll(bdClasses, x.dictionary());
+ if (! x.ro().isEmpty())
+ readOnly =
Boolean.valueOf(x.ro());
+ if (! x.wo().isEmpty())
+ writeOnly =
Boolean.valueOf(x.wo());
+ });
bc.forEachAnnotation(Swap.class, getter, x ->
true, x -> swap = getPropertySwap(x));
}
@@ -227,17 +227,17 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
if (rawTypeMeta == null)
rawTypeMeta =
bc.resolveClassMeta(last(lp), setter.getGenericParameterTypes()[0],
typeVarImpls);
isUri |= (rawTypeMeta.isUri() ||
bc.hasAnnotation(Uri.class, setter));
- for (Beanp p : lp) {
+ lp.forEach(x -> {
if (swap == null)
- swap = getPropertySwap(p);
- if (properties != null && !
p.properties().isEmpty())
- properties =
split(p.properties());
- addAll(bdClasses, p.dictionary());
- if (! p.ro().isEmpty())
- readOnly =
Boolean.valueOf(p.ro());
- if (! p.wo().isEmpty())
- writeOnly =
Boolean.valueOf(p.wo());
- }
+ swap = getPropertySwap(x);
+ if (properties != null && !
x.properties().isEmpty())
+ properties =
split(x.properties());
+ addAll(bdClasses, x.dictionary());
+ if (! x.ro().isEmpty())
+ readOnly =
Boolean.valueOf(x.ro());
+ if (! x.wo().isEmpty())
+ writeOnly =
Boolean.valueOf(x.wo());
+ });
bc.forEachAnnotation(Swap.class, setter, x ->
true, x -> swap = getPropertySwap(x));
}
@@ -316,7 +316,7 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
return new BeanPropertyMeta(this);
}
- private ObjectSwap getPropertySwap(Beanp p) throws Exception {
+ private ObjectSwap getPropertySwap(Beanp p) {
if (! p.format().isEmpty())
return
BeanCreator.of(ObjectSwap.class).type(StringFormatSwap.class).arg(String.class,
p.format()).run();
return null;
@@ -630,8 +630,7 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
Collection c = (Collection)o;
List l = list(c.size());
ClassMeta childType =
rawTypeMeta.getElementType();
- for (Object cc : c)
-
l.add(applyChildPropertiesFilter(session, childType, cc));
+ c.forEach(x ->
l.add(applyChildPropertiesFilter(session, childType, x)));
return l;
} else {
return
applyChildPropertiesFilter(session, rawTypeMeta, o);
@@ -728,15 +727,13 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
if
(propertyClass.isInstance(valueMap)) {
if (!
valueType.isObject()) {
- boolean
needsConversion = false;
- for
(Map.Entry e : (Set<Map.Entry>)valueMap.entrySet()) {
-
Object v = e.getValue();
+ Flag
needsConversion = Flag.create();
+
valueMap.forEach((k,v) -> {
if (v != null && ! valueType.getInnerClass().isInstance(v)) {
-
needsConversion = true;
-
break;
+
needsConversion.set();
}
- }
- if
(needsConversion)
+ });
+ if
(needsConversion.isSet())
valueMap = (Map)session.convertToType(valueMap, rawTypeMeta);
}
invokeSetter(bean, pName, valueMap);
@@ -753,13 +750,12 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
}
// Set the values.
- for (Map.Entry e :
(Set<Map.Entry>)valueMap.entrySet()) {
- Object k = e.getKey();
- Object v = e.getValue();
+ Map propMap2 = propMap;
+ valueMap.forEach((k,v) -> {
if (! valueType.isObject())
v =
session.convertToType(v, valueType);
- propMap.put(k, v);
- }
+ propMap2.put(k, v);
+ });
if (setter != null || field != null)
invokeSetter(bean, pName,
propMap);
@@ -810,11 +806,12 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
}
// Set the values.
- for (Object v : valueList) {
+ Collection propList2 = propList;
+ valueList.forEach(x -> {
if (! elementType.isObject())
- v =
session.convertToType(v, elementType);
- propList.add(v);
- }
+ x =
session.convertToType(x, elementType);
+ propList2.add(x);
+ });
} else {
if (swap != null && value != null &&
swap.getSwapClass().isParentOf(value.getClass())) {
@@ -904,8 +901,7 @@ public final class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
if (isDyna) {
if (extraKeys != null && getter != null && !
isDynaGetterMap) {
Map<String,Object> m = map();
- for (String key :
(Collection<String>)extraKeys.invoke(bean))
- m.put(key, getter.invoke(bean, key));
+
((Collection<String>)extraKeys.invoke(bean)).forEach(x -> safeRun(()->m.put(x,
getter.invoke(bean, x))));
return m;
}
if (getter != null && isDynaGetterMap)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
index b1387b6..db662ff 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanRegistry.java
@@ -56,11 +56,9 @@ public class BeanRegistry {
this.beanContext = beanContext;
this.map = new ConcurrentHashMap<>();
this.reverseMap = new ConcurrentHashMap<>();
- for (Class<?> c : beanContext.getBeanDictionary())
- addClass(c);
+ beanContext.getBeanDictionary().forEach(c -> addClass(c));
if (parent != null)
- for (Map.Entry<String,ClassMeta<?>> e :
parent.map.entrySet())
- addToMap(e.getKey(), e.getValue());
+ parent.map.forEach((k,v) -> addToMap(k, v));
for (Class<?> c : classes)
addClass(c);
isEmpty = map.isEmpty();
@@ -71,19 +69,17 @@ public class BeanRegistry {
if (c != null) {
ClassInfo ci = ClassInfo.of(c);
if (ci.isChildOf(Collection.class)) {
- @SuppressWarnings("rawtypes")
- Collection cc =
BeanCreator.of(Collection.class).type(c).run();
- for (Object o : cc) {
- if (o instanceof Class)
- addClass((Class<?>)o);
+ Collection<?> cc =
BeanCreator.of(Collection.class).type(c).run();
+ cc.forEach(x -> {
+ if (x instanceof Class)
+ addClass((Class<?>)x);
else
throw new
BeanRuntimeException("Collection class ''{0}'' passed to BeanRegistry does not
contain Class objects.", className(c));
- }
+ });
} else if (ci.isChildOf(Map.class)) {
Map<?,?> m =
BeanCreator.of(Map.class).type(c).run();
- for (Map.Entry<?,?> e : m.entrySet()) {
- String typeName =
stringify(e.getKey());
- Object v = e.getValue();
+ m.forEach((k,v) -> {
+ String typeName = stringify(k);
ClassMeta<?> val = null;
if (v instanceof Type)
val =
beanContext.getClassMeta((Type)v);
@@ -92,7 +88,7 @@ public class BeanRegistry {
else
throw new
BeanRuntimeException("Class ''{0}'' was passed to BeanRegistry but value of
type ''{1}'' found in map is not a Type object.", className(c), className(v));
addToMap(typeName, val);
- }
+ });
} else {
Value<String> typeName = Value.empty();
ci.forEachAnnotation(beanContext,
Bean.class, x -> isNotEmpty(x.typeName()), x -> typeName.set(x.typeName()));
@@ -176,8 +172,7 @@ public class BeanRegistry {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append('{');
- for (Map.Entry<String,ClassMeta<?>> e : map.entrySet())
-
sb.append(e.getKey()).append(":").append(e.getValue().toString(true)).append(",
");
+ map.forEach((k,v) ->
sb.append(k).append(":").append(v.toString(true)).append(", "));
sb.append('}');
return sb.toString();
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
index ebd1202..3ec774a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
@@ -729,19 +729,19 @@ public class BeanSession extends ContextSession {
if (from.isMap()) {
Map m =
to.canCreateNewInstance(outer) ? (Map)to.newInstance(outer) : newGenericMap(to);
ClassMeta keyType =
to.getKeyType(), valueType = to.getValueType();
- for (Map.Entry e :
(Set<Map.Entry>)((Map)value).entrySet()) {
- Object k = e.getKey();
+ ((Map<?,?>)value).forEach((k,v)
-> {
+ Object k2 = k;
if
(keyType.isNotObject()) {
if
(keyType.isString() && k.getClass() != Class.class)
- k =
k.toString();
+ k2 =
k.toString();
else
- k =
convertToMemberType(m, k, keyType);
+ k2 =
convertToMemberType(m, k, keyType);
}
- Object v = e.getValue();
+ Object v2 = v;
if
(valueType.isNotObject())
- v =
convertToMemberType(m, v, valueType);
- m.put(k, v);
- }
+ v2 =
convertToMemberType(m, v, valueType);
+ m.put(k2, v2);
+ });
return (T)m;
} else if
(!to.canCreateNewInstanceFromString(outer)) {
JsonMap m =
JsonMap.ofJson(value.toString());
@@ -763,8 +763,7 @@ public class BeanSession extends ContextSession {
for (Object o : (Object[])value)
l.add(elementType.isObject() ? o : convertToMemberType(l, o, elementType));
else if (from.isCollection())
- for (Object o :
(Collection)value)
-
l.add(elementType.isObject() ? o : convertToMemberType(l, o, elementType));
+ ((Collection)value).forEach(x
-> l.add(elementType.isObject() ? x : convertToMemberType(l, x, elementType)));
else if (from.isMap())
l.add(elementType.isObject() ?
value : convertToMemberType(l, value, elementType));
else if (isNullOrEmpty(value))
@@ -774,8 +773,7 @@ public class BeanSession extends ContextSession {
if (isJsonArray(s, false)) {
JsonList l2 =
JsonList.ofJson(s);
l2.setBeanSession(this);
- for (Object o : l2)
-
l.add(elementType.isObject() ? o : convertToMemberType(l, o, elementType));
+ l2.forEach(x ->
l.add(elementType.isObject() ? x : convertToMemberType(l, x, elementType)));
} else {
throw new
InvalidDataConversionException(value.getClass(), to, null);
}
@@ -957,22 +955,23 @@ public class BeanSession extends ContextSession {
return null;
ClassMeta<?> componentType = type.isArgs() ? object() :
type.getElementType();
Object array = Array.newInstance(componentType.getInnerClass(),
list.size());
- int i = 0;
- for (Object o : list) {
- if (! type.getInnerClass().isInstance(o)) {
- if (componentType.isArray() && o instanceof
Collection)
- o = toArray(componentType,
(Collection<?>)o);
- else if (o == null &&
componentType.isPrimitive())
- o = componentType.getPrimitiveDefault();
+ IntValue i = IntValue.create();
+ list.forEach(x -> {
+ Object x2 = x;
+ if (! type.getInnerClass().isInstance(x)) {
+ if (componentType.isArray() && x instanceof
Collection)
+ x2 = toArray(componentType,
(Collection<?>)x);
+ else if (x == null &&
componentType.isPrimitive())
+ x2 =
componentType.getPrimitiveDefault();
else
- o = convertToType(o, componentType);
+ x2 = convertToType(x, componentType);
}
try {
- Array.set(array, i++, o);
+ Array.set(array, i.getAndIncrement(), x2);
} catch (IllegalArgumentException e) {
throw e;
}
- }
+ });
return array;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanTraverseSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanTraverseSession.java
index b11a781..6b18331 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanTraverseSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanTraverseSession.java
@@ -362,18 +362,18 @@ public class BeanTraverseSession extends BeanSession {
*/
protected String getStack(boolean full) {
StringBuilder sb = new StringBuilder();
- for (StackElement e : stack) {
+ stack.forEach(x -> {
if (full) {
sb.append("\n\t");
- for (int i = 1; i < e.depth; i++)
+ for (int i = 1; i < x.depth; i++)
sb.append(" ");
- if (e.depth > 0)
+ if (x.depth > 0)
sb.append("->");
- sb.append(e.toString(false));
+ sb.append(x.toString(false));
} else {
- sb.append(" > ").append(e.toString(true));
+ sb.append(" > ").append(x.toString(true));
}
- }
+ });
return sb.toString();
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index 7b49599..2b582b1 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -492,31 +492,27 @@ public final class ClassMeta<T> implements Type {
}
}
- for (MethodInfo m : ci.getDeclaredMethods()) {
- if (m.hasAnnotation(bc, Example.class)) {
- if (! (m.isStatic() &&
m.hasFuzzyParamTypes(BeanSession.class) &&
ci.isParentOf(m.getReturnType().inner())))
- throw new
ClassMetaRuntimeException(c, "@Example used on invalid method ''{0}''. Must be
static and return an instance of the declaring class.", m.toString());
- m.setAccessible();
- exampleMethod = m.inner();
- }
- }
+ ci.forEachDeclaredMethod(m -> m.hasAnnotation(bc,
Example.class), m -> {
+ if (! (m.isStatic() &&
m.hasFuzzyParamTypes(BeanSession.class) &&
ci.isParentOf(m.getReturnType().inner())))
+ throw new ClassMetaRuntimeException(c,
"@Example used on invalid method ''{0}''. Must be static and return an
instance of the declaring class.", m.toString());
+ m.setAccessible();
+ exampleMethod = m.inner();
+ });
// Note: Primitive types are normally abstract.
isAbstract = ci.isAbstract() && ci.isNotPrimitive();
// Find constructor(String) method if present.
- for (ConstructorInfo cs : ci.getPublicConstructors()) {
- if (cs.isPublic() && cs.isNotDeprecated()) {
- List<ClassInfo> pt = cs.getParamTypes();
- if (pt.size() == (isMemberClass ? 1 :
0) && c != Object.class && ! isAbstract) {
- noArgConstructor = cs;
- } else if (pt.size() == (isMemberClass
? 2 : 1)) {
- ClassInfo arg =
pt.get(isMemberClass ? 1 : 0);
- if (arg.is(String.class))
- stringConstructor = cs;
- }
+ ci.forEachPublicConstructor(cs -> cs.isPublic() &&
cs.isNotDeprecated(), cs -> {
+ List<ClassInfo> pt = cs.getParamTypes();
+ if (pt.size() == (isMemberClass ? 1 : 0) && c
!= Object.class && ! isAbstract) {
+ noArgConstructor = cs;
+ } else if (pt.size() == (isMemberClass ? 2 :
1)) {
+ ClassInfo arg = pt.get(isMemberClass ?
1 : 0);
+ if (arg.is(String.class))
+ stringConstructor = cs;
}
- }
+ });
primitiveDefault = ci.getPrimitiveDefault();
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
index 0827ed0..2c019f4 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
@@ -322,11 +322,9 @@ public abstract class Context implements
AnnotationProvider {
* @return <jk>true</jk> if any of the annotations/appliers can
be applied to this builder.
*/
public boolean canApply(AnnotationWorkList work) {
- for (AnnotationWork w : work)
- for (Object b : builders)
- if (w.canApply(b))
- return true;
- return false;
+ Flag f = Flag.create();
+ work.forEach(x -> builders.forEach(b ->
f.setIf(x.canApply(b))));
+ return f.isSet();
}
/**
@@ -360,9 +358,7 @@ public abstract class Context implements AnnotationProvider
{
@FluentSetter
public Builder apply(AnnotationWorkList work) {
applied.addAll(work);
- for (AnnotationWork w : work)
- for (Object b : builders)
- w.apply(b);
+ work.forEach(x -> builders.forEach(y -> x.apply(y)));
return this;
}
@@ -847,7 +843,7 @@ public abstract class Context implements AnnotationProvider
{
ReflectionMap.Builder<Annotation> rmb =
ReflectionMap.create(Annotation.class);
- for (Annotation a : annotations) {
+ annotations.forEach(a -> {
try {
ClassInfo ci = ClassInfo.of(a.getClass());
@@ -870,7 +866,7 @@ public abstract class Context implements AnnotationProvider
{
} catch (Exception e) {
throw new ConfigException(e, "Invalid
annotation @{0} used in BEAN_annotations property.", className(a));
}
- }
+ });
this.annotationMap = rmb.build();
boolean disabled =
Boolean.getBoolean("juneau.disableAnnotationCaching");
classAnnotationCache = new TwoKeyConcurrentCache<>(disabled,
(k1,k2) -> annotationMap.appendAll(k1, k2, k1.getAnnotationsByType(k2)));
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledFilter.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledFilter.java
index bfa0673..8f7a177 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledFilter.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/MarshalledFilter.java
@@ -81,12 +81,12 @@ public final class MarshalledFilter {
*/
public Builder applyAnnotations(List<Marshalled> annotations) {
- for (Marshalled b : annotations) {
- if (isNotVoid(b.implClass()))
- implClass(b.implClass());
- if (isNotEmpty(b.example()))
- example(b.example());
- }
+ annotations.forEach(x -> {
+ if (isNotVoid(x.implClass()))
+ implClass(x.implClass());
+ if (isNotEmpty(x.example()))
+ example(x.example());
+ });
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Value.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Value.java
index 3e98835..6eb67da 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Value.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Value.java
@@ -174,6 +174,17 @@ public class Value<T> {
}
/**
+ * Returns the value and then unsets it.
+ *
+ * @return The value before it was unset.
+ */
+ public T getAndUnset() {
+ T t2 = t;
+ t = null;
+ return t2;
+ }
+
+ /**
* Returns <jk>true</jk> if the value is set.
*
* @return <jk>true</jk> if the value is set.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/BasicHtmlDocTemplate.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/BasicHtmlDocTemplate.java
index 7debca9..75bdb9b 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/BasicHtmlDocTemplate.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/BasicHtmlDocTemplate.java
@@ -14,7 +14,6 @@ package org.apache.juneau.html;
import static org.apache.juneau.html.AsideFloat.*;
-import org.apache.juneau.*;
import org.apache.juneau.internal.*;
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
index eb1df27..a3d22b7 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ArrayUtils.java
@@ -125,40 +125,6 @@ public final class ArrayUtils {
}
/**
- * Returns an iterator against an array.
- *
- * <p>
- * This works with any array type (e.g. <c>String[]</c>,
<c>Object[]</c>,
- * <code><jk>int</jk>[]</code>, etc...).
- *
- * @param array The array to create an iterator over.
- * @return An iterator over the specified array.
- */
- public static Iterator<Object> iterator(final Object array) {
- return new Iterator<Object>() {
- int i = 0;
- int length = array == null ? 0 : Array.getLength(array);
-
- @Override /* Iterator */
- public boolean hasNext() {
- return i < length;
- }
-
- @Override /* Iterator */
- public Object next() {
- if (i >= length)
- throw new NoSuchElementException();
- return Array.get(array, i++);
- }
-
- @Override /* Iterator */
- public void remove() {
- throw unsupportedOperationException("Not
supported.");
- }
- };
- }
-
- /**
* Converts the specified collection to an array.
*
* <p>
@@ -351,7 +317,7 @@ public final class ArrayUtils {
/**
* Reverses the entries in an array.
- *
+ *
* @param array The array to reverse.
* @return The same array.
*/
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Flag.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/Flag.java
similarity index 65%
rename from
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Flag.java
rename to
juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/Flag.java
index dd6cc94..412f626 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Flag.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/Flag.java
@@ -10,33 +10,33 @@
// * "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;
+package org.apache.juneau.internal;
import static org.apache.juneau.internal.ThrowableUtils.*;
import org.apache.juneau.assertions.*;
/**
- * A simple settable flag.
+ * A simple settable boolean value.
*/
-public class Flag {
+public final class Flag {
private boolean value;
/**
- * Creates an unset flag.
+ * Creates a boolean value initialized to <jk>false</jk>.
*
- * @return A new unset flag.
+ * @return A new boolean value.
*/
public static Flag create() {
return of(false);
}
/**
- * Creates a flag with the specified initial state.
+ * Creates a boolean value with the specified initial state.
*
- * @param value The initial state of the flag.
- * @return A new flag.
+ * @param value The initial state of the value.
+ * @return A new boolean value.
*/
public static Flag of(boolean value) {
return new Flag(value);
@@ -47,11 +47,11 @@ public class Flag {
}
/**
- * Runs a snippet of code if the flag is set.
+ * Runs a snippet of code if the boolean value is <jk>true</jk>.
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
- * Flag <jv>flag</jv> = Flag.<jsm>create</jsm>();
+ * BoolValue <jv>flag</jv> = BoolValue.<jsm>create</jsm>();
* ...
* <jv>flag</jv>.ifSet(()-><jsm>doSomething</jsm>());
* </p>
@@ -66,11 +66,11 @@ public class Flag {
}
/**
- * Runs a snippet of code if the flag is not set.
+ * Runs a snippet of code if the boolean value is <jk>false</jk>.
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
- * Flag <jv>flag</jv> = Flag.<jsm>create</jsm>();
+ * BoolValue <jv>flag</jv> = BoolValue.<jsm>create</jsm>();
* ...
* <jv>flag</jv>.ifNotSet(()-><jsm>doSomething</jsm>());
* </p>
@@ -97,7 +97,7 @@ public class Flag {
}
/**
- * Sets the flag and returns the value before it was set.
+ * Sets the boolean value to <jk>true</jk> and returns the value before
it was set.
*
* @return The previous value.
*/
@@ -108,7 +108,18 @@ public class Flag {
}
/**
- * Sets the flag.
+ * Sets the boolean value to <jk>false</jk> and returns the value
before it was set.
+ *
+ * @return The previous value.
+ */
+ public boolean getAndUnset() {
+ boolean v = value;
+ value = false;
+ return v;
+ }
+
+ /**
+ * Sets the boolean value to <jk>true</jk>.
*
* @return This object.
*/
@@ -118,7 +129,7 @@ public class Flag {
}
/**
- * Unsets the flag.
+ * Sets the boolean value to <jk>false</jk>.
*
* @return This object.
*/
@@ -126,4 +137,33 @@ public class Flag {
value = false;
return this;
}
+
+ /**
+ * Returns <jk>true</jk> if the boolean value is <jk>true</jk>.
+ *
+ * @return <jk>true</jk> if the boolean value is <jk>true</jk>.
+ */
+ public boolean isSet() {
+ return value;
+ }
+
+ /**
+ * Returns <jk>true</jk> if the boolean value is <jk>false</jk>.
+ *
+ * @return <jk>true</jk> if the boolean value is <jk>false</jk>.
+ */
+ public boolean isUnset() {
+ return ! value;
+ }
+
+ /**
+ * Sets the boolean value to <jk>true</jk> if the value is
<jk>true</jk>.
+ *
+ * @param value The value to set.
+ * @return This object.
+ */
+ public Flag setIf(boolean value) {
+ this.value |= value;
+ return this;
+ }
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/IntValue.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/IntValue.java
new file mode 100644
index 0000000..b2e072a
--- /dev/null
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/IntValue.java
@@ -0,0 +1,75 @@
+//
***************************************************************************************************************************
+// * 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.internal;
+
+/**
+ * A simple settable integer value.
+ */
+public final class IntValue {
+
+ private int value;
+
+ /**
+ * Creates a new integer value initialized to <code>0</code>.
+ *
+ * @return A new integer value.
+ */
+ public static IntValue create() {
+ return of(0);
+ }
+
+ /**
+ * Creates an integer value with the specified initial state.
+ *
+ * @param value The initial state of the value.
+ * @return A new integer value.
+ */
+ public static IntValue of(int value) {
+ return new IntValue(value);
+ }
+
+ private IntValue(int value) {
+ this.value = value;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * @param value The new value.
+ * @return This object.
+ */
+ public IntValue set(int value) {
+ this.value = value;
+ return this;
+ }
+
+ /**
+ * Returns the value.
+ *
+ * @return The value.
+ */
+ public int get() {
+ return value;
+ }
+
+ /**
+ * Returns the current value and then increments it.
+ *
+ * @return The current value.
+ */
+ public int getAndIncrement() {
+ int v = value;
+ value++;
+ return v;
+ }
+}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
index 7223355..3802a6a 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ConstructorInfo.java
@@ -260,6 +260,5 @@ public final class ConstructorInfo extends ExecutableInfo
implements Comparable<
super.accessible();
return this;
}
-
// </FluentSetters>
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
index e1501b7..beb4fed 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ExecutableInfo.java
@@ -146,6 +146,20 @@ public abstract class ExecutableInfo {
}
/**
+ * Performs an action on every parameter that matches the specified
filter.
+ *
+ * @param filter The filter, can be <jk>null</jk>.
+ * @param action The action to perform.
+ * @return This object.
+ */
+ public ExecutableInfo forEachParam(Predicate<ParamInfo> filter,
Consumer<ParamInfo> action) {
+ for (ParamInfo pi : _getParams())
+ if (passes(filter, pi))
+ action.accept(pi);
+ return this;
+ }
+
+ /**
* Returns parameter information at the specified index.
*
* @param index The parameter index.
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolverSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolverSession.java
index a2d9419..f6b4035 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolverSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolverSession.java
@@ -18,7 +18,6 @@ import static org.apache.juneau.internal.StringUtils.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
-
import org.apache.juneau.cp.*;
import org.apache.juneau.internal.*;
@@ -182,20 +181,22 @@ public class VarResolverSession {
return false;
}
- @SuppressWarnings("rawtypes")
- private static boolean containsVars(Collection c) {
- for (Object o : c)
- if (o instanceof CharSequence &&
o.toString().contains("$"))
- return true;
- return false;
+ private static boolean containsVars(Collection<?> c) {
+ Flag f = Flag.create();
+ c.forEach(x -> {
+ if (x instanceof CharSequence &&
x.toString().contains("$"))
+ f.set();
+ });
+ return f.isSet();
}
- @SuppressWarnings("rawtypes")
- private static boolean containsVars(Map m) {
- for (Object o : m.values())
- if (o instanceof CharSequence &&
o.toString().contains("$"))
- return true;
- return false;
+ private static boolean containsVars(Map<?,?> m) {
+ Flag f = Flag.create();
+ m.forEach((k,v) -> {
+ if (v instanceof CharSequence &&
v.toString().contains("$"))
+ f.set();
+ });
+ return f.isSet();
}
/*
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
index ce21c2f..ea6ae87 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingSerializerSession.java
@@ -12,8 +12,8 @@
//
***************************************************************************************************************************
package org.apache.juneau.urlencoding;
-import static org.apache.juneau.internal.ArrayUtils.*;
import static org.apache.juneau.internal.IOUtils.*;
+import static org.apache.juneau.internal.StringUtils.*;
import java.io.*;
import java.lang.reflect.*;
@@ -319,9 +319,8 @@ public class UrlEncodingSerializerSession extends
UonSerializerSession {
*/
private static Map<Integer,Object> getCollectionMap(Collection<?> c) {
Map<Integer,Object> m = new TreeMap<>();
- int i = 0;
- for (Object o : c)
- m.put(i++, o);
+ IntValue i = IntValue.create();
+ c.forEach(o -> m.put(i.getAndIncrement(), o));
return m;
}
@@ -341,46 +340,47 @@ public class UrlEncodingSerializerSession extends
UonSerializerSession {
ClassMeta<?> keyType = type.getKeyType(), valueType =
type.getValueType();
- boolean addAmp = false;
+ Flag addAmp = Flag.create();
for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) {
Object key = generalize(e.getKey(), keyType);
Object value = e.getValue();
if (shouldUseExpandedParams(value)) {
- Iterator i = value instanceof Collection ?
((Collection)value).iterator() : iterator(value);
- while (i.hasNext()) {
- if (addAmp)
- out.cr(indent).append('&');
- out.appendObject(key, true).append('=');
- super.serializeAnything(out, i.next(),
null, (key == null ? null : key.toString()), null);
- addAmp = true;
+ if (value instanceof Collection) {
+ ((Collection<?>)value).forEach(x -> {
+
addAmp.ifSet(()->out.cr(indent).append('&')).set();
+ out.appendObject(key,
true).append('=');
+ super.serializeAnything(out, x,
null, stringify(key), null);
+ });
+ } else /* array */ {
+ for (int i = 0; i <
Array.getLength(value); i++) {
+
addAmp.ifSet(()->out.cr(indent).append('&')).set();
+ out.appendObject(key,
true).append('=');
+ super.serializeAnything(out,
Array.get(value, i), null, stringify(key), null);
+ }
}
} else {
- if (addAmp)
- out.cr(indent).append('&');
+
addAmp.ifSet(()->out.cr(indent).append('&')).set();
out.appendObject(key, true).append('=');
super.serializeAnything(out, value, valueType,
(key == null ? null : key.toString()), null);
- addAmp = true;
}
}
return out;
}
- private SerializerWriter serializeCollectionMap(UonWriter out, Map m,
ClassMeta<?> type) throws SerializeException {
+ private SerializerWriter serializeCollectionMap(UonWriter out, Map<?,?>
m, ClassMeta<?> type) throws SerializeException {
ClassMeta<?> valueType = type.getValueType();
- boolean addAmp = false;
+ Flag addAmp = Flag.create();
- for (Map.Entry e : (Set<Map.Entry>)m.entrySet()) {
- if (addAmp)
- out.cr(indent).append('&');
- out.append(e.getKey()).append('=');
- super.serializeAnything(out, e.getValue(), valueType,
null, null);
- addAmp = true;
- }
+ m.forEach((k,v) -> {
+ addAmp.ifSet(()->out.cr(indent).append('&')).set();
+ out.append(k).append('=');
+ super.serializeAnything(out, v, valueType, null, null);
+ });
return out;
}
@@ -408,11 +408,18 @@ public class UrlEncodingSerializerSession extends
UonSerializerSession {
if (value != null && shouldUseExpandedParams(pMeta)) {
// Transformed object array bean properties may
be transformed resulting in ArrayLists,
// so we need to check type if we think it's an
array.
- Iterator i = (sMeta.isCollection() || value
instanceof Collection) ? ((Collection)value).iterator() : iterator(value);
- while (i.hasNext()) {
-
addAmp.ifSet(()->out.cr(indent).append('&')).set();
- out.appendObject(key, true).append('=');
- super.serializeAnything(out, i.next(),
cMeta.getElementType(), key, pMeta);
+ if (sMeta.isCollection() || value instanceof
Collection) {
+ ((Collection<?>)value).forEach(x -> {
+
addAmp.ifSet(()->out.cr(indent).append('&')).set();
+ out.appendObject(key,
true).append('=');
+ super.serializeAnything(out, x,
cMeta.getElementType(), key, pMeta);
+ });
+ } else /* array */ {
+ for (int i = 0; i <
Array.getLength(value); i++) {
+
addAmp.ifSet(()->out.cr(indent).append('&')).set();
+ out.appendObject(key,
true).append('=');
+ super.serializeAnything(out,
Array.get(value, i), cMeta.getElementType(), key, pMeta);
+ }
}
} else {
addAmp.ifSet(()->out.cr(indent).append('&')).set();
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/BeanDiff.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/BeanDiff.java
index e64d533..8a975bc 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/BeanDiff.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/BeanDiff.java
@@ -203,7 +203,7 @@ public class BeanDiff {
BeanMap<?> bm1 = first == null ? null : bc.toBeanMap(first);
BeanMap<?> bm2 = second == null ? null : bc.toBeanMap(second);
Set<String> keys = bm1 != null ? bm1.keySet() : bm2.keySet();
- for (String k : keys) {
+ keys.forEach(k -> {
if ((include == null || include.contains(k)) &&
(exclude == null || ! exclude.contains(k))) {
Object o1 = bm1 == null ? null : bm1.get(k);
Object o2 = bm2 == null ? null : bm2.get(k);
@@ -214,7 +214,7 @@ public class BeanDiff {
v2.put(k, o2);
}
}
- }
+ });
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ManifestFile.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ManifestFile.java
index e76ad95..aed1b65 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ManifestFile.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ManifestFile.java
@@ -17,7 +17,6 @@ import static org.apache.juneau.internal.IOUtils.*;
import java.io.*;
import java.net.*;
-import java.util.*;
import java.util.jar.*;
import org.apache.juneau.collections.*;
@@ -114,15 +113,13 @@ public class ManifestFile extends JsonMap {
}
private void load(Manifest mf) {
- for (Map.Entry<Object,Object> e :
mf.getMainAttributes().entrySet())
- put(e.getKey().toString(), e.getValue().toString());
+ mf.getMainAttributes().forEach((k,v) -> put(k.toString(),
v.toString()));
}
@Override /* Object */
public String toString() {
StringBuilder sb = new StringBuilder();
- for (Map.Entry<String,Object> e : entrySet())
- sb.append(e.getKey()).append(": ").append(e.getValue());
+ forEach((k,v) -> sb.append(k).append(": ").append(v));
return sb.toString();
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
index f1edb41..359e0d8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/PojoQuery.java
@@ -276,29 +276,25 @@ public final class PojoQuery {
ClassMeta cm = session.getClassMetaForObject(o);
if (cm.isCollection()) {
JsonList l = new
DelegateList(session.getClassMetaForObject(o));
- for (Object o2 : (Collection)o)
- l.add(replaceWithMutables(o2));
+ ((Collection)o).forEach(x ->
l.add(replaceWithMutables(x)));
return l;
}
if (cm.isMap() && o instanceof BeanMap) {
BeanMap bm = (BeanMap)o;
DelegateBeanMap dbm = new DelegateBeanMap(bm.getBean(),
session);
- for (Object key : bm.keySet())
- dbm.addKey(key.toString());
+ bm.forEach((k,v) -> dbm.addKey(k.toString()));
return dbm;
}
if (cm.isBean()) {
BeanMap bm = session.toBeanMap(o);
DelegateBeanMap dbm = new DelegateBeanMap(bm.getBean(),
session);
- for (Object key : bm.keySet())
- dbm.addKey(key.toString());
+ bm.forEach((k,v) -> dbm.addKey(k.toString()));
return dbm;
}
if (cm.isMap()) {
Map m = (Map)o;
DelegateMap dm = new DelegateMap(m, session);
- for (Map.Entry e : (Set<Map.Entry>)m.entrySet())
- dm.put(e.getKey().toString(), e.getValue());
+ m.forEach((k,v) -> dm.put(k.toString(), v));
return dm;
}
if (cm.isArray()) {
@@ -411,9 +407,10 @@ public final class PojoQuery {
Map<String,IMatcher> entryMatchers = new HashMap<>();
public MapMatcher(Map query, boolean ignoreCase) {
- for (Map.Entry e : (Set<Map.Entry>)query.entrySet())
- if (e.getKey() != null && e.getValue() != null)
-
entryMatchers.put(e.getKey().toString(), new
ObjectMatcher(e.getValue().toString(), ignoreCase));
+ query.forEach((k,v) -> {
+ if (k != null && v != null)
+ entryMatchers.put(k.toString(), new
ObjectMatcher(v.toString(), ignoreCase));
+ });
}
@Override /* IMatcher */
@@ -962,9 +959,9 @@ public final class PojoQuery {
List<Pattern> ands = new LinkedList<>();
List<Pattern> nots = new LinkedList<>();
- for (String arg : breakUpTokens(searchPattern)) {
- char prefix = arg.charAt(0);
- String token = arg.substring(1);
+ breakUpTokens(searchPattern).forEach(x -> {
+ char prefix = x.charAt(0);
+ String token = x.substring(1);
token =
token.replaceAll("([\\?\\*\\+\\\\\\[\\]\\{\\}\\(\\)\\^\\$\\.])", "\\\\$1");
token = token.replace("\u9997", ".*");
@@ -987,7 +984,7 @@ public final class PojoQuery {
ands.add(p);
else if (prefix == '-')
nots.add(p);
- }
+ });
orPatterns = ors.toArray(new Pattern[ors.size()]);
andPatterns = ands.toArray(new Pattern[ands.size()]);
notPatterns = nots.toArray(new Pattern[nots.size()]);
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ReflectionMap.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ReflectionMap.java
index 6f7e1d9..b70057b 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ReflectionMap.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ReflectionMap.java
@@ -20,6 +20,7 @@ import static org.apache.juneau.internal.StringUtils.*;
import java.lang.reflect.*;
import java.util.*;
+import java.util.function.*;
/**
* Allows arbitrary objects to be mapped to classes and methods base on
class/method name keys.
@@ -198,7 +199,7 @@ public class ReflectionMap<V> {
if (isEmpty(key))
throw runtimeException("Invalid reflection
signature: [{0}]", key);
try {
- for (String k : ReflectionMap.splitNames(key)) {
+ splitNames(key, k -> {
if (k.endsWith(")")) {
int i = k.substring(0,
k.indexOf('(')).lastIndexOf('.');
if (i == -1 ||
isUpperCase(k.charAt(i+1))) {
@@ -218,7 +219,7 @@ public class ReflectionMap<V> {
fieldEntries.add(new
FieldEntry<>(k, value));
}
}
- }
+ });
} catch (IndexOutOfBoundsException e) {
throw runtimeException("Invalid reflection
signature: [{0}]", key);
}
@@ -266,27 +267,25 @@ public class ReflectionMap<V> {
this.constructorEntries = b.constructorEntries.toArray(new
ConstructorEntry[b.constructorEntries.size()]);
}
- static List<String> splitNames(String key) {
- if (key.indexOf(',') == -1)
- return Collections.singletonList(key.trim());
- List<String> l = list();
-
- int m = 0;
- boolean escaped = false;
- for (int i = 0; i < key.length(); i++) {
- char c = key.charAt(i);
- if (c == '(')
- escaped = true;
- else if (c == ')')
- escaped = false;
- else if (c == ',' && ! escaped) {
- l.add(key.substring(m, i).trim());
- m = i+1;
+ static void splitNames(String key, Consumer<String> consumer) {
+ if (key.indexOf(',') == -1) {
+ consumer.accept(key);
+ } else {
+ int m = 0;
+ boolean escaped = false;
+ for (int i = 0; i < key.length(); i++) {
+ char c = key.charAt(i);
+ if (c == '(')
+ escaped = true;
+ else if (c == ')')
+ escaped = false;
+ else if (c == ',' && ! escaped) {
+ consumer.accept(key.substring(m,
i).trim());
+ m = i+1;
+ }
}
+ consumer.accept(key.substring(m).trim());
}
- l.add(key.substring(m).trim());
-
- return l;
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/SearchArgs.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/SearchArgs.java
index 2f01a40..11f4b06 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/SearchArgs.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/SearchArgs.java
@@ -208,14 +208,14 @@ public class SearchArgs {
* @return This object.
*/
public Builder sort(Collection<String> sortArgs) {
- for (String s : sortArgs) {
+ sortArgs.forEach(x -> {
boolean isDesc = false;
- if (endsWith(s, '-', '+')) {
- isDesc = endsWith(s, '-');
- s = s.substring(0, s.length()-1);
+ if (endsWith(x, '-', '+')) {
+ isDesc = endsWith(x, '-');
+ x = x.substring(0, x.length()-1);
}
- this.sort.put(s, isDesc);
- }
+ this.sort.put(x, isDesc);
+ });
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/Namespace.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/Namespace.java
index c44d8b4..6205614 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/Namespace.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/Namespace.java
@@ -143,9 +143,9 @@ public final class Namespace {
int i = 0;
for (Object o2 : c){
if (o2 instanceof Namespace)
- n[i] = (Namespace)o2;
+ n[i++] = (Namespace)o2;
else if (o2 instanceof CharSequence)
- n[i] = create(o2.toString());
+ n[i++] = create(o2.toString());
else
throw runtimeException("Invalid type
passed to NamespaceFactory.createArray: ''{0}''", o);
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
index 114b6a7..87a33ef 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlBeanMeta.java
@@ -100,7 +100,7 @@ public class XmlBeanMeta extends ExtendedBeanMeta {
throw new BeanRuntimeException(c,
"Invalid format specified in @Xml annotation on bean: {0}. Must be one of the
following: DEFAULT,ATTRS,ELEMENTS,VOID", x.format());
});
- for (BeanPropertyMeta p : beanMeta.getPropertyMetas()) {
+ beanMeta.forEachProperty(null, p -> {
XmlFormat xf =
mp.getXmlBeanPropertyMeta(p).getXmlFormat();
ClassMeta<?> pcm = p.getClassMeta();
if (xf == ATTR) {
@@ -138,7 +138,7 @@ public class XmlBeanMeta extends ExtendedBeanMeta {
throw new
BeanRuntimeException(c, "Multiple properties found with the child name
''{0}''.", n);
collapsedProperties.put(n, p);
}
- }
+ });
}
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
index afa777f..6887bde 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializerSession.java
@@ -338,37 +338,30 @@ public class XmlSerializerSession extends
WriterSerializerSession {
bm = toBeanMap(o);
} else if (aType.isDelegate()) {
ClassMeta<?> innerType =
((Delegate<?>)o).getClassMeta();
- Namespace ns =
getXmlClassMeta(innerType).getNamespace();
- if (ns != null) {
- if (ns.uri != null)
- addNamespace(ns);
+ Value<Namespace >ns =
Value.of(getXmlClassMeta(innerType).getNamespace());
+ if (ns.isPresent()) {
+ if (ns.get().uri != null)
+ addNamespace(ns.get());
else
- ns = null;
+ ns.getAndUnset();
}
if (innerType.isBean()) {
- for (BeanPropertyMeta bpm :
innerType.getBeanMeta().getPropertyMetas()) {
- if (bpm.canRead()) {
- ns =
getXmlBeanPropertyMeta(bpm).getNamespace();
- if (ns != null &&
ns.uri != null)
-
addNamespace(ns);
- }
- }
-
+
innerType.getBeanMeta().forEachProperty(x -> x.canRead(), x -> {
+
ns.set(getXmlBeanPropertyMeta(x).getNamespace());
+ if (ns.isPresent() &&
ns.get().uri != null)
+ addNamespace(ns.get());
+ });
} else if (innerType.isMap()) {
- for (Object o2 : ((Map<?,?>)o).values())
- findNsfMappings(o2);
+ ((Map<?,?>)o).forEach((k,v) ->
findNsfMappings(v));
} else if (innerType.isCollection()) {
- for (Object o2 : ((Collection<?>)o))
- findNsfMappings(o2);
+ ((Collection<?>)o).forEach(x ->
findNsfMappings(x));
}
} else if (aType.isMap()) {
- for (Object o2 : ((Map<?,?>)o).values())
- findNsfMappings(o2);
+ ((Map<?,?>)o).forEach((k,v) ->
findNsfMappings(v));
} else if (aType.isCollection()) {
- for (Object o2 : ((Collection<?>)o))
- findNsfMappings(o2);
+ ((Collection<?>)o).forEach(x ->
findNsfMappings(x));
} else if (aType.isArray() && !
aType.getElementType().isPrimitive()) {
for (Object o2 : ((Object[])o))
findNsfMappings(o2);
@@ -768,8 +761,7 @@ public class XmlSerializerSession extends
WriterSerializerSession {
} else /* Map */ {
Map m2 = (Map)value;
if (m2 != null)
- for (Map.Entry
e : (Set<Map.Entry>)(m2.entrySet()))
-
out.attr(ns, toString(e.getKey()), e.getValue());
+
m2.forEach((k,v) -> out.attr(ns, stringify(k), v));
}
} else {
out.attr(ns, key, value);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
b/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
index ddbaed0..deb7154 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/utils/ArrayUtilsTest.java
@@ -25,16 +25,6 @@ import org.junit.*;
public class ArrayUtilsTest {
//====================================================================================================
- // iterator(T[])
-
//====================================================================================================
- @Test
- public void testArrayIterator() throws Exception {
- assertObject(iterator(new
Object[]{1,2,3})).asJson().is("[1,2,3]");
- assertObject(iterator(new int[]{1,2,3})).asJson().is("[1,2,3]");
- assertObject(iterator(null)).asJson().is("[]");
- }
-
-
//====================================================================================================
// append(T[], T...)
//====================================================================================================
@Test
@@ -75,21 +65,6 @@ public class ArrayUtilsTest {
}
//====================================================================================================
- // iterator(T[])
-
//====================================================================================================
- @Test
- public void testIterator() throws Exception {
- String[] s = null;
-
- s = new String[]{"a"};
- Iterator<Object> i = iterator(s);
- assertEquals("a", i.next());
-
-
assertThrown(()->i.remove()).isType(UnsupportedOperationException.class);
- assertThrown(()->i.next()).isType(NoSuchElementException.class);
- }
-
-
//====================================================================================================
// combine(T[]...)
//====================================================================================================
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/utils/ReflectionMapTest.java
b/juneau-utest/src/test/java/org/apache/juneau/utils/ReflectionMapTest.java
index ce2315d..c12235c 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/utils/ReflectionMapTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/utils/ReflectionMapTest.java
@@ -369,20 +369,4 @@ public class ReflectionMapTest {
assertFalse(RM_G.find(C1.class.getField("f1"),
null).isPresent());
assertFalse(RM_G.find(D1.class.getConstructor(),
null).isPresent());
}
-
-
//------------------------------------------------------------------------------------------------------------------
- // Split names test
-
//------------------------------------------------------------------------------------------------------------------
-
- @Test
- public void h01_splitNamesTest() throws Exception {
-
assertObject(ReflectionMap.splitNames("foo")).asJson().is("['foo']");
- assertObject(ReflectionMap.splitNames(" foo
")).asJson().is("['foo']");
-
assertObject(ReflectionMap.splitNames("foo,bar")).asJson().is("['foo','bar']");
- assertObject(ReflectionMap.splitNames(" foo , bar
")).asJson().is("['foo','bar']");
-
assertObject(ReflectionMap.splitNames("foo(),bar()")).asJson().is("['foo()','bar()']");
- assertObject(ReflectionMap.splitNames(" foo() , bar()
")).asJson().is("['foo()','bar()']");
-
assertObject(ReflectionMap.splitNames("foo(bar,baz),bar(baz,qux)")).asJson().is("['foo(bar,baz)','bar(baz,qux)']");
- assertObject(ReflectionMap.splitNames(" foo(bar,baz) ,
bar(baz,qux) ")).asJson().is("['foo(bar,baz)','bar(baz,qux)']");
- }
}