Skip to content

Commit 79d8f40

Browse files
authored
release: 1.2.7 (#17)
- JList, JSet added - Bugfix: meta init for ExecutionContext - library upgrade
1 parent ea0ed66 commit 79d8f40

File tree

10 files changed

+121
-11
lines changed

10 files changed

+121
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ framework and objects.
4949
<dependency>
5050
<groupId>com.javaquery</groupId>
5151
<artifactId>util</artifactId>
52-
<version>1.2.6</version>
52+
<version>1.2.7</version>
5353
</dependency>
5454
```
5555

5656
# Gradle
5757

5858
```
59-
implementation 'com.javaquery:util:1.2.6'
59+
implementation 'com.javaquery:util:1.2.7'
6060
```

build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ plugins {
55
}
66

77
sourceCompatibility = 1.8
8+
targetCompatibility = 1.8
89
group 'com.javaquery'
910
archivesBaseName = 'util'
10-
version '1.2.6'
11+
version '1.2.7'
1112

1213
repositories {
1314
mavenCentral()
1415
}
1516

1617
dependencies {
17-
implementation('org.slf4j:slf4j-api:2.0.11')
18-
implementation('org.json:json:20231013')
19-
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.16.1'
18+
implementation 'org.slf4j:slf4j-api:2.0.16'
19+
implementation 'org.json:json:20250107'
20+
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.18.2'
2021

2122
testImplementation 'net.logstash.logback:logstash-logback-encoder:7.4'
22-
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.14'
23-
testImplementation('org.junit.jupiter:junit-jupiter:5.7.0')
23+
testImplementation 'ch.qos.logback:logback-classic:1.3.15'
24+
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
2425
}
2526

2627
test {

src/main/java/com/javaquery/util/ExecutionContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class ExecutionContext<T, V> {
4242

4343
public ExecutionContext() {
4444
this.createdAt = Dates.current();
45+
this.meta = new HashMap<>();
4546
}
4647

4748
public ExecutionContext(String requestId){
@@ -123,6 +124,10 @@ public Object getMeta(String key, Object defaultValue){
123124
return meta.getOrDefault(key, defaultValue);
124125
}
125126

127+
public String optString(String key, String defaultValue){
128+
return String.valueOf(getMeta(key, defaultValue));
129+
}
130+
126131
public void addMeta(String key, Object value){
127132
this.meta.put(key, value);
128133
}

src/main/java/com/javaquery/util/Is.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ public static boolean nonNull(Object obj) {
4747
return Objects.nonNull(obj);
4848
}
4949

50+
/**
51+
* Execute code if the provided reference is non-{@code null}.
52+
*
53+
* @param obj a reference to be checked against {@code null}
54+
* @param executableFunction lambda function given executed if the provided reference is non-{@code null}.
55+
*/
56+
public static void nonNull(Object obj, ExecutableFunction executableFunction){
57+
if(nonNull(obj)){
58+
executableFunction.execute();
59+
}
60+
}
61+
5062
/**
5163
* Returns {@code true} if the provided String is {@code null} or empty otherwise returns {@code
5264
* false}.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.javaquery.util.collection;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
/**
7+
* @author javaquery
8+
* @since 1.2.7
9+
*/
10+
public class JList {
11+
12+
@SafeVarargs
13+
public static <E> List<E> of(E... elements) {
14+
return Arrays.asList(elements);
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.javaquery.util.collection;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
7+
/**
8+
* @author javaquery
9+
* @since 1.2.7
10+
*/
11+
public class JSet {
12+
public static <E> Set<E> of(E... elements) {
13+
return new HashSet<>(Arrays.asList(elements));
14+
}
15+
}

src/main/java/com/javaquery/util/number/Numbers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class Numbers {
1111

1212
/**
1313
* Round the decimal number.
14-
* example: roundDecimal(10.123456789, 2) => 10.12
15-
* example: roundDecimal(10.123456789, 4) => 10.1235
16-
* example: roundDecimal(10.576, 2) => 10.58
14+
* example: roundDecimal(10.123456789, 2) = 10.12
15+
* example: roundDecimal(10.123456789, 4) = 10.1235
16+
* example: roundDecimal(10.576, 2) = 10.58
1717
*
1818
* @param number number to round
1919
* @param decimalPlaces decimal places to round

src/test/java/com/javaquery/util/TestExecutionContext.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void defaultConstructor(){
4545
executionContext.setRequestId(UniqueIdGenerator.generate());
4646

4747
UserContext userContext = (UserContext) executionContext.getUserContext();
48+
assertNotNull(executionContext.getMeta());
4849
assertEquals(50L, userContext.getUserId());
4950
assertNotNull(executionContext.getCreatedAt());
5051
assertNotNull(executionContext.getRequestId());
@@ -102,6 +103,7 @@ public void constructorWithActionAndMeta(){
102103
assertEquals(ExecutionContextAction.ONE, executionContext.getAction());
103104
assertNull(executionContext.getReferenceId());
104105
assertEquals("value", executionContext.getMeta("key", null));
106+
assertEquals("not found", executionContext.optString("key2", "not found"));
105107
assertNotNull(executionContext.getCreatedAt());
106108

107109
/* set meta */
@@ -142,4 +144,15 @@ public void constructorWithActionMaxRetries(){
142144
assertNotNull(executionContext.getMeta());
143145
assertNotNull(executionContext.getCreatedAt());
144146
}
147+
148+
@Test
149+
public void metaDataTest(){
150+
ExecutionContext<String, Void> executionContext = new ExecutionContext<>();
151+
executionContext.addMeta("key", "value");
152+
assertEquals("value", executionContext.getMeta("key", null));
153+
assertEquals("value", executionContext.optString("key", null));
154+
assertEquals("not found", executionContext.optString("key2", "not found"));
155+
executionContext.addMeta("key", "value2");
156+
assertEquals("value2", executionContext.getMeta("key", null));
157+
}
145158
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.javaquery.util.collection;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.List;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
10+
/**
11+
* @author javaquery
12+
* @since 2025-01-20
13+
*/
14+
public class TestJList {
15+
16+
@Test
17+
public void test_of(){
18+
List<String> list = JList.of("a", "b", "c");
19+
assertEquals(3, list.size());
20+
assertTrue(list.contains("a"));
21+
assertTrue(list.contains("b"));
22+
assertTrue(list.contains("c"));
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.javaquery.util.collection;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.Set;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
10+
/**
11+
* @author javaquery
12+
* @since 2025-01-20
13+
*/
14+
public class TestJSet {
15+
16+
@Test
17+
public void test_of(){
18+
Set<String> set = JSet.of("a", "b", "c");
19+
assertEquals(3, set.size());
20+
assertTrue(set.contains("a"));
21+
assertTrue(set.contains("b"));
22+
assertTrue(set.contains("c"));
23+
}
24+
}

0 commit comments

Comments
 (0)