-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add EntityManager interface and Entity class
- Loading branch information
1 parent
1e1a67b
commit a5c9f5a
Showing
2 changed files
with
102 additions
and
265 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
database/src/main/java/com/georgev22/library/utilities/Entity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.georgev22.library.utilities; | ||
|
||
import com.georgev22.library.maps.ConcurrentObjectMap; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* The {@code Entity} interface represents an entity with a unique identifier. | ||
* It provides methods for managing custom data associated with the entity. | ||
* Custom data can be added, retrieved, and accessed using key-value pairs. | ||
*/ | ||
public interface Entity { | ||
|
||
/** | ||
* Returns the unique identifier of the entity. | ||
* | ||
* @return the {@link UUID} representing the entity's ID | ||
*/ | ||
UUID getId(); | ||
|
||
/** | ||
* Adds custom data to the entity with the specified key and value. | ||
* | ||
* @param key the key of the custom data | ||
* @param value the value of the custom data | ||
* @return the updated entity with the added custom data | ||
*/ | ||
default Entity addCustomData(String key, Object value) { | ||
this.getCustomData().append(key, value); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds custom data to the entity with the specified key and value if the key does not already exist. | ||
* | ||
* @param key the key of the custom data | ||
* @param value the value of the custom data | ||
* @return the updated entity with the added custom data (if the key did not already exist) | ||
*/ | ||
default Entity addCustomDataIfNotExists(String key, Object value) { | ||
this.getCustomData().appendIfTrue(key, value, this.getCustomData().containsKey(key)); | ||
return this; | ||
} | ||
|
||
/** | ||
* Retrieves the value of the custom data associated with the specified key. | ||
* | ||
* @param key the key of the custom data | ||
* @param <T> the type of the value to retrieve | ||
* @return the value associated with the specified key, or {@code null} if the key does not exist | ||
*/ | ||
default <T> T getCustomData(String key) { | ||
return (T) getCustomData().get(key); | ||
} | ||
|
||
/** | ||
* Retrieves the map of custom data associated with the entity. | ||
* | ||
* @return the {@link ConcurrentObjectMap} containing the custom data of the entity | ||
*/ | ||
ConcurrentObjectMap<String, Object> getCustomData(); | ||
|
||
} |
Oops, something went wrong.