Class EventProperty

java.lang.Object
de.julianweinelt.datacat.dbx.api.events.EventProperty

public final class EventProperty extends Object
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

    Constructors
    Constructor
    Description
    Constructs an EventProperty with the specified value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Retrieves the stored value as a boolean.
    double
    Retrieves the stored value as a double.
    float
    Retrieves the stored value as a float.
    int
    Retrieves the stored value as an int.
    Retrieves the stored value as a String.
    <T> T
    Retrieves the stored value as the original type using Java's type casting.
    <T> T
    asValue(Class<T> expectedType)
     
    Retrieves the raw stored value without any type casting.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventProperty

      EventProperty(Object value)
      Constructs an EventProperty with the specified value.
      Parameters:
      value - Object The value to store in this event property. Can be of any type.

      Example:

           EventProperty property = new EventProperty(42);
       
  • Method Details

    • asValue

      public <T> T asValue(Class<T> expectedType)
      Type Parameters:
      T - The type of object
      Parameters:
      expectedType - The Class<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 of expectedType
    • 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

      public String 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

      public Object 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"