Class List<E>

Type Parameters:
E - The element type must be a MemorySegment, a String, a primitive value, or implement the Proxy interface. It is assumed that integers are stored in the pointer with GINT_TO_POINTER() and GPOINTER_TO_INT().
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, SequencedCollection<E>, Proxy

@NullMarked public class List<E> extends AbstractSequentialList<@Nullable E> implements Proxy
Java wrapper for GLib.List that implements List.
  • Constructor Details

    • List

      public List(@Nullable MemorySegment address, Function<@Nullable MemorySegment, E> make, @Nullable Consumer<@Nullable E> free, TransferOwnership ownership)
      Create a new GLib.List wrapper.
      Parameters:
      address - the memory address of the head element of the List
      make - a function to construct element instances
      free - a function to free element instances. If ownership is "none" or "container", this can safely be set to null.
      ownership - whether to free memory automatically
    • List

      public List(Function<@Nullable MemorySegment, E> make, @Nullable Consumer<E> free, TransferOwnership ownership)
      Create a wrapper for a new, empty GLib.List.
      Parameters:
      make - a function to construct element instances
      free - a function to free element instances. If ownership is "none" or "container", this can safely be set to null.
      ownership - whether to free memory automatically
    • List

      public List(@Nullable MemorySegment address, Function<@Nullable MemorySegment, E> make, TransferOwnership ownership)
      Create a new GLib.List wrapper.
      Parameters:
      address - the memory address of the head element of the List
      make - a function to construct element instances
      ownership - whether to free memory automatically
  • Method Details

    • setOwnership

      public void setOwnership(TransferOwnership ownership)
      Change ownership status of this list
      Parameters:
      ownership - the new ownership status
    • listIterator

      public ListIterator<E> listIterator(int index)
      Returns a list iterator over the elements in this GLib.List (in proper sequence).
      Specified by:
      listIterator in interface List<E>
      Specified by:
      listIterator in class AbstractSequentialList<@Nullable E>
      Parameters:
      index - index of first element to be returned from the list iterator (by a call to the next method)
      Returns:
      a list iterator over the elements in this list (in proper sequence).
    • size

      public int size()
      Retrieve the size of the list. This is an expensive operation for long lists, because the entire length must be traversed.
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface List<E>
      Specified by:
      size in class AbstractCollection<E>
      Returns:
      the length of the list
    • isEmpty

      public boolean isEmpty()
      Checks if the list has no elements (the head of the list is null).
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
      Overrides:
      isEmpty in class AbstractCollection<E>
      Returns:
      whether the list is empty
    • handle

      public MemorySegment handle()
      Returns the memory address of the head of the list. This address can change if the list is modified.
      Specified by:
      handle in interface Proxy
      Returns:
      the memory address of the current GLib.List head, or MemorySegment.NULL if the head is null.
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout of one list node