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 org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gio.ListModel
ListModel.ItemsChangedCallback, ListModel.ListModel$Impl, ListModel.ListModelInterfaceNested classes/interfaces inherited from interface org.javagi.gio.ListModelJavaList
ListModelJavaList.SubList<E extends @Nullable GObject,List extends ListModelJavaList<E>> Nested classes/interfaces inherited from interface org.javagi.gio.ListModelJavaListMutable
ListModelJavaListMutable.SubList<E extends @Nullable GObject,List extends ListModelJavaListMutable<E>> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ListStore.ListStore(MemorySegment address) Create a ListStore proxy 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()Returns 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 @Nullable TypegetType()Get the GType of the ListStore classvoidInsertsiteminto 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 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, 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 org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, equals, getFirst, getLast, hashCode, removeFirst, removeLast, replaceAll, reversed, sort, spliteratorMethods inherited from interface org.gnome.gio.ListModel
emitItemsChanged, getItem, getItemType, getNItems, itemsChanged, onItemsChangedMethods inherited from interface org.javagi.gio.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 proxy 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()Creates a new ListStore.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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
Appendsitemtostore.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 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.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 givenitemin 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 additionaluserDatathat 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
Insertsiteminto 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
Insertsiteminto 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 atposition.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 removingnRemovalsitems 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)Removes the item from this ListStore that is atposition.positionmust 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
-
removeAt(int)