com.uniscon:default-immutables
Default-Styles and Helper-Classes for common use cases of Immutables, a framework based on annotation processors to generate simple, safe and consistent value objects
Value style
After defining an immutable with data class style
@Value.Immutable
@ValueStyle
public interface _ExampleValue {
String getName();
int counter();
}
there is a builder
ExampleValue value = ExampleValue.builder()
.name("foo")
.counter(123)
.build();
which has a copy function in the builder:
ExampleValue otherValue = ExampleValue.builder()
.from(value)
.name("bar")
.build();
or a with
method
ExampleValue anotherValue = value.withName("baz");
Tuple style
After defining an immutable with tuple style
@Value.Immutable
@TupleStyle
public interface ExampleTuple {
String name();
int count();
static ImmutableExampleTuple of(String name, int count) {
return ImmutableExampleTuple.of(name, count);
}
}
there is a static constructor method
ExampleTuple tuple = ExampleTuple.of("foo", 123);
Typed Objects
Typed "primitives" can be easily defined:
@Value.Immutable
@Wrapped
public abstract class _ExampleTypedString extends Wrapper<String> {}
and used:
ExampleTypedString typedString = ExampleTypedString.of("foo");
value()
, .hashCode()
, .equals(<other>)
and .toString()
are already there.