├── .gitattributes ├── .gitignore ├── graalvm ├── .gitignore ├── CountUppercase.java ├── HelloWorld.js ├── Notes.md └── pom.xml ├── java18 ├── Notes.md ├── docs │ ├── index.html │ └── java18 │ │ ├── allclasses-index.html │ │ ├── allpackages-index.html │ │ ├── copy.svg │ │ ├── element-list │ │ ├── example │ │ ├── Example.html │ │ ├── Example2.html │ │ ├── Example3.html │ │ ├── package-summary.html │ │ └── package-tree.html │ │ ├── help-doc.html │ │ ├── index-all.html │ │ ├── index.html │ │ ├── jquery-ui.overrides.css │ │ ├── legal │ │ ├── ADDITIONAL_LICENSE_INFO │ │ ├── ASSEMBLY_EXCEPTION │ │ ├── LICENSE │ │ ├── jquery.md │ │ └── jqueryUI.md │ │ ├── member-search-index.js │ │ ├── module-search-index.js │ │ ├── overview-tree.html │ │ ├── package-search-index.js │ │ ├── resources │ │ ├── glass.png │ │ └── x.png │ │ ├── script-dir │ │ ├── images │ │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ │ ├── ui-bg_glass_65_dadada_1x400.png │ │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ │ ├── ui-bg_highlight-soft_75_cccccc_1x100.png │ │ │ ├── ui-icons_222222_256x240.png │ │ │ ├── ui-icons_2e83ff_256x240.png │ │ │ ├── ui-icons_454545_256x240.png │ │ │ ├── ui-icons_888888_256x240.png │ │ │ └── ui-icons_cd0a0a_256x240.png │ │ ├── jquery-3.5.1.min.js │ │ ├── jquery-ui.min.css │ │ ├── jquery-ui.min.js │ │ └── jquery-ui.structure.min.css │ │ ├── script.js │ │ ├── search.js │ │ ├── stylesheet.css │ │ ├── tag-search-index.js │ │ └── type-search-index.js ├── snippet-files │ └── ShowOptional.java ├── src │ ├── example │ │ ├── Example.java │ │ ├── Example2.java │ │ └── Example3.java │ └── provider │ │ ├── META-INF │ │ └── services │ │ │ └── java.net.spi.InetAddressResolverProvider │ │ └── impl │ │ └── SimpleResolverProviderImpl.java └── test.txt ├── java19 └── Notes.md ├── java20 └── Notes.md ├── java21 ├── Notes.md └── hello.java ├── java22 ├── Greetings.java ├── Hello.java └── Notes.md ├── java23 └── Notes.md ├── javaagent ├── Notes.md └── hello.java ├── key-value-stores ├── .gitattributes ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── example │ │ │ ├── App.java │ │ │ ├── IOUtils.java │ │ │ └── StringUtils.java │ │ └── test │ │ └── java │ │ └── org │ │ └── example │ │ ├── AppTest.java │ │ ├── ForStDBTest.java │ │ ├── MapDBTest.java │ │ └── RockDBTest.java ├── gradle.properties ├── gradle │ ├── libs.versions.toml │ └── wrapper │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── regex ├── app ├── build.gradle └── src │ ├── main │ └── java │ │ └── com │ │ └── galiglobal │ │ └── java │ │ └── playground │ │ ├── App.java │ │ └── regex │ │ ├── Hyperscale.java │ │ └── RegexApp.java │ └── test │ └── groovy │ └── com │ └── galiglobal │ └── java │ └── playground │ └── AppTest.groovy ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle build output directory 2 | .gradle/ 3 | build 4 | .idea/ 5 | 6 | # NewRelic agent 7 | javaagent/newrelic 8 | 9 | # Java 10 | *.jar 11 | *.class 12 | -------------------------------------------------------------------------------- /graalvm/.gitignore: -------------------------------------------------------------------------------- 1 | graaljs-* 2 | graalnodejs-* 3 | -------------------------------------------------------------------------------- /graalvm/CountUppercase.java: -------------------------------------------------------------------------------- 1 | public class CountUppercase { 2 | static final int ITERATIONS = Math.max(Integer.getInteger("iterations", 1), 1); 3 | 4 | public static void main(String[] args) { 5 | String sentence = String.join(" ", args); 6 | for (int iter = 0; iter < ITERATIONS; iter++) { 7 | if (ITERATIONS != 1) { 8 | System.out.println("-- iteration " + (iter + 1) + " --"); 9 | } 10 | long total = 0, start = System.currentTimeMillis(), last = start; 11 | for (int i = 1; i < 10_000_000; i++) { 12 | total += sentence 13 | .chars() 14 | .filter(Character::isUpperCase) 15 | .count(); 16 | if (i % 1_000_000 == 0) { 17 | long now = System.currentTimeMillis(); 18 | System.out.printf("%d (%d ms)%n", i / 1_000_000, now - last); 19 | last = now; 20 | } 21 | } 22 | System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /graalvm/HelloWorld.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | var server = http.createServer(function (request, response) { 4 | response.writeHead(200, {"Content-Type": "text/plain"}); 5 | console.log("Received HelloWorld!"); 6 | response.end("Hello World!\n"); 7 | }); 8 | 9 | server.listen(8000); 10 | 11 | console.log("Server running at http://localhost:8000/"); 12 | -------------------------------------------------------------------------------- /graalvm/Notes.md: -------------------------------------------------------------------------------- 1 | # Java 21 2 | 3 | - 4 | 5 | > The first production-ready version, GraalVM 19.0, was released in May 2019 6 | 7 | > Pure Java implementation. 8 | 9 | > License: Community Edition: GPLv2. Enterprise Edition: Trialware 10 | 11 | ## Install GraalVM 12 | 13 | ```sh 14 | sdk list java 15 | sdk install java 21-graalce 16 | sdk use java 21-graalce 17 | java -version 18 | ``` 19 | 20 | ## Graal JIT compiler 21 | 22 | ```sh 23 | javac CountUppercase.java 24 | java CountUppercase "Hello Codely!" 25 | 26 | java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler CountUppercase "Hello Codely!" 27 | java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Dgraal.PrintCompilation=true CountUppercase "Hello Codely!" 28 | ``` 29 | 30 | ## Truffle Language Implementation Framework 31 | 32 | - https://www.graalvm.org/latest/graalvm-as-a-platform/language-implementation-framework/LanguageTutorial/ 33 | - https://github.com/oracle/graaljs/releases/ 34 | 35 | ```sh 36 | wget https://github.com/oracle/graaljs/releases/download/graal-23.1.0/graaljs-community-23.1.0-macos-aarch64.tar.gz 37 | wget https://github.com/oracle/graaljs/releases/download/graal-23.1.0/graalnodejs-community-23.1.0-macos-aarch64.tar.gz 38 | sudo xattr -r -d com.apple.quarantine graaljs-community-23.1.0-macos-aarch64.tar.gz 39 | sudo xattr -r -d com.apple.quarantine graalnodejs-community-23.1.0-macos-aarch64.tar.gz 40 | tar -zxvf graaljs-community-23.1.0-macos-aarch64.tar.gz 41 | tar -zxvf graalnodejs-community-23.1.0-macos-aarch64.tar.gz 42 | graaljs-community-23.1.0-macos-aarch64/bin/js --version 43 | graalnodejs-community-23.1.0-macos-aarch64/bin/node -v 44 | graaljs-community-23.1.0-macos-aarch64/bin/js 45 | ``` 46 | 47 | ```javascript 48 | var BigInteger = Java.type('java.math.BigInteger'); 49 | console.log(BigInteger.valueOf(200000).toString(16)); 50 | ``` 51 | 52 | ```sh 53 | mvn compile com.github.johnpoth:jshell-maven-plugin:1.4:run 54 | ``` 55 | 56 | ```java 57 | import org.graalvm.polyglot.*; 58 | import org.graalvm.polyglot.proxy.*; 59 | 60 | String JS_CODE = "(function myFun(param){console.log('hello '+param);})"; 61 | 62 | System.out.println("Hello Java!"); 63 | try (Context context = Context.create()) { 64 | Value value = context.eval("js", JS_CODE); 65 | value.execute("Hello Codely!"); 66 | } 67 | ``` 68 | 69 | ```java 70 | try (Context context = Context.create()) { 71 | Value value = context.eval("python", "print('Hello Python!')"); 72 | } 73 | ``` 74 | 75 | - https://github.com/graalvm/polyglot-embedding-demo/blob/main/src/main/java/org/example/embedding/Main.java 76 | 77 | ## GraalVM Native Image 78 | 79 | ```sh 80 | javac CountUppercase.java 81 | java CountUppercase "Hello Codely!" 82 | 83 | native-image CountUppercase 84 | ls -lah countuppercase 85 | 86 | ./countuppercase "Hello Codely" 87 | 88 | time java CountUppercase "Hello Codely!" 89 | time ./countuppercase "Hello Codely" 90 | ``` 91 | 92 | - https://medium.com/graalvm/graalvm-for-jdk-21-is-here-ee01177dd12d 93 | - https://graalvm.github.io/native-build-tools/latest/index.html 94 | 95 | ## Resources 96 | 97 | - 98 | - 99 | -------------------------------------------------------------------------------- /java18/Notes.md: -------------------------------------------------------------------------------- 1 | # Java 18 2 | 3 | - https://en.wikipedia.org/wiki/Java_version_history 4 | - https://openjdk.java.net/projects/jdk/18/ 5 | - https://blogs.oracle.com/javamagazine/post/java-project-amber-lambda-loom-panama-valhalla 6 | 7 | ## Install Java 18 8 | 9 | ```sh 10 | sdk install java 18-open 11 | sdk use java 18-open 12 | jshell 13 | ``` 14 | 15 | ## [JEP 408](https://openjdk.java.net/jeps/408): Simple Web Server 16 | 17 | ```sh 18 | jwebserver 19 | ``` 20 | 21 | ```java 22 | import java.net.InetSocketAddress; 23 | import java.nio.file.Path; 24 | import com.sun.net.httpserver.*; 25 | import com.sun.net.httpserver.SimpleFileServer.*; 26 | 27 | var s1 = SimpleFileServer.createFileServer(new InetSocketAddress(8000), Path.of(System.getProperty("user.dir")), OutputLevel.VERBOSE); 28 | s1.start() 29 | s1.stop(0) 30 | ``` 31 | 32 | ```java 33 | var s2 = HttpServer.create(new InetSocketAddress(8000), 0); 34 | s2.start(); 35 | 36 | var handler = SimpleFileServer.createFileHandler(Path.of(System.getProperty("user.dir"))); 37 | s2.createContext("/browse/", handler) 38 | 39 | s2.createContext("/", HttpHandlers.of(200, Headers.of("Allow", "GET"), "Hello World!")); 40 | 41 | Predicate IS_GET = r -> r.getRequestMethod().equals("GET"); 42 | var handler = HttpHandlers.handleOrElse(IS_GET, HttpHandlers.of(200, Headers.of(), "It's GET"), HttpHandlers.of(200, Headers.of(), "It isn't GET")); 43 | s2.createContext("/test", handler); 44 | 45 | import java.net.http.*; 46 | var client = HttpClient.newHttpClient(); 47 | var request = HttpRequest.newBuilder(URI.create("http://localhost:8000/test")).GET().build(); 48 | var response = client.send(request, HttpResponse.BodyHandlers.ofString()) 49 | System.out.println(response.body()) 50 | 51 | var request = HttpRequest.newBuilder(URI.create("http://localhost:8000/test")).POST(HttpRequest.BodyPublishers.ofString("hello")).build(); 52 | var response = client.send(request, HttpResponse.BodyHandlers.ofString()) 53 | System.out.println(response.body()) 54 | 55 | s2.stop(0) 56 | 57 | var filter = SimpleFileServer.createOutputFilter(System.out, OutputLevel.INFO); 58 | var s3 = HttpServer.create(new InetSocketAddress(8000), 10, "/", HttpHandlers.of(200, Headers.of("Allow", "GET"), "Hello World!"), filter); 59 | s3.start() 60 | 61 | s3.stop(0) 62 | ``` 63 | 64 | ## [JEP 413](https://openjdk.java.net/jeps/413): Code Snippets in Java API Documentation 65 | 66 | ```sh 67 | javadoc -private -d ../docs/java18/ -sourcepath src/ example --snippet-path ./snippet-files 68 | 69 | javac snippet-files/ShowOptional.java 70 | ``` 71 | ## [JEP 400](https://openjdk.java.net/jeps/400): UTF-8 by Default 72 | 73 | ```sh 74 | JAVA_TOOL_OPTIONS=-Dfile.encoding=x-windows-950 jshell 75 | ``` 76 | 77 | ```java 78 | import java.nio.charset.Charset; 79 | Charset.defaultCharset() 80 | Charset.availableCharsets() 81 | 82 | var fileReader = new FileReader("test.txt"); 83 | 84 | int data = fileReader.read(); 85 | while(data != -1) { 86 | System.out.print((char) data); 87 | data = fileReader.read(); 88 | } 89 | fileReader.close(); 90 | ``` 91 | 92 | ## [JEP 420](https://openjdk.java.net/jeps/420): Pattern Matching for switch (Second Preview) 93 | 94 | ```sh 95 | jshell --enable-preview 96 | ``` 97 | 98 | ```java 99 | 100 | // Java 17 101 | 102 | Object test = "test!"; 103 | switch (test) { 104 | case Integer i -> System.out.println("Integer!"); 105 | case String s -> System.out.println("Hello " + s); 106 | default -> System.out.println("Nop!"); 107 | } 108 | ``` 109 | 110 | ```java 111 | 112 | Object test = "test!"; 113 | switch (test) { 114 | case String s -> System.out.println("Hello " + s); 115 | case String s && s.equals("unreachable code") -> System.out.println("Hello " + s); 116 | default -> System.out.println("Nop!"); 117 | } 118 | ``` 119 | 120 | ```java 121 | 122 | sealed interface S permits A, B, C {} 123 | final class A implements S {} 124 | final class B implements S {} 125 | record C(int i) implements S {} // Implicitly final 126 | 127 | static int testSealedExhaustive(S s) { 128 | return switch (s) { 129 | case A a -> 1; 130 | case B b -> 2; 131 | case C c -> 3; 132 | }; 133 | } 134 | ``` 135 | 136 | ## [JEP 421](https://openjdk.java.net/jeps/421): Deprecate Finalization for Removal 137 | 138 | ```java 139 | FileInputStream input = null; 140 | FileOutputStream output = null; 141 | try { 142 | input = new FileInputStream("test.txt"); 143 | output = new FileOutputStream("test2.txt"); 144 | //... copy bytes from input to output ... 145 | output.close(); output = null; 146 | input.close(); input = null; 147 | } finally { 148 | if (output != null) output.close(); 149 | if (input != null) input.close(); 150 | } 151 | ``` 152 | 153 | ```java 154 | 155 | try (FileInputStream input = new FileInputStream("test.txt"); 156 | FileOutputStream output = new FileOutputStream("test2.txt")) { 157 | //... copy bytes from input to output ... 158 | } 159 | ``` 160 | 161 | ```java 162 | 163 | // Java 9: deprecated 164 | // Java 18: deprecated for removal 165 | 166 | class A { 167 | @Override 168 | public void finalize() {} 169 | } 170 | ``` 171 | 172 | ## [JEP 416](https://openjdk.java.net/jeps/416): Reimplement Core Reflection with Method Handles 173 | 174 | > Reimplement java.lang.reflect on top of method handles as the common underlying reflective mechanism of 175 | > the platform by replacing the bytecode-generating implementations of Method::invoke, Constructor::newInstance, 176 | > Field::get, and Field::set. 177 | 178 | MethodHandles: https://www.baeldung.com/java-method-handles 179 | 180 | ```java 181 | import java.lang.reflect.*; 182 | import java.lang.invoke.*; 183 | 184 | public record Demo(String s) { 185 | private String hello() { 186 | return s; 187 | } 188 | } 189 | 190 | MethodHandles.Lookup lookup = MethodHandles.publicLookup(); 191 | Method helloMethod = Demo.class.getDeclaredMethod("hello"); 192 | helloMethod.setAccessible(true); 193 | MethodHandle demoMH = lookup.unreflect(helloMethod); 194 | 195 | var demo = new Demo("Anton") 196 | demo.hello() 197 | (String) demoMH.invoke(demo) 198 | ``` 199 | 200 | ## [JEP 418](https://openjdk.java.net/jeps/418): Internet-Address Resolution SPI 201 | 202 | ```sh 203 | javac src/provider/impl/SimpleResolverProviderImpl.java 204 | jar cvf simpleresolverprovider.jar -C src/provider/ . 205 | ``` 206 | 207 | ```java 208 | InetAddress.getByName("www.galiglobal.com") 209 | /env -class-path simpleresolverprovider.jar 210 | InetAddress.getByName("www.galiglobal.com") 211 | ``` 212 | 213 | ## [JEP 417](https://openjdk.java.net/jeps/417): Vector API (Third Incubator) 214 | 215 | See https://www.morling.dev/blog/fizzbuzz-simd-style/ 216 | 217 | ```sh 218 | jshell -v --add-modules jdk.incubator.vector 219 | ``` 220 | 221 | ```java 222 | 223 | void scalarComputation(float[] a, float[] b, float[] c) { 224 | for (int i = 0; i < a.length; i++) { 225 | c[i] = (a[i] * a[i] + b[i] * b[i]) * -1.0f; 226 | } 227 | } 228 | 229 | import jdk.incubator.vector.*; 230 | static final VectorSpecies SPECIES = FloatVector.SPECIES_PREFERRED; 231 | 232 | void vectorComputation(float[] a, float[] b, float[] c) { 233 | int i = 0; 234 | int upperBound = SPECIES.loopBound(a.length); 235 | for (; i < upperBound; i += SPECIES.length()) { 236 | // FloatVector va, vb, vc; 237 | var va = FloatVector.fromArray(SPECIES, a, i); 238 | var vb = FloatVector.fromArray(SPECIES, b, i); 239 | var vc = va.mul(va) 240 | .add(vb.mul(vb)) 241 | .neg(); 242 | vc.intoArray(c, i); 243 | } 244 | for (; i < a.length; i++) { 245 | c[i] = (a[i] * a[i] + b[i] * b[i]) * -1.0f; 246 | } 247 | } 248 | 249 | float[] a = new float[10_000_000]; 250 | float[] b = new float[10_000_000]; 251 | float[] r = new float[10_000_000]; 252 | Arrays.fill(a, 1L); 253 | Arrays.fill(b, 2L); 254 | 255 | int i; 256 | long t0; 257 | for(t0=System.nanoTime(),i=0; i<1000; ++i){ 258 | scalarComputation(a, b, r); 259 | } long elapsed=System.nanoTime()-t0; 260 | 261 | for(t0=System.nanoTime(),i=0; i<1000; ++i){ 262 | vectorComputation(a, b, r); 263 | } long elapsed=System.nanoTime()-t0; 264 | 265 | ``` 266 | 267 | 268 | ## [JEP 419](https://openjdk.java.net/jeps/419): Foreign Function & Memory API (Second Incubator) 269 | 270 | See https://foojay.io/today/project-panama-for-newbies-part-1/ 271 | 272 | ```sh 273 | jshell -v --add-modules jdk.incubator.foreign 274 | ``` 275 | 276 | ```java 277 | import static jdk.incubator.foreign.ResourceScope.newConfinedScope; 278 | import static jdk.incubator.foreign.SegmentAllocator.implicitAllocator; 279 | import static org.unix.stdio_h.printf; 280 | 281 | try (var scope = newConfinedScope()) { 282 | MemorySegment cString = implicitAllocator().allocateUtf8String("Hello World! Panama style\n"); 283 | printf(cString); 284 | System.out.println(cString); 285 | } 286 | ``` 287 | 288 | ## Resources 289 | 290 | - https://sdkman.io/ 291 | - https://cr.openjdk.java.net/~rfield/tutorial/JShellTutorial.html 292 | - https://www.jbang.dev/ 293 | - https://www.happycoders.eu/java/java-18-features/ 294 | -------------------------------------------------------------------------------- /java18/docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Java Playground 5 | 6 | 7 | Java 18 Example 8 | 9 | 10 | -------------------------------------------------------------------------------- /java18/docs/java18/allclasses-index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | All Classes and Interfaces 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 47 |
48 |
49 |
50 |

All Classes and Interfaces

51 |
52 |
53 |
Classes
54 |
55 |
Class
56 |
Description
57 | 58 |
59 |
The following code shows how to use Optional.isPresent: 60 | 61 |
62 |
if (v.isPresent()) {
 63 |     System.out.println("v: " + v.get());
 64 | }
 65 | 
66 |
67 |
68 |
69 | 70 |
71 |
The following code shows how to use Optional.isPresent: 72 | 73 |
74 |
if (x.isPresent()) {
 75 |     System.out.println("x: " + x.get());
 76 | }
 77 | 
78 |
79 |
80 |
81 | 82 |
83 |
The following code shows how to use Optional.isPresent: 84 | 85 |
86 |
if (v.isPresent()) {
 87 |     System.out.println("v: " + v.get());
 88 | }
 89 | 
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | 99 | 100 | -------------------------------------------------------------------------------- /java18/docs/java18/allpackages-index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | All Packages 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 47 |
48 |
49 |
50 |

All Packages

51 |
52 |
Package Summary
53 |
54 |
Package
55 |
Description
56 | 57 |
 
58 |
59 |
60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /java18/docs/java18/copy.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 27 | 28 | 29 | 31 | 33 | 34 | -------------------------------------------------------------------------------- /java18/docs/java18/element-list: -------------------------------------------------------------------------------- 1 | example 2 | -------------------------------------------------------------------------------- /java18/docs/java18/example/Example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Example 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 81 |
82 |
83 | 84 |
85 |
Package example
86 |

Class Example

87 |
88 |
java.lang.Object 89 |
example.Example
90 |
91 |
92 |
93 |
public class Example 94 | extends Object
95 |
The following code shows how to use Optional.isPresent: 96 | 97 |
98 |
if (v.isPresent()) {
 99 |     System.out.println("v: " + v.get());
100 | }
101 | 
102 |
103 |
104 |
105 |
106 | 132 |
133 |
134 |
    135 | 136 |
  • 137 |
    138 |

    Constructor Details

    139 |
      140 |
    • 141 |
      142 |

      Example

      143 |
      public Example()
      144 |
      Constructor.
      145 |
      146 |
    • 147 |
    148 |
    149 |
  • 150 |
151 |
152 | 153 |
154 |
155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /java18/docs/java18/example/Example2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Example2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 81 |
82 |
83 | 84 |
85 |
Package example
86 |

Class Example2

87 |
88 |
java.lang.Object 89 |
example.Example2
90 |
91 |
92 |
93 |
public class Example2 94 | extends Object
95 |
The following code shows how to use Optional.isPresent: 96 | 97 |
98 |
if (x.isPresent()) {
 99 |     System.out.println("x: " + x.get());
100 | }
101 | 
102 |
103 |
104 |
105 |
106 | 132 |
133 |
134 |
    135 | 136 |
  • 137 |
    138 |

    Constructor Details

    139 |
      140 |
    • 141 |
      142 |

      Example2

      143 |
      public Example2()
      144 |
      Constructor.
      145 |
      146 |
    • 147 |
    148 |
    149 |
  • 150 |
151 |
152 | 153 |
154 |
155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /java18/docs/java18/example/Example3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Example3 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 81 |
82 |
83 | 84 |
85 |
Package example
86 |

Class Example3

87 |
88 |
java.lang.Object 89 |
example.Example3
90 |
91 |
92 |
93 |
public class Example3 94 | extends Object
95 |
The following code shows how to use Optional.isPresent: 96 | 97 |
98 |
if (v.isPresent()) {
 99 |     System.out.println("v: " + v.get());
100 | }
101 | 
102 |
103 |
104 |
105 |
106 | 132 |
133 |
134 |
    135 | 136 |
  • 137 |
    138 |

    Constructor Details

    139 |
      140 |
    • 141 |
      142 |

      Example3

      143 |
      public Example3()
      144 |
      Constructor.
      145 |
      146 |
    • 147 |
    148 |
    149 |
  • 150 |
151 |
152 | 153 |
154 |
155 |
156 | 157 | 158 | -------------------------------------------------------------------------------- /java18/docs/java18/example/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | example 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 65 |
66 |
67 |
68 |

Package example

69 |
70 |
71 |
package example
72 |
73 |
    74 |
  • 75 |
    76 |
    Classes
    77 |
    78 |
    Class
    79 |
    Description
    80 | 81 |
    82 |
    The following code shows how to use Optional.isPresent: 83 | 84 |
    85 |
    if (v.isPresent()) {
     86 |     System.out.println("v: " + v.get());
     87 | }
     88 | 
    89 |
    90 |
    91 |
    92 | 93 |
    94 |
    The following code shows how to use Optional.isPresent: 95 | 96 |
    97 |
    if (x.isPresent()) {
     98 |     System.out.println("x: " + x.get());
     99 | }
    100 | 
    101 |
    102 |
    103 |
    104 | 105 |
    106 |
    The following code shows how to use Optional.isPresent: 107 | 108 |
    109 |
    if (v.isPresent()) {
    110 |     System.out.println("v: " + v.get());
    111 | }
    112 | 
    113 |
    114 |
    115 |
    116 |
    117 |
    118 |
  • 119 |
120 |
121 |
122 |
123 |
124 | 125 | 126 | -------------------------------------------------------------------------------- /java18/docs/java18/example/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | example Class Hierarchy 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 47 |
48 |
49 |
50 |

Hierarchy For Package example

51 |
52 |
53 |

Class Hierarchy

54 | 63 |
64 |
65 |
66 |
67 | 68 | 69 | -------------------------------------------------------------------------------- /java18/docs/java18/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | API Help 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 63 |
64 |
65 |

JavaDoc Help

66 | 84 |
85 |
86 |

Navigation

87 | Starting from the Overview page, you can browse the documentation using the links in each page, and in the navigation bar at the top of each page. The Index and Search box allow you to navigate to specific declarations and summary pages, including: All Packages, All Classes and Interfaces 88 | 98 |
99 |
100 |
101 |

Kinds of Pages

102 | The following sections describe the different kinds of pages in this collection. 103 |
104 |

Package

105 |

Each package has a page that contains a list of its classes and interfaces, with a summary for each. These pages may contain the following categories:

106 |
    107 |
  • Interfaces
  • 108 |
  • Classes
  • 109 |
  • Enum Classes
  • 110 |
  • Exception Classes
  • 111 |
  • Annotation Interfaces
  • 112 |
113 |
114 |
115 |

Class or Interface

116 |

Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a declaration and description, member summary tables, and detailed member descriptions. Entries in each of these sections are omitted if they are empty or not applicable.

117 |
    118 |
  • Class Inheritance Diagram
  • 119 |
  • Direct Subclasses
  • 120 |
  • All Known Subinterfaces
  • 121 |
  • All Known Implementing Classes
  • 122 |
  • Class or Interface Declaration
  • 123 |
  • Class or Interface Description
  • 124 |
125 |
126 |
    127 |
  • Nested Class Summary
  • 128 |
  • Enum Constant Summary
  • 129 |
  • Field Summary
  • 130 |
  • Property Summary
  • 131 |
  • Constructor Summary
  • 132 |
  • Method Summary
  • 133 |
  • Required Element Summary
  • 134 |
  • Optional Element Summary
  • 135 |
136 |
137 |
    138 |
  • Enum Constant Details
  • 139 |
  • Field Details
  • 140 |
  • Property Details
  • 141 |
  • Constructor Details
  • 142 |
  • Method Details
  • 143 |
  • Element Details
  • 144 |
145 |

Note: Annotation interfaces have required and optional elements, but not methods. Only enum classes have enum constants. The components of a record class are displayed as part of the declaration of the record class. Properties are a feature of JavaFX.

146 |

The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

147 |
148 |
149 |

Other Files

150 |

Packages and modules may contain pages with additional information related to the declarations nearby.

151 |
152 |
153 |

Tree (Class Hierarchy)

154 |

There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. Classes are organized by inheritance structure starting with java.lang.Object. Interfaces do not inherit from java.lang.Object.

155 |
    156 |
  • When viewing the Overview page, clicking on TREE displays the hierarchy for all packages.
  • 157 |
  • When viewing a particular package, class or interface page, clicking on TREE displays the hierarchy for only that package.
  • 158 |
159 |
160 |
161 |

All Packages

162 |

The All Packages page contains an alphabetic index of all packages contained in the documentation.

163 |
164 |
165 |

All Classes and Interfaces

166 |

The All Classes and Interfaces page contains an alphabetic index of all classes and interfaces contained in the documentation, including annotation interfaces, enum classes, and record classes.

167 |
168 |
169 |

Index

170 |

The Index contains an alphabetic index of all classes, interfaces, constructors, methods, and fields in the documentation, as well as summary pages such as All Packages, All Classes and Interfaces.

171 |
172 |
173 |
174 | This help file applies to API documentation generated by the standard doclet.
175 |
176 |
177 | 178 | 179 | -------------------------------------------------------------------------------- /java18/docs/java18/index-all.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Index 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 47 |
48 |
49 |
50 |

Index

51 |
52 | E 
All Classes and Interfaces|All Packages 53 |

E

54 |
55 |
example - package example
56 |
 
57 |
Example - Class in example
58 |
59 |
The following code shows how to use Optional.isPresent: 60 | 61 |
62 |
if (v.isPresent()) {
 63 |     System.out.println("v: " + v.get());
 64 | }
 65 | 
66 |
67 |
68 |
69 |
Example() - Constructor for class example.Example
70 |
71 |
Constructor.
72 |
73 |
Example2 - Class in example
74 |
75 |
The following code shows how to use Optional.isPresent: 76 | 77 |
78 |
if (x.isPresent()) {
 79 |     System.out.println("x: " + x.get());
 80 | }
 81 | 
82 |
83 |
84 |
85 |
Example2() - Constructor for class example.Example2
86 |
87 |
Constructor.
88 |
89 |
Example3 - Class in example
90 |
91 |
The following code shows how to use Optional.isPresent: 92 | 93 |
94 |
if (v.isPresent()) {
 95 |     System.out.println("v: " + v.get());
 96 | }
 97 | 
98 |
99 |
100 |
101 |
Example3() - Constructor for class example.Example3
102 |
103 |
Constructor.
104 |
105 |
106 | E 
All Classes and Interfaces|All Packages
107 |
108 |
109 | 110 | 111 | -------------------------------------------------------------------------------- /java18/docs/java18/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Generated Documentation (Untitled) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 |
20 | 23 |

example/package-summary.html

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /java18/docs/java18/jquery-ui.overrides.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | .ui-state-active, 27 | .ui-widget-content .ui-state-active, 28 | .ui-widget-header .ui-state-active, 29 | a.ui-button:active, 30 | .ui-button:active, 31 | .ui-button.ui-state-active:hover { 32 | /* Overrides the color of selection used in jQuery UI */ 33 | background: #F8981D; 34 | } 35 | -------------------------------------------------------------------------------- /java18/docs/java18/legal/ADDITIONAL_LICENSE_INFO: -------------------------------------------------------------------------------- 1 | ADDITIONAL INFORMATION ABOUT LICENSING 2 | 3 | Certain files distributed by Oracle America, Inc. and/or its affiliates are 4 | subject to the following clarification and special exception to the GPLv2, 5 | based on the GNU Project exception for its Classpath libraries, known as the 6 | GNU Classpath Exception. 7 | 8 | Note that Oracle includes multiple, independent programs in this software 9 | package. Some of those programs are provided under licenses deemed 10 | incompatible with the GPLv2 by the Free Software Foundation and others. 11 | For example, the package includes programs licensed under the Apache 12 | License, Version 2.0 and may include FreeType. Such programs are licensed 13 | to you under their original licenses. 14 | 15 | Oracle facilitates your further distribution of this package by adding the 16 | Classpath Exception to the necessary parts of its GPLv2 code, which permits 17 | you to use that code in combination with other independent modules not 18 | licensed under the GPLv2. However, note that this would not permit you to 19 | commingle code under an incompatible license with Oracle's GPLv2 licensed 20 | code by, for example, cutting and pasting such code into a file also 21 | containing Oracle's GPLv2 licensed code and then distributing the result. 22 | 23 | Additionally, if you were to remove the Classpath Exception from any of the 24 | files to which it applies and distribute the result, you would likely be 25 | required to license some or all of the other code in that distribution under 26 | the GPLv2 as well, and since the GPLv2 is incompatible with the license terms 27 | of some items included in the distribution by Oracle, removing the Classpath 28 | Exception could therefore effectively compromise your ability to further 29 | distribute the package. 30 | 31 | Failing to distribute notices associated with some files may also create 32 | unexpected legal consequences. 33 | 34 | Proceed with caution and we recommend that you obtain the advice of a lawyer 35 | skilled in open source matters before removing the Classpath Exception or 36 | making modifications to this package which may subsequently be redistributed 37 | and/or involve the use of third party software. 38 | -------------------------------------------------------------------------------- /java18/docs/java18/legal/ASSEMBLY_EXCEPTION: -------------------------------------------------------------------------------- 1 | 2 | OPENJDK ASSEMBLY EXCEPTION 3 | 4 | The OpenJDK source code made available by Oracle America, Inc. (Oracle) at 5 | openjdk.java.net ("OpenJDK Code") is distributed under the terms of the GNU 6 | General Public License version 2 7 | only ("GPL2"), with the following clarification and special exception. 8 | 9 | Linking this OpenJDK Code statically or dynamically with other code 10 | is making a combined work based on this library. Thus, the terms 11 | and conditions of GPL2 cover the whole combination. 12 | 13 | As a special exception, Oracle gives you permission to link this 14 | OpenJDK Code with certain code licensed by Oracle as indicated at 15 | http://openjdk.java.net/legal/exception-modules-2007-05-08.html 16 | ("Designated Exception Modules") to produce an executable, 17 | regardless of the license terms of the Designated Exception Modules, 18 | and to copy and distribute the resulting executable under GPL2, 19 | provided that the Designated Exception Modules continue to be 20 | governed by the licenses under which they were offered by Oracle. 21 | 22 | As such, it allows licensees and sublicensees of Oracle's GPL2 OpenJDK Code 23 | to build an executable that includes those portions of necessary code that 24 | Oracle could not provide under GPL2 (or that Oracle has provided under GPL2 25 | with the Classpath exception). If you modify or add to the OpenJDK code, 26 | that new GPL2 code may still be combined with Designated Exception Modules 27 | if the new code is made subject to this exception by its copyright holder. 28 | -------------------------------------------------------------------------------- /java18/docs/java18/legal/jquery.md: -------------------------------------------------------------------------------- 1 | ## jQuery v3.5.1 2 | 3 | ### jQuery License 4 | ``` 5 | jQuery v 3.5.1 6 | Copyright JS Foundation and other contributors, https://js.foundation/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the 10 | "Software"), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be 17 | included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | ****************************************** 28 | 29 | The jQuery JavaScript Library v3.5.1 also includes Sizzle.js 30 | 31 | Sizzle.js includes the following license: 32 | 33 | Copyright JS Foundation and other contributors, https://js.foundation/ 34 | 35 | This software consists of voluntary contributions made by many 36 | individuals. For exact contribution history, see the revision history 37 | available at https://github.com/jquery/sizzle 38 | 39 | The following license applies to all parts of this software except as 40 | documented below: 41 | 42 | ==== 43 | 44 | Permission is hereby granted, free of charge, to any person obtaining 45 | a copy of this software and associated documentation files (the 46 | "Software"), to deal in the Software without restriction, including 47 | without limitation the rights to use, copy, modify, merge, publish, 48 | distribute, sublicense, and/or sell copies of the Software, and to 49 | permit persons to whom the Software is furnished to do so, subject to 50 | the following conditions: 51 | 52 | The above copyright notice and this permission notice shall be 53 | included in all copies or substantial portions of the Software. 54 | 55 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 56 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 57 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 58 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 59 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 60 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 61 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 62 | 63 | ==== 64 | 65 | All files located in the node_modules and external directories are 66 | externally maintained libraries used by this software which have their 67 | own licenses; we recommend you read them, as their terms may differ from 68 | the terms above. 69 | 70 | ********************* 71 | 72 | ``` 73 | -------------------------------------------------------------------------------- /java18/docs/java18/legal/jqueryUI.md: -------------------------------------------------------------------------------- 1 | ## jQuery UI v1.12.1 2 | 3 | ### jQuery UI License 4 | ``` 5 | Copyright jQuery Foundation and other contributors, https://jquery.org/ 6 | 7 | This software consists of voluntary contributions made by many 8 | individuals. For exact contribution history, see the revision history 9 | available at https://github.com/jquery/jquery-ui 10 | 11 | The following license applies to all parts of this software except as 12 | documented below: 13 | 14 | ==== 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining 17 | a copy of this software and associated documentation files (the 18 | "Software"), to deal in the Software without restriction, including 19 | without limitation the rights to use, copy, modify, merge, publish, 20 | distribute, sublicense, and/or sell copies of the Software, and to 21 | permit persons to whom the Software is furnished to do so, subject to 22 | the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be 25 | included in all copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 30 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 31 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 32 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 33 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 | 35 | ==== 36 | 37 | Copyright and related rights for sample code are waived via CC0. Sample 38 | code is defined as all source code contained within the demos directory. 39 | 40 | CC0: http://creativecommons.org/publicdomain/zero/1.0/ 41 | 42 | ==== 43 | 44 | All files located in the node_modules and external directories are 45 | externally maintained libraries used by this software which have their 46 | own licenses; we recommend you read them, as their terms may differ from 47 | the terms above. 48 | 49 | ``` 50 | -------------------------------------------------------------------------------- /java18/docs/java18/member-search-index.js: -------------------------------------------------------------------------------- 1 | memberSearchIndex = [{"p":"example","c":"Example","l":"Example()","u":"%3Cinit%3E()"},{"p":"example","c":"Example2","l":"Example2()","u":"%3Cinit%3E()"},{"p":"example","c":"Example3","l":"Example3()","u":"%3Cinit%3E()"}];updateSearchResults(); -------------------------------------------------------------------------------- /java18/docs/java18/module-search-index.js: -------------------------------------------------------------------------------- 1 | moduleSearchIndex = [];updateSearchResults(); -------------------------------------------------------------------------------- /java18/docs/java18/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Class Hierarchy 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 24 |
25 | 47 |
48 |
49 |
50 |

Hierarchy For All Packages

51 | Package Hierarchies: 52 | 55 |
56 |
57 |

Class Hierarchy

58 | 67 |
68 |
69 |
70 |
71 | 72 | 73 | -------------------------------------------------------------------------------- /java18/docs/java18/package-search-index.js: -------------------------------------------------------------------------------- 1 | packageSearchIndex = [{"l":"All Packages","u":"allpackages-index.html"},{"l":"example"}];updateSearchResults(); -------------------------------------------------------------------------------- /java18/docs/java18/resources/glass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/resources/glass.png -------------------------------------------------------------------------------- /java18/docs/java18/resources/x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/resources/x.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-bg_glass_65_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-bg_glass_65_dadada_1x400.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonmry/java-playground/16d4f7ecac74df90671151b4573948ea61195b6b/java18/docs/java18/script-dir/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /java18/docs/java18/script-dir/jquery-ui.structure.min.css: -------------------------------------------------------------------------------- 1 | /*! jQuery UI - v1.12.1 - 2018-12-06 2 | * http://jqueryui.com 3 | * Copyright jQuery Foundation and other contributors; Licensed MIT */ 4 | 5 | .ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important;pointer-events:none}.ui-icon{display:inline-block;vertical-align:middle;margin-top:-.25em;position:relative;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-icon-block{left:50%;margin-left:-8px;display:block}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{margin:0;cursor:pointer;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")}.ui-menu .ui-menu-item-wrapper{position:relative;padding:3px 1em 3px .4em}.ui-menu .ui-menu-divider{margin:5px 0;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-state-focus,.ui-menu .ui-state-active{margin:-1px}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item-wrapper{padding-left:2em}.ui-menu .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0} -------------------------------------------------------------------------------- /java18/docs/java18/script.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | var moduleSearchIndex; 27 | var packageSearchIndex; 28 | var typeSearchIndex; 29 | var memberSearchIndex; 30 | var tagSearchIndex; 31 | function loadScripts(doc, tag) { 32 | createElem(doc, tag, 'search.js'); 33 | 34 | createElem(doc, tag, 'module-search-index.js'); 35 | createElem(doc, tag, 'package-search-index.js'); 36 | createElem(doc, tag, 'type-search-index.js'); 37 | createElem(doc, tag, 'member-search-index.js'); 38 | createElem(doc, tag, 'tag-search-index.js'); 39 | } 40 | 41 | function createElem(doc, tag, path) { 42 | var script = doc.createElement(tag); 43 | var scriptElement = doc.getElementsByTagName(tag)[0]; 44 | script.src = pathtoroot + path; 45 | scriptElement.parentNode.insertBefore(script, scriptElement); 46 | } 47 | 48 | function show(tableId, selected, columns) { 49 | if (tableId !== selected) { 50 | document.querySelectorAll('div.' + tableId + ':not(.' + selected + ')') 51 | .forEach(function(elem) { 52 | elem.style.display = 'none'; 53 | }); 54 | } 55 | document.querySelectorAll('div.' + selected) 56 | .forEach(function(elem, index) { 57 | elem.style.display = ''; 58 | var isEvenRow = index % (columns * 2) < columns; 59 | elem.classList.remove(isEvenRow ? oddRowColor : evenRowColor); 60 | elem.classList.add(isEvenRow ? evenRowColor : oddRowColor); 61 | }); 62 | updateTabs(tableId, selected); 63 | } 64 | 65 | function updateTabs(tableId, selected) { 66 | document.querySelector('div#' + tableId +' .summary-table') 67 | .setAttribute('aria-labelledby', selected); 68 | document.querySelectorAll('button[id^="' + tableId + '"]') 69 | .forEach(function(tab, index) { 70 | if (selected === tab.id || (tableId === selected && index === 0)) { 71 | tab.className = activeTableTab; 72 | tab.setAttribute('aria-selected', true); 73 | tab.setAttribute('tabindex',0); 74 | } else { 75 | tab.className = tableTab; 76 | tab.setAttribute('aria-selected', false); 77 | tab.setAttribute('tabindex',-1); 78 | } 79 | }); 80 | } 81 | 82 | function switchTab(e) { 83 | var selected = document.querySelector('[aria-selected=true]'); 84 | if (selected) { 85 | if ((e.keyCode === 37 || e.keyCode === 38) && selected.previousSibling) { 86 | // left or up arrow key pressed: move focus to previous tab 87 | selected.previousSibling.click(); 88 | selected.previousSibling.focus(); 89 | e.preventDefault(); 90 | } else if ((e.keyCode === 39 || e.keyCode === 40) && selected.nextSibling) { 91 | // right or down arrow key pressed: move focus to next tab 92 | selected.nextSibling.click(); 93 | selected.nextSibling.focus(); 94 | e.preventDefault(); 95 | } 96 | } 97 | } 98 | 99 | var updateSearchResults = function() {}; 100 | 101 | function indexFilesLoaded() { 102 | return moduleSearchIndex 103 | && packageSearchIndex 104 | && typeSearchIndex 105 | && memberSearchIndex 106 | && tagSearchIndex; 107 | } 108 | 109 | function copySnippet(button) { 110 | var textarea = document.createElement("textarea"); 111 | textarea.style.height = 0; 112 | document.body.appendChild(textarea); 113 | textarea.value = button.nextElementSibling.innerText; 114 | textarea.select(); 115 | document.execCommand("copy"); 116 | document.body.removeChild(textarea); 117 | var span = button.firstElementChild; 118 | var copied = span.getAttribute("data-copied"); 119 | if (span.innerHTML !== copied) { 120 | var initialLabel = span.innerHTML; 121 | span.innerHTML = copied; 122 | var parent = button.parentElement; 123 | parent.onmouseleave = parent.ontouchend = function() { 124 | span.innerHTML = initialLabel; 125 | }; 126 | } 127 | } 128 | 129 | // Workaround for scroll position not being included in browser history (8249133) 130 | document.addEventListener("DOMContentLoaded", function(e) { 131 | var contentDiv = document.querySelector("div.flex-content"); 132 | window.addEventListener("popstate", function(e) { 133 | if (e.state !== null) { 134 | contentDiv.scrollTop = e.state; 135 | } 136 | }); 137 | window.addEventListener("hashchange", function(e) { 138 | history.replaceState(contentDiv.scrollTop, document.title); 139 | }); 140 | contentDiv.addEventListener("scroll", function(e) { 141 | var timeoutID; 142 | if (!timeoutID) { 143 | timeoutID = setTimeout(function() { 144 | history.replaceState(contentDiv.scrollTop, document.title); 145 | timeoutID = null; 146 | }, 100); 147 | } 148 | }); 149 | if (!location.hash) { 150 | history.replaceState(contentDiv.scrollTop, document.title); 151 | } 152 | }); 153 | -------------------------------------------------------------------------------- /java18/docs/java18/search.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | var noResult = {l: "No results found"}; 27 | var loading = {l: "Loading search index..."}; 28 | var catModules = "Modules"; 29 | var catPackages = "Packages"; 30 | var catTypes = "Classes and Interfaces"; 31 | var catMembers = "Members"; 32 | var catSearchTags = "Search Tags"; 33 | var highlight = "$&"; 34 | var searchPattern = ""; 35 | var fallbackPattern = ""; 36 | var RANKING_THRESHOLD = 2; 37 | var NO_MATCH = 0xffff; 38 | var MIN_RESULTS = 3; 39 | var MAX_RESULTS = 500; 40 | var UNNAMED = ""; 41 | function escapeHtml(str) { 42 | return str.replace(//g, ">"); 43 | } 44 | function getHighlightedText(item, matcher, fallbackMatcher) { 45 | var escapedItem = escapeHtml(item); 46 | var highlighted = escapedItem.replace(matcher, highlight); 47 | if (highlighted === escapedItem) { 48 | highlighted = escapedItem.replace(fallbackMatcher, highlight) 49 | } 50 | return highlighted; 51 | } 52 | function getURLPrefix(ui) { 53 | var urlPrefix=""; 54 | var slash = "/"; 55 | if (ui.item.category === catModules) { 56 | return ui.item.l + slash; 57 | } else if (ui.item.category === catPackages && ui.item.m) { 58 | return ui.item.m + slash; 59 | } else if (ui.item.category === catTypes || ui.item.category === catMembers) { 60 | if (ui.item.m) { 61 | urlPrefix = ui.item.m + slash; 62 | } else { 63 | $.each(packageSearchIndex, function(index, item) { 64 | if (item.m && ui.item.p === item.l) { 65 | urlPrefix = item.m + slash; 66 | } 67 | }); 68 | } 69 | } 70 | return urlPrefix; 71 | } 72 | function createSearchPattern(term) { 73 | var pattern = ""; 74 | var isWordToken = false; 75 | term.replace(/,\s*/g, ", ").trim().split(/\s+/).forEach(function(w, index) { 76 | if (index > 0) { 77 | // whitespace between identifiers is significant 78 | pattern += (isWordToken && /^\w/.test(w)) ? "\\s+" : "\\s*"; 79 | } 80 | var tokens = w.split(/(?=[A-Z,.()<>[\/])/); 81 | for (var i = 0; i < tokens.length; i++) { 82 | var s = tokens[i]; 83 | if (s === "") { 84 | continue; 85 | } 86 | pattern += $.ui.autocomplete.escapeRegex(s); 87 | isWordToken = /\w$/.test(s); 88 | if (isWordToken) { 89 | pattern += "([a-z0-9_$<>\\[\\]]*?)"; 90 | } 91 | } 92 | }); 93 | return pattern; 94 | } 95 | function createMatcher(pattern, flags) { 96 | var isCamelCase = /[A-Z]/.test(pattern); 97 | return new RegExp(pattern, flags + (isCamelCase ? "" : "i")); 98 | } 99 | $(function() { 100 | var search = $("#search-input"); 101 | var reset = $("#reset-button"); 102 | search.val(''); 103 | search.prop("disabled", false); 104 | reset.prop("disabled", false); 105 | reset.click(function() { 106 | search.val('').focus(); 107 | }); 108 | search.focus(); 109 | }); 110 | $.widget("custom.catcomplete", $.ui.autocomplete, { 111 | _create: function() { 112 | this._super(); 113 | this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)"); 114 | }, 115 | _renderMenu: function(ul, items) { 116 | var rMenu = this; 117 | var currentCategory = ""; 118 | rMenu.menu.bindings = $(); 119 | $.each(items, function(index, item) { 120 | var li; 121 | if (item.category && item.category !== currentCategory) { 122 | ul.append("
  • " + item.category + "
  • "); 123 | currentCategory = item.category; 124 | } 125 | li = rMenu._renderItemData(ul, item); 126 | if (item.category) { 127 | li.attr("aria-label", item.category + " : " + item.l); 128 | li.attr("class", "result-item"); 129 | } else { 130 | li.attr("aria-label", item.l); 131 | li.attr("class", "result-item"); 132 | } 133 | }); 134 | }, 135 | _renderItem: function(ul, item) { 136 | var label = ""; 137 | var matcher = createMatcher(escapeHtml(searchPattern), "g"); 138 | var fallbackMatcher = new RegExp(fallbackPattern, "gi") 139 | if (item.category === catModules) { 140 | label = getHighlightedText(item.l, matcher, fallbackMatcher); 141 | } else if (item.category === catPackages) { 142 | label = getHighlightedText(item.l, matcher, fallbackMatcher); 143 | } else if (item.category === catTypes) { 144 | label = (item.p && item.p !== UNNAMED) 145 | ? getHighlightedText(item.p + "." + item.l, matcher, fallbackMatcher) 146 | : getHighlightedText(item.l, matcher, fallbackMatcher); 147 | } else if (item.category === catMembers) { 148 | label = (item.p && item.p !== UNNAMED) 149 | ? getHighlightedText(item.p + "." + item.c + "." + item.l, matcher, fallbackMatcher) 150 | : getHighlightedText(item.c + "." + item.l, matcher, fallbackMatcher); 151 | } else if (item.category === catSearchTags) { 152 | label = getHighlightedText(item.l, matcher, fallbackMatcher); 153 | } else { 154 | label = item.l; 155 | } 156 | var li = $("
  • ").appendTo(ul); 157 | var div = $("
    ").appendTo(li); 158 | if (item.category === catSearchTags && item.h) { 159 | if (item.d) { 160 | div.html(label + " (" + item.h + ")
    " 161 | + item.d + "
    "); 162 | } else { 163 | div.html(label + " (" + item.h + ")"); 164 | } 165 | } else { 166 | if (item.m) { 167 | div.html(item.m + "/" + label); 168 | } else { 169 | div.html(label); 170 | } 171 | } 172 | return li; 173 | } 174 | }); 175 | function rankMatch(match, category) { 176 | if (!match) { 177 | return NO_MATCH; 178 | } 179 | var index = match.index; 180 | var input = match.input; 181 | var leftBoundaryMatch = 2; 182 | var periferalMatch = 0; 183 | // make sure match is anchored on a left word boundary 184 | if (index === 0 || /\W/.test(input[index - 1]) || "_" === input[index]) { 185 | leftBoundaryMatch = 0; 186 | } else if ("_" === input[index - 1] || (input[index] === input[index].toUpperCase() && !/^[A-Z0-9_$]+$/.test(input))) { 187 | leftBoundaryMatch = 1; 188 | } 189 | var matchEnd = index + match[0].length; 190 | var leftParen = input.indexOf("("); 191 | var endOfName = leftParen > -1 ? leftParen : input.length; 192 | // exclude peripheral matches 193 | if (category !== catModules && category !== catSearchTags) { 194 | var delim = category === catPackages ? "/" : "."; 195 | if (leftParen > -1 && leftParen < index) { 196 | periferalMatch += 2; 197 | } else if (input.lastIndexOf(delim, endOfName) >= matchEnd) { 198 | periferalMatch += 2; 199 | } 200 | } 201 | var delta = match[0].length === endOfName ? 0 : 1; // rank full match higher than partial match 202 | for (var i = 1; i < match.length; i++) { 203 | // lower ranking if parts of the name are missing 204 | if (match[i]) 205 | delta += match[i].length; 206 | } 207 | if (category === catTypes) { 208 | // lower ranking if a type name contains unmatched camel-case parts 209 | if (/[A-Z]/.test(input.substring(matchEnd))) 210 | delta += 5; 211 | if (/[A-Z]/.test(input.substring(0, index))) 212 | delta += 5; 213 | } 214 | return leftBoundaryMatch + periferalMatch + (delta / 200); 215 | 216 | } 217 | function doSearch(request, response) { 218 | var result = []; 219 | searchPattern = createSearchPattern(request.term); 220 | fallbackPattern = createSearchPattern(request.term.toLowerCase()); 221 | if (searchPattern === "") { 222 | return this.close(); 223 | } 224 | var camelCaseMatcher = createMatcher(searchPattern, ""); 225 | var fallbackMatcher = new RegExp(fallbackPattern, "i"); 226 | 227 | function searchIndexWithMatcher(indexArray, matcher, category, nameFunc) { 228 | if (indexArray) { 229 | var newResults = []; 230 | $.each(indexArray, function (i, item) { 231 | item.category = category; 232 | var ranking = rankMatch(matcher.exec(nameFunc(item)), category); 233 | if (ranking < RANKING_THRESHOLD) { 234 | newResults.push({ranking: ranking, item: item}); 235 | } 236 | return newResults.length <= MAX_RESULTS; 237 | }); 238 | return newResults.sort(function(e1, e2) { 239 | return e1.ranking - e2.ranking; 240 | }).map(function(e) { 241 | return e.item; 242 | }); 243 | } 244 | return []; 245 | } 246 | function searchIndex(indexArray, category, nameFunc) { 247 | var primaryResults = searchIndexWithMatcher(indexArray, camelCaseMatcher, category, nameFunc); 248 | result = result.concat(primaryResults); 249 | if (primaryResults.length <= MIN_RESULTS && !camelCaseMatcher.ignoreCase) { 250 | var secondaryResults = searchIndexWithMatcher(indexArray, fallbackMatcher, category, nameFunc); 251 | result = result.concat(secondaryResults.filter(function (item) { 252 | return primaryResults.indexOf(item) === -1; 253 | })); 254 | } 255 | } 256 | 257 | searchIndex(moduleSearchIndex, catModules, function(item) { return item.l; }); 258 | searchIndex(packageSearchIndex, catPackages, function(item) { 259 | return (item.m && request.term.indexOf("/") > -1) 260 | ? (item.m + "/" + item.l) : item.l; 261 | }); 262 | searchIndex(typeSearchIndex, catTypes, function(item) { 263 | return request.term.indexOf(".") > -1 ? item.p + "." + item.l : item.l; 264 | }); 265 | searchIndex(memberSearchIndex, catMembers, function(item) { 266 | return request.term.indexOf(".") > -1 267 | ? item.p + "." + item.c + "." + item.l : item.l; 268 | }); 269 | searchIndex(tagSearchIndex, catSearchTags, function(item) { return item.l; }); 270 | 271 | if (!indexFilesLoaded()) { 272 | updateSearchResults = function() { 273 | doSearch(request, response); 274 | } 275 | result.unshift(loading); 276 | } else { 277 | updateSearchResults = function() {}; 278 | } 279 | response(result); 280 | } 281 | $(function() { 282 | var expanded = false; 283 | var windowWidth; 284 | function collapse() { 285 | if (expanded) { 286 | $("div#navbar-top").removeAttr("style"); 287 | $("button#navbar-toggle-button") 288 | .removeClass("expanded") 289 | .attr("aria-expanded", "false"); 290 | expanded = false; 291 | } 292 | } 293 | $("button#navbar-toggle-button").click(function (e) { 294 | if (expanded) { 295 | collapse(); 296 | } else { 297 | $("div#navbar-top").height($("#navbar-top").prop("scrollHeight")); 298 | $("button#navbar-toggle-button") 299 | .addClass("expanded") 300 | .attr("aria-expanded", "true"); 301 | expanded = true; 302 | windowWidth = window.innerWidth; 303 | } 304 | }); 305 | $("ul.sub-nav-list-small li a").click(collapse); 306 | $("input#search-input").focus(collapse); 307 | $("main").click(collapse); 308 | $(window).on("orientationchange", collapse).on("resize", function(e) { 309 | if (expanded && windowWidth !== window.innerWidth) collapse(); 310 | }); 311 | $("#search-input").catcomplete({ 312 | minLength: 1, 313 | delay: 300, 314 | source: doSearch, 315 | response: function(event, ui) { 316 | if (!ui.content.length) { 317 | ui.content.push(noResult); 318 | } else { 319 | $("#search-input").empty(); 320 | } 321 | }, 322 | autoFocus: true, 323 | focus: function(event, ui) { 324 | return false; 325 | }, 326 | position: { 327 | collision: "flip" 328 | }, 329 | select: function(event, ui) { 330 | if (ui.item.category) { 331 | var url = getURLPrefix(ui); 332 | if (ui.item.category === catModules) { 333 | url += "module-summary.html"; 334 | } else if (ui.item.category === catPackages) { 335 | if (ui.item.u) { 336 | url = ui.item.u; 337 | } else { 338 | url += ui.item.l.replace(/\./g, '/') + "/package-summary.html"; 339 | } 340 | } else if (ui.item.category === catTypes) { 341 | if (ui.item.u) { 342 | url = ui.item.u; 343 | } else if (ui.item.p === UNNAMED) { 344 | url += ui.item.l + ".html"; 345 | } else { 346 | url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.l + ".html"; 347 | } 348 | } else if (ui.item.category === catMembers) { 349 | if (ui.item.p === UNNAMED) { 350 | url += ui.item.c + ".html" + "#"; 351 | } else { 352 | url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.c + ".html" + "#"; 353 | } 354 | if (ui.item.u) { 355 | url += ui.item.u; 356 | } else { 357 | url += ui.item.l; 358 | } 359 | } else if (ui.item.category === catSearchTags) { 360 | url += ui.item.u; 361 | } 362 | if (top !== window) { 363 | parent.classFrame.location = pathtoroot + url; 364 | } else { 365 | window.location.href = pathtoroot + url; 366 | } 367 | $("#search-input").focus(); 368 | } 369 | } 370 | }); 371 | }); 372 | -------------------------------------------------------------------------------- /java18/docs/java18/tag-search-index.js: -------------------------------------------------------------------------------- 1 | tagSearchIndex = [];updateSearchResults(); -------------------------------------------------------------------------------- /java18/docs/java18/type-search-index.js: -------------------------------------------------------------------------------- 1 | typeSearchIndex = [{"l":"All Classes and Interfaces","u":"allclasses-index.html"},{"p":"example","l":"Example"},{"p":"example","l":"Example2"},{"p":"example","l":"Example3"}];updateSearchResults(); -------------------------------------------------------------------------------- /java18/snippet-files/ShowOptional.java: -------------------------------------------------------------------------------- 1 | import java.util.Optional; 2 | 3 | public class ShowOptional { 4 | void show(Optional x) { 5 | // @start region="example" 6 | if (x.isPresent()) { 7 | System.out.println("x: " + x.get()); 8 | } 9 | // @end 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /java18/src/example/Example.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | /** 4 | * The following code shows how to use {@code Optional.isPresent}: 5 | * {@snippet : 6 | * if (v.isPresent()) { 7 | * System.out.println("v: " + v.get()); 8 | * } 9 | * } 10 | */ 11 | public class Example { 12 | /** 13 | * Constructor. 14 | */ 15 | public Example(); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /java18/src/example/Example2.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | /** 4 | * The following code shows how to use {@code Optional.isPresent}: 5 | * {@snippet class="ShowOptional" region="example"} 6 | */ 7 | public class Example2 { 8 | /** 9 | * Constructor. 10 | */ 11 | public Example2(); 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /java18/src/example/Example3.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | /** 4 | * The following code shows how to use {@code Optional.isPresent}: 5 | * {@snippet : 6 | * if (v.isPresent()) { 7 | * System.out.println("v: " + v.get()); // @highlight substring="println" 8 | * } 9 | * } 10 | */ 11 | public class Example3 { 12 | /** 13 | * Constructor. 14 | */ 15 | public Example3(); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /java18/src/provider/META-INF/services/java.net.spi.InetAddressResolverProvider: -------------------------------------------------------------------------------- 1 | impl.SimpleResolverProviderImpl 2 | -------------------------------------------------------------------------------- /java18/src/provider/impl/SimpleResolverProviderImpl.java: -------------------------------------------------------------------------------- 1 | package impl; 2 | 3 | import java.net.InetAddress; 4 | import java.net.UnknownHostException; 5 | import java.net.spi.InetAddressResolver; 6 | import java.net.spi.InetAddressResolver.LookupPolicy; 7 | import java.net.spi.InetAddressResolverProvider; 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.List; 11 | import java.util.logging.Logger; 12 | import java.util.stream.Stream; 13 | 14 | public class SimpleResolverProviderImpl extends InetAddressResolverProvider { 15 | 16 | @Override 17 | public InetAddressResolver get(Configuration configuration) { 18 | System.out.println("The following provider will be used by current test:" + this.getClass().getCanonicalName()); 19 | return new InetAddressResolver() { 20 | @Override 21 | public Stream lookupByName(String host, LookupPolicy lookupPolicy) throws UnknownHostException { 22 | return Stream.of(InetAddress.getByName("127.0.0.1")); 23 | } 24 | 25 | @Override 26 | public String lookupByAddress(byte[] addr) throws UnknownHostException { 27 | return "localhost"; 28 | } 29 | }; 30 | } 31 | 32 | @Override 33 | public String name() { 34 | return "simpleInetAddressResolver"; 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /java18/test.txt: -------------------------------------------------------------------------------- 1 | dale caña, Antón! 2 | -------------------------------------------------------------------------------- /java19/Notes.md: -------------------------------------------------------------------------------- 1 | # Java 19 2 | 3 | - 4 | - 5 | - 6 | 7 | ## Install Java 19 8 | 9 | ```sh 10 | sdk install java 19.ea.36-open 11 | sdk use java 19.ea.36-open 12 | jshell --enable-preview --add-modules jdk.incubator.concurrent 13 | ``` 14 | 15 | ## New features 16 | 17 | ## [JEP 425](https://openjdk.java.net/jeps/425): Virtual Threads (Preview) 18 | 19 | > virtual threads can significantly improve application throughput when 20 | > 21 | > The number of concurrent tasks is high (more than a few thousand), and 22 | > The workload is not CPU-bound, since having many more threads than processor 23 | > cores cannot improve throughput in that case. 24 | 25 | ```java 26 | 27 | var thread = Thread.startVirtualThread(() -> { 28 | System.out.println("Hello from the virtual thread"); 29 | }); 30 | 31 | thread.join(); 32 | 33 | Thread.ofPlatform().start(() -> System.out.println(Thread.currentThread())); 34 | Thread.ofVirtual().start(() -> System.out.println(Thread.currentThread())); 35 | 36 | ``` 37 | 38 | ```java 39 | 40 | try (var executor = Executors.newFixedThreadPool(1_000)) { 41 | IntStream.range(0, 10_000).forEach(i -> { 42 | executor.submit(() -> { 43 | Thread.sleep(1000); 44 | return i; 45 | }); 46 | }); 47 | } 48 | 49 | try (var executor = Executors.newVirtualThreadPerTaskExecutor()) { 50 | IntStream.range(0, 10_000).forEach(i -> { 51 | executor.submit(() -> { 52 | Thread.sleep(1000); 53 | return i; 54 | }); 55 | }); 56 | } 57 | ``` 58 | 59 | ```java 60 | Thread thread = Thread.ofVirtual().start(() -> {int result = 12 / 0;}); 61 | 62 | Thread thread = Thread.ofPlatform().start(() -> {int result = 12 / 0;}); 63 | ``` 64 | 65 | There's no silver bullet. Be careful with: 66 | - Framework / library support 67 | - Thread fairness 68 | - Synchronization 69 | - JNI 70 | - ThreadLocal variables 71 | 72 | - [Virtual Thread Deep Dive - Inside Java Newscast #23](https://nipafx.dev/inside-java-newscast-23/) 73 | - [Launching 10 millions virtual threads with Loom - JEP Café #12](https://inside.java/2022/07/07/jepcafe12/) 74 | - [Java 19 Virtual Threads - JEP Café #11](https://inside.java/2022/06/08/jepcafe11/) 75 | - [Loom and Thread Fairness](https://www.morling.dev/blog/loom-and-thread-fairness/) 76 | - [Going inside Java's Project Loom and virtual threads](https://blogs.oracle.com/javamagazine/post/going-inside-javas-project-loom-and-virtual-threads) 77 | 78 | ## [JEP 428](https://openjdk.java.net/jeps/428): Structured Concurrency (Incubator) 79 | 80 | ```java 81 | String getUser() throws InterruptedException { 82 | Thread.sleep(3000); 83 | return "Anton"; 84 | }; 85 | 86 | Integer getOrder() throws InterruptedException { 87 | Thread.sleep(2000); 88 | return 10; 89 | // return 10/0; 90 | }; 91 | 92 | String theUser = getUser(); 93 | int theOrder = getOrder(); 94 | System.out.println(theUser + ": " + theOrder); 95 | ``` 96 | 97 | ```java 98 | ExecutorService esvc = Executors.newFixedThreadPool(2); 99 | Future user = esvc.submit(() -> getUser()); 100 | Future order = esvc.submit(() -> getOrder()); 101 | String theUser = user.get(); // Join findUser 102 | int theOrder = order.get(); // Join fetchOrder 103 | System.out.println(theUser + ": " + theOrder); 104 | ``` 105 | 106 | ```java 107 | import jdk.incubator.concurrent.StructuredTaskScope; 108 | 109 | try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { 110 | Future user = scope.fork(() -> getUser()); 111 | Future order = scope.fork(() -> getOrder()); 112 | 113 | scope.join(); // Join both forks 114 | scope.throwIfFailed(); // ... and propagate errors 115 | 116 | // Here, both forks have succeeded, so compose their results 117 | System.out.println(user.resultNow() + ": " + order.resultNow()); 118 | } 119 | ``` 120 | 121 | - [Java Asynchronous Programming Full Tutorial with Loom and Structured Concurrency - JEP Café #13](https://inside.java/2022/08/02/jepcafe13/) 122 | - [Project Loom Brings Structured Concurrency - Inside Java Newscast #17](https://www.youtube.com/watch?v=2J2tJm_iwk0) 123 | 124 | ## [JEP 427](https://openjdk.java.net/jeps/427): Pattern Matching for switch (Third Preview) 125 | 126 | ```java 127 | Object o = "Anton"; 128 | 129 | switch (o) { 130 | case Integer i -> { 131 | if (i >= 0) 132 | System.out.println("Positive number"); 133 | else 134 | System.out.println("Negative number"); 135 | } 136 | case String s -> { 137 | if (s.contains("foo")) 138 | System.out.println("String with 'foo'"); 139 | else 140 | System.out.println("String without 'foo'"); 141 | } 142 | default -> System.out.println("No String or Integer"); 143 | } 144 | ``` 145 | 146 | ```java 147 | switch (o) { 148 | case Integer i when i >= 0 -> System.out.println("Positive number"); 149 | case Integer i -> System.out.println("Negative number"); 150 | case String s when s.contains("foo") -> System.out.println("String with 'foo'"); 151 | case String s -> System.out.println("String without 'foo'"); 152 | default -> System.out.println("No String or Integer"); 153 | } 154 | ``` 155 | 156 | ```java 157 | 158 | sealed interface S permits A, B {} 159 | record A(int x, int y) implements S {} 160 | record B(int x, int y) implements S {} 161 | 162 | S o = new A(0, 0); 163 | 164 | switch (o) { 165 | case A(int x, int y) when x >= 0 -> System.out.println("A, positive x"); 166 | case A(int x, int y) when x < 0 -> System.out.println("B, negative x"); 167 | case B(int x, int y) -> System.out.println("B"); 168 | default -> System.out.println("Any of the previous options"); 169 | } 170 | ``` 171 | 172 | ```java 173 | S o = null; 174 | 175 | switch (o) { 176 | case A(int x, int y) when x >= 0 -> System.out.println("A, positive x"); 177 | case A(int x, int y) when x < 0 -> System.out.println("B, negative x"); 178 | case B(int x, int y) -> System.out.println("B"); 179 | //case null -> System.out.println("Null"); 180 | default -> System.out.println("Any of the previous options"); 181 | } 182 | ``` 183 | 184 | - [when And null In Pattern Matching](https://nipafx.dev/inside-java-newscast-24/) 185 | 186 | ## [JEP 405](https://openjdk.java.net/jeps/405): Record Patterns (Preview) 187 | 188 | ```java 189 | sealed interface S permits A, B {} 190 | record A(int x, int y) implements S {} 191 | record B(int x, int y) implements S {} 192 | 193 | S o = new A(0, 0); 194 | 195 | //JEP 394, java 16 196 | if (o instanceof A a) { 197 | System.out.println(a.x() + a.y()); 198 | } 199 | 200 | if (o instanceof A(int x, int y)) { 201 | System.out.println(x + y); 202 | } 203 | 204 | ``` 205 | 206 | ## [JEP 422](https://openjdk.java.net/jeps/422): Linux/RISC-V Port 207 | 208 | ## [JEP 424](https://openjdk.java.net/jeps/424): Foreign Function & Memory API (Preview) 209 | 210 | ## [JEP 426](https://openjdk.java.net/jeps/426): Vector API (Fourth Incubator) 211 | 212 | ## Resources 213 | 214 | - 215 | - 216 | - 217 | - [Java 19 - The Best Java Release? - Inside Java Newscast #27](https://www.youtube.com/watch?v=UG9nViGZCEw) 218 | 219 | -------------------------------------------------------------------------------- /java20/Notes.md: -------------------------------------------------------------------------------- 1 | # Java 20 2 | 3 | - 4 | - 5 | - 6 | 7 | ## Install Java 20 8 | 9 | ```sh 10 | sdk install java 20.ea.36-open 11 | sdk use java 20.ea.36-open 12 | jshell --enable-preview --add-modules jdk.incubator.concurrent --enable-native-access=ALL-UNNAMED 13 | ``` 14 | 15 | ## New features 16 | 17 | ## [JEP 433](https://openjdk.java.net/jeps/433): Pattern Matching for switch (Fourth Preview) 18 | 19 | - An exhaustive switch (i.e., a switch expression or a pattern switch 20 | statement) over an enum class now throws MatchException rather than 21 | IncompatibleClassChangeError if no switch label applies at run time. 22 | - The grammar for switch labels is simpler. 23 | - Inference of type arguments for generic record patterns is now supported in 24 | switch expressions and statements, along with the other constructs that 25 | support patterns. 26 | 27 | ```java 28 | 29 | sealed interface S permits A, B, C {} // Java 17, JEP 409 30 | final class A implements S {} 31 | final class B implements S {} 32 | record C(int i) implements S {} // Implicitly final 33 | 34 | static int testSealedExhaustive(S s) { 35 | return switch (s) { 36 | case A a -> 1; 37 | case B b -> 2; 38 | case C c -> 3; 39 | }; 40 | } 41 | ``` 42 | 43 | ```java 44 | enum Color { RED, GREEN, BLUE; } 45 | var c = Color.RED; 46 | var result = switch(c) { 47 | case RED -> 0; 48 | case GREEN -> 1; 49 | case BLUE -> 2; 50 | } 51 | ``` 52 | 53 | ```java 54 | 55 | sealed interface S permits A, B {} 56 | record A(int x, int y) implements S {} 57 | record B(int x, int y) implements S {} 58 | 59 | S o = new A(0, 0); 60 | 61 | switch (o) { 62 | case A(int x, int y) when x >= 10 -> System.out.println("A, positive x"); 63 | case A(int x, int y) when x < 0 -> System.out.println("B, negative x"); 64 | case B(int x, int y) -> System.out.println("B"); 65 | //default -> System.out.println("Any of the previous options"); 66 | } 67 | ``` 68 | 69 | ## [JEP 432](https://openjdk.java.net/jeps/432): Record Patterns (Second Preview) 70 | 71 | - Add support for inference of type arguments of generic record patterns, 72 | - Add support for record patterns to appear in the header of an enhanced for 73 | statement, and 74 | - Remove support for named record patterns. 75 | 76 | ```java 77 | sealed interface S permits A{} 78 | record A(int x, int y) implements S {} 79 | 80 | // Java 19 81 | S o = new A(0, 0); 82 | 83 | if (o instanceof A(int x, int y)) { 84 | System.out.println(x + y); 85 | } 86 | 87 | // Java 20 88 | A[] as = new A[]{new A(0,0), new A(1,1)} 89 | for (A(var x, var y): as) { 90 | System.out.println(x+y); 91 | } 92 | 93 | ``` 94 | 95 | ## [JEP 436](https://openjdk.java.net/jeps/436): Virtual Threads (Second Preview) 96 | 97 | - Minor changes since the first preview. 98 | 99 | ```java 100 | Thread.ofPlatform().start(() -> System.out.println(Thread.currentThread())); 101 | Thread.ofVirtual().start(() -> System.out.println(Thread.currentThread())); 102 | ``` 103 | 104 | ## [JEP 437](https://openjdk.java.net/jeps/437): Structured Concurrency (Second Incubator) 105 | 106 | - No changes since the first preview. 107 | 108 | ```java 109 | String getUser() throws InterruptedException { 110 | Thread.sleep(3_000); 111 | return "Anton"; 112 | }; 113 | 114 | Integer getOrder() throws InterruptedException { 115 | Thread.sleep(2_000); 116 | // return 10; 117 | return 10/0; 118 | }; 119 | 120 | String theUser = getUser(); 121 | int theOrder = getOrder(); 122 | System.out.println(theUser + ": " + theOrder); 123 | ``` 124 | 125 | ```java 126 | import jdk.incubator.concurrent.StructuredTaskScope; 127 | 128 | try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { 129 | Future user = scope.fork(() -> getUser()); 130 | Future order = scope.fork(() -> getOrder()); 131 | 132 | scope.join(); // Join both forks 133 | scope.throwIfFailed(); // ... and propagate errors 134 | 135 | // Here, both forks have succeeded, so compose their results 136 | System.out.println(user.resultNow() + ": " + order.resultNow()); 137 | } 138 | ``` 139 | 140 | - [Java Asynchronous Programming Full Tutorial with Loom and Structured Concurrency - JEP Café #13](https://inside.java/2022/08/02/jepcafe13/) 141 | - [Project Loom Brings Structured Concurrency - Inside Java Newscast #17](https://www.youtube.com/watch?v=2J2tJm_iwk0) 142 | 143 | ## [JEP 429](https://openjdk.java.net/jeps/429): Scoped Values (Incubator) 144 | 145 | ```java 146 | final static ThreadLocal TL = new ThreadLocal<>(); 147 | TL.set("Hello"); 148 | TL.get(); 149 | Thread.ofVirtual().start(() -> System.out.println(TL.get())); 150 | Thread.ofPlatform().start(() -> System.out.println(TL.get())); 151 | 152 | final static InheritableThreadLocal TL = new InheritableThreadLocal<>(); 153 | TL.set("Hello"); 154 | TL.get(); 155 | Thread.ofVirtual().start(() -> System.out.println(TL.get())); 156 | Thread.ofPlatform().start(() -> System.out.println(TL.get())); 157 | 158 | Thread.ofVirtual().start(() -> { 159 | TL.set("Hello from virtual"); 160 | System.out.println(TL.get());}) 161 | 162 | TL.get(); 163 | ``` 164 | 165 | Design flaws with ThreadLocal: 166 | 167 | - Unconstrained mutability: variable's get() and set() methods can be called at 168 | any time. 169 | - Unbounded lifetime: developers often forget to call ThreadLocal.remove(). 170 | - Expensive inheritance: the overhead of thread-local variables when utilizing 171 | a large number of threads. 172 | 173 | ```java 174 | import jdk.incubator.concurrent.ScopedValue 175 | static final ScopedValue sv = ScopedValue.newInstance(); 176 | ScopedValue.where(sv, "anton", () -> System.out.println(sv.get())); 177 | ``` 178 | 179 | Advantages of Scoped Values: 180 | 181 | - They are only valid during the lifetime of the Runnable passed to the where 182 | method. 183 | - A scoped value is immutable - it can only be reset for a new scope by 184 | rebinding. 185 | - The child threads created by StructuredTaskScope have access to the scoped 186 | value of the parent thread. 187 | 188 | ```java 189 | import jdk.incubator.concurrent.StructuredTaskScope; 190 | 191 | class Example { 192 | 193 | public static final ScopedValue SV = ScopedValue.newInstance(); 194 | 195 | static String getUser() { 196 | try { 197 | Thread.sleep(3_000); 198 | } catch (InterruptedException e) {} 199 | return SV.get(); 200 | }; 201 | 202 | static Integer getOrder() { 203 | try { 204 | Thread.sleep(2_000); 205 | } catch (InterruptedException e) {} 206 | return 1; 207 | }; 208 | 209 | static void printMessage() { 210 | try { 211 | try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { 212 | Future user = scope.fork(() -> getUser()); 213 | Future order = scope.fork(() -> getOrder()); 214 | 215 | scope.join(); 216 | scope.throwIfFailed(); 217 | 218 | System.out.println(user.resultNow() + ": " + order.resultNow()); 219 | } 220 | } catch (Exception e) {} 221 | } 222 | } 223 | 224 | ScopedValue.where(Example.SV, "anton").run(() -> Example.printMessage()) 225 | ``` 226 | 227 | Rebinding Scoped Values: 228 | 229 | ```java 230 | class Example { 231 | 232 | public static final ScopedValue SV = ScopedValue.newInstance(); 233 | 234 | static String getUser() { 235 | try { 236 | Thread.sleep(3_000); 237 | } catch (InterruptedException e) {} 238 | 239 | // Rebinding the scoped value: 240 | ScopedValue.where(Example.SV, "Non Anton").run(() -> System.out.println(Example.SV.get())); 241 | return SV.get(); 242 | }; 243 | 244 | static Integer getOrder() { 245 | try { 246 | Thread.sleep(2_000); 247 | } catch (InterruptedException e) {} 248 | return 1; 249 | }; 250 | 251 | static void printMessage() { 252 | try { 253 | try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { 254 | Future user = scope.fork(() -> getUser()); 255 | Future order = scope.fork(() -> getOrder()); 256 | 257 | scope.join(); 258 | scope.throwIfFailed(); 259 | 260 | System.out.println(user.resultNow() + ": " + order.resultNow()); 261 | } 262 | } catch (Exception e) {} 263 | } 264 | } 265 | 266 | ScopedValue.where(Example.SV, "anton"). run(() -> Example.printMessage()) 267 | ``` 268 | 269 | - [Java API](https://download.java.net/java/early_access/loom/docs/api/jdk.incubator.concurrent/jdk/incubator/concurrent/ScopedValue.html) 270 | - [JEP Cafe - Java 20 - From ThreadLocal to ScopedValue with Loom Full Tutorial](https://www.youtube.com/watch?v=fjvGzBFmyhM) 271 | - [JEP 429: Extent-Local Variables to Promote Immutability in Java](https://www.infoq.com/news/2022/09/extent-local-variables-java/) 272 | - [Scoped values in Java](https://www.happycoders.eu/java/scoped-values/) 273 | 274 | ## [JEP 434](https://openjdk.java.net/jeps/434): Foreign Function & Memory API (Second Preview) 275 | 276 | ```java 277 | import java.lang.foreign.*; 278 | import java.lang.invoke.MethodHandle; 279 | import static java.lang.foreign.ValueLayout.ADDRESS; 280 | import static java.lang.foreign.ValueLayout.JAVA_LONG; 281 | 282 | public long getStringLength(String content) throws Throwable { 283 | // 1. Get a lookup object for commonly used libraries 284 | SymbolLookup stdlib = Linker.nativeLinker().defaultLookup(); 285 | 286 | // 2. Get a handle on the strlen function in the C standard library 287 | MethodHandle strlen = Linker.nativeLinker().downcallHandle( 288 | stdlib.find("strlen").orElseThrow(), 289 | FunctionDescriptor.of(JAVA_LONG, ADDRESS)); 290 | 291 | long len = 0; 292 | 293 | // 3. Convert Java String to C string and store it in off-heap memory 294 | try (Arena offHeap = Arena.openConfined()) { 295 | MemorySegment str = offHeap.allocateUtf8String(content); 296 | 297 | // 4. Invoke the foreign function 298 | len = (long) strlen.invoke(str); 299 | } 300 | // 5. Off-heap memory is deallocated at the end of try-with-resources 301 | // 6. Return the length. 302 | return len; 303 | } 304 | 305 | getStringLength("Java 20 demo!") 306 | 307 | ``` 308 | 309 | - [Java 20 sneak peek](https://blogs.oracle.com/post/java-20-preview) 310 | - [Java 20: Colossal Sparse Memory Segments](https://minborgsjavapot.blogspot.com/2023/01/java-20-colossal-sparse-memory-segments.html) 311 | - [Java 20: An Almost Infinite Memory Segment Allocator](https://minborgsjavapot.blogspot.com/2023/01/java-20-almost-infinite-memory-segment.html) 312 | 313 | ## [JEP 438](https://openjdk.java.net/jeps/438): Vector API (Fifth Incubator) 314 | 315 | Small set of bug fixes and performance enhancements 316 | 317 | ## Resources 318 | 319 | - 320 | - 321 | - 322 | -------------------------------------------------------------------------------- /java21/Notes.md: -------------------------------------------------------------------------------- 1 | # Java 21 2 | 3 | - 4 | - 5 | - 6 | 7 | ## Install Java 21 8 | 9 | ```sh 10 | sdk install java 21.ea.35-open 11 | sdk use java 21.ea.35-open 12 | jshell --enable-preview --enable-native-access=ALL-UNNAMED 13 | ``` 14 | 15 | ## New features 16 | 17 | ## [JEP 444](https://openjdk.java.net/jeps/444): Virtual Threads 18 | ## [JEP 453](https://openjdk.java.net/jeps/453): Structured Concurrency (Preview) 19 | ## [JEP 446](https://openjdk.java.net/jeps/446): Scoped Values (Preview) 20 | 21 | Already covered in Java 20. 22 | 23 | ```java 24 | Thread.ofPlatform().start(() -> System.out.println(Thread.currentThread())); 25 | Thread.ofVirtual().start(() -> System.out.println(Thread.currentThread())); 26 | ``` 27 | 28 | > The only significant change is that the StructuredTaskScope::fork(...) method returns a [Subtask] rather than a Future 29 | 30 | ## [JEP 441](https://openjdk.java.net/jeps/441): Pattern Matching for switch 31 | ## [JEP 440](https://openjdk.java.net/jeps/440): Record Patterns 32 | 33 | Already covered in Java 20 (and before) 34 | 35 | ```java 36 | 37 | sealed interface S permits A {} 38 | record A(int x, int y) implements S {} 39 | 40 | S o = new A(0, 1); 41 | 42 | switch (o) { 43 | case A(int x, int y) when x >= 10 -> x; 44 | case A(int x, int y) when x <= 0 -> y; 45 | default -> -1; 46 | } 47 | ``` 48 | 49 | ## [JEP 443](https://openjdk.java.net/jeps/443): Unnamed Patterns and Variables (Preview) 50 | 51 | ```java 52 | 53 | sealed interface S permits A{} 54 | record A(int x, int y) implements S {} 55 | 56 | S o = new A(0, 1); 57 | 58 | if (o instanceof A(int x, int y)) { 59 | System.out.println(x + y); 60 | } 61 | 62 | if (o instanceof A(int x, _)) {System.out.println(x);} 63 | 64 | A[] as = new A[]{new A(0,0), new A(1,1)} 65 | 66 | for (A a: as) { 67 | System.out.println(a.x()+a.y()); 68 | } 69 | 70 | for (A _: as) {System.out.println("Hello");} 71 | 72 | try { 73 | int i = Integer.parseInt("a"); 74 | } catch (NumberFormatException e) { 75 | System.out.println("Bad number"); 76 | } 77 | 78 | try { int i = Integer.parseInt("a");} catch (NumberFormatException _) { System.out.println("Bad number");} 79 | ``` 80 | 81 | ## [JEP 445](https://openjdk.java.net/jeps/445): Unnamed Classes and Instance Main Methods (Preview) 82 | 83 | ```java 84 | public class HelloWorld { 85 | public static void main(String[] args) { 86 | System.out.println("Hello world!"); 87 | } 88 | } 89 | ``` 90 | 91 | ```java 92 | void main() { 93 | System.out.println("Hello world!"); 94 | } 95 | ``` 96 | 97 | ```sh 98 | javac -source 21 --enable-preview hello.java 99 | java --enable-preview hello 100 | rm hello.class 101 | 102 | java --source 21 --enable-preview hello.java 103 | ``` 104 | 105 | ## [JEP 430](https://openjdk.java.net/jeps/430): String Templates (Preview) 106 | 107 | See https://openjdk.org/jeps/430 108 | 109 | ```java 110 | int x = 10, y = 2; 111 | String s = STR."\{x} + \{y} = \{x + y}"; 112 | 113 | String str = "\{x} + \{y} = \{x + y}"; 114 | 115 | import static java.lang.StringTemplate.RAW 116 | StringTemplate str = RAW."\{x} + \{y} = \{x + y}"; 117 | String info = STR.process(str); 118 | 119 | import static java.util.FormatProcessor.FMT; 120 | String s = FMT."%03d\{x} + %03d\{y} = %03d\{x + y}"; 121 | 122 | ``` 123 | 124 | - STR, FMT, and RAW are static instances of the default JDK provided 125 | StringFormatters which return String instances 126 | - Slash for backward compability 127 | 128 | > ResultSet rs = DB."SELECT * FROM Person p WHERE p.last_name = \{name}"; 129 | 130 | ## [JEP 431](https://openjdk.java.net/jeps/431): Sequenced Collections 131 | 132 | ```java 133 | interface SequencedCollection extends Collection { 134 | // new method 135 | SequencedCollection reversed(); 136 | // methods promoted from Deque 137 | void addFirst(E); 138 | void addLast(E); 139 | E getFirst(); 140 | E getLast(); 141 | E removeFirst(); 142 | E removeLast(); 143 | } 144 | ``` 145 | 146 | ```java 147 | var list = List.of(1,2,3,4) 148 | 149 | list.get(0) 150 | list.getFirst() 151 | 152 | list.get(list.size() - 1) 153 | list.getLast() 154 | 155 | list.reversed() 156 | 157 | IntStream.rangeClosed(1, list.size()).forEach(i -> System.out.println("Value: " + list.get(list.size() - i))) 158 | list.reversed().forEach(i -> System.out.println("Value: " + i)) 159 | ``` 160 | 161 | ```java 162 | var map = Map.of("key1", "value1", "key2", "value2"); 163 | 164 | map.firstEntry() 165 | 166 | var map = new LinkedHashMap<>(); 167 | map.put( "key1", "value1" ); 168 | map.put( "key2", "value2" ); 169 | 170 | map 171 | map.firstEntry() 172 | map 173 | map.pollFirstEntry() 174 | map 175 | ``` 176 | 177 | ## [JEP 439](https://openjdk.java.net/jeps/439): Generational ZGC 178 | 179 | > ZGC (JEP 333) is designed for low latency and high scalability. 180 | > It has been available for production use since JDK 15 (JEP 377). 181 | 182 | > Improve application performance by extending the Z Garbage Collector (ZGC) to 183 | > maintain separate generations for young and old objects. This will allow ZGC 184 | > to collect young objects - which tend to die young - more frequently. 185 | 186 | ## [JEP 442](https://openjdk.java.net/jeps/442): Foreign Function & Memory API (Third Preview) 187 | ## [JEP 448](https://openjdk.java.net/jeps/448): Vector API (Sixth Incubator) 188 | 189 | Already covered in Java 20 (or before) 190 | 191 | ## [JEP 449](https://openjdk.java.net/jeps/449): Deprecate the Windows 32-bit x86 Port for Removal 192 | ## [JEP 451](https://openjdk.java.net/jeps/451): Prepare to Disallow the Dynamic Loading of Agents 193 | ## [JEP 452](https://openjdk.java.net/jeps/452): Key Encapsulation Mechanism API 194 | 195 | ## Resources 196 | 197 | - [Java 21: sneak peek](https://blogs.oracle.com/javamagazine/post/java-21-sneak-peek) 198 | - 199 | - 200 | - 201 | -------------------------------------------------------------------------------- /java21/hello.java: -------------------------------------------------------------------------------- 1 | void main() { 2 | System.out.println("Hello world!"); 3 | } 4 | -------------------------------------------------------------------------------- /java22/Greetings.java: -------------------------------------------------------------------------------- 1 | public class Greetings { 2 | public static String greet(String name) { 3 | return "Hello %s!%n".formatted(name); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /java22/Hello.java: -------------------------------------------------------------------------------- 1 | void main() { 2 | System.out.println(Greetings.greet("Anton")); 3 | } 4 | -------------------------------------------------------------------------------- /java22/Notes.md: -------------------------------------------------------------------------------- 1 | # Java 22 2 | 3 | - 4 | - 5 | - 6 | 7 | ## Install Java 22 8 | 9 | ```sh 10 | sdk install java 22.ea.36-open 11 | sdk use java 22.ea.36-open 12 | jshell --enable-preview --enable-native-access=ALL-UNNAMED 13 | ``` 14 | 15 | ## New features 16 | 17 | ## [JEP 456](https://openjdk.java.net/jeps/456): Unnamed Variables & Patterns 18 | 19 | In preview in Java 21, finalized in Java 22. 20 | 21 | ```java 22 | try { 23 | int number = Integer.parseInt("a"); 24 | } catch (NumberFormatException e) { 25 | System.err.println("Not a number"); 26 | } 27 | 28 | try { 29 | int number = Integer.parseInt("a"); 30 | } catch (NumberFormatException _) { 31 | System.err.println("Not a number"); 32 | } 33 | ``` 34 | 35 | ```java 36 | Map map = new HashMap<>(); 37 | map.put("John", 5); 38 | map.forEach((_, x) -> System.out.println(x)) 39 | ``` 40 | 41 | ## [JEP 447](https://openjdk.java.net/jeps/447): Statements before super(...) (Preview) 42 | 43 | ```java 44 | 45 | public class Rectangle { 46 | String color; 47 | double width; 48 | double length; 49 | 50 | public Rectangle(String color, double width, double lenght) { 51 | color = color; 52 | width = width; 53 | length = length; 54 | } 55 | }; 56 | 57 | public class Square extends Rectangle { 58 | public Square(String color, int area) { 59 | this(color, Math.sqrt(validateArea(area))); 60 | } 61 | 62 | private static int validateArea(int area) { 63 | if (area < 0) throw new IllegalArgumentException(); 64 | return area; 65 | } 66 | 67 | private Square(String color, double sideLength) { 68 | super(color, sideLength, sideLength); 69 | } 70 | } 71 | 72 | public class Square extends Rectangle { 73 | public Square(String color, int area) { 74 | if (area < 0) throw new IllegalArgumentException(); 75 | double sideLength = Math.sqrt(area); 76 | super(color, sideLength, sideLength); 77 | } 78 | } 79 | 80 | ``` 81 | 82 | ## [JEP 461](https://openjdk.java.net/jeps/461): Stream Gatherers (Preview) 83 | 84 | https://download.java.net/java/early_access/jdk23/docs/api/java.base/java/util/stream/Gatherers.html 85 | 86 | ```java 87 | Stream.of(1,2,3,4,5,6,7,8).gather(Gatherers.windowFixed(3)).toList(); 88 | 89 | Stream.of(1,2,3,4,5,6,7,8).gather(Gatherers.windowSliding(2)).toList(); 90 | 91 | Stream.of(1,2,3,4,5,6,7,8).gather(Gatherers.windowSliding(6)).toList(); 92 | 93 | Stream.of(1,2,3,4,5,6,7,8,9).gather( 94 | Gatherers.fold(() -> "", (string, number) -> string + number) 95 | ).findFirst(); 96 | 97 | Stream.of(1,2,3,4,5,6,7,8,9). 98 | gather( 99 | Gatherers.scan(() -> "", (string, number) -> string + number) 100 | ).toList(); 101 | 102 | Stream.of("a","b","c","d","e","f","g","h","i"). 103 | gather( 104 | Gatherers.mapConcurrent(10, s -> s.toUpperCase(Locale.ROOT)) 105 | ).toList(); 106 | 107 | ``` 108 | 109 | ## [JEP 458](https://openjdk.java.net/jeps/458): Launch Multi-File Source-Code Programs 110 | ## [JEP 463](https://openjdk.java.net/jeps/463): Implicitly Declared Classes and Instance Main Methods (Second Preview) 111 | 112 | ```sh 113 | java --enable-preview --source 22 Hello.java Anton 114 | ``` 115 | 116 | ## [JEP 454](https://openjdk.java.net/jeps/454): Foreign Function & Memory API 117 | 118 | JNI -> Joylessly Navigating the Inferno 119 | 120 | > Project Panama finalization after a total of eight incubator and preview versions 121 | 122 | ```java 123 | import java.lang.foreign.Linker; 124 | import java.lang.foreign.SymbolLookup; 125 | import java.lang.foreign.FunctionDescriptor; 126 | import java.lang.foreign.ValueLayout; 127 | import java.lang.foreign.MemorySegment; 128 | import java.lang.foreign.Arena; 129 | import java.lang.invoke.MethodHandle; 130 | 131 | SymbolLookup stdlib = Linker.nativeLinker().defaultLookup(); 132 | 133 | MethodHandle strlen = Linker.nativeLinker().downcallHandle( 134 | stdlib.find("strlen").orElseThrow(),FunctionDescriptor.of( 135 | ValueLayout.JAVA_LONG, ValueLayout.ADDRESS)); 136 | 137 | try (Arena offHeap = Arena.ofConfined()) { 138 | MemorySegment str = offHeap.allocateFrom("Happy Coding!"); 139 | long len = (long) strlen.invoke(str); 140 | System.out.println("len = " + len); 141 | } 142 | 143 | ``` 144 | 145 | ## [JEP 457](https://openjdk.java.net/jeps/457): Class-File API (Preview) 146 | 147 | > The new API is intended to replace the bytecode manipulation framework ASM, 148 | > which is used intensively in the JDK. 149 | 150 | ## [JEP 423](https://openjdk.java.net/jeps/423): Region Pinning for G1 151 | 152 | JNI related. Avoid unnecesary pauses. 153 | 154 | ## [JEP 459](https://openjdk.java.net/jeps/459): String Templates (Second Preview) 155 | 156 | Already covered in Java 21 session. 157 | 158 | ## [JEP 464](https://openjdk.java.net/jeps/464): Scoped Values (Second Preview) 159 | ## [JEP 462](https://openjdk.java.net/jeps/462): Structured Concurrency (Second Preview) 160 | 161 | Already covered in Java 20 session. 162 | 163 | ## [JEP 460](https://openjdk.java.net/jeps/460): Vector API (Seventh Incubator) 164 | 165 | Already covered in Java 18 session. 166 | 167 | ## Resources 168 | 169 | - [Java 22 with examples](https://www.happycoders.eu/java/java-22-features/) 170 | - [Hello, Java 22!](https://spring.io/blog/2024/03/19/hello-java-22) 171 | - 172 | - 173 | - 174 | -------------------------------------------------------------------------------- /java23/Notes.md: -------------------------------------------------------------------------------- 1 | # Java 23 2 | 3 | - 4 | - 5 | - 6 | 7 | ## Install Java 23 8 | 9 | ```sh 10 | sdk install java 22.ea.36-open 11 | sdk use java 22.ea.36-open 12 | jshell --enable-preview --enable-native-access=ALL-UNNAMED 13 | ``` 14 | 15 | ## New features 16 | 17 | ## [JEP 456](https://openjdk.java.net/jeps/456): Unnamed Variables & Patterns 18 | 19 | In preview in Java 21, finalized in Java 22. 20 | 21 | ```java 22 | try { 23 | int number = Integer.parseInt("a"); 24 | } catch (NumberFormatException e) { 25 | System.err.println("Not a number"); 26 | } 27 | 28 | try { 29 | int number = Integer.parseInt("a"); 30 | } catch (NumberFormatException _) { 31 | System.err.println("Not a number"); 32 | } 33 | ``` 34 | 35 | ```java 36 | Map map = new HashMap<>(); 37 | map.put("John", 5); 38 | map.forEach((_, x) -> System.out.println(x)) 39 | ``` 40 | 41 | ## [JEP 447](https://openjdk.java.net/jeps/447): Statements before super(...) (Preview) 42 | 43 | ```java 44 | 45 | public class Rectangle { 46 | String color; 47 | double width; 48 | double length; 49 | 50 | public Rectangle(String color, double width, double lenght) { 51 | color = color; 52 | width = width; 53 | length = length; 54 | } 55 | }; 56 | 57 | public class Square extends Rectangle { 58 | public Square(String color, int area) { 59 | this(color, Math.sqrt(validateArea(area))); 60 | } 61 | 62 | private static int validateArea(int area) { 63 | if (area < 0) throw new IllegalArgumentException(); 64 | return area; 65 | } 66 | 67 | private Square(String color, double sideLength) { 68 | super(color, sideLength, sideLength); 69 | } 70 | } 71 | 72 | public class Square extends Rectangle { 73 | public Square(String color, int area) { 74 | if (area < 0) throw new IllegalArgumentException(); 75 | double sideLength = Math.sqrt(area); 76 | super(color, sideLength, sideLength); 77 | } 78 | } 79 | 80 | ``` 81 | 82 | ## [JEP 461](https://openjdk.java.net/jeps/461): Stream Gatherers (Preview) 83 | 84 | https://download.java.net/java/early_access/jdk23/docs/api/java.base/java/util/stream/Gatherers.html 85 | 86 | ```java 87 | Stream.of(1,2,3,4,5,6,7,8).gather(Gatherers.windowFixed(3)).toList(); 88 | 89 | Stream.of(1,2,3,4,5,6,7,8).gather(Gatherers.windowSliding(2)).toList(); 90 | 91 | Stream.of(1,2,3,4,5,6,7,8).gather(Gatherers.windowSliding(6)).toList(); 92 | 93 | Stream.of(1,2,3,4,5,6,7,8,9).gather( 94 | Gatherers.fold(() -> "", (string, number) -> string + number) 95 | ).findFirst(); 96 | 97 | Stream.of(1,2,3,4,5,6,7,8,9). 98 | gather( 99 | Gatherers.scan(() -> "", (string, number) -> string + number) 100 | ).toList(); 101 | 102 | Stream.of("a","b","c","d","e","f","g","h","i"). 103 | gather( 104 | Gatherers.mapConcurrent(10, s -> s.toUpperCase(Locale.ROOT)) 105 | ).toList(); 106 | 107 | ``` 108 | 109 | ## [JEP 458](https://openjdk.java.net/jeps/458): Launch Multi-File Source-Code Programs 110 | ## [JEP 463](https://openjdk.java.net/jeps/463): Implicitly Declared Classes and Instance Main Methods (Second Preview) 111 | 112 | ```sh 113 | java --enable-preview --source 22 Hello.java Anton 114 | ``` 115 | 116 | ## [JEP 454](https://openjdk.java.net/jeps/454): Foreign Function & Memory API 117 | 118 | JNI -> Joylessly Navigating the Inferno 119 | 120 | > Project Panama finalization after a total of eight incubator and preview versions 121 | 122 | ```java 123 | import java.lang.foreign.Linker; 124 | import java.lang.foreign.SymbolLookup; 125 | import java.lang.foreign.FunctionDescriptor; 126 | import java.lang.foreign.ValueLayout; 127 | import java.lang.foreign.MemorySegment; 128 | import java.lang.foreign.Arena; 129 | import java.lang.invoke.MethodHandle; 130 | 131 | SymbolLookup stdlib = Linker.nativeLinker().defaultLookup(); 132 | 133 | MethodHandle strlen = Linker.nativeLinker().downcallHandle( 134 | stdlib.find("strlen").orElseThrow(),FunctionDescriptor.of( 135 | ValueLayout.JAVA_LONG, ValueLayout.ADDRESS)); 136 | 137 | try (Arena offHeap = Arena.ofConfined()) { 138 | MemorySegment str = offHeap.allocateFrom("Happy Coding!"); 139 | long len = (long) strlen.invoke(str); 140 | System.out.println("len = " + len); 141 | } 142 | 143 | ``` 144 | 145 | ## [JEP 457](https://openjdk.java.net/jeps/457): Class-File API (Preview) 146 | 147 | > The new API is intended to replace the bytecode manipulation framework ASM, 148 | > which is used intensively in the JDK. 149 | 150 | ## [JEP 423](https://openjdk.java.net/jeps/423): Region Pinning for G1 151 | 152 | JNI related. Avoid unnecesary pauses. 153 | 154 | ## [JEP 459](https://openjdk.java.net/jeps/459): String Templates (Second Preview) 155 | 156 | Already covered in Java 21 session. 157 | 158 | ## [JEP 464](https://openjdk.java.net/jeps/464): Scoped Values (Second Preview) 159 | ## [JEP 462](https://openjdk.java.net/jeps/462): Structured Concurrency (Second Preview) 160 | 161 | Already covered in Java 20 session. 162 | 163 | ## [JEP 460](https://openjdk.java.net/jeps/460): Vector API (Seventh Incubator) 164 | 165 | Already covered in Java 18 session. 166 | 167 | ## Resources 168 | 169 | - [Java 22 with examples](https://www.happycoders.eu/java/java-22-features/) 170 | - [Hello, Java 22!](https://spring.io/blog/2024/03/19/hello-java-22) 171 | - 172 | - 173 | - 174 | -------------------------------------------------------------------------------- /javaagent/Notes.md: -------------------------------------------------------------------------------- 1 | jbang --javaagent $(pwd)/newrelic/newrelic.jar hello.java 2 | 3 | https://docs.newrelic.com/docs/apm/agents/java-agent/installation/install-java-agent/ 4 | -------------------------------------------------------------------------------- /javaagent/hello.java: -------------------------------------------------------------------------------- 1 | ///usr/bin/env jbang "$0" "$@" ; exit $? 2 | //DEPS info.picocli:picocli:4.5.0 3 | 4 | 5 | import picocli.CommandLine; 6 | import picocli.CommandLine.Command; 7 | import picocli.CommandLine.Parameters; 8 | 9 | import java.util.concurrent.Callable; 10 | 11 | @Command(name = "hello", mixinStandardHelpOptions = true, version = "hello 0.1", 12 | description = "hello made with jbang") 13 | class hello implements Callable { 14 | 15 | @Parameters(index = "0", description = "The greeting to print", defaultValue = "World!") 16 | private String greeting; 17 | 18 | public static void main(String... args) { 19 | int exitCode = new CommandLine(new hello()).execute(args); 20 | System.exit(exitCode); 21 | } 22 | 23 | @Override 24 | public Integer call() throws Exception { // your business logic goes here... 25 | while (true) { 26 | try { 27 | System.out.println("Hello " + greeting); 28 | Thread.sleep(1000); 29 | } catch (InterruptedException e) { 30 | System.out.println("InterruptedException Exception" + e.getMessage()); 31 | return 0; 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /key-value-stores/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # Linux start script should use lf 5 | /gradlew text eol=lf 6 | 7 | # These are Windows script files and should use crlf 8 | *.bat text eol=crlf 9 | 10 | # Binary files should be left untouched 11 | *.jar binary 12 | 13 | -------------------------------------------------------------------------------- /key-value-stores/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | -------------------------------------------------------------------------------- /key-value-stores/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This generated file contains a sample Java application project to get you started. 5 | * For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.12/userguide/building_java_projects.html in the Gradle documentation. 6 | */ 7 | 8 | plugins { 9 | // Apply the application plugin to add support for building a CLI application in Java. 10 | id 'application' 11 | } 12 | 13 | repositories { 14 | // Use Maven Central for resolving dependencies. 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | 20 | implementation 'org.mapdb:mapdb:3.0.10' 21 | implementation 'org.rocksdb:rocksdbjni:8.5.3' 22 | implementation 'com.ververica:forstjni:0.1.4-beta' 23 | 24 | // Use JUnit test framework. 25 | testImplementation libs.junit 26 | 27 | // This dependency is used by the application. 28 | implementation libs.guava 29 | } 30 | 31 | // Apply a specific Java toolchain to ease working on different environments. 32 | java { 33 | toolchain { 34 | languageVersion = JavaLanguageVersion.of(21) 35 | } 36 | } 37 | 38 | application { 39 | // Define the main class for the application. 40 | mainClass = 'org.example.App' 41 | } 42 | -------------------------------------------------------------------------------- /key-value-stores/app/src/main/java/org/example/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file was generated by the Gradle 'init' task 3 | */ 4 | package org.example; 5 | 6 | public class App { 7 | public String getGreeting() { 8 | return "Hello World!"; 9 | } 10 | 11 | public static void main(String[] args) { 12 | System.out.println(new App().getGreeting()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /key-value-stores/app/src/main/java/org/example/IOUtils.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import java.io.File; 4 | 5 | public class IOUtils { 6 | 7 | public static long getDirectorySize(File directory) { 8 | long size = 0; 9 | if (directory.isDirectory()) { 10 | for (File file : directory.listFiles()) { 11 | if (file.isFile()) { 12 | size += file.length(); 13 | } else { 14 | size += getDirectorySize(file); 15 | } 16 | } 17 | } 18 | return size; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /key-value-stores/app/src/main/java/org/example/StringUtils.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import java.security.SecureRandom; 4 | 5 | public class StringUtils { 6 | 7 | private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 8 | private static final SecureRandom RANDOM = new SecureRandom(); 9 | 10 | public static String generate_random_string(int length) { 11 | StringBuilder sb = new StringBuilder(length); 12 | for (int i = 0; i < length; i++) { 13 | sb.append(CHARACTERS.charAt(RANDOM.nextInt(CHARACTERS.length()))); 14 | } 15 | return sb.toString(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /key-value-stores/app/src/test/java/org/example/AppTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file was generated by the Gradle 'init' task 3 | */ 4 | package org.example; 5 | 6 | import org.junit.Test; 7 | import static org.junit.Assert.*; 8 | 9 | public class AppTest { 10 | @Test public void appHasAGreeting() { 11 | App classUnderTest = new App(); 12 | assertNotNull("app should have a greeting", classUnderTest.getGreeting()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /key-value-stores/app/src/test/java/org/example/ForStDBTest.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import org.junit.Test; 4 | import org.forstdb.OptimisticTransactionDB; 5 | import org.forstdb.Options; 6 | import org.forstdb.ReadOptions; 7 | import org.forstdb.RocksDBException; 8 | import org.forstdb.Transaction; 9 | import org.forstdb.WriteOptions; 10 | 11 | import java.io.File; 12 | 13 | import static java.nio.charset.StandardCharsets.UTF_8; 14 | 15 | // compile test classes from Maven by running: mvn test-compile 16 | public class ForStDBTest { 17 | static final String dbPath = "/tmp/fortstsdb_10m_test"; 18 | static OptimisticTransactionDB txnDb; 19 | static WriteOptions writeOptions; 20 | static ReadOptions readOptions; 21 | static Options options; 22 | 23 | @Test 24 | public void test1() throws RocksDBException { 25 | int N = 10_000; 26 | System.out.print("opening DB\n"); 27 | openDB(); 28 | measureDBSize(); 29 | System.out.printf("inserting %d records\n", N); 30 | putRecords(N); 31 | measureDBSize(); 32 | System.out.print("closing DB\n"); 33 | closeDB(); 34 | measureDBSize(); 35 | 36 | System.out.print("opening DB\n"); 37 | openDB(); 38 | measureDBSize(); 39 | System.out.printf("inserting %d records\n", 1); 40 | putRecords(1); 41 | measureDBSize(); 42 | System.out.print("closing DB\n"); 43 | closeDB(); 44 | measureDBSize(); 45 | } 46 | 47 | private void measureDBSize() { 48 | var size = IOUtils.getDirectorySize(new File(dbPath)); 49 | System.out.printf("DB Size = %d bytes\n", size); 50 | } 51 | 52 | private void openDB() throws RocksDBException, org.forstdb.RocksDBException { 53 | long start = System.currentTimeMillis(); 54 | options = new Options().setCreateIfMissing(true); 55 | txnDb = OptimisticTransactionDB.open(options, dbPath); 56 | writeOptions = new WriteOptions(); 57 | readOptions = new ReadOptions(); 58 | long end = System.currentTimeMillis(); 59 | long duration = end - start; 60 | System.out.printf("Time: %d ms\n", duration); 61 | } 62 | 63 | private void putRecords(int count) throws RocksDBException { 64 | long start = System.currentTimeMillis(); 65 | try (final Transaction txn = txnDb.beginTransaction(writeOptions)) { 66 | for (var i = 0; i < count; i++) { 67 | var key = StringUtils.generate_random_string(16); 68 | var value = StringUtils.generate_random_string(100); 69 | txn.put(key.getBytes(UTF_8), value.getBytes(UTF_8)); 70 | } 71 | // Commit transaction - this is when data gets persisted to the DB 72 | txn.commit(); 73 | } 74 | long end = System.currentTimeMillis(); 75 | long duration = end - start; 76 | System.out.printf("Time: %d ms\n", duration); 77 | } 78 | 79 | private void closeDB() { 80 | long start = System.currentTimeMillis(); 81 | writeOptions.close(); 82 | readOptions.close(); 83 | txnDb.close(); 84 | options.close(); 85 | long end = System.currentTimeMillis(); 86 | long duration = end - start; 87 | System.out.printf("Time: %d ms\n", duration); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /key-value-stores/app/src/test/java/org/example/MapDBTest.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import org.junit.Test; 4 | import org.mapdb.DB; 5 | import org.mapdb.DBMaker; 6 | import org.mapdb.Serializer; 7 | 8 | import java.io.File; 9 | import java.util.concurrent.ConcurrentMap; 10 | 11 | /** 12 | * mvn test -Dtest=com.mycompany.app.MapDbTest3 13 | * output: 14 | */ 15 | public class MapDBTest { 16 | 17 | private static final String dbPath = "/tmp/mapdb"; 18 | private static final String dbFilename = "/tmp/mapdb/file.db"; 19 | private static final int TRANSACTION_SIZE = 100_000; 20 | private static DB db; 21 | private static ConcurrentMap map; 22 | 23 | public static void openDB() { 24 | long start = System.currentTimeMillis(); 25 | db = DBMaker 26 | .fileDB(dbFilename) 27 | .transactionEnable() 28 | .fileMmapEnable() 29 | .make(); 30 | 31 | // it also has a ConcurrentNavigableMap that is backed by a treeMap 32 | // https://jankotek.gitbooks.io/mapdb/content/db/ 33 | map = db.hashMap("my map", Serializer.STRING, Serializer.STRING) // you can also do db.treeMap to get a map backed by tree data structure instead of hashtable 34 | .createOrOpen(); 35 | 36 | long end = System.currentTimeMillis(); 37 | long duration = end - start; 38 | System.out.printf("Time: %d ms\n", duration); 39 | } 40 | 41 | @Test 42 | // https://gist.github.com/siddhsql/7d22b837001c910ac2dfe62b044ebaeb 43 | public void test1() { 44 | 45 | int N = 10_000_000; 46 | 47 | openDB(); 48 | measureDBSize(); 49 | insertDB(N); 50 | measureDBSize(); 51 | closeDB(); 52 | measureDBSize(); 53 | 54 | openDB(); 55 | measureDBSize(); 56 | insertDB(1); 57 | measureDBSize(); 58 | closeDB(); 59 | measureDBSize(); 60 | } 61 | 62 | private void measureDBSize() { 63 | var size = IOUtils.getDirectorySize(new File(dbPath)); 64 | System.out.printf("DB Size = %d bytes\n", size); 65 | } 66 | 67 | private void insertDB(int N) { 68 | // insert 10 million entries 69 | long start = System.currentTimeMillis(); 70 | 71 | for (var i = 0; i < N; i++) { 72 | if (i != 0 && i % 300_000 == 0) { 73 | System.out.printf("now at %d of %d\n", i, N); 74 | } 75 | String id = StringUtils.generate_random_string(16); 76 | String text = StringUtils.generate_random_string(100); 77 | map.put(id, text); 78 | if (i != 0 && i % TRANSACTION_SIZE == 0) { 79 | System.out.printf("commiting %d records ", TRANSACTION_SIZE); 80 | db.commit(); 81 | } 82 | } 83 | long end = System.currentTimeMillis(); 84 | long duration = end - start; 85 | System.out.printf("%d insert operations took %d ms\n", N, duration); 86 | System.out.printf("applying final commit\n"); 87 | db.commit(); 88 | } 89 | 90 | private void closeDB() { 91 | var start = System.currentTimeMillis(); 92 | db.close(); 93 | var end = System.currentTimeMillis(); 94 | var duration = end - start; 95 | System.out.printf("closing the db took %d ms\n", duration); 96 | } 97 | } -------------------------------------------------------------------------------- /key-value-stores/app/src/test/java/org/example/RockDBTest.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | import org.junit.Test; 4 | import org.rocksdb.OptimisticTransactionDB; 5 | import org.rocksdb.Options; 6 | import org.rocksdb.ReadOptions; 7 | import org.rocksdb.RocksDBException; 8 | import org.rocksdb.Transaction; 9 | import org.rocksdb.WriteOptions; 10 | 11 | import java.io.File; 12 | 13 | import static java.nio.charset.StandardCharsets.UTF_8; 14 | 15 | // compile test classes from Maven by running: mvn test-compile 16 | public class RockDBTest { 17 | static final String dbPath = "/tmp/rocksdb_10m_test"; 18 | static OptimisticTransactionDB txnDb; 19 | static WriteOptions writeOptions; 20 | static ReadOptions readOptions; 21 | static Options options; 22 | 23 | @Test 24 | public void test1() throws RocksDBException { 25 | int N = 10_000; 26 | System.out.print("opening DB\n"); 27 | openDB(); 28 | measureDBSize(); 29 | System.out.printf("inserting %d records\n", N); 30 | putRecords(N); 31 | measureDBSize(); 32 | System.out.print("closing DB\n"); 33 | closeDB(); 34 | measureDBSize(); 35 | 36 | System.out.print("opening DB\n"); 37 | openDB(); 38 | measureDBSize(); 39 | System.out.printf("inserting %d records\n", 1); 40 | putRecords(1); 41 | measureDBSize(); 42 | System.out.print("closing DB\n"); 43 | closeDB(); 44 | measureDBSize(); 45 | } 46 | 47 | private void measureDBSize() { 48 | var size = IOUtils.getDirectorySize(new File(dbPath)); 49 | System.out.printf("DB Size = %d bytes\n", size); 50 | } 51 | 52 | private void openDB() throws RocksDBException { 53 | long start = System.currentTimeMillis(); 54 | options = new Options().setCreateIfMissing(true); 55 | txnDb = OptimisticTransactionDB.open(options, dbPath); 56 | writeOptions = new WriteOptions(); 57 | readOptions = new ReadOptions(); 58 | long end = System.currentTimeMillis(); 59 | long duration = end - start; 60 | System.out.printf("Time: %d ms\n", duration); 61 | } 62 | 63 | private void putRecords(int count) throws RocksDBException { 64 | long start = System.currentTimeMillis(); 65 | try (final Transaction txn = txnDb.beginTransaction(writeOptions)) { 66 | for (var i = 0; i < count; i++) { 67 | var key = StringUtils.generate_random_string(16); 68 | var value = StringUtils.generate_random_string(100); 69 | txn.put(key.getBytes(UTF_8), value.getBytes(UTF_8)); 70 | } 71 | // Commit transaction - this is when data gets persisted to the DB 72 | txn.commit(); 73 | } 74 | long end = System.currentTimeMillis(); 75 | long duration = end - start; 76 | System.out.printf("Time: %d ms\n", duration); 77 | } 78 | 79 | private void closeDB() { 80 | long start = System.currentTimeMillis(); 81 | writeOptions.close(); 82 | readOptions.close(); 83 | txnDb.close(); 84 | options.close(); 85 | long end = System.currentTimeMillis(); 86 | long duration = end - start; 87 | System.out.printf("Time: %d ms\n", duration); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /key-value-stores/gradle.properties: -------------------------------------------------------------------------------- 1 | # This file was generated by the Gradle 'init' task. 2 | # https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties 3 | 4 | org.gradle.configuration-cache=true 5 | 6 | -------------------------------------------------------------------------------- /key-value-stores/gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | # This file was generated by the Gradle 'init' task. 2 | # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format 3 | 4 | [versions] 5 | guava = "33.3.1-jre" 6 | junit = "4.13.2" 7 | 8 | [libraries] 9 | guava = { module = "com.google.guava:guava", version.ref = "guava" } 10 | junit = { module = "junit:junit", version.ref = "junit" } 11 | -------------------------------------------------------------------------------- /key-value-stores/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /key-value-stores/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | org.gradle.wrapper.GradleWrapperMain \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /key-value-stores/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /key-value-stores/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.12/userguide/multi_project_builds.html in the Gradle documentation. 6 | */ 7 | 8 | plugins { 9 | // Apply the foojay-resolver plugin to allow automatic download of JDKs 10 | id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' 11 | } 12 | 13 | rootProject.name = 'key-value-stores' 14 | include('app') 15 | -------------------------------------------------------------------------------- /regex/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This generated file contains a sample Java application project to get you started. 5 | * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle 6 | * User Manual available at https://docs.gradle.org/7.0/userguide/building_java_projects.html 7 | */ 8 | 9 | plugins { 10 | // Apply the groovy plugin to also add support for Groovy (needed for Spock) 11 | id 'groovy' 12 | 13 | // Apply the application plugin to add support for building a CLI application in Java. 14 | id 'application' 15 | } 16 | 17 | repositories { 18 | // Use Maven Central for resolving dependencies. 19 | mavenCentral() 20 | mavenLocal() 21 | } 22 | 23 | dependencies { 24 | // Use the latest Groovy version for Spock testing 25 | testImplementation 'org.codehaus.groovy:groovy:3.0.7' 26 | 27 | // Use the awesome Spock testing and specification framework even with Java 28 | testImplementation 'org.spockframework:spock-core:2.0-M4-groovy-3.0' 29 | testImplementation 'junit:junit:4.13.1' 30 | 31 | // This dependency is used by the application. 32 | implementation 'com.google.guava:guava:30.0-jre' 33 | 34 | // RegexApp 35 | implementation 'org.apache.ant:ant-apache-regexp:1.10.10' 36 | implementation 'com.google.re2j:re2j:1.6' 37 | implementation 'com.gliwka.hyperscan:hyperscan:5.4.0-2.0.0' 38 | 39 | // Memory Size 40 | implementation 'org.openjdk.jol:jol-core:0.15' 41 | implementation 'org.ehcache:sizeof:0.4.0' 42 | implementation 'com.github.jbellis:jamm:0.4.0' 43 | 44 | // Note: 45 | /** 46 | Download from https://github.com/piotr-yuxuan/jamm/packages/415322 47 | mvn install:install-file -Dfile=jamm-0.4.0.jar \ 48 | -DgroupId=com.github.jbellis \ 49 | -DartifactId=jamm \ 50 | -Dversion=0.4.0 \ 51 | -Dpackaging=jar \ 52 | -DgeneratePom=true 53 | */ 54 | } 55 | 56 | application { 57 | // Define the main class for the application. 58 | mainClass = 'com.galiglobal.java.playground.App' 59 | } 60 | 61 | tasks.named('test') { 62 | // Use junit platform for unit tests. 63 | useJUnitPlatform() 64 | } 65 | -------------------------------------------------------------------------------- /regex/app/src/main/java/com/galiglobal/java/playground/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This Java source file was generated by the Gradle 'init' task. 3 | */ 4 | package com.galiglobal.java.playground; 5 | 6 | public class App { 7 | public String getGreeting() { 8 | return "Hello World!"; 9 | } 10 | 11 | public static void main(String[] args) { 12 | System.out.println(new App().getGreeting()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /regex/app/src/main/java/com/galiglobal/java/playground/regex/Hyperscale.java: -------------------------------------------------------------------------------- 1 | package com.galiglobal.java.playground.regex; 2 | 3 | import com.gliwka.hyperscan.util.PatternFilter; 4 | import com.gliwka.hyperscan.wrapper.CompileErrorException; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.regex.Matcher; 9 | import java.util.regex.Pattern; 10 | 11 | public class Hyperscale { 12 | 13 | public static void main(String[] args) throws CompileErrorException { 14 | List patterns = Arrays.asList( 15 | Pattern.compile("The number is ([0-9]+)", Pattern.CASE_INSENSITIVE), 16 | Pattern.compile("The color is (blue|red|orange)") 17 | //, Pattern.compile("^[\\w\\-]+(\\.[\\w\\-]+)*@[\\w\\-]+(\\.[\\w\\-]+)*(\\.)[a-zA-Z]+$"), 18 | , Pattern.compile("(?s)^(\\.\\*\\??)?(.*)") // It doesn't work well -> null 19 | ); 20 | 21 | //not thread-safe, create per thread 22 | PatternFilter filter = new PatternFilter(patterns); 23 | 24 | //this list now only contains the probably matching patterns, in this case the first one 25 | //List matchers = filter.filter("The number is 7 the NUMber is 27"); 26 | List matchers = filter.filter("email@email.com"); 27 | 28 | //now we use the regular java regex api to check for matches - this is not hyperscan specific 29 | for (Matcher matcher : matchers) { 30 | while (matcher.find()) { 31 | // will print 7 and 27 32 | System.out.println(matcher.group(1)); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /regex/app/src/main/java/com/galiglobal/java/playground/regex/RegexApp.java: -------------------------------------------------------------------------------- 1 | package com.galiglobal.java.playground.regex; 2 | 3 | import com.gliwka.hyperscan.util.PatternFilter; 4 | import org.apache.regexp.RE; 5 | import org.ehcache.sizeof.SizeOf; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.Random; 10 | import java.util.regex.Pattern; 11 | import java.util.stream.Collectors; 12 | 13 | public class RegexApp { 14 | 15 | private static long totalHyperscan = 0; 16 | private static long totalApacheRegex = 0; 17 | private static long totalUtil = 0; 18 | private static long totalUtilComp = 0; 19 | private static long totalRe2 = 0; 20 | private static long totalRe2Comp = 0; 21 | 22 | public static void main(String[] args) throws Exception { 23 | 24 | // DISCLAIMER 25 | // This is a quick and dirty benchmark. Use JMH for better results 26 | // Results: https://excalidraw.com/#json=5109261076004864,b8cy0HOxaAn587sKrDhz6Q 27 | 28 | SizeOf sizeOf = SizeOf.newInstance(); 29 | 30 | //long totalRecords = 10_000_000; 31 | long totalRecords = 100_000; 32 | 33 | Random random = new Random(); 34 | var randoms = random 35 | .longs(totalRecords, 10, 1000000000) 36 | .mapToObj(String::valueOf) 37 | .collect(Collectors.toList()); 38 | 39 | var regexps = Arrays.asList( 40 | "^[\\w\\-]+(\\.[\\w\\-]+)*@[\\w\\-]+(\\.[\\w\\-]+)*(\\.)[a-zA-Z]+$", // Email 41 | "(?s)^(\\.\\*\\??)?(.*)", // Bomb! 42 | "([0-9]{4})-?(1[0-2]|0[1-9])-?(3[01]|0[1-9]|[12][0-9])", // Date 43 | "[\\w\\.]+@[\\w\\.]+", // Email 2 44 | "([0-9]{3})-([0-9]{3})-([0-9]{4})", // Phone 2 45 | "($+((((($+((a+a*)+(b+c))*)((cc)(b+b))+a)+((b+c*)+(c+c)))+a)+(c*a+($+(c+c)b))))+c", // Random 46 | "[0-8][0-9]{2}-[0-9]{2}-[0-9]{4}", // Social 47 | "A[ZLRK]|C[TAO]|D[CE]|FL|GA|HI|I[ALND]|K[SY]|LA|M[ADEINOST]|" 48 | + "N[HCDEJMVY]|O[HKR]|PA|RI|S[CD]|T[XN]|UT|V[AT]|W[VAIY]" // States 49 | ); 50 | 51 | //***************************************************************/ 52 | // Hyperscan: https://github.com/gliwka/hyperscan-java / 53 | //***************************************************************/ 54 | 55 | List patterns = regexps.stream().map(Pattern::compile).collect(Collectors.toList()); 56 | 57 | //not thread-safe, create per thread 58 | final PatternFilter filter = new PatternFilter(patterns); 59 | 60 | long startTimeHyperScale = System.nanoTime(); 61 | randoms.forEach( 62 | r -> filter.filter(r).forEach(m -> { 63 | if (m.find()) totalHyperscan++; 64 | }) 65 | ); 66 | 67 | long elapsedTimeHyperScale = System.nanoTime() - startTimeHyperScale; 68 | long hyperscaleShallowSize = sizeOf.sizeOf(filter); 69 | long hyperscaleDeepSize = sizeOf.deepSizeOf(filter); 70 | 71 | System.out.println("> hyperscan shallow size is: " + hyperscaleShallowSize); 72 | System.out.println("> hyperscan deep size is: " + hyperscaleDeepSize); 73 | System.out.println("> Hyperscale found " + totalHyperscan + " in " + elapsedTimeHyperScale / 1000000 + " ms."); 74 | 75 | //***************************************************************/ 76 | // Apache Regex / 77 | //***************************************************************/ 78 | 79 | List res = regexps.stream().map(r -> { 80 | try { 81 | return new RE(r); 82 | } catch (Exception e) { 83 | System.out.println("Apache Regex: 1 exception compiling one model"); 84 | return new RE("a"); 85 | } 86 | } 87 | ).collect(Collectors.toList()); 88 | 89 | long startApacheRegex = System.nanoTime(); 90 | randoms.forEach( 91 | r -> res.forEach(re -> { 92 | if (re.match(r)) totalApacheRegex++; 93 | }) 94 | ); 95 | 96 | long elapsedApacheRegex = System.nanoTime() - startApacheRegex; 97 | long apacheRegexShallowSize = sizeOf.sizeOf(res); 98 | long apacheRegexDeepSize = sizeOf.deepSizeOf(res); 99 | 100 | System.out.println("> Apache Regex shallow size is: " + apacheRegexShallowSize); 101 | System.out.println("> Apache Regex deep size is: " + apacheRegexDeepSize); 102 | System.out.println("> Apache Regex found " + totalApacheRegex + " in " + elapsedApacheRegex / 1000000 + " ms."); 103 | 104 | //***************************************************************/ 105 | // java.util.regex without previous compilation / 106 | //***************************************************************/ 107 | 108 | long startUtil = System.nanoTime(); 109 | randoms.forEach( 110 | r -> regexps.forEach(regexp -> { 111 | if (Pattern.matches(regexp, r)) totalUtil++; 112 | }) 113 | ); 114 | 115 | long elapsedUtil = System.nanoTime() - startUtil; 116 | long utilShallowSize = sizeOf.sizeOf(regexps); 117 | long utilDeepSize = sizeOf.deepSizeOf(regexps); 118 | 119 | System.out.println("> java.util.regex without compilation shallow size is: " + utilShallowSize); 120 | System.out.println("> java.util.regex without compilation deep size is: " + utilDeepSize); 121 | System.out.println("> java.util.regex without compilation found " + totalUtil + " in " + elapsedUtil / 1000000 + " ms."); 122 | 123 | //***************************************************************/ 124 | // java.util.regex with previous compilation / 125 | //***************************************************************/ 126 | 127 | long startUtilComp = System.nanoTime(); 128 | randoms.forEach( 129 | r -> patterns.forEach(pu -> { 130 | if (pu.matcher(r).find()) totalUtilComp++; 131 | }) 132 | ); 133 | 134 | long elapsedUtilComp = System.nanoTime() - startUtilComp; 135 | // Note: we can't create patterns again, the JVM will optimize to use the same object... 136 | long utilCompShallowSize = hyperscaleShallowSize; 137 | long utilCompDeepSize = hyperscaleDeepSize; 138 | 139 | System.out.println("> java.util.regex with compilation shallow size is: " + utilCompShallowSize); 140 | System.out.println("> java.util.regex with compilation deep size is: " + utilCompDeepSize); 141 | System.out.println("> java.util.regex with compilation found " + totalUtilComp + " in " + elapsedUtilComp / 1000000 + " ms."); 142 | 143 | //***************************************************************/ 144 | // Google Re2 without compilation / 145 | //***************************************************************/ 146 | 147 | //long totalRe2j = randoms.stream().filter(v -> com.google.re2j.Pattern.matches(regexp, v)).count(); 148 | 149 | long startRe2 = System.nanoTime(); 150 | randoms.forEach( 151 | r -> regexps.forEach(regexp -> { 152 | if (com.google.re2j.Pattern.matches(regexp, r)) totalRe2++; 153 | }) 154 | ); 155 | 156 | long elapsedRe2 = System.nanoTime() - startRe2; 157 | // Note: avoid JVM optimizations 158 | long re2ShallowSize = utilShallowSize; 159 | long re2DeepSize = utilShallowSize; 160 | 161 | System.out.println("> Google Re2 without compilation shallow size is: " + re2ShallowSize); 162 | System.out.println("> Google Re2 without compilation deep size is: " + re2DeepSize); 163 | System.out.println("> Google Re2 without compilation found " + totalRe2 + " in " + elapsedRe2 / 1000000 + " ms."); 164 | 165 | 166 | //***************************************************************/ 167 | // Google Re2 with previous compilation / 168 | //***************************************************************/ 169 | 170 | List patternsRe2 = regexps.stream().map(com.google.re2j.Pattern::compile).collect(Collectors.toList()); 171 | 172 | long startRe2Comp = System.nanoTime(); 173 | randoms.forEach( 174 | r -> patternsRe2.forEach(pu -> { 175 | if (pu.matcher(r).find()) totalRe2Comp++; 176 | }) 177 | ); 178 | 179 | long elapsedRe2Comp = System.nanoTime() - startRe2Comp; 180 | // Todo: is the JVM reusing part of patterns? 181 | long re2CompShallowSize = sizeOf.sizeOf(patternsRe2); 182 | long re2CompDeepSize = sizeOf.deepSizeOf(patternsRe2); 183 | 184 | System.out.println("> Google Re2 with compilation shallow size is: " + re2CompShallowSize); 185 | System.out.println("> Google Re2 with compilation deep size is: " + re2CompDeepSize); 186 | System.out.println("> Google Re2 with compilation found " + totalRe2Comp + " in " + elapsedRe2Comp / 1000000 + " ms."); 187 | 188 | //***************************************************************/ 189 | // Print CSVs / 190 | //***************************************************************/ 191 | 192 | System.out.println("--------------------"); 193 | System.out.println("RegexEngine,ShallowSize " + regexps.stream().count() + " regex (bytes)"); 194 | System.out.println("Hyperscale," + hyperscaleShallowSize); 195 | System.out.println("ApacheRegex," + apacheRegexShallowSize); 196 | System.out.println("util," + utilShallowSize); 197 | System.out.println("util comp," + utilCompShallowSize); 198 | System.out.println("Re2," + re2ShallowSize); 199 | System.out.println("Re2Comp," + re2CompShallowSize); 200 | System.out.println("--------------------"); 201 | System.out.println("RegexEngine,DeepSize " + regexps.stream().count() + " regex (bytes)"); 202 | System.out.println("Hyperscale," + hyperscaleDeepSize); 203 | System.out.println("ApacheRegex," + apacheRegexDeepSize); 204 | System.out.println("util," + utilDeepSize); 205 | System.out.println("utilComp," + utilCompDeepSize); 206 | System.out.println("Re2," + re2DeepSize); 207 | System.out.println("Re2Comp," + re2CompDeepSize); 208 | System.out.println("--------------------"); 209 | System.out.println("RegexEngine,TotalTime for " + totalRecords + " strings (ms)"); 210 | System.out.println("Hyperscale," + elapsedTimeHyperScale); 211 | System.out.println("ApacheRegex," + elapsedApacheRegex); 212 | System.out.println("util," + elapsedUtil); 213 | System.out.println("utilComp," + elapsedUtilComp); 214 | System.out.println("Re2," + elapsedRe2); 215 | System.out.println("Re2Comp," + elapsedRe2Comp); 216 | } 217 | } 218 | 219 | /** 220 | * Different ways to measure size: 221 | *

    222 | * System.out.println("> Google Re2j compiled found " + totalRe2jCompiled + " in " + elapsedTime5 / 1000000 + " ms."); 223 | * System.out.println("> Jol: regex string shallow size is: " + VM.current().sizeOf(regexp)); 224 | * System.out.println("> Jol: java.util.regex.Pattern shallow size is: " + VM.current().sizeOf(pattern)); 225 | * System.out.println("> Jol: com.google.re2j.Pattern shallow size is: " + VM.current().sizeOf(re2jPattern)); 226 | * SizeOf sizeOf = SizeOf.newInstance(); 227 | * System.out.println("> ehcache: regex string shallow size is: " + sizeOf.sizeOf(regexp)); 228 | * System.out.println("> ehcache: java.util.regex.Pattern shallow size is: " + sizeOf.sizeOf(pattern)); 229 | * System.out.println("> ehcache: com.google.re2j.Pattern shallow size is: " + sizeOf.sizeOf(re2jPattern)); 230 | * System.out.println("> ehcache: java.util.regex.Pattern deep size is: " + sizeOf.deepSizeOf(pattern)); 231 | * System.out.println("> ehcache: com.google.re2j.Pattern deep size is: " + sizeOf.deepSizeOf(re2jPattern)); 232 | * MemoryMeter meter = MemoryMeter.builder().build(); 233 | * System.out.println("> jamm: regex string shallow size is: " + meter.measure(regexp)); 234 | * System.out.println("> jamm: java.util.regex.Pattern shallow size is: " + meter.measure(pattern)); 235 | * System.out.println("> jamm: com.google.re2j.Pattern shallow size is: " + meter.measure(re2jPattern)); 236 | * System.out.println("> jamm: java.util.regex.Pattern deep size is: " + meter.measureDeep(pattern)); 237 | * System.out.println("> jamm: com.google.re2j.Pattern deep size is: " + meter.measureDeep(re2jPattern)); 238 | */ 239 | -------------------------------------------------------------------------------- /regex/app/src/test/groovy/com/galiglobal/java/playground/AppTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * This Spock specification was generated by the Gradle 'init' task. 3 | */ 4 | package com.galiglobal.java.playground 5 | 6 | import spock.lang.Specification 7 | 8 | class AppTest extends Specification { 9 | def "application has a greeting"() { 10 | setup: 11 | def app = new App() 12 | 13 | when: 14 | def result = app.greeting 15 | 16 | then: 17 | result != null 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /regex/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /regex/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /regex/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /regex/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.0/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'java-playground' 11 | include('app') 12 | --------------------------------------------------------------------------------