This is an automated email from the ASF dual-hosted git repository.
pawan pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new 4275825 Improved: Replace anonymous types with lambda expressions(OFBIZ-11833) 4275825 is described below commit 4275825b4af7eb5746ebada46cd68b043b308dd2 Author: Pawan Verma <[hidden email]> AuthorDate: Wed Jun 24 14:11:05 2020 +0530 Improved: Replace anonymous types with lambda expressions(OFBIZ-11833) --- .../ofbiz/content/cms/ContentJsonEvents.java | 29 +++++------ .../ofbiz/content/data/DataResourceWorker.java | 15 +++--- .../java/org/apache/ofbiz/base/util/SSLUtil.java | 58 ++++++++++------------ .../ofbiz/common/authentication/AuthHelper.java | 17 +++---- .../ofbiz/entity/condition/EntityFunction.java | 20 ++------ .../ofbiz/widget/model/ModelWidgetCondition.java | 14 +----- 6 files changed, 56 insertions(+), 97 deletions(-) diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/cms/ContentJsonEvents.java b/applications/content/src/main/java/org/apache/ofbiz/content/cms/ContentJsonEvents.java index 652c6cb..3bb61c5 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/cms/ContentJsonEvents.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/cms/ContentJsonEvents.java @@ -66,25 +66,20 @@ public class ContentJsonEvents { nodes.add(getTreeNode(assoc)); } - Collections.sort(nodes, new Comparator<Map<String, Object>>() { - - @Override - public int compare(Map<String, Object> node1, Map<String, Object> node2) { - Map<String, Object> data1 = UtilGenerics.cast(node1.get("data")); - Map<String, Object> data2 = UtilGenerics.cast(node2.get("data")); - if (data1 == null || data2 == null) { - return 0; - } - - String title1 = (String) data1.get("title"); - String title2 = (String) data2.get("title"); - if (title1 == null || title2 == null) { - return 0; - } - - return title1.toLowerCase(Locale.getDefault()).compareTo(title2.toLowerCase(Locale.getDefault())); + Collections.sort(nodes, (node1, node2) -> { + Map<String, Object> data1 = UtilGenerics.cast(node1.get("data")); + Map<String, Object> data2 = UtilGenerics.cast(node2.get("data")); + if (data1 == null || data2 == null) { + return 0; } + String title1 = (String) data1.get("title"); + String title2 = (String) data2.get("title"); + if (title1 == null || title2 == null) { + return 0; + } + + return title1.toLowerCase(Locale.getDefault()).compareTo(title2.toLowerCase(Locale.getDefault())); }); IOUtils.write(JSON.from(nodes).toString(), response.getOutputStream(), Charset.defaultCharset()); diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java index 8d9e77f..254317e 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java @@ -531,16 +531,13 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.Data } // descending comparator - Comparator<Object> desc = new Comparator<Object>() { - @Override - public int compare(Object o1, Object o2) { - if ((Long) o1 > (Long) o2) { - return -1; - } else if ((Long) o1 < (Long) o2) { - return 1; - } - return 0; + Comparator<Object> desc = (o1, o2) -> { + if ((Long) o1 > (Long) o2) { + return -1; + } else if ((Long) o1 < (Long) o2) { + return 1; } + return 0; }; // check for the latest subdirectory diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java index bad977e..783953e 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/SSLUtil.java @@ -250,45 +250,37 @@ public final class SSLUtil { public static HostnameVerifier getHostnameVerifier(int level) { switch (level) { case HOSTCERT_MIN_CHECK: - return new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - Certificate[] peerCerts; + return (hostname, session) -> { + Certificate[] peerCerts; + try { + peerCerts = session.getPeerCertificates(); + } catch (SSLPeerUnverifiedException e) { + // cert not verified + Debug.logWarning(e.getMessage(), MODULE); + return false; + } + for (Certificate peerCert : peerCerts) { try { - peerCerts = session.getPeerCertificates(); - } catch (SSLPeerUnverifiedException e) { - // cert not verified - Debug.logWarning(e.getMessage(), MODULE); - return false; - } - for (Certificate peerCert : peerCerts) { - try { - Principal x500s = session.getPeerPrincipal(); - Map<String, String> subjectMap = KeyStoreUtil.getX500Map(x500s); - if (Debug.infoOn()) { - byte[] encodedCert = peerCert.getEncoded(); - Debug.logInfo(new BigInteger(encodedCert).toString(16) - + " :: " + subjectMap.get("CN"), MODULE); - } - peerCert.verify(peerCert.getPublicKey()); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - // certificate not valid - Debug.logWarning("Certificate is not valid!", MODULE); - return false; + Principal x500s = session.getPeerPrincipal(); + Map<String, String> subjectMap = KeyStoreUtil.getX500Map(x500s); + if (Debug.infoOn()) { + byte[] encodedCert = peerCert.getEncoded(); + Debug.logInfo(new BigInteger(encodedCert).toString(16) + + " :: " + subjectMap.get("CN"), MODULE); } + peerCert.verify(peerCert.getPublicKey()); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + // certificate not valid + Debug.logWarning("Certificate is not valid!", MODULE); + return false; } - return true; } + return true; }; case HOSTCERT_NO_CHECK: - return new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; + return (hostname, session) -> true; default: return null; } diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/authentication/AuthHelper.java b/framework/common/src/main/java/org/apache/ofbiz/common/authentication/AuthHelper.java index 9746ae3..c5107b7 100644 --- a/framework/common/src/main/java/org/apache/ofbiz/common/authentication/AuthHelper.java +++ b/framework/common/src/main/java/org/apache/ofbiz/common/authentication/AuthHelper.java @@ -131,17 +131,14 @@ public final class AuthHelper { */ private static ClassLoader getContextClassLoader() { return AccessController.doPrivileged( - new PrivilegedAction<ClassLoader>() { - @Override - public ClassLoader run() { - ClassLoader cl = null; - try { - cl = Thread.currentThread().getContextClassLoader(); - } catch (SecurityException e) { - Debug.logError(e, e.getMessage(), MODULE); - } - return cl; + (PrivilegedAction<ClassLoader>) () -> { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (SecurityException e) { + Debug.logError(e, e.getMessage(), MODULE); } + return cl; }); } } diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/condition/EntityFunction.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/condition/EntityFunction.java index c3b0004..45c13b4 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/condition/EntityFunction.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/condition/EntityFunction.java @@ -65,10 +65,7 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond * */ public static class LENGTH extends EntityFunctionSingle<Integer> { - public static final Fetcher<Integer> FETCHER = new Fetcher<Integer>() { - @Override - public Integer getValue(Object value) { return value.toString().length(); } - }; + public static final Fetcher<Integer> FETCHER = value -> value.toString().length(); private LENGTH(Object value) { super(FETCHER, SQLFunction.LENGTH, value); @@ -80,10 +77,7 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond * */ public static class TRIM extends EntityFunctionSingle<String> { - public static final Fetcher<String> FETCHER = new Fetcher<String>() { - @Override - public String getValue(Object value) { return value.toString().trim(); } - }; + public static final Fetcher<String> FETCHER = value -> value.toString().trim(); private TRIM(Object value) { super(FETCHER, SQLFunction.TRIM, value); @@ -95,10 +89,7 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond * */ public static class UPPER extends EntityFunctionSingle<String> { - public static final Fetcher<String> FETCHER = new Fetcher<String>() { - @Override - public String getValue(Object value) { return value.toString().toUpperCase(Locale.getDefault()); } - }; + public static final Fetcher<String> FETCHER = value -> value.toString().toUpperCase(Locale.getDefault()); private UPPER(Object value) { super(FETCHER, SQLFunction.UPPER, value); @@ -110,10 +101,7 @@ public abstract class EntityFunction<T extends Comparable<?>> extends EntityCond * */ public static class LOWER extends EntityFunctionSingle<String> { - public static final Fetcher<String> FETCHER = new Fetcher<String>() { - @Override - public String getValue(Object value) { return value.toString().toLowerCase(Locale.getDefault()); } - }; + public static final Fetcher<String> FETCHER = value -> value.toString().toLowerCase(Locale.getDefault()); private LOWER(Object value) { super(FETCHER, SQLFunction.LOWER, value); diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java index a70e5c7..6824a5a 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelWidgetCondition.java @@ -147,18 +147,8 @@ public abstract class ModelWidgetCondition implements Serializable { } public static class DefaultConditionFactory implements ConditionFactory { - public static final Condition TRUE = new Condition() { - @Override - public boolean eval(Map<String, Object> context) { - return true; - } - }; - public static final Condition FALSE = new Condition() { - @Override - public boolean eval(Map<String, Object> context) { - return false; - } - }; + public static final Condition TRUE = context -> true; + public static final Condition FALSE = context -> false; @Override public Condition newInstance(ModelWidget modelWidget, Element conditionElement) { |
Free forum by Nabble | Edit this page |