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

public Class Variant<T>

extends Object
Class Inheritance
Imports
org.freedesktop.dbus.Marshalling, org.freedesktop.dbus.exceptions.DBusException, org.freedesktop.dbus.utils.DBusObjects, org.slf4j.Logger, .LoggerFactory, java.lang.reflect.Type, java.util.ArrayList, .List, .Objects

A Wrapper class for Variant values. A method on DBus can send or receive a Variant. This will wrap another value whose type is determined at runtime. The Variant may be parameterized to restrict the types it may accept.

Field Summary

Modifier and TypeField and Description
private final Logger
private final String
private final Type
private final T

Constructor Summary

AccessConstructor and Description
public
Variant(T
The wrapped value.
_value
)

Create a Variant from a basic type object.

public
Variant(T
The wrapped value.
_value
,
Type
The explicit type of the value.
_type
)

Create a Variant.

public
Variant(T
The wrapped value.
_value
,
String
The explicit type of the value, as a dbus type string.
_sig
)

Create a Variant.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

boolean
equals
(Object
other object
_obj
)

Overrides java.lang.Object.equals.

Compare this Variant with another by comparing contents.

public String

Returns:

signature
getSig
()

Return the dbus signature of the wrapped value.

public Type

Returns:

type
getType
()

Return the type of the wrapped value.

public T

Returns:

value
getValue
()

Return the wrapped value.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Format the Variant as a string.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

loggerback to summary
private final Logger logger
sigback to summary
private final String sig
typeback to summary
private final Type type
valueback to summary
private final T value

Constructor Detail

Variantback to summary
public Variant(T _value) throws IllegalArgumentException

Create a Variant from a basic type object.

Parameters
_value:T

The wrapped value.

Exceptions
IllegalArgumentException:
If you try and wrap Null or an object of a non-basic type.
Variantback to summary
public Variant(T _value, Type _type) throws IllegalArgumentException

Create a Variant.

Parameters
_value:T

The wrapped value.

_type:Type

The explicit type of the value.

Exceptions
IllegalArgumentException:
If you try and wrap Null or an object which cannot be sent over DBus.
Variantback to summary
public Variant(T _value, String _sig) throws IllegalArgumentException

Create a Variant.
It is expected that the given value is compatible with the provided DBus signature String.
This constructor is intended to be used when a generic using class/interface should be wrapped.
Map or List are two examples where it is not possible to determine the internal data type (the type represented by a generic placeholder) due to type erasure.
Therefore the only way to properly serialize these Maps/Lists is by providing a suitable signature manually.

Parameters
_value:T

The wrapped value.

_sig:String

The explicit type of the value, as a dbus type string.

Exceptions
IllegalArgumentException:
If you try and wrap Null or an object which cannot be sent over DBus.

Method Detail

equalsback to summary
public boolean equals(Object _obj)

Overrides java.lang.Object.equals.

Compare this Variant with another by comparing contents.

Parameters
_obj:Object

other object

Returns:boolean

boolean

Annotations
@Override
getSigback to summary
public String getSig()

Return the dbus signature of the wrapped value.

Returns:String

signature

getTypeback to summary
public Type getType()

Return the type of the wrapped value.

Returns:Type

type

getValueback to summary
public T getValue()

Return the wrapped value.

Returns:T

value

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Format the Variant as a string.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override