Class Topica.Database.Topic

java.lang.Object
me.autobot.lib.server.topica.Topica.Database.Topic
Enclosing class:
Topica.Database

public static class Topica.Database.Topic extends Object
A topic of the database.
  • Constructor Details

    • Topic

      public Topic(String path, byte type, byte[] data)
      Creates a new topic.
      Parameters:
      path - The path of the topic. This is the unique identifier of the topic.
      data - The data of the topic as a byte array. This is the value of the topic.
    • Topic

      public Topic(byte type, byte[] data)
      Creates a dummy topic that is not added to the Database instance.
      Parameters:
      type - The type of the data
      data - The raw byte data, can also pass `new byte[0]` and use `this#update()`.
    • Topic

      public Topic(String path, int data)
      Creates a new topic from a int.
      Parameters:
      path - The path of the topic.
      data - The data of the topic as an int.
    • Topic

      public Topic(String path, long data)
      Creates a new topic from a long.
      Parameters:
      path - The path of the topic.
      data - The data of the topic as a long.
    • Topic

      public Topic(String path, float data)
      Creates a new topic from a float.
      Parameters:
      path - The path of the topic.
      data - The data of the topic as a float.
    • Topic

      public Topic(String path, double data)
      Creates a new topic from a double.
      Parameters:
      path - The path of the topic.
      data - The data of the topic as a double.
    • Topic

      public Topic(String path, String data)
      Creates a new topic from a string.
      Parameters:
      path - The path of the topic.
      data - The data of the topic as a string.
    • Topic

      public Topic(String path, boolean data)
      Creates a new topic from a boolean.
      Parameters:
      path - The path of the topic.
      data - The data of the topic as a boolean.
    • Topic

      public Topic(String path, Topica.Database.EncodeableTopic data)
      Creates a new topic from a custom encodeable topic.
      Parameters:
      path - The path of the topic.
      data - The data of the topic as a custom encodeable topic.
  • Method Details

    • addCallback

      public void addCallback(Topica.Database.Topic.UpdateCallback callback)
      Adds a callback to the topic.
      Parameters:
      callback - The callback to add.
    • removeCallback

      public void removeCallback(Topica.Database.Topic.UpdateCallback callback)
      Removes a callback from the topic.
      Parameters:
      callback - The callback to remove.
    • getPath

      public String getPath()
      Gets the path of the topic.
      Returns:
      The path of the topic.
    • getData

      public byte[] getData()
      Gets the data of the topic as a byte array.
      Returns:
      The data of the topic as a byte array.
    • getAsInt

      public int getAsInt()
      Gets the data of the topic as an int.
      Returns:
      The data of the topic as an int.
    • getAsLong

      public long getAsLong()
      Gets the data of the topic as a long.
      Returns:
      The data of the topic as a long.
    • getAsFloat

      public float getAsFloat()
      Gets the data of the topic as a float.
      Returns:
      The data of the topic as a float.
    • getAsDouble

      public double getAsDouble()
      Gets the data of the topic as a double.
      Returns:
      The data of the topic as a double.
    • getAsString

      public String getAsString()
      Gets the data of the topic as a string.
      Returns:
      The data of the topic as a string.
    • getAsBoolean

      public boolean getAsBoolean()
      Gets the data of the topic as a boolean.
      Returns:
      The data of the topic as a boolean.
    • update

      public void update(int data)
      Updates the data of the topic.
      Parameters:
      data - The new data.
    • update

      public void update(long data)
      Updates the data of the topic.
      Parameters:
      data - The new data.
    • update

      public void update(float data)
      Updates the data of the topic.
      Parameters:
      data - The new data.
    • update

      public void update(double data)
      Updates the data of the topic.
      Parameters:
      data - The new data.
    • update

      public void update(String data)
      Updates the data of the topic.
      Parameters:
      data - The new data.
    • update

      public void update(boolean data)
      Updates the data of the topic.
      Parameters:
      data - The new data.
    • update

      public void update(byte[] data)
      Updates the data of the topic.
      Parameters:
      data - The new data.
    • runCallbacks

      protected void runCallbacks()
      Sends a notification to all callbacks that the topic has been updated.
    • getEncodeable

      public <T extends Topica.Database.EncodeableTopic> T getEncodeable()
      Gets the data of the topic as a custom encodeable topic.
      Type Parameters:
      T - The type of the encodeable topic. Must implement Topica.Database.EncodeableTopic.
      Returns:
      The data of the topic as a custom encodeable topic.
    • getType

      public byte getType()
      Gets the type of the topic.
      Returns:
      The type of the topic.
    • getName

      public String getName()
      Get the name/path of the topic.
      Returns:
      The name/path of the topic.
    • bind

      public void bind(ByteSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bind

      public void bind(ShortSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bind

      public void bind(IntSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bind

      public void bind(LongSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bind

      public void bind(FloatSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bind

      public void bind(DoubleSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bind

      public void bind(StringSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bind

      public void bind(BooleanSupplier supplier)
      Binds the topic to a supplier.
      Parameters:
      supplier - The supplier to bind to.
    • bindLoopTime

      public void bindLoopTime(long time)
      Sets the update time of the topic.
      Parameters:
      time - The time to update the topic.