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 class
An 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.boolean
This method performs a breadth-first-search of the tree rooted at this node.static SList
copyOf
(SourceLocation location, Iterable<? extends Sexpr<?>> list) Factory Method.static SList
copyOf
(SourceLocation location, Iterator<? extends Sexpr<?>> stream) Factory Method.static SList
copyOf
(SourceLocation location, Stream<? extends Sexpr<?>> stream) Factory Method.static SList
Factory Method.static SList
Factory Method.static SList
Factory Method.boolean
This method performs a depth-first-search of the tree rooted at this node.final boolean
first()
This method retrieves the first element of this list.static SList
fromMap
(SourceLocation location, Map<? extends Sexpr<?>, ? extends Sexpr<?>> map) This method creates a new two-dimensional list from the given map.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.get
(int i) int
hashCode()
boolean
isAtom()
This method determines whether this object is a SAtom.boolean
isList()
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 SList
Factory Method.static SList
of
(SourceLocation location, Sexpr<?>... elements) Factory Method.static SList
This method converts the textual representation of a SList to an actual corresponding SList object.static SList
This method converts the textual representation of a SList to an actual corresponding SList object.static SList
This method converts the textual representation of a text file to an actual corresponding SList object.static SList
parseResource
(String path) This method converts the textual representation of a resource file to an actual corresponding SList object.boolean
This method performs a post-order-search of the tree rooted at this node.boolean
This method performs a pre-order-search of the tree rooted at this node.int
size()
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.void
This method performs a traversal of the tree rooted at this node.int
This method determines the height of the tree rooted at this node.int
This method counts the leaf nodes in the tree rooted at this node.int
treeSize()
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, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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:
size
in interfaceCollection<Sexpr<?>>
- Specified by:
size
in interfaceList<Sexpr<?>>
- Specified by:
size
in 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:
treeHeight
in 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:
treeLeafCount
in 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:
equals
in interfaceCollection<Sexpr<?>>
- Specified by:
equals
in interfaceList<Sexpr<?>>
- Overrides:
equals
in classAbstractList<Sexpr<?>>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<Sexpr<?>>
- Specified by:
hashCode
in interfaceList<Sexpr<?>>
- Overrides:
hashCode
in 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.
-