Skip to content

Commit

Permalink
Release 0.1.27: add LangUtil.seq, with
Browse files Browse the repository at this point in the history
  • Loading branch information
jianwu committed Sep 2, 2022
1 parent 71b59d0 commit 0a6fa12
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CliArg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>CliArg</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion HiveUDF/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>HiveUDF</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion JSONCoder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>JSONCoder</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion SnapshotTest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>SnapshotTest</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jsonex/core/util/BeanProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Object get(Object obj){
return field.get(obj);
}
} catch(Exception e) {
throw new InvokeRuntimeException("error get value:" + name + ", class:" + obj.getClass(), e);
throw new InvokeRuntimeException("error get value:" + name + ", class:" + obj.getClass() + ";hasChecker:" + hasChecker, e);
}
throw new InvokeRuntimeException("field is not readable: " + name + ", class:" + obj.getClass());
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jsonex/core/util/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ private static Map<String, BeanProperty> getPropertiesNoCache(Class<?> cls) {
case has: prop.hasChecker = m; break;
case set: prop.setter = m; break;
case is:
if (prop.getter == null)
prop.getter = m;
else
prop.hasChecker = m ;
break;
case get:
if (prop.getter == null)
prop.getter = m;
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/org/jsonex/core/util/LangUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.SneakyThrows;
import org.jsonex.core.type.Nullable;

import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -124,4 +125,16 @@ public static <T> T seq(Runnable action1, Runnable action2, T val) {
action2.run();
return val;
}

/**
* Convert a block of code with local variables definitions into an single expression, it's useful to avoid code block
* in lambda statement.
*/
public static <T, R> R with(T val, Function<T, R> action) {
return action.apply(val);
}

public static <T1, T2, R> R with(T1 val1, T2 val2, BiFunction<T1, T2, R> action) {
return action.apply(val1, val2);
}
}
5 changes: 5 additions & 0 deletions core/src/test/java/org/jsonex/core/util/LangUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ static class C {
assertEquals(val, LangUtil.seq(() -> i[0] += 1, () -> i[0] += 1, val));
assertEquals(3, i[0]);
}

@Test public void testWith() {
assertEquals("abcd", LangUtil.with("abc", a -> a + "d"));
assertEquals("abcd", LangUtil.with("abc", "d", (a, b) -> a + b));
}
}
2 changes: 1 addition & 1 deletion csv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>csv</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<packaging>pom</packaging>
<name>JSONCoder Parent</name>
<description>JSONCoder Parent</description>
Expand Down
2 changes: 1 addition & 1 deletion treedoc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jsonex</groupId>
<artifactId>jcParent</artifactId>
<version>0.1.26</version>
<version>0.1.27</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>treedoc</artifactId>
Expand Down

0 comments on commit 0a6fa12

Please sign in to comment.