|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.erights.e.elib.tables.EMap
Safe: A EMap is a finite single-valued map from keys to values. Equivalently, it can be considered a finite set of pairs, where each is a pair of a key and a value, and no two pairs have the same key. 'EMap' is a query-only interface that's agnostic about whether the data can change and whether a EMap can be cast to an object by which to change it. 'EMap' is also agnostic about the basis for equality between tables. Subtypes do pin these issues down:
ConstMap guarantees immutability, uses value-based equality, and can be transparently passed-by-copy over the network.
FlexMap extends EMap with mutation operations.
Based on java.util.Dictionary, but not polymorphic with it since EMaps don't satisfy Dictionary's contract. In particular, Dictionaries explicitly disallow nulls as keys or values, whereas EMaps explicitly allow them.
Actually, for the sake of determinism, an EMap is a sequence of key-value pairs, where this sequence is the enumeration order, and is derived deterministically from the operations that resulted in this map. Putting in a new key adds it to the end of the sequence. Removing a key causes the last key to take the place of the removed key in the sequence. Other operations, like or(), specify how they determine the resulting sequence.
It is normally considered bad style to attach meaning to the sequence, but is in the contract, so you may if you wish. If you do, document that, since your readers should usually be able to make the no-meaning assumption.
Field Summary | |
private static long |
serialVersionUID
|
private static Object |
ThePumpkin
This object must never be stored as a value in a map. |
Fields inherited from interface org.erights.e.elib.serial.Persistent |
HONORARY, HONORED_NAMES |
Constructor Summary | |
(package private) |
EMap()
Only subclasses within the package |
Method Summary | |
ConstMap |
and(EMap mask)
Enabled: The subset of this map whose keys are keys of 'mask'. |
ConstMap |
butNot(EMap mask)
Enabled: The subset of this map whose keys are not keys of 'mask'. |
boolean |
contains(Object candidate)
Enabled: Is the candidate the same as any of this table's values? |
FlexMap |
diverge()
Enabled: 'keyType' and 'valueType' default to Object.class |
FlexMap |
diverge(Class keyType,
Class valueType)
Enabled: Returns a FlexMap whose initial state is a snapshot of the state of this map at the time of the diverge() request. |
abstract ESet |
domain()
Enabled: Returns a set providing a read-only view of the domain of this map. |
Object[] |
extract(Object key,
Object defaultValue)
Enabled: Like optExtract/1, but allows one to provide a defaultValue for missing keys. |
Object |
get(Object key)
Enabled: What value does 'key' map to? |
abstract Object |
get(Object key,
Object instead)
Enabled: What value does 'key' map to? Returns 'instead' if key doesn't map to anything. |
Object |
getKeys()
Enabled: Defaults to an array of keyType() |
abstract Object |
getKeys(Class type)
Enabled: Returns a divergent array-of-type of all the keys in order. |
Object[] |
getPair()
Enabled: Returns a pair (a two element list) of the results of getKeys() and getValues(). |
Object[] |
getPair(Class keyType,
Class valueType)
Enabled: Returns a pair (a two element list) of the results of getKeys(keyType) and getValues(valueType). |
Object |
getValues()
Enabled: Defaults to an array of valueType() |
abstract Object |
getValues(Class type)
Enabled: Returns a divergent array-of-type of all the values in order. |
boolean |
intersects(EMap other)
Enabled: Do these tables have any keys in common? |
void |
iterate(AssocFunc func)
Enabled: Call 'func' with each key-value pair in the table, in order. |
abstract Class |
keyType()
Enabled: All keys in this map must be of this type. |
boolean |
maps(Object key)
Enabled: Is there a mapping for 'key'? |
Object[] |
optExtract(Object key)
Enabled: Used by the expansion of map-patterns. |
ConstMap |
or(EMap behind)
Enabled: Defaults to not strict. |
ConstMap |
or(EMap behind,
boolean strict)
Enabled: Returns a map that has the union of the domains of this map. |
private ConstMap |
permute(Number[] permutation,
Object oldKeys,
Object oldVals)
|
void |
printOn(String left,
String map,
String sep,
String right,
TextWriter out)
Enabled: Onto out, print 'left' key0 'map' value0 'sep' ... |
abstract EMap |
readOnly()
Enabled: Returns a read-only facet on this map. |
abstract int |
size()
Enabled: How many entries are in the table? |
abstract ConstMap |
snapshot()
Enabled: Returns a ConstMap whose state is a snapshot of the state of this map at the time of the snapshot() request. |
ConstMap |
sortKeys()
Enabled: Returns a snapshot of this mapping, but reordered so the keys are in ascending order. |
ConstMap |
sortKeys(CompFunc func)
Enabled: Returns a snapshot of this mapping, but reordered so the keys are in ascending order according to func. |
ConstMap |
sortValues()
Enabled: Returns a snapshot of this mapping, but reordered so the values are in ascending order. |
ConstMap |
sortValues(CompFunc func)
Enabled: Returns a snapshot of this mapping, but reordered so the values are in ascending order according to func. |
String |
toString()
Suppressed: |
abstract Class |
valueType()
Enabled: All values in this map must be of this type |
ConstMap |
with(Object key,
Object newValue)
Enabled: Returns a ConstMap just like this one, except that 'key' maps to 'newValue'. |
ConstMap |
without(Object key)
Enabled: Returns a ConstMap just like this one, except that there is no ConstMap for 'key'. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.erights.e.elib.oldeio.EPrintable |
__printOn |
Field Detail |
private static final long serialVersionUID
private static final Object ThePumpkin
Constructor Detail |
EMap()
Method Detail |
public abstract ConstMap snapshot()
public abstract EMap readOnly()
public FlexMap diverge(Class keyType, Class valueType)
Further changes to the original and/or the new map are independent -- they diverge.
The new map is constrained to only hold associations from 'keyType' to 'valueType'. XXX keyType and valueType should be declared as ValueGuards rather than Classes.
public FlexMap diverge()
public Object get(Object key) throws IndexOutOfBoundsException
key
- nullOk;
IndexOutOfBoundsException
- if key doesn't map to anything.org.erights.e.elib.ref.Ref#isSettled
public Object[] optExtract(Object key)
key
- nullOk;
without(java.lang.Object)
that key-value association. If the
key is not found, optExtract/1 returns null.public Object[] extract(Object key, Object defaultValue)
key
- nullOk;
without(java.lang.Object)
that key-value association. If the key is not
found, extract/2 returns a pair of defaultValue and this map.public boolean contains(Object candidate)
public boolean intersects(EMap other)
public abstract int size()
public void iterate(AssocFunc func)
iterate
in interface Iteratable
public ConstMap or(EMap behind, boolean strict)
If both maps have keys in common, then if strict, throw an exception. Otherwise, take the value from the receiver (the left-hand operand). We can think of the receiver as being in front of and occluding 'behind'.
In the order, the 'behind' keys come first in their original order, then the receiver's remaining keys in their original order.
public ConstMap or(EMap behind)
public ConstMap and(EMap mask)
The order of keys in the intersection is taken from the smaller of the original two. If they're the same size, then the receiver's order is used.
public ConstMap butNot(EMap mask)
The order is the order of the receiver, as modified by removal of the keys in mask in mask's order.
public boolean maps(Object key)
key
- nullOk;public abstract Object get(Object key, Object instead)
key
- nullOk;instead
- nullOk;
org.erights.e.elib.ref.Ref#isSettled
public Object getKeys()
public abstract Object getKeys(Class type)
XXX Should 'type' be a ValueGuard rather than a Class?
public abstract ESet domain()
public Object getValues()
public abstract Object getValues(Class type)
XXX Should 'type' be a ValueGuard rather than a Class?
public Object[] getPair()
Unlike calling them individually, by getting them both together, they are guaranteed to correspond.
public Object[] getPair(Class keyType, Class valueType)
Unlike calling them individually, by getting them both together, they are guaranteed to correspond. The default implementation here does just call getKeys(keyType), and then calls getValues(valueType), as that is fine for everything but the WeakValuesMap.
XXX Should keyType and valueType be ValueGuards rather than Classes?
public ConstMap with(Object key, Object newValue)
This is currently horribly inefficient. Can be made efficient by using backward deltas.
key
- nullOk;newValue
- nullOk;public ConstMap without(Object key)
This is currently horribly inefficient. Can be made efficient by using backward deltas.
key
- nullOk;public ConstMap sortKeys()
public ConstMap sortKeys(CompFunc func)
public ConstMap sortValues()
public ConstMap sortValues(CompFunc func)
private ConstMap permute(Number[] permutation, Object oldKeys, Object oldVals)
public abstract Class keyType()
XXX Should this return a ValueGuard rather than a Class?
public abstract Class valueType()
XXX Should this return a ValueGuard rather than a Class?
public void printOn(String left, String map, String sep, String right, TextWriter out) throws IOException
IOException
public String toString()
toString
in class Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |