org.erights.e.elib.tables
Class ROList

java.lang.Object
  |
  +--org.erights.e.elib.tables.EList
        |
        +--org.erights.e.elib.tables.ROList
All Implemented Interfaces:
Amplifiable, EPrintable, Iteratable, Marker, PassByProxy, Persistent, Serializable

class ROList
extends EList
implements Amplifiable, PassByProxy

A ROList gives read-only access to an underlying potentially mutable list.

Author:
Mark S. Miller
See Also:
org.erights.e.elib.tables.ConstList, org.erights.e.elib.tables.FlexList

Field Summary
private  FlexList myPrecious
          the list we're protecting
(package private) static long serialVersionUID
           
 
Fields inherited from interface org.erights.e.elib.serial.PassByProxy
HONORARY, HONORED_NAMES
 
Fields inherited from interface org.erights.e.elib.serial.Persistent
HONORARY, HONORED_NAMES
 
Constructor Summary
(package private) ROList(FlexList precious)
           
 
Method Summary
 void __printOn(TextWriter out)
          Not transparently forwarded.
 ConstList add(Object other)
          Enabled: Concatenates (snapshots of) this list and other.
 ConstMap asKeys()
          Enabled: Turns [a, b, ...] into [a => null, b => null, ...]
 ConstMap asMap()
          Enabled: Turns [a, b, ...] into [0 => a, 1 => b, ...]
 boolean contains(Object candidate)
          Enabled: Does the candidate appear as a value in this list?
 FlexList diverge(Class valueType)
          Enabled: Returns a FlexList whose initial state is a snapshot of the state of this list at the time of the diverge() request.
 Object get(int index)
          Enabled: What value does 'index' map to?
 boolean includes(EList candidate)
          Enabled: Does this list include candidate as a sub-list?
 int indexOf1(Object candidate)
          Enabled: The first index at which 'candidate' appears in this list, or -1 if none.
 int indexOf1(Object candidate, int start)
          Enabled: The first index >= 'start' at which 'candidate' appears in this list, or -1 if none.
 void iterate(AssocFunc func)
          Enabled: Call 'func' with each index-value pair in the table in order.
 int lastIndexOf1(Object candidate)
          Enabled: The last index at which 'candidate' appears in this list, or -1 if none.
 int lastIndexOf1(Object candidate, int start)
          Enabled: The last index <= 'start' at which 'candidate' appears in this list, or -1 if none.
 int lastStartOf(EList candidate)
          Enabled: The last index at which 'candidate' begins as a sub-list of this list, or -1 if none.
 int lastStartOf(EList candidate, int start)
          Enabled: The last index <= start at which 'candidate' appears as a sub-list of this list, or -1 if none.
 ConstList multiply(int n)
          Enabled: Return the result of concatenating n snapshots of this list
 SealedBox optSealedDispatch(Brand brand)
          Divulges itself only to a holder of PersistentKeyHolder.THE_UNSEALER.
 EList readOnly()
          Just returns itself rather than forwarding
 ConstList run(int start, int bound)
          Enabled: Returns a snapshot of the sublist from 'start' (inclusive) to 'bound' (exclusive).
 ConstList run(Object intReg)
          Enabled: Returns a snapshot of the run at intReg.
 int size()
          Enabled: How many entries are in the list?
 ConstList snapshot()
          Enabled: Returns a ConstList whose state is a snapshot of the state of this list at the time of the snapshot() request.
 int startOf(EList candidate)
          Enabled: The first index at which 'candidate' begins as a sub-list of this list, or -1 if none.
 int startOf(EList candidate, int start)
          Enabled: The first index >= start at which 'candidate' begins as a sub-list of this list, or -1 if none.
 Class valueType()
          Enabled: All values in this table must be of this type
 
Methods inherited from class org.erights.e.elib.tables.EList
asSet, diverge, getArray, getArray, getArray, last, printOn, sort, sort, toString, with, with
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID

myPrecious

private final FlexList myPrecious
the list we're protecting

Constructor Detail

ROList

ROList(FlexList precious)
Method Detail

snapshot

public ConstList snapshot()
Description copied from class: EList
Enabled: Returns a ConstList whose state is a snapshot of the state of this list at the time of the snapshot() request. A ConstList returns itself.

Specified by:
snapshot in class EList

readOnly

public EList readOnly()
Just returns itself rather than forwarding

Specified by:
readOnly in class EList

diverge

public FlexList diverge(Class valueType)
Description copied from class: EList
Enabled: Returns a FlexList whose initial state is a snapshot of the state of this list at the time of the diverge() request.

Further changes to the original and/or the new list are independent -- they diverge.

The new list is constrained to only hold values of 'valueType'. XXX valueType should be of type ValueGuard rather than Class.

Overrides:
diverge in class EList

get

public Object get(int index)
           throws IndexOutOfBoundsException
Description copied from class: EList
Enabled: What value does 'index' map to?

Specified by:
get in class EList
Returns:
nullOk; the value at index may be null.
Throws:
IndexOutOfBoundsException - if index isn't in 0..!size.

contains

public boolean contains(Object candidate)
Description copied from class: EList
Enabled: Does the candidate appear as a value in this list?

Overrides:
contains in class EList

size

public int size()
Description copied from class: EList
Enabled: How many entries are in the list?

Specified by:
size in class EList

iterate

public void iterate(AssocFunc func)
Description copied from class: EList
Enabled: Call 'func' with each index-value pair in the table in order.

Specified by:
iterate in interface Iteratable
Overrides:
iterate in class EList

valueType

public Class valueType()
Description copied from class: EList
Enabled: All values in this table must be of this type

XXX Should this return a ValueGuard rather than a Class?

Specified by:
valueType in class EList

add

public ConstList add(Object other)
Description copied from class: EList
Enabled: Concatenates (snapshots of) this list and other.

XXX If they have a common class, we should use it.

The default implementation here insists that other coerces to an EList, but this is overridden in the Twine subclass.

Overrides:
add in class EList

multiply

public ConstList multiply(int n)
Description copied from class: EList
Enabled: Return the result of concatenating n snapshots of this list

Overrides:
multiply in class EList

asMap

public ConstMap asMap()
Description copied from class: EList
Enabled: Turns [a, b, ...] into [0 => a, 1 => b, ...]

Overrides:
asMap in class EList

asKeys

public ConstMap asKeys()
Description copied from class: EList
Enabled: Turns [a, b, ...] into [a => null, b => null, ...]

Overrides:
asKeys in class EList

includes

public boolean includes(EList candidate)
Description copied from class: EList
Enabled: Does this list include candidate as a sub-list?

Overrides:
includes in class EList

run

public ConstList run(Object intReg)
Description copied from class: EList
Enabled: Returns a snapshot of the run at intReg.

Overrides:
run in class EList

run

public ConstList run(int start,
                     int bound)
Description copied from class: EList
Enabled: Returns a snapshot of the sublist from 'start' (inclusive) to 'bound' (exclusive).

Overrides:
run in class EList

indexOf1

public int indexOf1(Object candidate)
Description copied from class: EList
Enabled: The first index at which 'candidate' appears in this list, or -1 if none.

Overrides:
indexOf1 in class EList

indexOf1

public int indexOf1(Object candidate,
                    int start)
Description copied from class: EList
Enabled: The first index >= 'start' at which 'candidate' appears in this list, or -1 if none.

Overrides:
indexOf1 in class EList

lastIndexOf1

public int lastIndexOf1(Object candidate)
Description copied from class: EList
Enabled: The last index at which 'candidate' appears in this list, or -1 if none.

Note that choosing '-1' leads to a programming pun that's too tempting to avoid (though it should be documented). If you want the index of, for example, the beginning of the last dot-separated substring of a string, you can say "lastIndexOf1('.')+1". If there is no dot, this returns 0, which is the correct answer for this case.

Overrides:
lastIndexOf1 in class EList

lastIndexOf1

public int lastIndexOf1(Object candidate,
                        int start)
Description copied from class: EList
Enabled: The last index <= 'start' at which 'candidate' appears in this list, or -1 if none.

Overrides:
lastIndexOf1 in class EList

startOf

public int startOf(EList candidate)
Description copied from class: EList
Enabled: The first index at which 'candidate' begins as a sub-list of this list, or -1 if none.

Overrides:
startOf in class EList

startOf

public int startOf(EList candidate,
                   int start)
Description copied from class: EList
Enabled: The first index >= start at which 'candidate' begins as a sub-list of this list, or -1 if none.

Overrides:
startOf in class EList

lastStartOf

public int lastStartOf(EList candidate)
Description copied from class: EList
Enabled: The last index at which 'candidate' begins as a sub-list of this list, or -1 if none.

Overrides:
lastStartOf in class EList

lastStartOf

public int lastStartOf(EList candidate,
                       int start)
Description copied from class: EList
Enabled: The last index <= start at which 'candidate' appears as a sub-list of this list, or -1 if none.

Overrides:
lastStartOf in class EList

optSealedDispatch

public SealedBox optSealedDispatch(Brand brand)
Divulges itself only to a holder of PersistentKeyHolder.THE_UNSEALER.

XXX Should provide an optional creation-time parameter of a Sealer to use in addition (or instead?) as a secret divulging channel.

Specified by:
optSealedDispatch in interface Amplifiable
Parameters:
brand -
Returns:

__printOn

public void __printOn(TextWriter out)
               throws IOException
Not transparently forwarded. Rather, prints as
      "[a, b, ...].diverge().readOnly()"
 

Specified by:
__printOn in interface EPrintable
IOException


comments?