Skip to content
Permalink
Browse files
Use lambdas.
  • Loading branch information
garydgregory committed Oct 25, 2020
1 parent 893276b commit 16145ecc044d7e68c573409c036e534b9bab3c51
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 76 deletions.
@@ -24,7 +24,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -224,12 +223,7 @@ private static void create(ClassMap cache, Permissions permissions, Class<?> cla
List<Method> lm = new ArrayList<Method>(cache.byKey.size());
lm.addAll(cache.byKey.values());
// sort all methods by name
lm.sort(new Comparator<Method>() {
@Override
public int compare(Method o1, Method o2) {
return o1.getName().compareTo(o2.getName());
}
});
lm.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
// put all lists of methods with same name in byName cache
int start = 0;
while (start < lm.size()) {
@@ -159,20 +159,17 @@ interface ResolverStrategy {
* If the operator is '[]' or if the operator is null and the object is a map, use the MAP list of resolvers;
* Other cases use the POJO list of resolvers.
*/
ResolverStrategy JEXL_STRATEGY = new ResolverStrategy() {
@Override
public List<PropertyResolver> apply(JexlOperator op, Object obj) {
if (op == JexlOperator.ARRAY_GET) {
return MAP;
}
if (op == JexlOperator.ARRAY_SET) {
return MAP;
}
if (op == null && obj instanceof Map) {
return MAP;
}
return POJO;
ResolverStrategy JEXL_STRATEGY = (op, obj) -> {
if (op == JexlOperator.ARRAY_GET) {
return MAP;
}
if (op == JexlOperator.ARRAY_SET) {
return MAP;
}
if (op == null && obj instanceof Map) {
return MAP;
}
return POJO;
};

/**
@@ -181,20 +178,17 @@ public List<PropertyResolver> apply(JexlOperator op, Object obj) {
* <p>If the operator is '[]' or if the object is a map, use the MAP list of resolvers.
* Otherwise, use the POJO list of resolvers.</p>
*/
ResolverStrategy MAP_STRATEGY = new ResolverStrategy() {
@Override
public List<PropertyResolver> apply(JexlOperator op, Object obj) {
if (op == JexlOperator.ARRAY_GET) {
return MAP;
}
if (op == JexlOperator.ARRAY_SET) {
return MAP;
}
if (obj instanceof Map) {
return MAP;
}
return POJO;
ResolverStrategy MAP_STRATEGY = (op, obj) -> {
if (op == JexlOperator.ARRAY_GET) {
return MAP;
}
if (op == JexlOperator.ARRAY_SET) {
return MAP;
}
if (obj instanceof Map) {
return MAP;
}
return POJO;
};

/**
@@ -255,11 +255,7 @@ public void test225() throws Exception {
}

private static void handle(ExecutorService pool, final JexlScript script, final Map<String, Object> payload) {
pool.submit(new Runnable() {
@Override public void run() {
script.execute(new MapContext(payload));
}
});
pool.submit(() -> script.execute(new MapContext(payload)));
}

@Test
@@ -688,17 +688,14 @@ public Object resolveNamespace(String name) {
return nsScript;
}
if ("functor".equals(name)) {
return new JexlContext.NamespaceFunctor() {
@Override
public Object createFunctor(JexlContext context) {
Map<String, Object> values = new HashMap<String, Object>();
if ("gin".equals(context.get("base"))) {
values.put("drink", "gin fizz");
} else {
values.put("drink", "champaign");
}
return values;
return (NamespaceFunctor) context -> {
Map<String, Object> values = new HashMap<String, Object>();
if ("gin".equals(context.get("base"))) {
values.put("drink", "gin fizz");
} else {
values.put("drink", "champaign");
}
return values;
};
}
return null;
@@ -73,12 +73,9 @@ public void testCallableCancel() throws Exception {
JexlScript e = JEXL.createScript("latch.release(); while(true);");
final Script.Callable c = (Script.Callable) e.callable(ctxt);
Object t = 42;
Callable<Object> kc = new Callable<Object>() {
@Override
public Object call() throws Exception {
latch.acquire();
return c.cancel();
}
Callable<Object> kc = () -> {
latch.acquire();
return c.cancel();
};
ExecutorService executor = Executors.newFixedThreadPool(2);
Future<?> future = executor.submit(c);
@@ -121,12 +118,9 @@ public void testCallableCancellation() throws Exception {
JexlScript e = JEXL.createScript("latch.release(); while(true);");
final Script.Callable c = (Script.Callable) e.callable(ctxt);
Object t = 42;
Callable<Object> kc = new Callable<Object>() {
@Override
public Object call() throws Exception {
latch.acquire();
return cancel.compareAndSet(false, true);
}
Callable<Object> kc = () -> {
latch.acquire();
return cancel.compareAndSet(false, true);
};
ExecutorService executor = Executors.newFixedThreadPool(2);
Future<?> future = executor.submit(c);
@@ -462,16 +456,13 @@ private void runInterrupt(JexlEngine jexl) throws Exception {
// cancel a sleep
try {
final Future<Object> fc = exec.submit(ssleep.callable(ctxt));
Runnable cancels = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(200L);
} catch (Exception xignore) {
Runnable cancels = () -> {
try {
Thread.sleep(200L);
} catch (Exception xignore) {

}
fc.cancel(true);
}
fc.cancel(true);
};
exec.submit(cancels);
t = f.get(100L, TimeUnit.MILLISECONDS);
@@ -496,16 +487,13 @@ public void run() {
// cancel a while(true)
try {
final Future<Object> fc = exec.submit(swhile.callable(ctxt));
Runnable cancels = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(200L);
} catch (Exception xignore) {
Runnable cancels = () -> {
try {
Thread.sleep(200L);
} catch (Exception xignore) {

}
fc.cancel(true);
}
fc.cancel(true);
};
exec.submit(cancels);
t = fc.get();

0 comments on commit 16145ec

Please sign in to comment.