Class SList
- All Implemented Interfaces:
Sexpr<SList>,Comparable<Sexpr<?>>,Iterable<Sexpr<?>>,Collection<Sexpr<?>>,List<Sexpr<?>>
Textually, a SList consists of an opening parenthesis, a the series of elements separated by spaces, followed by a closing parenthesis.
All instances of this interface are immutable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classAn instance of this interface simplifies the modification of symbolic-expressions, since they are immutable. -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Method Summary
Modifier and TypeMethodDescriptionasMap()This method retrieves this value, as a map.booleanThis method performs a breadth-first-search of the tree rooted at this node.static SListcopyOf(SourceLocation location, Iterable<? extends Sexpr<?>> list) Factory Method.static SListcopyOf(SourceLocation location, Iterator<? extends Sexpr<?>> stream) Factory Method.static SListcopyOf(SourceLocation location, Stream<? extends Sexpr<?>> stream) Factory Method.static SListFactory Method.static SListFactory Method.static SListFactory Method.booleanThis method performs a depth-first-search of the tree rooted at this node.final booleanfirst()This method retrieves the first element of this list.static SListfromMap(SourceLocation location, Map<? extends Sexpr<?>, ? extends Sexpr<?>> map) This method creates a new two-dimensional list from the given map.static SListfromMap(SourceLocation location, Map<? extends Sexpr<?>, ? extends Sexpr<?>> map, Sexpr<?> separator) This method creates a new two-dimensional list from the given map.get(int i) inthashCode()booleanisAtom()This method determines whether this object is a SAtom.booleanisList()This method determines whether this object is a SList.last()This method retrieves the last element of this list.location()This method retrieves an object describing the source from which this object we obtained.mutator()This method obtains a mutator that can be used to non-destructively modify the tree rooted at this node.static SListFactory Method.static SListof(SourceLocation location, Sexpr<?>... elements) Factory Method.static SListThis method converts the textual representation of a SList to an actual corresponding SList object.static SListThis method converts the textual representation of a SList to an actual corresponding SList object.static SListThis method converts the textual representation of a text file to an actual corresponding SList object.static SListparseResource(String path) This method converts the textual representation of a resource file to an actual corresponding SList object.booleanThis method performs a post-order-search of the tree rooted at this node.booleanThis method performs a pre-order-search of the tree rooted at this node.intsize()tail()This method retrieves the sub-list containing all of the elements of this list, except for the first element in linear-time.toString()This method retrieves the textual representation of this symbolic expression.voidThis method performs a traversal of the tree rooted at this node.intThis method determines the height of the tree rooted at this node.intThis method counts the leaf nodes in the tree rooted at this node.inttreeSize()This method counts the nodes in the tree rooted at this node.Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Method Details
-
of
Factory Method.- Parameters:
elements- will be the elements in this list.- Returns:
- the new symbolic-list.
-
of
Factory Method.- Parameters:
location- will be the location() of this list.elements- will be the elements in this list.- Returns:
- the new symbolic-list.
-
copyOf
Factory Method.- Parameters:
list- contains the elements for the new list.- Returns:
- the new symbolic-list.
-
copyOf
Factory Method.- Parameters:
location- will be the location() of this list.list- contains the elements for the new list.- Returns:
- the new symbolic-list.
-
copyOf
Factory Method.- Parameters:
stream- contains the elements for the new list.- Returns:
- the new symbolic-list.
-
copyOf
Factory Method.- Parameters:
location- will be the location() of this list.stream- contains the elements for the new list.- Returns:
- the new symbolic-list.
-
copyOf
Factory Method.- Parameters:
stream- contains the elements for the new list.- Returns:
- the new symbolic-list.
-
copyOf
Factory Method.- Parameters:
location- will be the location() of this list.stream- contains the elements for the new list.- Returns:
- the new symbolic-list.
-
fromMap
public static SList fromMap(SourceLocation location, Map<? extends Sexpr<?>, ? extends Sexpr<?>> map) This method creates a new two-dimensional list from the given map.The result will be a list of lists. Each inner list will correspond to a single entry in the map. Each inner list will have exactly two elements. The first element is the key from the map entry. The second element is the value from the map entry.
- Parameters:
location- will be the location() of this list.map- contains the entries to add to the list.- Returns:
- the new symbolic-list.
-
fromMap
public static SList fromMap(SourceLocation location, Map<? extends Sexpr<?>, ? extends Sexpr<?>> map, Sexpr<?> separator) This method creates a new two-dimensional list from the given map.The result will be a list of lists. Each inner list will correspond to a single entry in the map. Each inner list will have exactly three elements. The first element will be the key from the map entry. the second element will be the given separator. The third element will be the value from the map entry.
- Parameters:
location- will be the location() of this list.map- contains the entries to add to the list.separator- will be used as the key-value separator.- Returns:
- the new symbolic-list.
-
get
-
isAtom
public boolean isAtom()This method determines whether this object is a SAtom. -
isList
public boolean isList()This method determines whether this object is a SList. -
first
This method retrieves the first element of this list.- Returns:
- the first element, or null, if the list is empty.
-
last
This method retrieves the last element of this list.- Returns:
- the last element, or null, if the list is empty.
-
location
This method retrieves an object describing the source from which this object we obtained. -
mutator
This method obtains a mutator that can be used to non-destructively modify the tree rooted at this node.- Returns:
- the mutator.
-
size
public int size()- Specified by:
sizein interfaceCollection<Sexpr<?>>- Specified by:
sizein interfaceList<Sexpr<?>>- Specified by:
sizein classAbstractCollection<Sexpr<?>>
-
tail
This method retrieves the sub-list containing all of the elements of this list, except for the first element in linear-time.- Returns:
- the tail sub-list.
-
bfs
This method performs a breadth-first-search of the tree rooted at this node. -
dfs
This method performs a depth-first-search of the tree rooted at this node. -
preorder
This method performs a pre-order-search of the tree rooted at this node. -
postorder
This method performs a post-order-search of the tree rooted at this node. -
traverse
This method performs a traversal of the tree rooted at this node. -
asMap
This method retrieves this value, as a map.This list must be a list of sub-lists. Each sub-list will correspond to an entry in the new map. The first element in the sub-list will be used as a map-key. The last element in the sub-list will be used as a map-value. If the same map-key occurs multiple times, the last entry will prevail.
- Returns:
- the immutable value, if possible.
-
treeHeight
public int treeHeight()This method determines the height of the tree rooted at this node.This is a constant-time operation.
- Specified by:
treeHeightin interfaceSexpr<SList>- Returns:
- the height of this tree.
-
treeLeafCount
public int treeLeafCount()This method counts the leaf nodes in the tree rooted at this node.This is a constant-time operation.
- Specified by:
treeLeafCountin interfaceSexpr<SList>- Returns:
- the number of leaf nodes.
-
treeSize
public int treeSize()This method counts the nodes in the tree rooted at this node.This is a constant-time operation.
-
equals
- Specified by:
equalsin interfaceCollection<Sexpr<?>>- Specified by:
equalsin interfaceList<Sexpr<?>>- Overrides:
equalsin classAbstractList<Sexpr<?>>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Sexpr<?>>- Specified by:
hashCodein interfaceList<Sexpr<?>>- Overrides:
hashCodein classAbstractList<Sexpr<?>>
-
toString
This method retrieves the textual representation of this symbolic expression. -
parse
This method converts the textual representation of a SList to an actual corresponding SList object.This method inserts an implicit symbolic-list into the input. For example, the input "(1 2) (3 4)" will produce a SList equivalent to "((1 2) (3 4))".
- Parameters:
location- is a human-readable string indicating where the input came form.input- is the input to parse.- Returns:
- the resulting symbolic-list.
-
parse
This method converts the textual representation of a SList to an actual corresponding SList object.This method inserts an implicit symbolic-list into the input. For example, the input "(1 2) (3 4)" will produce a SList equivalent to "((1 2) (3 4))".
- Parameters:
input- is the input to parse.- Returns:
- the resulting symbolic-list.
-
parseResource
This method converts the textual representation of a resource file to an actual corresponding SList object.See method parse(*) for more parsing details.
- Parameters:
path- is the path to the resource file.- Returns:
- the new symbolic-list.
- Throws:
IOException- if the resource cannot be read.
-
parseFile
This method converts the textual representation of a text file to an actual corresponding SList object.See method parse(*) for more parsing details.
- Parameters:
file- is the path to the file.- Returns:
- the new symbolic-list.
- Throws:
IOException- if the resource cannot be read.
-