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
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS info.picocli:picocli:4.7.1 | |
//DEPS com.squareup.retrofit2:retrofit:2.9.0 | |
//DEPS com.squareup.retrofit2:converter-gson:2.9.0 | |
import okhttp3.OkHttpClient; | |
import picocli.CommandLine; | |
import picocli.CommandLine.Command; | |
import picocli.CommandLine.Parameters; |
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
class EndOfLife implements Callable<Integer> { | |
@Parameters(index = "0", description = "The product about which the end of life information are collected", defaultValue = "java") | |
private String product; | |
@Parameters(index = "1", description = "The release cycle for which the details must be fetched", defaultValue = "") | |
private String releaseCycle; | |
public static void main(String... args) { | |
int exitCode = new CommandLine(new EndOfLife()).execute(args); |
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
interface EndOfLifeService { | |
@GET("api/{product}.json") | |
public Call<List<ProductDetails>> getAllDetails(@Path("product") String product); | |
@GET("api/{product}/{cycle}.json") | |
public Call<ProductDetails> getSingleCycleDetails(@Path("product") String product, @Path("cycle") String cycle); | |
} |
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
class ProductDetails { | |
private String cycle; | |
private String releaseDate; | |
private String eol; | |
private String latest; | |
private String link; | |
private boolean lts; | |
private String support; | |
private String discontinued; | |
} |
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
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS info.picocli:picocli:4.6.3 | |
import picocli.CommandLine; | |
import picocli.CommandLine.Command; | |
import picocli.CommandLine.Parameters; | |
import java.util.concurrent.Callable; | |
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
//Pour exécuter avec JBang : jbang perfectNumber.jsh | |
//Pour exécuter avec JShell lancer jshell puis : /open perfectNumber.jsh | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
int sumOfDividers(int value){ | |
return IntStream.rangeClosed(1, value).filter(i -> value % i == 0).sum(); | |
} | |
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
double getDoubleUsingSwitch(Object o) { | |
return switch (o) { | |
case Integer i -> i.doubleValue(); | |
case Float f -> f.doubleValue(); | |
case String s -> Double.parseDouble(s); | |
default -> 0d; | |
}; | |
} | |
System.out.println(getDoubleUsingSwitch("56.6")); |
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
import java.io.*; | |
import java.math.*; | |
import java.net.*; | |
import java.nio.file.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.function.*; | |
import java.util.prefs.*; | |
import java.util.regex.*; | |
import java.util.stream.*; |
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
/open perfectNumber.jsh | |
/open PRINTING | |
print("Hello world!"); | |
/save -history save-history.jsh |
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
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
int sumOfDividers(int value){ | |
return IntStream.rangeClosed(1, value).filter(i -> value % i == 0).sum(); | |
} | |
var maxItems = 100; | |
System.out.println("Perfect Numbers up to : " + maxItems); | |
String list = IntStream.rangeClosed(1, maxItems).filter(num -> sumOfDividers(num) == 2 * num).mapToObj(i -> ((Integer) i).toString()).collect(Collectors.joining(", ")); | |
System.out.println(">> " + list); |