Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JDK 17 syntax #38

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading