-
Notifications
You must be signed in to change notification settings - Fork 0
Data
JonathanxD edited this page Jul 4, 2017
·
2 revisions
Simple maps (which does not extends Map
) of associated object keys to object values, Data classes also provides a set of utility methods. This was added to be used in CodeAPI processing system.
Examples:
Data data = new Data();
data.set("name", "Cup");
data.set("amount", 10);
int get = data.getOrSet("amount", 5);
Assert.assertEquals(5, get);
You can also use BaseData
instances to construct objects, example:
static class Product {
private final String name;
Product(String name) {
this.name = name;
}
}
public static class Stock {
private final Product product;
private final int amount;
public Stock(Product product, int amount) {
this.product = product;
this.amount = amount;
}
}
@Test
public void dataTest2() {
Data data = new Data();
data.set("product", new Product("Cup"));
data.set("amount", 10);
Stock construct = (Stock) DataReflect.construct(Stock.class, data);
Assert.assertEquals("Cup", construct.product.name);
Assert.assertEquals(10, construct.amount);
}
This is an implementation which stores value reified type. Values should be retrieved by key
and type
.