You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/09/13 00:55:41 UTC
[commons-beanutils] 02/02: More lambdas, less boilerplate.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit a8c10e565975c99f4e362278f661fb1aa3fe68f6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Sep 12 20:55:36 2019 -0400
More lambdas, less boilerplate.
---
.../org/apache/commons/beanutils2/BeanMap.java | 56 ++++------------------
.../commons/beanutils2/PropertyUtilsTestCase.java | 41 +++++++---------
.../commons/beanutils2/bugs/Jira509TestCase.java | 13 ++---
3 files changed, 28 insertions(+), 82 deletions(-)
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanMap.java b/src/main/java/org/apache/commons/beanutils2/BeanMap.java
index ba10257..c692739 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanMap.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanMap.java
@@ -71,75 +71,35 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable {
new HashMap<>();
defTransformers.put(
Boolean.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Boolean.valueOf( input.toString() );
- }
- }
+ input -> Boolean.valueOf( input.toString() )
);
defTransformers.put(
Character.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Character.valueOf( input.toString().charAt( 0 ) );
- }
- }
+ input -> Character.valueOf( input.toString().charAt( 0 ) )
);
defTransformers.put(
Byte.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Byte.valueOf( input.toString() );
- }
- }
+ input -> Byte.valueOf( input.toString() )
);
defTransformers.put(
Short.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Short.valueOf( input.toString() );
- }
- }
+ input -> Short.valueOf( input.toString() )
);
defTransformers.put(
Integer.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Integer.valueOf( input.toString() );
- }
- }
+ input -> Integer.valueOf( input.toString() )
);
defTransformers.put(
Long.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Long.valueOf( input.toString() );
- }
- }
+ input -> Long.valueOf( input.toString() )
);
defTransformers.put(
Float.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Float.valueOf( input.toString() );
- }
- }
+ input -> Float.valueOf( input.toString() )
);
defTransformers.put(
Double.TYPE,
- new Transformer() {
- @Override
- public Object transform( final Object input ) {
- return Double.valueOf( input.toString() );
- }
- }
+ input -> Double.valueOf( input.toString() )
);
return defTransformers;
}
diff --git a/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
index 5ebb024..ce94961 100644
--- a/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java
@@ -4465,25 +4465,20 @@ public class PropertyUtilsTestCase extends TestCase {
PropertyDescriptor nameDescriptor = findNameDescriptor(desc1);
assertNotNull("No write method", nameDescriptor.getWriteMethod());
- final BeanIntrospector bi = new BeanIntrospector() {
- // Only produce read-only property descriptors
- @Override
- public void introspect(final IntrospectionContext icontext)
- throws IntrospectionException {
- final Set<String> names = icontext.propertyNames();
- final PropertyDescriptor[] newDescs = new PropertyDescriptor[names
- .size()];
- int idx = 0;
- for (final Iterator<String> it = names.iterator(); it.hasNext(); idx++) {
- final String propName = it.next();
- final PropertyDescriptor pd = icontext
- .getPropertyDescriptor(propName);
- newDescs[idx] = new PropertyDescriptor(pd.getName(),
- pd.getReadMethod(), null);
- }
- icontext.addPropertyDescriptors(newDescs);
+ final BeanIntrospector bi = icontext -> {
+ final Set<String> names = icontext.propertyNames();
+ final PropertyDescriptor[] newDescs = new PropertyDescriptor[names
+ .size()];
+ int idx = 0;
+ for (final Iterator<String> it = names.iterator(); it.hasNext(); idx++) {
+ final String propName = it.next();
+ final PropertyDescriptor pd = icontext
+ .getPropertyDescriptor(propName);
+ newDescs[idx] = new PropertyDescriptor(pd.getName(),
+ pd.getReadMethod(), null);
}
- };
+ icontext.addPropertyDescriptors(newDescs);
+ };
PropertyUtils.clearDescriptors();
PropertyUtils.addBeanIntrospector(bi);
final PropertyDescriptor[] desc2 = PropertyUtils
@@ -4515,13 +4510,9 @@ public class PropertyUtilsTestCase extends TestCase {
* Tests whether exceptions during custom introspection are handled.
*/
public void testCustomIntrospectionEx() {
- final BeanIntrospector bi = new BeanIntrospector() {
- @Override
- public void introspect(final IntrospectionContext icontext)
- throws IntrospectionException {
- throw new IntrospectionException("TestException");
- }
- };
+ final BeanIntrospector bi = icontext -> {
+ throw new IntrospectionException("TestException");
+ };
PropertyUtils.clearDescriptors();
PropertyUtils.addBeanIntrospector(bi);
final PropertyDescriptor[] desc = PropertyUtils
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java
index e7496d0..439737f 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.apache.commons.beanutils2.WrapDynaClass;
@@ -57,14 +56,10 @@ public class Jira509TestCase {
Collection.class, Set.class, ArrayList.class, List.class, HashSet.class);
// All daemon threads.
- final ExecutorService executor = Executors.newFixedThreadPool(100, new ThreadFactory() {
-
- @Override
- public Thread newThread(final Runnable r) {
- final Thread thread = new Thread(r);
- thread.setDaemon(true);
- return thread;
- }
+ final ExecutorService executor = Executors.newFixedThreadPool(100, r -> {
+ final Thread thread = new Thread(r);
+ thread.setDaemon(true);
+ return thread;
});
try {