Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.")
);
}
}
```