Package me.autobot.lib.server.topica
Class Topica.Database.Topic
java.lang.Object
me.autobot.lib.server.topica.Topica.Database.Topic
- Enclosing class:
- Topica.Database
A topic of the database.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback class for when a topic is updated. -
Constructor Summary
ConstructorsConstructorDescriptionTopic(byte type, byte[] data) Creates a dummy topic that is not added to the Database instance.Creates a new topic from a boolean.Creates a new topic.Creates a new topic from a double.Creates a new topic from a float.Creates a new topic from a int.Creates a new topic from a long.Creates a new topic from a string.Topic(String path, Topica.Database.EncodeableTopic data) Creates a new topic from a custom encodeable topic. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a callback to the topic.voidbind(BooleanSupplier supplier) Binds the topic to a supplier.voidbind(DoubleSupplier supplier) Binds the topic to a supplier.voidbind(IntSupplier supplier) Binds the topic to a supplier.voidbind(LongSupplier supplier) Binds the topic to a supplier.voidbind(ByteSupplier supplier) Binds the topic to a supplier.voidbind(FloatSupplier supplier) Binds the topic to a supplier.voidbind(ShortSupplier supplier) Binds the topic to a supplier.voidbind(StringSupplier supplier) Binds the topic to a supplier.voidbindLoopTime(long time) Sets the update time of the topic.booleanGets the data of the topic as a boolean.doubleGets the data of the topic as a double.floatGets the data of the topic as a float.intgetAsInt()Gets the data of the topic as an int.longGets the data of the topic as a long.Gets the data of the topic as a string.byte[]getData()Gets the data of the topic as a byte array.<T extends Topica.Database.EncodeableTopic>
TGets the data of the topic as a custom encodeable topic.getName()Get the name/path of the topic.getPath()Gets the path of the topic.bytegetType()Gets the type of the topic.voidRemoves a callback from the topic.protected voidSends a notification to all callbacks that the topic has been updated.voidupdate(boolean data) Updates the data of the topic.voidupdate(byte[] data) Updates the data of the topic.voidupdate(double data) Updates the data of the topic.voidupdate(float data) Updates the data of the topic.voidupdate(int data) Updates the data of the topic.voidupdate(long data) Updates the data of the topic.voidUpdates the data of the topic.
-
Constructor Details
-
Topic
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 datadata- The raw byte data, can also pass `new byte[0]` and use `this#update()`.
-
Topic
Creates a new topic from a int.- Parameters:
path- The path of the topic.data- The data of the topic as an int.
-
Topic
Creates a new topic from a long.- Parameters:
path- The path of the topic.data- The data of the topic as a long.
-
Topic
Creates a new topic from a float.- Parameters:
path- The path of the topic.data- The data of the topic as a float.
-
Topic
Creates a new topic from a double.- Parameters:
path- The path of the topic.data- The data of the topic as a double.
-
Topic
Creates a new topic from a string.- Parameters:
path- The path of the topic.data- The data of the topic as a string.
-
Topic
Creates a new topic from a boolean.- Parameters:
path- The path of the topic.data- The data of the topic as a boolean.
-
Topic
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
Adds a callback to the topic.- Parameters:
callback- The callback to add.
-
removeCallback
Removes a callback from the topic.- Parameters:
callback- The callback to remove.
-
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
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
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
Gets the data of the topic as a custom encodeable topic.- Type Parameters:
T- The type of the encodeable topic. Must implementTopica.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
Get the name/path of the topic.- Returns:
- The name/path of the topic.
-
bind
Binds the topic to a supplier.- Parameters:
supplier- The supplier to bind to.
-
bind
Binds the topic to a supplier.- Parameters:
supplier- The supplier to bind to.
-
bind
Binds the topic to a supplier.- Parameters:
supplier- The supplier to bind to.
-
bind
Binds the topic to a supplier.- Parameters:
supplier- The supplier to bind to.
-
bind
Binds the topic to a supplier.- Parameters:
supplier- The supplier to bind to.
-
bind
Binds the topic to a supplier.- Parameters:
supplier- The supplier to bind to.
-
bind
Binds the topic to a supplier.- Parameters:
supplier- The supplier to bind to.
-
bind
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.
-