Class ListStore<T extends GObject>

All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, ListModel<T>, Proxy, ListModelJavaList<T>, ListModelJavaListMutable<T>

@Generated("org.javagi.JavaGI") public class ListStore<T extends GObject> extends GObject implements ListModel<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.

  • Constructor Details

    • ListStore

      public ListStore(MemorySegment address)
      Create a ListStore instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • ListStore

      public ListStore(Type itemType)
      Creates a new GListStore with items of type itemType. itemType must be a subclass of GObject.
      Parameters:
      itemType - the GType of items in the list
      Since:
      2.44
    • ListStore

      public ListStore()
      Create a new ListStore.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the ListStore class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected ListStore asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • append

      public void append(T item)

      Appends item to store. item must be of type GListStore: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:
      append in interface ListModelJavaListMutable<T extends GObject>
      Parameters:
      item - the new item
      Since:
      2.44
    • find

      public boolean find(T item, @Nullable Out<Integer> position)

      Looks up the given item in the list store by looping over the items until the first occurrence of item. If item was not found, then position will not be set, and this method will return false.

      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 item
      position - the first position of item, if it was found.
      Returns:
      Whether this ListStore contains item. If it was found, position will be set to the position where item occurred 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 item in the list store by looping over the items and comparing them with equalFunc until the first occurrence of item which matches. If item was not found, then position will not be set, and this method will return false.

      item is always passed as second parameter to equalFunc.

      Since GLib 2.76 it is possible to pass NULL for item.

      Parameters:
      item - an item
      equalFunc - A custom equality check function
      position - the first position of item, if it was found.
      Returns:
      Whether this ListStore contains item. If it was found, position will be set to the position where item occurred 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 userData that is passed to equalFunc.

      item is always passed as second parameter to equalFunc.

      Since GLib 2.76 it is possible to pass NULL for item.

      Parameters:
      item - an item
      equalFunc - A custom equality check function
      position - the first position of item, if it was found.
      Returns:
      Whether this ListStore contains item. If it was found, position will be set to the position where item occurred for the first time.
      Since:
      2.74
    • insert

      public void insert(int position, T item)

      Inserts item into this ListStore at position. item must be of type GListStore: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 item
      item - the new item
      Since:
      2.44
    • insertSorted

      public int insertSorted(T item, @Nullable CompareDataFunc compareFunc)

      Inserts item into this ListStore at a position to be determined by the compareFunc.

      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 item
      compareFunc - pairwise comparison function for sorting
      Returns:
      the position at which item was inserted
      Since:
      2.44
    • removeAt

      public void removeAt(int position)

      Removes the item from this ListStore that is at position. 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.

      Specified by:
      removeAt in interface ListModelJavaListMutable<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 from store.
      Since:
      2.44
    • sort

      public void sort(@Nullable CompareDataFunc compareFunc)
      Sort the items in this ListStore according to compareFunc.
      Parameters:
      compareFunc - pairwise comparison function for sorting
      Since:
      2.46
    • splice

      public void splice(int position, int nRemovals, @Nullable GObject @Nullable [] additions)

      Changes this ListStore by removing nRemovals items and adding nAdditions items to it. additions must contain nAdditions items of type GListStore: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 and nRemovals 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 change
      nRemovals - the number of items to remove
      additions - the items to add
      Since:
      2.44
    • builder

      public static ListStore.Builder<? extends ListStore.Builder> builder()
      A ListStore.Builder object constructs a ListStore with the specified properties. Use the various set...() methods to set properties, and finish construction with ListStore.Builder.build().
      Returns:
      the builder object
    • removeItem

      @Deprecated public void removeItem(int position)
      Deprecated.
      renamed to removeAt(int)

      Remove the item from this ListStore that is at position. position must 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