Class ListStore<T extends GObject>
- All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, ListModel<T>, Proxy, ListModelJavaList<T>, ListModelJavaListMutable<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
Nested ClassesModifier and TypeClassDescriptionstatic classListStore.Builder<B extends ListStore.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classListStore.ListStoreClass<T extends GObject>Nested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface ListModel
ListModel.ItemsChangedCallback, ListModel.ListModel$Impl, ListModel.ListModelInterfaceNested classes/interfaces inherited from interface ListModelJavaList
ListModelJavaList.SubList<E,List> Nested classes/interfaces inherited from interface ListModelJavaListMutable
ListModelJavaListMutable.SubList<E,List> -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new ListStore.ListStore(MemorySegment address) Create a ListStore instance for the provided memory address.Creates a newGListStorewith items of typeitemType.itemTypemust be a subclass ofGObject. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppendsitemtostore.itemmust be of typeGListStore:item-type.protected ListStoreasParent()Return this instance as if it were its parent type.static ListStore.Builder<? extends ListStore.Builder> builder()AListStore.Builderobject constructs aListStorewith the specified properties.booleanLooks up the givenitemin the list store by looping over the items until the first occurrence ofitem.Ifitemwas not found, thenpositionwill not be set, and this method will returnfalse.booleanfindWithEqualFunc(@Nullable GObject item, @Nullable EqualFunc equalFunc, @Nullable Out<Integer> position) Looks up the givenitemin the list store by looping over the items and comparing them withequalFuncuntil the first occurrence ofitemwhich matches.booleanfindWithEqualFuncFull(@Nullable GObject item, @Nullable EqualFuncFull equalFunc, @Nullable Out<Integer> position) Like g_list_store_find_with_equal_func() but with an additionaluserDatathat is passed toequalFunc.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the ListStore class.voidInsertsiteminto this ListStore atposition.itemmust be of typeGListStore:item-type or derived from it.intinsertSorted(T item, @Nullable CompareDataFunc compareFunc) Insertsiteminto this ListStore at a position to be determined by thecompareFunc.voidRemoves all items fromstore.voidremoveAt(int position) Removes the item from this ListStore that is atposition.positionmust be smaller than the current length of the list.voidremoveItem(int position) Deprecated.voidsort(@Nullable CompareDataFunc compareFunc) Sort the items in this ListStore according tocompareFunc.voidChanges this ListStore by removingnRemovalsitems and addingnAdditionsitems to it.Methods inherited from class 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, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, 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, withPropertiesMethods inherited from class TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliteratorMethods inherited from interface ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChangedMethods inherited from interface ListModelJavaList
addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, size, toArray, toArray
-
Constructor Details
-
ListStore
Create a ListStore instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
ListStore
Creates a newGListStorewith items of typeitemType.itemTypemust be a subclass ofGObject.- Parameters:
itemType- theGTypeof items in the list- Since:
- 2.44
-
ListStore
public ListStore()Create a new ListStore.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
-
append
Appends
itemtostore.itemmust 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.
- Specified by:
appendin interfaceListModelJavaListMutable<T extends GObject>- Parameters:
item- the new item- Since:
- 2.44
-
find
Looks up the given
itemin the list store by looping over the items until the first occurrence ofitem.Ifitemwas not found, thenpositionwill 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
GEqualFuncinstead.- Parameters:
item- an itemposition- the first position ofitem,if it was found.- Returns:
- Whether this ListStore contains
item.If it was found,positionwill be set to the position whereitemoccurred for the first time. - Since:
- 2.64
-
findWithEqualFunc
public boolean findWithEqualFunc(@Nullable GObject item, @Nullable EqualFunc equalFunc, @Nullable Out<Integer> position) Looks up the given
itemin the list store by looping over the items and comparing them withequalFuncuntil the first occurrence ofitemwhich matches. Ifitemwas not found, thenpositionwill not be set, and this method will returnfalse.itemis always passed as second parameter toequalFunc.Since GLib 2.76 it is possible to pass
NULLforitem.- 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,positionwill be set to the position whereitemoccurred for the first time. - Since:
- 2.64
-
findWithEqualFuncFull
public boolean findWithEqualFuncFull(@Nullable GObject item, @Nullable EqualFuncFull equalFunc, @Nullable Out<Integer> position) Like g_list_store_find_with_equal_func() but with an additional
userDatathat is passed toequalFunc.itemis always passed as second parameter toequalFunc.Since GLib 2.76 it is possible to pass
NULLforitem.- 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,positionwill be set to the position whereitemoccurred for the first time. - Since:
- 2.74
-
insert
Inserts
iteminto this ListStore atposition.itemmust be of typeGListStore:item-type or derived from it.positionmust 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- Since:
- 2.44
-
insertSorted
Inserts
iteminto 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
itemwas inserted - Since:
- 2.44
-
removeAt
public void removeAt(int position) Removes the item from this ListStore that is at
position.positionmust be smaller than the current length of the list.Use g_list_store_splice() to remove multiple items at the same time efficiently.
- Specified by:
removeAtin interfaceListModelJavaListMutable<T extends GObject>- Parameters:
position- the position of the item that is to be removed- Since:
- 2.44
-
removeAll
public void removeAll()Removes all items fromstore.- Since:
- 2.44
-
sort
Sort the items in this ListStore according tocompareFunc.- Parameters:
compareFunc- pairwise comparison function for sorting- Since:
- 2.46
-
splice
Changes this ListStore by removing
nRemovalsitems and addingnAdditionsitems to it.additionsmust containnAdditionsitems of typeGListStore:item-type.nullis 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
positionandnRemovalsmust be correct (ie:position+nRemovalsmust 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- Since:
- 2.44
-
builder
AListStore.Builderobject constructs aListStorewith the specified properties. Use the variousset...()methods to set properties, and finish construction withListStore.Builder.build().- Returns:
- the builder object
-
removeItem
Deprecated.renamed toremoveAt(int)Remove the item from this ListStore that is at
position.positionmust be smaller than the current length of the list.Use
splice(int, int, GObject[])to remove multiple items at the same time efficiently.- Parameters:
position- the position of the item that is to be removed
-
removeAt(int)