Skip to content

Commit

Permalink
Merge pull request #38 from hamnis/jdk17
Browse files Browse the repository at this point in the history
Use JDK 17 syntax
  • Loading branch information
hamnis authored Sep 13, 2024
2 parents 0440a33 + 3783f3c commit 8a583a7
Show file tree
Hide file tree
Showing 12 changed files with 972 additions and 925 deletions.
87 changes: 87 additions & 0 deletions ast/src/main/java/net/hamnaberg/json/Folder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package net.hamnaberg.json;

import java.util.function.Function;
import java.util.function.Supplier;

public interface Folder<A> {
A onNull();

A onBoolean(Json.JBoolean b);

A onNumber(Json.JNumber n);

A onString(Json.JString s);

A onArray(Json.JArray a);

A onObject(Json.JObject o);

default VoidFolder toVoid() {
var self = this;
return new VoidFolder() {
@Override
public void onNull() {
self.onNull();
}

@Override
public void onBoolean(Json.JBoolean b) {
self.onBoolean(b);
}

@Override
public void onNumber(Json.JNumber n) {
self.onNumber(n);
}

@Override
public void onString(Json.JString s) {
self.onString(s);
}

@Override
public void onArray(Json.JArray a) {
self.onArray(a);
}

@Override
public void onObject(Json.JObject o) {
self.onObject(o);
}
};
}

static <X> Folder<X> from(Function<Json.JString, X> fString, Function<Json.JBoolean, X> fBoolean, Function<Json.JNumber, X> fNumber, Function<Json.JObject, X> fObject, Function<Json.JArray, X> fArray, Supplier<X> fNull) {
return new Folder<>() {
@Override
public X onNull() {
return fNull.get();
}

@Override
public X onBoolean(Json.JBoolean b) {
return fBoolean.apply(b);
}

@Override
public X onNumber(Json.JNumber n) {
return fNumber.apply(n);
}

@Override
public X onString(Json.JString s) {
return fString.apply(s);
}

@Override
public X onArray(Json.JArray a) {
return fArray.apply(a);
}

@Override
public X onObject(Json.JObject o) {
return fObject.apply(o);
}
};
}
}
Loading

0 comments on commit 8a583a7

Please sign in to comment.