-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from hamnis/jdk17
Use JDK 17 syntax
- Loading branch information
Showing
12 changed files
with
972 additions
and
925 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.