-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(StartingInventory): Overhaul system; Improve documentation #13
Merged
Conversation
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
Simplify method signatures and and control flow.
- use an optional supplier to resolve an inventory item either as block or as item. - clean-up the dependency between `addToInventory` and `addNestedInventory` - add documentation for `resolveAsBlock` and `resolveAsItem`
skaldarnar
changed the title
refactor(StartingInventory): Overhaul system
refactor(StartingInventory): Overhaul system; Improve documentation
May 24, 2020
. add note about useful Java9 feature
…ead of the whole item object
skaldarnar
commented
May 24, 2020
Comment on lines
94
to
95
Optional<Supplier<EntityRef>> possibleItem = | ||
resolveAsBlock(item).map(Optional::of).orElseGet(() -> resolveAsItem(item)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this understandable? Should we change this? Here are some alternatives:
Suggested change
Optional<Supplier<EntityRef>> possibleItem = | |
resolveAsBlock(item).map(Optional::of).orElseGet(() -> resolveAsItem(item)); | |
Optional<Supplier<EntityRef>> possibleItem = resolveAsBlock(item); | |
if (!possibleItem.isPresent()) { | |
possibleItem = resolveAsItem(item); | |
} | |
if (!possibleItem.isPresent()) { | |
// use the item as it is present | |
} |
Suggested change
Optional<Supplier<EntityRef>> possibleItem = | |
resolveAsBlock(item).map(Optional::of).orElseGet(() -> resolveAsItem(item)); | |
final Supplier<EntityRef> possibleItem = | |
resolveAsBlock(item).orElse(resolveAsItem(item).orElse(null)); | |
if (possibleItem != null) { | |
// use the item as it is present | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Optional::or
(Java 9) mentioned in the comments this part would become:
final Optional<Supplier<EntityRef>> possibleItem =
resolveAsBlock(item.uri).or(() -> resolveAsItem(item.uri))
jdrueckert
approved these changes
May 25, 2020
This was referenced May 28, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PRs does an overhaul of the
StartingInventorySystem
to make it more concise. We are logging a few more warnings in case something is off, and also have more documentation now.This makes somewhat extensive use of functional features and Java streams, so any feedback on comprehensibility is welcome =)
Furthermore, methods
resolveAs{Block,Item}
might be better of inInventoryUtils
to be available for others to use. We're differentiating between items and blocks in way to many places ...