org.erights.e.elib.tables
Class Twine

java.lang.Object
  |
  +--org.erights.e.elib.tables.EList
        |
        +--org.erights.e.elib.tables.ConstList
              |
              +--org.erights.e.elib.tables.Twine
All Implemented Interfaces:
DeepPassByCopy, EPrintable, Guard, Iteratable, Marker, PassByConstruction, Persistent, Selfless, Serializable, SlotGuard, ValueGuard
Direct Known Subclasses:
AtomicTwine, CompositeTwine, EmptyTwine

public abstract class Twine
extends ConstList
implements DeepPassByCopy

Untamed:

See Also:
Serialized Form

Field Summary
private static StaticMaker OptTwineMaker
          Initialized lazily to avoid a circular initialization problem
private static long serialVersionUID
           
 
Fields inherited from class org.erights.e.elib.tables.ConstList
EmptyList
 
Fields inherited from interface org.erights.e.elib.serial.DeepPassByCopy
HONORARY, HONORED_NAMES
 
Fields inherited from interface org.erights.e.elib.serial.Persistent
HONORARY, HONORED_NAMES
 
Constructor Summary
(package private) Twine()
          Package scoped to deter the creation of any other immediate subclasses besides AtomicTwine and CompositeTwine.
 
Method Summary
 ConstList add(Object other)
          Enabled: Return a new Twine that represents a concatenation of the parts of this and other.
 Twine asFrom(String url)
          Enabled: startLine defaults to 1 and startCol defaults to 0
 Twine asFrom(String url, int startLine, int startCol)
          Enabled: Returns a new Twine on the same underlying bare String as this one, but marked as being contiguous text starting at the position described by the argument.
abstract  String bare()
          Enabled: Explicitly gets the String part of the twine.
 Twine canonical()
          Enabled: Each crlf is turned into an lf to deal with MSWindows, and then each remaining cr is turned into an lf to deal with Mac.
abstract  char charAt(int index)
          Enabled: From the E language, this is identical to get/1.
 double compareTo(ConstList other)
          Enabled: Compares the bare strings.
 int compareToIgnoreCase(String other)
          Enabled: Compares the bare strings ignoring case differences
 boolean endsWith(String suffix)
          Enabled: @see String#endsWith
 boolean equalsIgnoreCase(String other)
          Enabled: Compares the bare strings ignoring case differences
static Twine fromChars(ConstList chars, SourceSpan optSourceSpan)
          Enabled:
static Twine fromParts(ConstList parts)
          Enabled: Make a Twine whose parts are this list of AtomicTwines.
static Twine fromString(String str)
          Enabled: Makes a Twine with no information besides str.
static Twine fromString(String str, SourceSpan optSourceSpan)
          Enabled: Makes a Twine on str from optSourceSpan.
 Object get(int index)
          Enabled:
 byte[] getBytes()
          Enabled: In E, the encoding always defaults to "UTF-8", period.
 byte[] getBytes(String enc)
          Enabled: @see String#getBytes
abstract  SourceSpan getOptSpan()
          Enabled: Gets the sourceSpan part of the twine, if it's there.
 int[] getPartAt(int pos)
          Enabled: If pos is a position within this Twine, return a pair consisting of the index in the getParts() list of the AtomicTwine containing this position, and the offset into this part of this position.
abstract  ConstList getParts()
          Enabled: @return A list of AtomicTwines.
 ConstMap getSourceMap()
          Enabled: Returns a mapping from intervals in the Twine to spans showing where they came from.
static StaticMaker GetTwineMaker()
          Enabled:
 int indexOf(String str)
          Enabled: Just like EList.startOf(EList), but with a String argument for convenience of the Java programmer.
 int indexOf(String str, int fromIndex)
          Enabled: Just like startOf(EList, int), but with a String argument for convenience of the Java programmer.
 Twine infect(String str)
          Enabled: oneToOne defaults to false
 Twine infect(String str, boolean oneToOne)
          Enabled: Returns a Twine with str as the string part, and the source info from this Twine.
(package private) abstract  Twine infectOneToOne(String str)
           
abstract  boolean isBare()
          Enabled: Is the bare string all the info there is?
 int lastIndexOf(String str)
          Enabled: Just like EList.lastStartOf(EList), but with a String argument for convenience of the Java programmer.
 int lastIndexOf(String str, int fromIndex)
          Enabled: Just like lastStartOf(EList, int), but with a String argument for convenience of the Java programmer.
 int lastStartOf(EList candidate, int start)
          Enabled: Overridden for performance
 ConstList multiply(int reps)
          Enabled: The result will be a Twine
 Twine quote()
          Enabled: Returns a string that, when interpreted as a literal, represents the original string.
 Twine replaceAll(String oldStr, String newStr)
          Enabled: In E, we have the string-based replaceAll() rather than the character-based replace().
 Twine rjoin(Twine[] fields)
          Enabled: Like Python's joinFields(), but with the receiver and argument reversed (hence the initial "r").
abstract  ConstList run(int start, int bound)
          Enabled: Returns a Twine.
 ConstList run(Object intReg)
          Enabled: Returns a Twine.
 ConstList split(String sep)
          Enabled: Like Python's splitFields(), this returns a list of the "fields" of this twine (substrings of this twine), using 'sep' as a separator.
 int startOf(EList candidate, int start)
          Enabled: Overridden for performance
 boolean startsWith(String prefix)
          Enabled: @see String#startsWith
 boolean startsWith(String prefix, int offset)
          Enabled: @see String#startsWith
 Twine toLowerCase()
          Enabled:
 String toString()
          Suppressed:
 Twine toUpperCase()
          Enabled:
 Twine trim()
          Enabled:
 Class valueType()
          Enabled: @return Character.class
 
Methods inherited from class org.erights.e.elib.tables.ConstList
__optUncall, __printOn, accepts, and, butNot, coerce, coerce, compareTo, fromArray, fromArray, get, GetMaker, getName, makeSlot, makeSlot, match, not, or, readOnly, snapshot, xor
 
Methods inherited from class org.erights.e.elib.tables.EList
asKeys, asMap, asSet, contains, diverge, diverge, getArray, getArray, getArray, includes, indexOf1, indexOf1, iterate, last, lastIndexOf1, lastIndexOf1, lastStartOf, printOn, size, sort, sort, startOf, with, with
 
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.tables.Selfless
getSpreadUncall
 

Field Detail

serialVersionUID

private static final long serialVersionUID

OptTwineMaker

private static StaticMaker OptTwineMaker
Initialized lazily to avoid a circular initialization problem

Constructor Detail

Twine

Twine()
Package scoped to deter the creation of any other immediate subclasses besides AtomicTwine and CompositeTwine.

Method Detail

GetTwineMaker

public static StaticMaker GetTwineMaker()
Enabled:


fromParts

public static Twine fromParts(ConstList parts)
Enabled: Make a Twine whose parts are this list of AtomicTwines.

The list of parts is assumed to already be maximally merged. If it's an empty list, return the EmptyTwine. If it's a singleton list, return that part. Otherwise return a CompositeTwine on these parts.


fromString

public static Twine fromString(String str)
Enabled: Makes a Twine with no information besides str.

If str is empty, returns the empty CompositeTwine. Otherwise, returns a new SimpleTwine on str.


fromString

public static Twine fromString(String str,
                               SourceSpan optSourceSpan)
Enabled: Makes a Twine on str from optSourceSpan.

If str is empty, returns the EmptyTwine. Otherwise, returns a new SimpleTwine on str or a LocatedTwine on both args.


fromChars

public static Twine fromChars(ConstList chars,
                              SourceSpan optSourceSpan)
Enabled:

Parameters:
chars -
Returns:

asFrom

public Twine asFrom(String url)
Enabled: startLine defaults to 1 and startCol defaults to 0


asFrom

public Twine asFrom(String url,
                    int startLine,
                    int startCol)
Enabled: Returns a new Twine on the same underlying bare String as this one, but marked as being contiguous text starting at the position described by the argument.


getParts

public abstract ConstList getParts()
Enabled: @return A list of AtomicTwines. An empty Twine returns the empty list.


getPartAt

public int[] getPartAt(int pos)
                throws IndexOutOfBoundsException
Enabled: If pos is a position within this Twine, return a pair consisting of the index in the getParts() list of the AtomicTwine containing this position, and the offset into this part of this position.

IndexOutOfBoundsException

getSourceMap

public ConstMap getSourceMap()
Enabled: Returns a mapping from intervals in the Twine to spans showing where they came from.

Unfortunately, because of the way the E implementation is layered, the keys in this mapping cannot be int-regions (as these are implemented in the E language, which is in a layer that depends on this layer, and we're trying to avoid inter-layer cyclic dependencies). Instead, the keys are represented as a pair of ints representing start..!bound. Note that this is inclusive-exclusive, while the info in the spans are inclusive-inclusive.

The mapping is ordered to facilitate binary search. Intervals with no SourceSpan information are left out of the map.


bare

public abstract String bare()
Enabled: Explicitly gets the String part of the twine.

When using this call, this call itself will be the top level construct for breaking cycles. XXX where & what do we stabilize?


isBare

public abstract boolean isBare()
Enabled: Is the bare string all the info there is?


getOptSpan

public abstract SourceSpan getOptSpan()
Enabled: Gets the sourceSpan part of the twine, if it's there.

If this is an AtomicTwine, then, if the SourceSpan is there, it's as accurate as you're going to get. If this is a CompositeTwine, then, if the SourceSpan is there, it describes a span that includes all the individual spans. If a CompositeTwine returns null, there may still be SourceSpans on the atomic parts, but they couldn't all be summarized into one covering span.


infectOneToOne

abstract Twine infectOneToOne(String str)

infect

public Twine infect(String str)
Enabled: oneToOne defaults to false


infect

public Twine infect(String str,
                    boolean oneToOne)
Enabled: Returns a Twine with str as the string part, and the source info from this Twine.

Parameters:
str - The string to annotate with source-span info from this Twine.
oneToOne - If true, the two strings must be the same size, in which case this Twine's source-span info is mapped one to one onto the new string. If false, then the new string will only get a non-oneToOne form of this Twine's overall source-span.

add

public ConstList add(Object other)
Enabled: Return a new Twine that represents a concatenation of the parts of this and other.

The last part of this may be merged with the first part of other.

Overrides:
add in class EList

multiply

public ConstList multiply(int reps)
Enabled: The result will be a Twine

Overrides:
multiply in class EList

canonical

public Twine canonical()
Enabled: Each crlf is turned into an lf to deal with MSWindows, and then each remaining cr is turned into an lf to deal with Mac.


run

public ConstList run(Object intReg)
Enabled: Returns a Twine.

Overrides:
run in class EList

run

public abstract ConstList run(int start,
                              int bound)
Enabled: Returns a Twine.

Overrides:
run in class EList

quote

public Twine quote()
Enabled: Returns a string that, when interpreted as a literal, represents the original string.


get

public Object get(int index)
           throws IndexOutOfBoundsException
Enabled:

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

compareTo

public double compareTo(ConstList other)
Enabled: Compares the bare strings.

Optimized for the case where both are Twine. Otherwise should be identical.

Overrides:
compareTo in class ConstList

valueType

public Class valueType()
Enabled: @return Character.class

Specified by:
valueType in class EList

charAt

public abstract char charAt(int index)
                     throws IndexOutOfBoundsException
Enabled: From the E language, this is identical to get/1. But we provide it so the ELib programmer can avoid boxing the character.

IndexOutOfBoundsException
See Also:
String.charAt(int)

compareToIgnoreCase

public int compareToIgnoreCase(String other)
Enabled: Compares the bare strings ignoring case differences

See Also:
String.compareToIgnoreCase(java.lang.String)

equalsIgnoreCase

public boolean equalsIgnoreCase(String other)
Enabled: Compares the bare strings ignoring case differences

See Also:
String.equalsIgnoreCase(java.lang.String)

startsWith

public boolean startsWith(String prefix)
Enabled: @see String#startsWith


startsWith

public boolean startsWith(String prefix,
                          int offset)
Enabled: @see String#startsWith


endsWith

public boolean endsWith(String suffix)
Enabled: @see String#endsWith


getBytes

public byte[] getBytes()
                throws UnsupportedEncodingException
Enabled: In E, the encoding always defaults to "UTF-8", period.

UnsupportedEncodingException
See Also:
String.getBytes(int, int, byte[], int)

getBytes

public byte[] getBytes(String enc)
                throws UnsupportedEncodingException
Enabled: @see String#getBytes

UnsupportedEncodingException

indexOf

public int indexOf(String str)
Enabled: Just like EList.startOf(EList), but with a String argument for convenience of the Java programmer.


indexOf

public int indexOf(String str,
                   int fromIndex)
Enabled: Just like startOf(EList, int), but with a String argument for convenience of the Java programmer.


startOf

public int startOf(EList candidate,
                   int start)
Enabled: Overridden for performance

Overrides:
startOf in class EList

lastIndexOf

public int lastIndexOf(String str)
Enabled: Just like EList.lastStartOf(EList), but with a String argument for convenience of the Java programmer.


lastIndexOf

public int lastIndexOf(String str,
                       int fromIndex)
Enabled: Just like lastStartOf(EList, int), but with a String argument for convenience of the Java programmer.


lastStartOf

public int lastStartOf(EList candidate,
                       int start)
Enabled: Overridden for performance

Overrides:
lastStartOf in class EList

replaceAll

public Twine replaceAll(String oldStr,
                        String newStr)
Enabled: In E, we have the string-based replaceAll() rather than the character-based replace().

For each match, the source info from the twine matching oldStr infects the substituted newStr. Ignoring the source info, 'str replaceAll(oldStr, newStr)' should be equivalent to 'newStr rjoin(str split(oldStr))'.

If oldStr is the null string (""), replaceAll() throws an IllegalArgumentException.

See Also:
String.replace(char, char)

split

public ConstList split(String sep)
Enabled: Like Python's splitFields(), this returns a list of the "fields" of this twine (substrings of this twine), using 'sep' as a separator.

The returned list will have one more element than the number of non-overlapping occurrences of 'sep'.

Unlike Python, if sep is the null string (""), split() throws an IllegalArgumentException.


rjoin

public Twine rjoin(Twine[] fields)
Enabled: Like Python's joinFields(), but with the receiver and argument reversed (hence the initial "r").

Concatenates the fields with this twine as the intervening separator. Ignoring source info, and if 'sep' is not the null string, 'sep.rjoin(str.split(sep))' should be equivalent to 'str'.


toString

public String toString()
Suppressed:

Overrides:
toString in class EList
Returns:
a string representation of the object.

toLowerCase

public Twine toLowerCase()
Enabled:


toUpperCase

public Twine toUpperCase()
Enabled:


trim

public Twine trim()
Enabled:



comments?