Class Variants

java.lang.Object
org.javagi.interop.Variants

@NullMarked public class Variants extends Object
  • Constructor Details

    • Variants

      public Variants()
  • Method Details

    • unpack

      public static @Nullable Object unpack(@Nullable Variant v, boolean recursive)
      Unpack a GVariant into a Java Object.
      • A basic primitive type is returned as a Java boxed primitive.
      • A string, object path or type signature is returned as a Java String.
      • A nested GVariant is returned as a Java Variant (when recursive is false) or recursively unpacked (when recursive is true).
      • A Maybe type is returned as either null or the unpacked value.
      • An array is returned as an ArrayList<?> with unpacked values.
      • A dictionary is returned as a HashMap<?, ?> with unpacked entries.
      • A tuple is returned as a ArrayList<Object> with unpacked entries.
      Parameters:
      v - a Variant to unpack
      recursive - whether to recursively unpack nested GVariants
      Returns:
      the unpacked Java Object
    • pack

      public static Variant pack(@Nullable Object o)
      Create a GVariant from a Java Object.
      • a null value is returned as a maybe ("mv") GVariant with value null
      • a boolean is returned as a boolean GVariant
      • a byte is returned as a byte GVariant
      • a char is returned as a (single-character) string GVariant
      • an short is returned as an int16 GVariant
      • an int is returned as an int32 GVariant
      • an long is returned as an int64 GVariant
      • a float or double is returned as a double GVariant
      • a Java String is returned as a string GVariant
      • a Java List or Set is returned as an array GVariant with recursively packed elements
      • a Java Map is returned as a dictionary GVariant with recursively packed entries
      • a Java Optional is returned as a maybe ("m") GVariant with either the packed value or null (with type "mv")
      Note that arrays are not supported, only Lists.
      Parameters:
      o - the Java Object to pack into a GVariant
      Returns:
      the GVariant with the packed Object