Package com.ibm.icu.dev.util
Class UnicodeMap<T>
java.lang.Object
com.ibm.icu.dev.util.UnicodeMap<T>
- All Implemented Interfaces:
StringTransform
,Transform<String,
,String> Freezable<UnicodeMap<T>>
,Cloneable
,Iterable<String>
public final class UnicodeMap<T>
extends Object
implements Cloneable, Freezable<UnicodeMap<T>>, StringTransform, Iterable<String>
Class for mapping Unicode characters and strings to values, optimized for single code points,
where ranges of code points have the same value.
Much smaller storage than using HashMap, and much faster and more compact than
a list of UnicodeSets. The API design mimics Map<String,T> but can't extend it due to some
necessary changes (much as UnicodeSet mimics Set). Note that nulls are not permitted as values;
that is, a put(x,null) is the same as remove(x).
At this point "" is also not allowed as a key, although that may change.
At this point "" is also not allowed as a key, although that may change.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Used to add complex values, where the value isn't replaced but in some sense composedstatic class
Struct-like class used to iterate over a UnicodeMap in a for loop.private class
private class
private class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final boolean
For serializationprivate LinkedHashSet<T>
(package private) static final boolean
private boolean
(package private) static final long
(package private) static final long
private int
private int
private boolean
private boolean
private int[]
(package private) T[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int
__findIndex
(int codepoint) private void
_checkFind
(int codepoint, int value) (package private) void
private int
_findIndex
(int c) Finds an index such that inversionList[i] <= codepoint < inversionList[i+1] Assumes that 0 <= codepoint <= 0x10FFFFprivate void
_insertGapAt
(int index, int count) Add a gap from index to index+count-1.private UnicodeMap
Associates code point with value.private UnicodeMap
private void
_removeAt
(int index, int count) Remove the items from index through index+count-1.<U extends Map<T,
UnicodeSet>>
UaddInverseTo
(U target) Gets the inverse of this map, adding to the target.static boolean
clear()
Standard clone.composeWith
(UnicodeMap<T> other, UnicodeMap.Composer<T> composer) composeWith
(UnicodeSet set, T value, UnicodeMap.Composer<T> composer) boolean
containsKey
(int key) boolean
containsKey
(String key) boolean
containsValue
(T value) Returns an Iterable over EntryRange, designed for efficient for loops over UnicodeMaps.entrySet()
boolean
static int
findCommonPrefix
(String last, String s) Utility to find the maximal common prefix of two strings.freeze()
Freezes the object.static <T> Map<T,
UnicodeSet> freeze
(Map<T, UnicodeSet> target) Freeze an inverse map.get
(int codepoint) Gets the value associated with a given code point.Gets the value associated with a given code point.Old form for compatibility<U extends Collection<T>>
UgetAvailableValues
(U result) Old form for compatibilityboolean
Get the strings that are not in the ranges.int
Get the number of ranges; used for getRangeStart/End.int
getRangeEnd
(int range) Get the start of a range.int
getRangeStart
(int range) Get the start of a range.getRangeValue
(int range) Get the value for the range.Old form for compatibilitygetSet
(T value, UnicodeSet result) Old form for compatibilitygetValue
(int key) Old form for compatibilityOld form for compatibilityint
hashCode()
boolean
isEmpty()
boolean
isFrozen()
Determines whether the object has been frozen or not.iterator()
keySet()
Returns the keyset consisting of all the keys that would produce (non-null) values.Returns the keyset consisting of all the keys that would produce the given value.keySet
(T value, UnicodeSet result) Returns the keyset consisting of all the keys that would produce the given value.Sets the codepoint value.Sets the codepoint value.Adds bunch o' codepoints; otherwise like add.putAll
(UnicodeMap<T> unicodeMap) Add all the (main) values from a UnicodeMapputAll
(UnicodeSet codepoints, T value) Adds bunch o' codepoints; otherwise like put.putAllCodepointsInto
(U map) Utility for extracting mapputAllFiltered
(UnicodeMap<T> prop, UnicodeSet filter) Add all the (main) values from a Unicode propertyDeprecated.putAllInto
(U map) Utility for extracting mapputAllInverse
(Map<T, UnicodeSet> source) remove
(int key) final UnicodeMap<T>
removeAll
(UnicodeMap<T> reference) final UnicodeMap<T>
removeAll
(UnicodeSet set) private final UnicodeMap<T>
removeRetainAll
(UnicodeMap<T> reference, boolean remove) final UnicodeMap<T>
retainAll
(UnicodeMap<T> reference) final UnicodeMap<T>
retainAll
(UnicodeSet set) setErrorOnReset
(boolean errorOnReset) Puts the UnicodeMap into a state whereby new mappings are accepted, but changes to old mappings cause an exception.setMissing
(T value) Set the currently unmapped Unicode code points to the given value.int
size()
Returns the keys that consist of multiple code points.toString()
toString
(Comparator<T> collected) Change a new string from the source string according to the mappings.values()
Convenience method<U extends Collection<T>>
Uvalues
(U result) Returns the list of possible values.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ASSERTIONS
static final boolean ASSERTIONSFor serialization- See Also:
-
GROWTH_PERCENT
static final long GROWTH_PERCENT- See Also:
-
GROWTH_GAP
static final long GROWTH_GAP- See Also:
-
length
private int length -
transitions
private int[] transitions -
values
T[] values -
availableValues
-
staleAvailableValues
private transient boolean staleAvailableValues -
errorOnReset
private transient boolean errorOnReset -
locked
private transient volatile boolean locked -
lastIndex
private int lastIndex -
stringMap
-
DEBUG_WRITE
static final boolean DEBUG_WRITE- See Also:
-
-
Constructor Details
-
UnicodeMap
public UnicodeMap() -
UnicodeMap
-
-
Method Details
-
clear
-
equals
-
areEqual
-
hashCode
public int hashCode() -
cloneAsThawed
Standard clone. Warning, as with Collections, does not do deep clone.- Specified by:
cloneAsThawed
in interfaceFreezable<T>
-
_checkInvariants
void _checkInvariants() -
_findIndex
private int _findIndex(int c) Finds an index such that inversionList[i] <= codepoint < inversionList[i+1] Assumes that 0 <= codepoint <= 0x10FFFF- Parameters:
codepoint
-- Returns:
- the index
-
_checkFind
private void _checkFind(int codepoint, int value) -
__findIndex
private int __findIndex(int codepoint) -
_removeAt
private void _removeAt(int index, int count) Remove the items from index through index+count-1. Logically reduces the size of the internal arrays.- Parameters:
index
-count
-
-
_insertGapAt
private void _insertGapAt(int index, int count) Add a gap from index to index+count-1. The values there are undefined, and must be set. Logically grows arrays to accommodate. Actual growth is limited- Parameters:
index
-count
-
-
_put
Associates code point with value. Removes any previous association. All code that calls this MUST check for frozen first!- Parameters:
codepoint
-value
-- Returns:
- this, for chaining
-
_putAll
-
put
Sets the codepoint value.- Parameters:
codepoint
-value
-- Returns:
- this (for chaining)
-
put
Sets the codepoint value.- Parameters:
codepoint
-value
-- Returns:
- this (for chaining)
-
putAll
Adds bunch o' codepoints; otherwise like put.- Parameters:
codepoints
-value
-- Returns:
- this (for chaining)
-
putAll
Adds bunch o' codepoints; otherwise like add.- Parameters:
startCodePoint
-endCodePoint
-value
-- Returns:
- this (for chaining)
-
putAll
Add all the (main) values from a UnicodeMap- Parameters:
unicodeMap
- the property to add to the map- Returns:
- this (for chaining)
-
putAllFiltered
Add all the (main) values from a Unicode property- Parameters:
prop
- the property to add to the map- Returns:
- this (for chaining)
-
setMissing
Set the currently unmapped Unicode code points to the given value.- Parameters:
value
- the value to set- Returns:
- this (for chaining)
-
keySet
Returns the keyset consisting of all the keys that would produce the given value. Deposits into result if it is not null. Remember to clear if you just want the new values. -
keySet
Returns the keyset consisting of all the keys that would produce the given value. the new values. -
keySet
Returns the keyset consisting of all the keys that would produce (non-null) values. -
values
Returns the list of possible values. Deposits each non-null value into result. Creates result if it is null. Remember to clear result if you are not appending to existing collection.- Parameters:
result
-- Returns:
- result
-
values
Convenience method -
get
Gets the value associated with a given code point. Returns null, if there is no such value.- Parameters:
codepoint
-- Returns:
- the value
-
get
Gets the value associated with a given code point. Returns null, if there is no such value.- Parameters:
codepoint
-- Returns:
- the value
-
transform
Change a new string from the source string according to the mappings. For each code point cp, if getValue(cp) is null, append the character, otherwise append getValue(cp).toString() TODO: extend to strings -
composeWith
-
composeWith
-
toString
-
toString
-
getErrorOnReset
public boolean getErrorOnReset()- Returns:
- Returns the errorOnReset value.
-
setErrorOnReset
Puts the UnicodeMap into a state whereby new mappings are accepted, but changes to old mappings cause an exception.- Parameters:
errorOnReset
- The errorOnReset to set.
-
isFrozen
public boolean isFrozen()Description copied from interface:Freezable
Determines whether the object has been frozen or not. -
freeze
Description copied from interface:Freezable
Freezes the object. -
findCommonPrefix
Utility to find the maximal common prefix of two strings. TODO: fix supplemental support -
getRangeCount
public int getRangeCount()Get the number of ranges; used for getRangeStart/End. The ranges together cover all of the single-codepoint keys in the UnicodeMap. Other keys can be gotten with getStrings(). -
getRangeStart
public int getRangeStart(int range) Get the start of a range. All code points between start and end are in the UnicodeMap's keyset. -
getRangeEnd
public int getRangeEnd(int range) Get the start of a range. All code points between start and end are in the UnicodeMap's keyset. -
getRangeValue
Get the value for the range. -
getNonRangeStrings
Get the strings that are not in the ranges. Returns null if there are none.- Returns:
-
containsKey
-
containsKey
public boolean containsKey(int key) -
containsValue
-
isEmpty
public boolean isEmpty() -
putAll
-
putAllIn
Deprecated.Utility for extracting map -
putAllInto
Utility for extracting map -
putAllCodepointsInto
Utility for extracting map -
remove
-
remove
-
size
public int size() -
entrySet
-
entryRanges
Returns an Iterable over EntryRange, designed for efficient for loops over UnicodeMaps. Caution: For efficiency, the EntryRange may be reused, so the EntryRange may change on each iteration! The value is guaranteed never to be null. The entryRange.string values (non-null) are after all the ranges.- Returns:
- entry range, for for loops
-
iterator
-
getValue
Old form for compatibility -
getValue
Old form for compatibility -
getAvailableValues
Old form for compatibility -
getAvailableValues
Old form for compatibility -
getSet
Old form for compatibility -
getSet
Old form for compatibility -
removeAll
-
removeAll
-
retainAll
-
retainAll
-
removeRetainAll
-
stringKeys
Returns the keys that consist of multiple code points.- Returns:
-
addInverseTo
Gets the inverse of this map, adding to the target. Like putAllIn- Returns:
-
freeze
Freeze an inverse map.- Parameters:
target
-- Returns:
-
putAllInverse
- Parameters:
target
-- Returns:
-