Top Description Fields Constructors Methods
org.freedesktop.dbus.types

public final Class VariantBuilder

extends Object
Class Inheritance
Imports
org.freedesktop.dbus.Marshalling, org.freedesktop.dbus.messages.constants.ArgumentType, java.util.*

Builder to create Variants for parameterized types like Collections or Maps more easily.

When working with Variants you can use the default constructor which is taking your object, but that will not work if you use Maps/Collections because the actual type(s) used inside of those objects are not known on runtime (due to Java type erasure).

In this case you can use this builder providing the Class type you want to have inside of your Variant (e.g. Map.class) and the generic class types used inside of the Map.

Example:

  VariantBuilder.of(Map.class).withGenericTypes(String.class, Integer.class).create(myMap);

Author
hypfvieh
Since
5.1.1 - 2024-08-16

Field Summary

Modifier and TypeField and Description
private final Class<?>
private final List<Class<?>>

Constructor Summary

AccessConstructor and Description
private
VariantBuilder(Class<?> _baseClass)

Method Summary

Modifier and TypeMethod and Description
public <
Type inside of the Variant
X
>
Variant<X>

Returns:

Variant
create
(X
data to store in Variant
_data
)

Create the Variant instance using the provided data object.

public static VariantBuilder

Returns:

new instance
of
(Class<?>
class to use, never null
_clz
)

Create a new instance using the given class as starting point.

public VariantBuilder

Returns:

this
withGenericTypes
(Class<?>...
generic classes to add
_clz
)

Add one or more generic types.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseClassback to summary
private final Class<?> baseClass
genericTypesback to summary
private final List<Class<?>> genericTypes

Constructor Detail

VariantBuilderback to summary
private VariantBuilder(Class<?> _baseClass)

Method Detail

createback to summary
public <X> Variant<X> create(X _data)

Create the Variant instance using the provided data object.

Parameters
<X>
Type inside of the Variant
_data:X

data to store in Variant

Returns:Variant<X>

Variant

Exceptions
IllegalArgumentException:
when provided data object is not compatible with class given in constuctor
NullPointerException:
when null is given
ofback to summary
public static VariantBuilder of(Class<?> _clz)

Create a new instance using the given class as starting point.

If you want to create Variant containing a Map or List, this would be Map/List.class.

Parameters
_clz:Class<?>

class to use, never null

Returns:VariantBuilder

new instance

withGenericTypesback to summary
public VariantBuilder withGenericTypes(Class<?>... _clz)

Add one or more generic types.

Use this if you want to create a Variant containing a Map, Collection. You have to provide the data types used inside of your Map/Collection to this method. E.g. you have Map>Integer,String< than you have to provide Integer.class and String.class to this method.

Parameters
_clz:Class<?>[]

generic classes to add

Returns:VariantBuilder

this