Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
// data api
Optional<DisplayNameData> wrappedDisplayName = entity.getData(DisplayNameData.class);
if (wrappedDisplayName.isPresent()) {
DisplayNameData displayname = wrappedDisplayName.get();
displayname.setDisplayName(Texts.of(displayName.get(), "hai!"));
// equivalent POJO
if (entity.displayName != null) {
entity.displayName = Texts.of(entity.displayName, "hai!");
// static imports
if (entity.supports(DISPLAY_NAME)) {
entity.set(DISPLAY_NAME, Texts.of(entity.tryGet(DISPLAY_NAME)), "hai!");
// value api
if (entity.supports(Values.DISPLAY_NAME)) {
entity.set(Values.DISPLAY_NAME, Texts.of(entity.tryGet(Values.DISPLAY_NAME)), "hai!");
// inverted value api fun!
if (Values.DISPLAY_NAME.supportedBy(entity)) {
Values.DISPLAY_NAME.set(entity, Texts.of(Values.DISPLAY_NAME.tryGet(entity), "hai!");
// bound data?
BoundValue<Text> displayName = entity.bind(Values.DISPLAY_NAME)
if (displayName.exists() {
displayName.set(Texts.of(displayName.get(entity)), "hai!");
// transforms?
Values.DISPLAY_NAME.transform(entity, new Function<Text, Text>() {
Text apply(Text input) {
return Texts.of(input, "hai!");
// j8
Values.DISPLAY_NAME.transform(entity, (Text input) -> Texts.of(input, "hai!"));
// there's still some verbosity in terms of doing Values.DISPLAY_NAME, but I don't think it's fixable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.