-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upgrading gradle * string templates example * more examples
- Loading branch information
Showing
6 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-rc-2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.mageddo.java21; | ||
|
||
public record Response(String user, Integer order) { | ||
} |
6 changes: 6 additions & 0 deletions
6
java-features/src/main/java/com/mageddo/java21/stringtemplates/StringTemplatesMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mageddo.java21.stringtemplates; | ||
|
||
public class StringTemplatesMain { | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...es/src/main/java/com/mageddo/java21/structured_concurrency/StructuredConcurrencyMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.mageddo.java21.structured_concurrency; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.StructuredTaskScope; | ||
import java.util.function.Supplier; | ||
|
||
import com.mageddo.java21.Response; | ||
|
||
public class StructuredConcurrencyMain { | ||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
System.out.println(handle()); | ||
} | ||
|
||
static Response handle() throws ExecutionException, InterruptedException { | ||
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { | ||
Supplier<String> user = scope.fork(() -> findUser()); | ||
Supplier<Integer> order = scope.fork(() -> fetchOrder()); | ||
|
||
scope.join() // Join both subtasks | ||
.throwIfFailed(); // ... and propagate errors | ||
|
||
// Here, both subtasks have succeeded, so compose their results | ||
return new Response(user.get(), order.get()); | ||
} | ||
} | ||
|
||
static Integer fetchOrder() { | ||
return 46114; | ||
} | ||
|
||
static String findUser() { | ||
return "Jose"; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
java-features/src/test/java/com/mageddo/java21/stringtemplates/StringTemplatesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.mageddo.java21.stringtemplates; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* https://openjdk.org/jeps/430 | ||
*/ | ||
class StringTemplatesTest { | ||
|
||
@Test | ||
void mustEvaluateString() { | ||
|
||
// arrange | ||
|
||
final var name = "John"; | ||
final var age = 23; | ||
final var pair = Pair.of("color", "green"); | ||
|
||
// act | ||
final String tpl = StringTemplate.STR.""" | ||
Hello \{name}, your age is \{age}, in the next year you will be \{age + 1}. | ||
\{pair.getKey()}=\{pair.getValue()} | ||
"""; | ||
|
||
// assert | ||
assertEquals(""" | ||
Hello John, your age is 23, in the next year you will be 24. | ||
color=green | ||
""", tpl); | ||
} | ||
} |