Package org.gnome.glib
Class Queue
java.lang.Object
io.github.jwharm.javagi.base.ProxyInstance
org.gnome.glib.Queue
- All Implemented Interfaces:
Proxy
Contains the public fields of a
[Queue][glib-Double-ended-Queues].
-
Constructor Summary
ConstructorDescriptionQueue()
Allocate a new Queue.Queue
(int length) Allocate a new Queue with the fields set to the provided values.Allocate a new Queue with the fields set to the provided values.Allocate a new Queue.Queue
(MemorySegment address) Create a Queue proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all the elements in this Queue.void
Convenience method, which frees all the memory used by aGQueue
, and calls the providedfreeFunc
on each item in theGQueue
.copy()
Copies a this Queue.void
deleteLink
(List<MemorySegment> link) Removeslink
from this Queue and frees it.find
(@Nullable MemorySegment data) Finds the first link in this Queue which containsdata
.findCustom
(@Nullable MemorySegment data, CompareFunc func) Finds an element in aGQueue
, using a supplied function to find the desired element.void
Callsfunc
for each element in the queue passinguserData
to the function.void
free()
Frees the memory allocated for theGQueue
.void
freeFull()
Convenience method, which frees all the memory used by aGQueue
, and calls the specified destroy function on every element's data.int
Returns the number of items in this Queue.static MemoryLayout
The memory layout of the native struct.int
index
(@Nullable MemorySegment data) Returns the position of the first element in this Queue which containsdata
.void
init()
A statically-allocatedGQueue
must be initialized with this function before it can be used.void
insertAfter
(@Nullable List<MemorySegment> sibling, @Nullable MemorySegment data) Insertsdata
into this Queue aftersibling
.void
insertAfterLink
(@Nullable List<MemorySegment> sibling, List<MemorySegment> link) Insertslink
into this Queue aftersibling
.void
insertBefore
(@Nullable List<MemorySegment> sibling, @Nullable MemorySegment data) Insertsdata
into this Queue beforesibling
.void
insertBeforeLink
(@Nullable List<MemorySegment> sibling, List<MemorySegment> link) Insertslink
into this Queue beforesibling
.void
insertSorted
(@Nullable MemorySegment data, CompareDataFunc func) Insertsdata
into this Queue usingfunc
to determine the new position.boolean
isEmpty()
Returnstrue
if the queue is empty.int
linkIndex
(List<MemorySegment> link) Returns the position oflink
in this Queue.static Queue
new_()
Creates a newGQueue
.peekHead()
Returns the first element of the queue.Returns the first link in this Queue.peekNth
(int n) Returns then
'th element of this Queue.peekNthLink
(int n) Returns the link at the given positionpeekTail()
Returns the last element of the queue.Returns the last link in this Queue.popHead()
Removes the first element of the queue and returns its data.Removes and returns the first element of the queue.popNth
(int n) Removes then
'th element of this Queue and returns its data.popNthLink
(int n) Removes and returns the link at the given position.popTail()
Removes the last element of the queue and returns its data.Removes and returns the last element of the queue.void
pushHead
(@Nullable MemorySegment data) Adds a new element at the head of the queue.void
pushHeadLink
(List<MemorySegment> link) Adds a new element at the head of the queue.void
pushNth
(@Nullable MemorySegment data, int n) Inserts a new element into this Queue at the given position.void
pushNthLink
(int n, List<MemorySegment> link) Insertslink
into this Queue at the given position.void
pushTail
(@Nullable MemorySegment data) Adds a new element at the tail of the queue.void
pushTailLink
(List<MemorySegment> link) Adds a new element at the tail of the queue.int
Read the value of the fieldlength
.boolean
remove
(@Nullable MemorySegment data) Removes the first element in this Queue that containsdata
.int
removeAll
(@Nullable MemorySegment data) Remove all elements whose data equalsdata
from this Queue.void
reverse()
Reverses the order of the items in this Queue.void
sort
(CompareDataFunc compareFunc) Sorts this Queue usingcompareFunc
.void
unlink
(List<MemorySegment> link) Unlinkslink
so that it will no longer be part of this Queue.void
writeLength
(int length) Write a value in the fieldlength
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Queue
Create a Queue proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Queue
Allocate a new Queue.- Parameters:
arena
- to control the memory allocation scope
-
Queue
public Queue()Allocate a new Queue. The memory is allocated withArena.ofAuto()
. -
Queue
Allocate a new Queue with the fields set to the provided values.- Parameters:
length
- value for the fieldlength
arena
- to control the memory allocation scope
-
Queue
public Queue(int length) Allocate a new Queue with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
length
- value for the fieldlength
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readLength
public int readLength()Read the value of the fieldlength
.- Returns:
- The value of the field
length
-
writeLength
public void writeLength(int length) Write a value in the fieldlength
.- Parameters:
length
- The new value for the fieldlength
-
new_
-
clear
public void clear()Removes all the elements in this Queue. If queue elements contain dynamically-allocated memory, they should be freed first. -
clearFull
public void clearFull()Convenience method, which frees all the memory used by aGQueue
, and calls the providedfreeFunc
on each item in theGQueue
. -
copy
Copies a this Queue. Note that is a shallow copy. If the elements in the queue consist of pointers to data, the pointers are copied, but the actual data is not.- Returns:
- a copy of this Queue
-
deleteLink
Removeslink
from this Queue and frees it.link
must be part of this Queue.- Parameters:
link
- aGList
link that must be part of this Queue
-
find
Finds the first link in this Queue which containsdata
.- Parameters:
data
- data to find- Returns:
- the first link in this Queue which contains
data
-
findCustom
Finds an element in aGQueue
, using a supplied function to find the desired element. It iterates over the queue, calling the given function which should return 0 when the desired element is found. The function takes two gconstpointer arguments, theGQueue
element's data as the first argument and the given user data as the second argument.- Parameters:
data
- user data passed tofunc
func
- aGCompareFunc
to call for each element. It should return 0 when the desired element is found- Returns:
- the found link, or
null
if it wasn't found
-
foreach
Callsfunc
for each element in the queue passinguserData
to the function.It is safe for
func
to remove the element from this Queue, but it must not modify any part of the queue after that element.- Parameters:
func
- the function to call for each element's data
-
free
public void free()Frees the memory allocated for theGQueue
. Only call this function if this Queue was created with g_queue_new(). If queue elements contain dynamically-allocated memory, they should be freed first.If queue elements contain dynamically-allocated memory, you should either use g_queue_free_full() or free them manually first.
-
freeFull
public void freeFull()Convenience method, which frees all the memory used by aGQueue
, and calls the specified destroy function on every element's data.freeFunc
should not modify the queue (eg, by removing the freed element from it). -
getLength
public int getLength()Returns the number of items in this Queue.- Returns:
- the number of items in this Queue
-
index
Returns the position of the first element in this Queue which containsdata
.- Parameters:
data
- the data to find- Returns:
- the position of the first element in this Queue which
contains
data
, or -1 if no element in this Queue containsdata
-
init
public void init()A statically-allocatedGQueue
must be initialized with this function before it can be used. Alternatively you can initialize it withG_QUEUE_INIT
. It is not necessary to initialize queues created with g_queue_new(). -
insertAfter
public void insertAfter(@Nullable @Nullable List<MemorySegment> sibling, @Nullable @Nullable MemorySegment data) Insertsdata
into this Queue aftersibling
.sibling
must be part of this Queue. Since GLib 2.44 anull
sibling pushes the data at the head of the queue.- Parameters:
sibling
- aGList
link that must be part of this Queue, ornull
to push at the head of the queue.data
- the data to insert
-
insertAfterLink
public void insertAfterLink(@Nullable @Nullable List<MemorySegment> sibling, List<MemorySegment> link) Insertslink
into this Queue aftersibling
.sibling
must be part of this Queue.- Parameters:
sibling
- aGList
link that must be part of this Queue, ornull
to push at the head of the queue.link
- aGList
link to insert which must not be part of any other list.
-
insertBefore
public void insertBefore(@Nullable @Nullable List<MemorySegment> sibling, @Nullable @Nullable MemorySegment data) Insertsdata
into this Queue beforesibling
.sibling
must be part of this Queue. Since GLib 2.44 anull
sibling pushes the data at the tail of the queue.- Parameters:
sibling
- aGList
link that must be part of this Queue, ornull
to push at the tail of the queue.data
- the data to insert
-
insertBeforeLink
public void insertBeforeLink(@Nullable @Nullable List<MemorySegment> sibling, List<MemorySegment> link) Insertslink
into this Queue beforesibling
.sibling
must be part of this Queue.- Parameters:
sibling
- aGList
link that must be part of this Queue, ornull
to push at the tail of the queue.link
- aGList
link to insert which must not be part of any other list.
-
insertSorted
Insertsdata
into this Queue usingfunc
to determine the new position.- Parameters:
data
- the data to insertfunc
- theGCompareDataFunc
used to compare elements in the queue. It is called with two elements of the this Queue anduserData
. It should return 0 if the elements are equal, a negative value if the first element comes before the second, and a positive value if the second element comes before the first.
-
isEmpty
public boolean isEmpty()Returnstrue
if the queue is empty.- Returns:
true
if the queue is empty
-
linkIndex
Returns the position oflink
in this Queue.- Parameters:
link
- aGList
link- Returns:
- the position of
link
, or -1 if the link is not part of this Queue
-
peekHead
Returns the first element of the queue.- Returns:
- the data of the first element in the queue, or
null
if the queue is empty
-
peekHeadLink
Returns the first link in this Queue.- Returns:
- the first link in this Queue, or
null
if this Queue is empty
-
peekNth
Returns then
'th element of this Queue.- Parameters:
n
- the position of the element- Returns:
- the data for the
n
'th element of this Queue, ornull
ifn
is off the end of this Queue
-
peekNthLink
Returns the link at the given position- Parameters:
n
- the position of the link- Returns:
- the link at the
n
'th position, ornull
ifn
is off the end of the list
-
peekTail
Returns the last element of the queue.- Returns:
- the data of the last element in the queue, or
null
if the queue is empty
-
peekTailLink
Returns the last link in this Queue.- Returns:
- the last link in this Queue, or
null
if this Queue is empty
-
popHead
Removes the first element of the queue and returns its data.- Returns:
- the data of the first element in the queue, or
null
if the queue is empty
-
popHeadLink
Removes and returns the first element of the queue.- Returns:
- the
GList
element at the head of the queue, ornull
if the queue is empty
-
popNth
Removes then
'th element of this Queue and returns its data.- Parameters:
n
- the position of the element- Returns:
- the element's data, or
null
ifn
is off the end of this Queue
-
popNthLink
Removes and returns the link at the given position.- Parameters:
n
- the link's position- Returns:
- the
n
'th link, ornull
ifn
is off the end of this Queue
-
popTail
Removes the last element of the queue and returns its data.- Returns:
- the data of the last element in the queue, or
null
if the queue is empty
-
popTailLink
Removes and returns the last element of the queue.- Returns:
- the
GList
element at the tail of the queue, ornull
if the queue is empty
-
pushHead
Adds a new element at the head of the queue.- Parameters:
data
- the data for the new element.
-
pushHeadLink
Adds a new element at the head of the queue.- Parameters:
link
- a singleGList
element, not a list with more than one element
-
pushNth
Inserts a new element into this Queue at the given position.- Parameters:
data
- the data for the new elementn
- the position to insert the new element. Ifn
is negative or larger than the number of elements in the this Queue, the element is added to the end of the queue.
-
pushNthLink
Insertslink
into this Queue at the given position.- Parameters:
n
- the position to insert the link. If this is negative or larger than the number of elements in this Queue, the link is added to the end of this Queue.link
- the link to add to this Queue
-
pushTail
Adds a new element at the tail of the queue.- Parameters:
data
- the data for the new element
-
pushTailLink
Adds a new element at the tail of the queue.- Parameters:
link
- a singleGList
element, not a list with more than one element
-
remove
Removes the first element in this Queue that containsdata
.- Parameters:
data
- the data to remove- Returns:
true
ifdata
was found and removed from this Queue
-
removeAll
Remove all elements whose data equalsdata
from this Queue.- Parameters:
data
- the data to remove- Returns:
- the number of elements removed from this Queue
-
reverse
public void reverse()Reverses the order of the items in this Queue. -
sort
Sorts this Queue usingcompareFunc
.- Parameters:
compareFunc
- theGCompareDataFunc
used to sort this Queue. This function is passed two elements of the queue and should return 0 if they are equal, a negative value if the first comes before the second, and a positive value if the second comes before the first.
-
unlink
Unlinkslink
so that it will no longer be part of this Queue. The link is not freed.link
must be part of this Queue.- Parameters:
link
- aGList
link that must be part of this Queue
-