Skip to content

Commit d48c6e4

Browse files
authored
Merge pull request #35 from ccxt/java-new
feat: add Java lang
2 parents 383ffd8 + 0c9e8ca commit d48c6e4

38 files changed

+5966
-28
lines changed

helpers/java/helpers.java

Lines changed: 746 additions & 0 deletions
Large diffs are not rendered by default.

java-demo/.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+

java-demo/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build

java-demo/app/build.gradle.kts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
application
11+
}
12+
13+
repositories {
14+
// Use Maven Central for resolving dependencies.
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
// Use JUnit Jupiter for testing.
20+
testImplementation(libs.junit.jupiter)
21+
22+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
23+
24+
// This dependency is used by the application.
25+
implementation(libs.guava)
26+
}
27+
28+
// Apply a specific Java toolchain to ease working on different environments.
29+
java {
30+
toolchain {
31+
languageVersion = JavaLanguageVersion.of(21)
32+
}
33+
}
34+
35+
application {
36+
// Define the main class for the application.
37+
mainClass = "org.example.App"
38+
}
39+
40+
tasks.named<Test>("test") {
41+
// Use JUnit Platform for unit tests.
42+
useJUnitPlatform()
43+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* This source file was generated by the Gradle 'init' task
3+
*/
4+
package org.example;
5+
6+
import java.util.concurrent.CompletableFuture;
7+
8+
9+
public class App {
10+
11+
public String a = "a";
12+
public String b = "b";
13+
public boolean c = false;
14+
15+
public void aa()
16+
{
17+
var a = 1;
18+
Object b = 2;
19+
System.out.println("HEREEEE::" + a);
20+
var data = new java.util.HashMap<String, Object>() {{
21+
put( "1", 1 );
22+
put( "2", 2 );
23+
}};
24+
var lista = new java.util.ArrayList<Object>(java.util.Arrays.asList(1, 3, 4, "5"));
25+
Helpers.GetValue(data, "1");
26+
Aux.fix();
27+
// System.out.println(a);
28+
// System.out.println(data["1"]);
29+
// System.out.println(lista[2]);
30+
// for (var i = 0; isLessThan(i, getArrayLength(lista)); i++)
31+
// {
32+
// System.out.println(lista[i]);
33+
// }
34+
}
35+
36+
public void test() {
37+
System.out.println("test");
38+
}
39+
40+
public void retryingTask(int... retries) {
41+
int n = (retries.length == 0) ? 3 : retries[0]; // default = 3
42+
System.out.println("n: " + n);
43+
// ...
44+
}
45+
46+
public String getGreeting() {
47+
var i = 1;
48+
i += 1;
49+
var a = "aaa";
50+
a += "bbb";
51+
// var c = new HashMap<String, String>();
52+
return "Hello World222!" + String.valueOf(i) + a;
53+
}
54+
55+
public CompletableFuture<Object> testAsync() {
56+
return CompletableFuture.supplyAsync(() -> {
57+
try {
58+
Thread.sleep(1000); // Simulate a delay
59+
throw new RuntimeException("Simulated exception");
60+
} catch (InterruptedException e) {
61+
Thread.currentThread().interrupt();
62+
}
63+
return "Async Result";
64+
});
65+
}
66+
67+
public void teste()
68+
{
69+
Object aaa = (this.fWithParams(3)).join();
70+
System.out.println(aaa);
71+
var c = this.fWithParams(5);
72+
}
73+
74+
public java.util.concurrent.CompletableFuture<Object> fWithParams(Object a)
75+
{
76+
return java.util.concurrent.CompletableFuture.supplyAsync(() -> {
77+
return 42;
78+
});
79+
80+
}
81+
82+
public java.util.concurrent.CompletableFuture teste(Object a)
83+
{
84+
return java.util.concurrent.CompletableFuture.supplyAsync(() -> {
85+
System.out.println(a);
86+
throw new Error("test") ;
87+
});
88+
89+
}
90+
91+
public Object getVar(Object v) {
92+
return v;
93+
}
94+
95+
public void teste33(String a)
96+
{
97+
var x = 1;
98+
x = 2;
99+
Object newObj = new java.util.HashMap<String, Object>() {{
100+
put( "a", App.this.getVar(x) );
101+
put( "a", a );
102+
// put( "b", this.getValue(this.getValue(this.getValue(2))) );
103+
}};
104+
throw new Error("test") ;
105+
}
106+
107+
public java.util.concurrent.CompletableFuture<Object> fetchData(Object input3)
108+
{
109+
final Object input2 = input3;
110+
return java.util.concurrent.CompletableFuture.supplyAsync(() -> {
111+
Object input = input2;
112+
input = 3;
113+
return Helpers.add(input, 2);
114+
});
115+
116+
}
117+
118+
public java.util.concurrent.CompletableFuture<Object> fetchData(Object input2, Object... optionalArgs)
119+
{
120+
final Object input3 = input2;
121+
return java.util.concurrent.CompletableFuture.supplyAsync(() -> {
122+
Object input = input3;
123+
System.out.println(input);
124+
return null;
125+
});
126+
127+
}
128+
129+
public static void main(String[] args) {
130+
// this.retryingTask();
131+
132+
var base = 3;
133+
System.out.println(new App().getGreeting());
134+
var app = new App();
135+
app.teste33("example");
136+
// app.retryingTask();
137+
try {
138+
var res = app.testAsync().join();
139+
System.out.println("res: " + res);
140+
} catch (Exception e) {
141+
System.out.println("Error: " + e.getMessage());
142+
}
143+
144+
// System.out.println(app.getGreeting());
145+
// app.test();
146+
// app.aa();
147+
// for (var i = 0; i < 5; ((int) i)++) {
148+
// System.out.println("i: " + i);
149+
// }
150+
}
151+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.example;
2+
3+
public class Aux {
4+
5+
public static void fix() {
6+
System.out.println("fix");
7+
}
8+
}

0 commit comments

Comments
 (0)