Package ru.ispras.fortress.data
Class Data
- java.lang.Object
-
- ru.ispras.fortress.data.Data
-
public final class Data extends java.lang.Object
TheData
class is a storage of data being processed. This data will be used as an input or an output parameter of a constraint solver.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
static boolean
equalTypes(Data... args)
Checks whether allData
objects in the specified array have equal types.static boolean
equalValues(Data... args)
Checks whether allData
objects in the specified array have equal values.BitVector
getBitVector()
Returns a BitVector value stored in the data object.boolean
getBoolean()
Returns a boolean value stored in the data object.java.math.BigInteger
getInteger()
Returns a BigInteger value stored in the data object.DataMap
getMap()
Returns aDataMap
value stored in the data object.double
getReal()
Returns a Double value stored in the data object.java.lang.String
getString()
Returns a String value stored in the data object.DataType
getType()
Returns information about the type of the stored value.java.lang.Object
getUserData()
Returns the value of the used-defined property.java.lang.Object
getValue()
Returns an object that holds the data.<T> T
getValue(java.lang.Class<T> clazz)
Returns an object of given type that holds the data.int
hashCode()
boolean
hasValue()
Checks whether a value assigned to the the data object.boolean
isType(DataType type)
Checks whether the stored value has the specified type (comparison is based onDataType
).boolean
isType(DataTypeId typeId)
Checks whether the stored value has the specified type (comparison is based onDataTypeId
).static Data
newBitVector(boolean value)
Creates a data object of the BIT_VECTOR type from a boolean value.static Data
newBitVector(int value, int size)
Creates a data object of the BIT_VECTOR type from an integer value.static Data
newBitVector(long value, int size)
Creates a data object of the BIT_VECTOR type from a long integer value.static Data
newBitVector(java.lang.String bitVectorStr, int radix, int size)
Creates a data object of the BIT_VECTOR type from a string.static Data
newBitVector(java.math.BigInteger value, int size)
Creates a data object of the BIT_VECTOR type from a BigInteger object.static Data
newBitVector(BitVector value)
Creates a data object of the BIT_VECTOR type from a BitVector object.static Data
newBoolean(boolean value)
Creates a data object of the BOOLEAN type from a boolean value.static Data
newInteger(int value)
Creates a data object of the INTEGER type from an integer value.static Data
newInteger(long value)
Creates a data object of the INTEGER type from a long value.static Data
newInteger(java.lang.String text, int radix)
Creates a data object of the INTEGER type from a string.static Data
newInteger(java.math.BigInteger value)
Creates a data object of the INTEGER type from aBigInteger
value.static Data
newMap(DataMap map)
Creates a data object of the MAP type from the specifiedDataMap
object.static Data
newReal(double value)
Creates a data object of the REAL type from an double value.static Data
newString(java.lang.String value)
Creates a data object of the STRING type from a String value.static Data
newUnknown(java.lang.Object value)
Creates a data object from an object value of an unknown type (UNKNOWN will be used as target type).void
setUserData(java.lang.Object obj)
Assigns value to the user-defined property.java.lang.String
toString()
-
-
-
Constructor Detail
-
Data
public Data(DataType type, java.lang.Object value)
Constructs a data object of the specified type and initializes its value with the specified value object.- Parameters:
type
- The type of the data.value
- An object of related type that stores the data.- Throws:
java.lang.IllegalArgumentException
- if thetype
parameter isnull
.
-
-
Method Detail
-
newInteger
public static Data newInteger(java.math.BigInteger value)
Creates a data object of the INTEGER type from aBigInteger
value.- Parameters:
value
- A BitInteger value.- Returns:
- New data object.
- Throws:
java.lang.IllegalArgumentException
- if the parameter equalsnull
.
-
newInteger
public static Data newInteger(long value)
Creates a data object of the INTEGER type from a long value.- Parameters:
value
- A long value.- Returns:
- New data object.
-
newInteger
public static Data newInteger(int value)
Creates a data object of the INTEGER type from an integer value.- Parameters:
value
- An integer value.- Returns:
- New data object.
-
newInteger
public static Data newInteger(java.lang.String text, int radix)
Creates a data object of the INTEGER type from a string.- Parameters:
text
- String to be parsed.radix
- Radix to be used for parsing.- Returns:
- New data object.
- Throws:
java.lang.IllegalArgumentException
- if thetext
parameter equalsnull
.java.lang.NumberFormatException
- if failed to parse the string.
-
newReal
public static Data newReal(double value)
Creates a data object of the REAL type from an double value.- Parameters:
value
- A double value.- Returns:
- An new data object.
-
newString
public static Data newString(java.lang.String value)
Creates a data object of the STRING type from a String value.- Parameters:
value
- A String value.- Returns:
- An new data object.
- Throws:
java.lang.IllegalArgumentException
- if the parameter equalsnull
.
-
newBoolean
public static Data newBoolean(boolean value)
Creates a data object of the BOOLEAN type from a boolean value.- Parameters:
value
- A boolean value.- Returns:
- A new data object.
-
newUnknown
public static Data newUnknown(java.lang.Object value)
Creates a data object from an object value of an unknown type (UNKNOWN will be used as target type). Method for wrapping uninterpreted data that should not be passed to the solver.- Parameters:
value
- A value of an unknown type.- Returns:
- New data object.
-
newBitVector
public static Data newBitVector(java.math.BigInteger value, int size)
Creates a data object of the BIT_VECTOR type from a BigInteger object.- Parameters:
value
- A BigInteger object that stores binary data for a bit vector.size
- The bit vector size (in bits).- Returns:
- A new data object.
- Throws:
java.lang.IllegalArgumentException
- if thevalue
parameter equalsnull
.
-
newBitVector
public static Data newBitVector(BitVector value)
Creates a data object of the BIT_VECTOR type from a BitVector object.- Parameters:
value
- A BitVector object.- Returns:
- A new data object.
- Throws:
java.lang.IllegalArgumentException
- if thevalue
parameter equalsnull
.
-
newBitVector
public static Data newBitVector(java.lang.String bitVectorStr, int radix, int size)
Creates a data object of the BIT_VECTOR type from a string.- Parameters:
bitVectorStr
- Textual representation of the bit vector.radix
- Radix to be used for parsing.size
- Size of the resulting bit vector in bits.- Returns:
- A new data object.
- Throws:
java.lang.IllegalArgumentException
- if thes
parameter equalsnull
.
-
newBitVector
public static Data newBitVector(int value, int size)
Creates a data object of the BIT_VECTOR type from an integer value.- Parameters:
value
- Integer value to be converted.size
- The bit vector size (in bits).- Returns:
- A new data object.
-
newBitVector
public static Data newBitVector(long value, int size)
Creates a data object of the BIT_VECTOR type from a long integer value.- Parameters:
value
- Long integer value to be converted.size
- The bit vector size (in bits).- Returns:
- A new data object.
-
newBitVector
public static Data newBitVector(boolean value)
Creates a data object of the BIT_VECTOR type from a boolean value.- Parameters:
value
- Boolean value to be converted.- Returns:
- A new data object.
-
newMap
public static Data newMap(DataMap map)
Creates a data object of the MAP type from the specifiedDataMap
object.- Parameters:
map
- ADataMap
object.- Returns:
- A new data object.
- Throws:
java.lang.IllegalArgumentException
- if themap
parameter equalsnull
.
-
getType
public DataType getType()
Returns information about the type of the stored value.- Returns:
- A
DataType
object.
-
hasValue
public boolean hasValue()
Checks whether a value assigned to the the data object.- Returns:
- true if a value is assigned or false otherwise.
-
getValue
public java.lang.Object getValue()
Returns an object that holds the data.- Returns:
- A type-dependent object that stores the data.
-
getValue
public <T> T getValue(java.lang.Class<T> clazz)
Returns an object of given type that holds the data.- Type Parameters:
T
- Type of the value object.- Parameters:
clazz
- Class object that describes the type of the value object.- Returns:
- A type-dependent object that stores the data.
-
getUserData
public java.lang.Object getUserData()
Returns the value of the used-defined property.- Returns:
- User-defined object.
-
setUserData
public void setUserData(java.lang.Object obj)
Assigns value to the user-defined property.- Parameters:
obj
- User-defined object.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isType
public boolean isType(DataTypeId typeId)
Checks whether the stored value has the specified type (comparison is based onDataTypeId
).- Parameters:
typeId
-DataTypeId
object the data type is to be compared to.- Returns:
true
if the type matches the type specified by thetypeId
argument orfalse
otherwise.
-
isType
public boolean isType(DataType type)
Checks whether the stored value has the specified type (comparison is based onDataType
).- Parameters:
type
-DataType
object the data type is to be compared to.- Returns:
true
if the type matches the type specified by thetype
argument orfalse
otherwise.
-
getInteger
public java.math.BigInteger getInteger()
Returns a BigInteger value stored in the data object. Applicable to data objects of typeDataTypeId.LOGIC_INTEGER
.- Returns:
- Stored value represented by a BigInteger.
- Throws:
java.lang.IllegalStateException
- if the stored data is not convertible toBigInteger
.
-
getBitVector
public BitVector getBitVector()
Returns a BitVector value stored in the data object. Applicable to data objects of typeDataTypeId.BIT_VECTOR
.
-
getBoolean
public boolean getBoolean()
Returns a boolean value stored in the data object. Applicable to data objects of typeDataTypeId.LOGIC_BOOLEAN
.- Returns:
- Stored value represented by a boolean.
- Throws:
java.lang.IllegalStateException
- if the stored data is not convertible toBoolean
.
-
getReal
public double getReal()
Returns a Double value stored in the data object. Applicable to data objects of typeDataTypeId.LOGIC_REAL
.- Returns:
- Stored value represented by a Double.
- Throws:
java.lang.IllegalStateException
- if the stored data is not convertible toDouble
.
-
getString
public java.lang.String getString()
Returns a String value stored in the data object. Applicable to data objects of typeDataTypeId.LOGIC_STRING
.- Returns:
- Stored value represented by a String.
- Throws:
java.lang.IllegalStateException
- if the stored data is not convertible toString
.
-
getMap
public DataMap getMap()
Returns aDataMap
value stored in the data object. Applicable to data objects of typeDataTypeId.MAP
.- Returns:
- Stored value represented by a
DataMap
. - Throws:
java.lang.IllegalStateException
- if the stored data is not convertible toDataMap
.
-
equalValues
public static boolean equalValues(Data... args)
Checks whether allData
objects in the specified array have equal values.- Parameters:
args
- Array of Data objects to be checked.- Returns:
true
if all objects have equal values orfalse
otherwise.- Throws:
java.lang.IllegalArgumentException
- if any of the arguments equalsnull
.
-
equalTypes
public static boolean equalTypes(Data... args)
Checks whether allData
objects in the specified array have equal types.- Parameters:
args
- Array of Data objects to be checked.- Returns:
true
if all objects have equal types orfalse
otherwise.- Throws:
java.lang.IllegalArgumentException
- if any of the arguments equalsnull
.
-
-