Class EventProperty
java.lang.Object
de.julianweinelt.datacat.dbx.api.events.EventProperty
Represents a generic event property that can hold a value of any type.
Provides utility methods to retrieve the value as different data types.
This class is useful for handling dynamic event properties where the type is not known beforehand.
-
Constructor Summary
ConstructorsConstructorDescriptionEventProperty(Object value) Constructs an EventProperty with the specified value. -
Method Summary
Modifier and TypeMethodDescriptionbooleanRetrieves the stored value as a boolean.doubleasDouble()Retrieves the stored value as a double.floatasFloat()Retrieves the stored value as a float.intasInt()Retrieves the stored value as an int.asString()Retrieves the stored value as a String.<T> TasValue()Retrieves the stored value as the original type using Java's type casting.<T> TgetRaw()Retrieves the raw stored value without any type casting.
-
Constructor Details
-
Method Details
-
asValue
- Type Parameters:
T- The type of object- Parameters:
expectedType- TheClass<T>that is expected to be returned- Returns:
- The stored value cast to the expected type
- Throws:
ClassCastException- if the stored is not a type ofexpectedType
-
asValue
@Experimental public <T> T asValue()Retrieves the stored value as the original type using Java's type casting.Important: This method is experimental, as there are no checks done. If you want to use the type-safe variant, please use
asValue(Class).- Type Parameters:
T- The type of the class- Returns:
- The stored value cast to their original type.
-
asString
Retrieves the stored value as a String. Equivalent to calling `getAs(String.class)`.- Returns:
- The stored value as a String.
- Throws:
ClassCastException- if the value cannot be cast to a String. Example:EventProperty property = new EventProperty("Hello"); String text = property.asString(); // Returns "Hello"
-
asInt
public int asInt()Retrieves the stored value as an int. Equivalent to calling `getAs(Integer.class)`.- Returns:
- The stored value as an int.
- Throws:
ClassCastException- if the value cannot be cast to an Integer.Example:
EventProperty property = new EventProperty(100); int number = property.asInt(); // Returns 100
-
asBoolean
public boolean asBoolean()Retrieves the stored value as a boolean. Equivalent to calling `getAs(Boolean.class)`.- Returns:
- The stored value as a boolean.
- Throws:
ClassCastException- if the value cannot be cast to a Boolean.Example:
EventProperty property = new EventProperty(true); boolean flag = property.asBoolean(); // Returns true
-
asFloat
public float asFloat()Retrieves the stored value as a float. Equivalent to calling `getAs(Float.class)`.- Returns:
- The stored value as a float.
- Throws:
ClassCastException- if the value cannot be cast to a Float.Example:
EventProperty property = new EventProperty(3.14f); float pi = property.asFloat(); // Returns 3.14f
-
asDouble
public double asDouble()Retrieves the stored value as a double. Equivalent to calling `getAs(Double.class)`.- Returns:
- The stored value as a double.
- Throws:
ClassCastException- if the value cannot be cast to a Double.Example:
EventProperty property = new EventProperty(2.718); double e = property.asDouble(); // Returns 2.718
-
getRaw
Retrieves the raw stored value without any type casting.- Returns:
- The stored value as an Object.
Example:
EventProperty property = new EventProperty("Dynamic Value"); Object rawValue = property.getRaw(); // Returns "Dynamic Value"
-