Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skozlov/jadt
Basic ADT interfaces for Java
https://github.com/skozlov/jadt
adt java java8
Last synced: about 1 month ago
JSON representation
Basic ADT interfaces for Java
- Host: GitHub
- URL: https://github.com/skozlov/jadt
- Owner: skozlov
- License: apache-2.0
- Created: 2019-02-02T14:02:44.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-06T16:59:03.000Z (almost 6 years ago)
- Last Synced: 2024-10-13T15:41:32.917Z (3 months ago)
- Topics: adt, java, java8
- Language: Java
- Homepage: https://skozlov.github.io/jadt/
- Size: 53.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jADT
Basic ADT interfaces for Java.
## Usage
Add maven dependency:
```xml
com.github.skozlov
jadt
0.1.0```
Then implement your ADT:
```java
package com.github.skozlov.jadt.demo;import com.github.skozlov.jadt.ADT2;
abstract class Person implements ADT2 {
private Person(){}@Override
public Class getSubtype1() {
return Bro.class;
}@Override
public Class getSubtype2() {
return NotBro.class;
}static final class Bro extends Person{
final String name;Bro(String name) {
this.name = name;
}}
static final class NotBro extends Person{
}
}
```Enjoy using it:
```java
package com.github.skozlov.jadt.demo;public class Main {
public static void main(String[] args) {
sayHello(new Person.Bro("John"));// prints "Hi John!"
sayHello(new Person.NotBro());//prints "You're not my bro."
}private static void sayHello(Person person){
person.forEach(
bro -> {
System.out.printf("Hi %s!", bro.name);
System.out.println();
},
notBro -> System.out.println("You're not my bro.")
);
}
}
```