Last active
August 29, 2015 14:13
-
-
Save maxov/7228ddb9730c3e7e9ec1 to your computer and use it in GitHub Desktop.
message computation
This file contains hidden or 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
| // All lists are immutable | |
| public ComputedMessage computeAll(@Nullable Message parent) { | |
| Message self = null; | |
| if (parent == null) { | |
| self = this; | |
| } else { | |
| self = Messages.compute(parent, self); | |
| } | |
| List<ComputedMessage> newChildren = new ArrayList<Message>(); | |
| for(Message message: getChildren()) { | |
| newChildren.add(message.computeAll(self)); | |
| } | |
| return new ComputedMessage(self, newChildren); | |
| } | |
| // compute Message{color = blue, children = [Message{}]} = ComputedMessage{color = blue, children = [ComputedMessage{color_computed=blue}] | |
| // Done so we can cache the original Message | |
| class ComputedMessage implements Message { | |
| private Message handle; | |
| private List<Message> children; | |
| public ComputedMessage(Message handle, List<Message> children) { | |
| this.handle = handle; | |
| } | |
| // also likely will have constructor if there is a parent message | |
| // this and other proxies | |
| public TextColor getColor() { | |
| return this.handle.getColor(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment