Package org.gnome.glib
Class SList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<E>
org.gnome.glib.SList<E>
- Type Parameters:
E
- The element type must be aMemorySegment
, aString
, a primitive value, or implement theProxy
interface.
- All Implemented Interfaces:
Proxy
,Iterable<E>
,Collection<E>
,List<E>
,SequencedCollection<E>
Java wrapper for GLib.SList
that implements
List
.
Because SList is a singly-linked list, attempts to navigate the list
backwards will throw an UnsupportedOperationException
.
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionSList
(MemorySegment address, Function<MemorySegment, E> make, boolean fullOwnership) Create a newGLib.SList
wrapper.SList
(MemorySegment address, Function<MemorySegment, E> make, Consumer<E> free, boolean fullOwnership) Create a newGLib.SList
wrapper.Create a wrapper for a new, emptyGLib.SList
. -
Method Summary
Modifier and TypeMethodDescriptionhandle()
Returns the memory address of the head of the list.boolean
isEmpty()
Checks if the list has no elements (the head of the list isnull
).@NotNull ListIterator
<E> listIterator
(int index) Returns a list iterator over the elements in thisGLib.SList
(in proper sequence).int
size()
Retrieve the size of the list.Methods inherited from class java.util.AbstractSequentialList
add, addAll, get, iterator, remove, set
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
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, addFirst, addLast, contains, containsAll, getFirst, getLast, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Constructor Details
-
SList
public SList(MemorySegment address, Function<MemorySegment, E> make, Consumer<E> free, boolean fullOwnership) Create a newGLib.SList
wrapper.- Parameters:
address
- the memory address of the head element of the SListmake
- a function to construct element instancesfree
- a function to free element instances. IffullOwnership
isfalse
, this can safely be set tonull
.fullOwnership
- whether to free element instances automatically
-
SList
Create a wrapper for a new, emptyGLib.SList
.- Parameters:
make
- a function to construct element instancesfree
- a function to free element instances. IffullOwnership
isfalse
, this can safely be set tonull
.fullOwnership
- whether to free element instances automatically
-
SList
Create a newGLib.SList
wrapper.- Parameters:
address
- the memory address of the head element of the SListmake
- a function to construct element instancesfullOwnership
- whether to free element instances automatically withGLib.free(java.lang.foreign.MemorySegment)
-
-
Method Details
-
listIterator
Returns a list iterator over the elements in thisGLib.SList
(in proper sequence).Because SList is a singly-linked list, the following iterator methods will throw an
UnsupportedOperationException
:- Specified by:
listIterator
in interfaceList<E>
- Specified by:
listIterator
in classAbstractSequentialList<E>
- Parameters:
index
- index of first element to be returned from the list iterator (by a call to thenext
method)- Returns:
- a list iterator over the elements in this list (in proper sequence).
-
size
public int size()Retrieve the size of the list. This is an expensive operation for long lists, because the entire length must be traversed.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
- Returns:
- the length of the list
-
isEmpty
public boolean isEmpty()Checks if the list has no elements (the head of the list isnull
).- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
- Returns:
- whether the list is empty
-
handle
Returns the memory address of the head of the list. This address can change if the list is modified.- Specified by:
handle
in interfaceProxy
- Returns:
- the memory address of the current GLib.SList head, or
MemorySegment.NULL
if the head isnull
.
-