Last active
August 29, 2015 14:21
-
-
Save maxov/723ff9b5e158cc86c18c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// data api | |
Optional<DisplayNameData> wrappedDisplayName = entity.getData(DisplayNameData.class); | |
if (wrappedDisplayName.isPresent()) { | |
DisplayNameData displayname = wrappedDisplayName.get(); | |
displayname.setDisplayName(Texts.of(displayName.get(), "hai!")); | |
entity.offer(displayname); | |
} | |
// 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