Package com.github.javaparser.ast
Class NodeList<N extends Node>
- java.lang.Object
-
- com.github.javaparser.ast.NodeList<N>
-
- Type Parameters:
N- the type of nodes contained.
- All Implemented Interfaces:
Observable,Visitable,HasParentNode<NodeList<N>>,Iterable<N>,Collection<N>,List<N>
public class NodeList<N extends Node> extends Object implements List<N>, Iterable<N>, HasParentNode<NodeList<N>>, Visitable, Observable
A list of nodes. It usually has a parent node. Unlike normal Nodes, this does not mean that it is a child of that parent. Instead, this list will make every node it contains a child of its parent. This way, a NodeList does not create an extra level inside the AST.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <R,A>
Raccept(GenericVisitor<R,A> v, A arg)Accept method for visitor support.<A> voidaccept(VoidVisitor<A> v, A arg)Accept method for visitor support.voidadd(int index, N node)booleanadd(N node)booleanaddAll(int index, Collection<? extends N> c)voidaddAll(NodeList<N> otherList)booleanaddAll(Collection<? extends N> c)voidclear()booleancontains(Object o)booleancontains(N node)booleancontainsAll(Collection<?> c)booleanequals(Object o)voidforEach(Consumer<? super N> action)Nget(int i)Optional<Node>getParentNode()Return the parent node or null, if no parent is set.NodegetParentNodeForChildren()this for everything except NodeLists.inthashCode()voidifNonEmpty(Consumer<? super NodeList<N>> consumer)intindexOf(Object o)booleanisEmpty()booleanisNonEmpty()booleanisRegistered(AstObserver observer)Was this observer registered? Note that equals is used to determine if the given observer was registered.Iterator<N>iterator()intlastIndexOf(Object o)ListIterator<N>listIterator()ListIterator<N>listIterator(int index)static <X extends Node>
NodeList<X>nodeList(NodeList<X> nodes)static <X extends Node>
NodeList<X>nodeList(Collection<X> nodes)static <X extends Node>
NodeList<X>nodeList(X... nodes)Stream<N>parallelStream()voidregister(AstObserver observer)Register an observer.Nremove(int index)booleanremove(Node node)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanremoveIf(Predicate<? super N> filter)booleanreplace(N old, N replacement)Replaces the first node that is equal to "old" with "replacement".voidreplaceAll(UnaryOperator<N> operator)booleanretainAll(Collection<?> c)Nset(int index, N element)NodeList<N>setParentNode(Node parentNode)Sets the parentNodeintsize()voidsort(Comparator<? super N> comparator)Spliterator<N>spliterator()List<N>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)static <T extends Node>
Collector<T,NodeList<T>,NodeList<T>>toNodeList()StringtoString()voidunregister(AstObserver observer)Unregister an observer.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
stream, toArray
-
Methods inherited from interface com.github.javaparser.HasParentNode
getAncestorOfType
-
-
-
-
Method Detail
-
add
public boolean add(N node)
-
remove
public boolean remove(Node node)
-
nodeList
@SafeVarargs public static <X extends Node> NodeList<X> nodeList(X... nodes)
-
nodeList
public static <X extends Node> NodeList<X> nodeList(Collection<X> nodes)
-
contains
public boolean contains(N node)
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
sort
public void sort(Comparator<? super N> comparator)
-
getParentNode
public Optional<Node> getParentNode()
Description copied from interface:HasParentNodeReturn the parent node or null, if no parent is set.- Specified by:
getParentNodein interfaceHasParentNode<N extends Node>
-
setParentNode
public NodeList<N> setParentNode(Node parentNode)
Sets the parentNode- Specified by:
setParentNodein interfaceHasParentNode<N extends Node>- Parameters:
parentNode- the parentNode- Returns:
- this, the NodeList
-
getParentNodeForChildren
public Node getParentNodeForChildren()
Description copied from interface:HasParentNodethis for everything except NodeLists. NodeLists use their parent as their children parent.- Specified by:
getParentNodeForChildrenin interfaceHasParentNode<N extends Node>
-
accept
public <R,A> R accept(GenericVisitor<R,A> v, A arg)
Description copied from interface:VisitableAccept method for visitor support.- Specified by:
acceptin interfaceVisitable- Type Parameters:
R- the type of the return value of the visitorA- the type the user argument passed to the visitor- Parameters:
v- the visitor implementationarg- the argument passed to the visitor (of type A)- Returns:
- the result of the visit (of type R)
-
accept
public <A> void accept(VoidVisitor<A> v, A arg)
Description copied from interface:VisitableAccept method for visitor support.
-
forEach
public void forEach(Consumer<? super N> action)
- Specified by:
forEachin interfaceIterable<N extends Node>- See Also:
Iterable.forEach(java.util.function.Consumer)
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<N extends Node>- Specified by:
containsin interfaceList<N extends Node>- See Also:
List.contains(java.lang.Object)
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<N extends Node>- Specified by:
toArrayin interfaceList<N extends Node>- See Also:
List.toArray()
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<N extends Node>- Specified by:
toArrayin interfaceList<N extends Node>- See Also:
List.toArray(java.lang.Object[])
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceCollection<N extends Node>- Specified by:
removein interfaceList<N extends Node>- See Also:
List.remove(java.lang.Object)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<N extends Node>- Specified by:
containsAllin interfaceList<N extends Node>- See Also:
List.containsAll(java.util.Collection)
-
addAll
public boolean addAll(Collection<? extends N> c)
- Specified by:
addAllin interfaceCollection<N extends Node>- Specified by:
addAllin interfaceList<N extends Node>- See Also:
List.addAll(java.util.Collection)
-
addAll
public boolean addAll(int index, Collection<? extends N> c)- Specified by:
addAllin interfaceList<N extends Node>- See Also:
List.addAll(int, java.util.Collection)
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<N extends Node>- Specified by:
removeAllin interfaceList<N extends Node>- See Also:
List.removeAll(java.util.Collection)
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<N extends Node>- Specified by:
retainAllin interfaceList<N extends Node>- See Also:
List.retainAll(java.util.Collection)
-
replaceAll
public void replaceAll(UnaryOperator<N> operator)
- Specified by:
replaceAllin interfaceList<N extends Node>- See Also:
List.replaceAll(java.util.function.UnaryOperator)
-
removeIf
public boolean removeIf(Predicate<? super N> filter)
- Specified by:
removeIfin interfaceCollection<N extends Node>- See Also:
Collection.removeIf(java.util.function.Predicate)
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<N extends Node>- Specified by:
clearin interfaceList<N extends Node>- See Also:
List.clear()
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
indexOf
public int indexOf(Object o)
- Specified by:
indexOfin interfaceList<N extends Node>- See Also:
List.indexOf(java.lang.Object)
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOfin interfaceList<N extends Node>- See Also:
List.lastIndexOf(java.lang.Object)
-
listIterator
public ListIterator<N> listIterator()
- Specified by:
listIteratorin interfaceList<N extends Node>- See Also:
List.listIterator()
-
listIterator
public ListIterator<N> listIterator(int index)
- Specified by:
listIteratorin interfaceList<N extends Node>- See Also:
List.listIterator(int)
-
parallelStream
public Stream<N> parallelStream()
- Specified by:
parallelStreamin interfaceCollection<N extends Node>- See Also:
Collection.parallelStream()
-
subList
public List<N> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfaceList<N extends Node>- See Also:
List.subList(int, int)
-
spliterator
public Spliterator<N> spliterator()
- Specified by:
spliteratorin interfaceCollection<N extends Node>- Specified by:
spliteratorin interfaceIterable<N extends Node>- Specified by:
spliteratorin interfaceList<N extends Node>- See Also:
List.spliterator()
-
unregister
public void unregister(AstObserver observer)
Description copied from interface:ObservableUnregister an observer. If the given observer was not registered there are no effects.- Specified by:
unregisterin interfaceObservable
-
register
public void register(AstObserver observer)
Description copied from interface:ObservableRegister an observer.- Specified by:
registerin interfaceObservable
-
isRegistered
public boolean isRegistered(AstObserver observer)
Description copied from interface:ObservableWas this observer registered? Note that equals is used to determine if the given observer was registered.- Specified by:
isRegisteredin interfaceObservable
-
replace
public boolean replace(N old, N replacement)
Replaces the first node that is equal to "old" with "replacement".- Returns:
- true if a replacement has happened.
-
isNonEmpty
public boolean isNonEmpty()
- Returns:
- the opposite of isEmpty()
-
-