Added Splitting Text and implemented Immutable Maps#1845
Draft
rehandxtr wants to merge 1 commit intoyegor256:masterfrom
Draft
Added Splitting Text and implemented Immutable Maps#1845rehandxtr wants to merge 1 commit intoyegor256:masterfrom
rehandxtr wants to merge 1 commit intoyegor256:masterfrom
Conversation
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
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.
Add Immutable Map Decorator and splitPreserveAllTokens Utility
Summary
This PR implements two features requested in recent issues:
Immutable Map Decorator (
org.cactoos.map.Immutable)Map<K, V>put,remove,putAll,clear)keySet,values,entrySet) and their iterators immutableEntry.setValue()on entries fromentrySet()list.Immutable,set.Immutable, etc.splitPreserveAllTokens Utility (
SplitPreserveAllTokens+TriFuncSplitPreserve)String.split()which discards trailing emptiesStringUtils.splitPreserveAllTokens()Iterable<Text>interface with flexible constructorsBoth features include:
Why These Changes Are Correct
Immutable Map
Mapdirectly (like existingImmutabledecorators), not extendingMapEnvelopeMap<? extends K, ? extends V>)ImmutableEntrySet, etc.)MapOfandHashMapentries correctlysplitPreserveAllTokens
TriFuncfor core logic,IterableEnvelopefor OO wrapperTest Coverage
Tests verify:
UnsupportedOperationExceptionString.split()differencesImportant Decisions
Immutable Map
implements Mapoverextends MapEnvelopefor full control (consistent with otherImmutableclasses)ImmutableEntryto blocksetValue()even for mutable entriesMappedKeys/MappedValuesfor covariant type safetysplitPreserveAllTokens
indexOf()(not regex) to match Apache Commons behaviorSplitclass)Iterable<Text>following Cactoos patternsReferences
SplitvsSplitPreserveAllTokenspattern