Class ListStore<T extends GObject>
- All Implemented Interfaces:
Proxy
,ListModelJavaList<T>
,Iterable<T>
,Collection<T>
,List<T>
,SequencedCollection<T>
,ListModel<T>
GListStore
is a simple implementation of ListModel
that stores
all items in memory.
It provides insertions, deletions, and lookups in logarithmic time with a fast path for the common case of iterating the list linearly.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ListStore.Builder<B extends ListStore.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
ListStore.ListStoreClass<T extends GObject>
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gio.ListModel
ListModel.ItemsChangedCallback, ListModel.ListModelImpl, ListModel.ListModelInterface
-
Constructor Summary
ConstructorDescriptionListStore
(MemorySegment address) Create a ListStore proxy instance for the provided memory address.Creates a newGListStore
with items of typeitemType
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Appendsitem
to this ListStore.protected ListStore
asParent()
Returns this instance as if it were its parent type.static ListStore.Builder
<? extends ListStore.Builder> builder()
AListStore.Builder
object constructs aListStore
with the specified properties.boolean
Looks up the givenitem
in the list store by looping over the items until the first occurrence ofitem
.boolean
findWithEqualFunc
(T item, EqualFunc equalFunc, @Nullable Out<Integer> position) Looks up the givenitem
in the list store by looping over the items and comparing them withequalFunc
until the first occurrence ofitem
which matches.boolean
findWithEqualFuncFull
(T item, EqualFuncFull equalFunc, @Nullable Out<Integer> position) Like g_list_store_find_with_equal_func() but with an additionaluserData
that is passed toequalFunc
.static Type
getType()
Get the GType of the ListStore classvoid
Insertsitem
into this ListStore atposition
.int
insertSorted
(T item, CompareDataFunc compareFunc) Insertsitem
into this ListStore at a position to be determined by thecompareFunc
.void
Removes all items from this ListStore.void
removeItem
(int position) Removes the item from this ListStore that is atposition
.void
sort
(CompareDataFunc compareFunc) Sort the items in this ListStore according tocompareFunc
.void
Changes this ListStore by removingnRemovals
items and addingnAdditions
items to it.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
Methods inherited from interface org.gnome.gio.ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChanged
Methods inherited from interface io.github.jwharm.javagi.gio.ListModelJavaList
add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray
-
Constructor Details
-
ListStore
Create a ListStore proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
ListStore
Creates a newGListStore
with items of typeitemType
.itemType
must be a subclass ofGObject
.- Parameters:
itemType
- theGType
of items in the list
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
append
Appendsitem
to this ListStore.item
must be of typeGListStore
:item-type.This function takes a ref on
item
.Use g_list_store_splice() to append multiple items at the same time efficiently.
- Parameters:
item
- the new item
-
find
Looks up the givenitem
in the list store by looping over the items until the first occurrence ofitem
. Ifitem
was not found, thenposition
will not be set, and this method will returnfalse
.If you need to compare the two items with a custom comparison function, use g_list_store_find_with_equal_func() with a custom
GEqualFunc
instead.- Parameters:
item
- an itemposition
- the first position ofitem
, if it was found.- Returns:
- Whether this ListStore contains
item
. If it was found,position
will be set to the position whereitem
occurred for the first time.
-
findWithEqualFunc
public boolean findWithEqualFunc(@Nullable T item, EqualFunc equalFunc, @Nullable @Nullable Out<Integer> position) Looks up the givenitem
in the list store by looping over the items and comparing them withequalFunc
until the first occurrence ofitem
which matches. Ifitem
was not found, thenposition
will not be set, and this method will returnfalse
.item
is always passed as second parameter toequalFunc
.Since GLib 2.76 it is possible to pass
NULL
foritem
.- Parameters:
item
- an itemequalFunc
- A custom equality check functionposition
- the first position ofitem
, if it was found.- Returns:
- Whether this ListStore contains
item
. If it was found,position
will be set to the position whereitem
occurred for the first time.
-
findWithEqualFuncFull
public boolean findWithEqualFuncFull(@Nullable T item, EqualFuncFull equalFunc, @Nullable @Nullable Out<Integer> position) Like g_list_store_find_with_equal_func() but with an additionaluserData
that is passed toequalFunc
.item
is always passed as second parameter toequalFunc
.Since GLib 2.76 it is possible to pass
NULL
foritem
.- Parameters:
item
- an itemequalFunc
- A custom equality check functionposition
- the first position ofitem
, if it was found.- Returns:
- Whether this ListStore contains
item
. If it was found,position
will be set to the position whereitem
occurred for the first time.
-
insert
Insertsitem
into this ListStore atposition
.item
must be of typeGListStore
:item-type or derived from it.position
must be smaller than the length of the list, or equal to it to append.This function takes a ref on
item
.Use g_list_store_splice() to insert multiple items at the same time efficiently.
- Parameters:
position
- the position at which to insert the new itemitem
- the new item
-
insertSorted
Insertsitem
into this ListStore at a position to be determined by thecompareFunc
.The list must already be sorted before calling this function or the result is undefined. Usually you would approach this by only ever inserting items by way of this function.
This function takes a ref on
item
.- Parameters:
item
- the new itemcompareFunc
- pairwise comparison function for sorting- Returns:
- the position at which
item
was inserted
-
removeItem
public void removeItem(int position) Removes the item from this ListStore that is atposition
.position
must be smaller than the current length of the list.Use g_list_store_splice() to remove multiple items at the same time efficiently.
- Parameters:
position
- the position of the item that is to be removed
-
removeAll
public void removeAll()Removes all items from this ListStore. -
sort
Sort the items in this ListStore according tocompareFunc
.- Parameters:
compareFunc
- pairwise comparison function for sorting
-
splice
Changes this ListStore by removingnRemovals
items and addingnAdditions
items to it.additions
must containnAdditions
items of typeGListStore
:item-type.null
is not permitted.This function is more efficient than g_list_store_insert() and g_list_store_remove(), because it only emits
GListModel
::items-changed once for the change.This function takes a ref on each item in
additions
.The parameters
position
andnRemovals
must be correct (ie:position
+nRemovals
must be less than or equal to the length of the list at the time this function is called).- Parameters:
position
- the position at which to make the changenRemovals
- the number of items to removeadditions
- the items to add
-
builder
AListStore.Builder
object constructs aListStore
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withListStore.Builder.build()
.
-