diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableString.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableString.java index 9231ecbd..4719a3da 100644 --- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableString.java +++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableString.java @@ -26,32 +26,109 @@ import org.apache.mnemonic.OutOfHybridMemory; import org.apache.mnemonic.RetrieveDurableEntityError; +/** + * This class defines a non-volatile string that can be stored in a durable + * (non-volatile) memory. + */ @DurableEntity public abstract class DurableString implements Durable, Comparable { + /** + * Called after the creation of the object. + * Can be used for initialization logic. + */ @Override public void initializeAfterCreate() { + // Initialization logic after creation } + /** + * Called after the object is restored from durable memory. + * Can be used for restoration logic. + */ @Override public void initializeAfterRestore() { + // Initialization logic after restoration } + /** + * Sets up generic information for the entity. + * + * @param efproxies the array of entity factory proxies + * @param gftypes the array of generic field types + */ @Override public void setupGenericInfo(EntityFactoryProxy[] efproxies, DurableType[] gftypes) { - + // Set up generic info } + /** + * Compares this DurableString to another DurableString. + * + * @param anotherString the other DurableString to compare to + * @return a negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object + */ + @Override public int compareTo(DurableString anotherString) { - int ret = getStr().compareTo(anotherString.getStr()); - return ret; + return getStr().compareTo(anotherString.getStr()); } + /** + * Gets the string value of this DurableString. + * + * @return the string value + * @throws RetrieveDurableEntityError if an error occurs while retrieving the string + */ @DurableGetter public abstract String getStr() throws RetrieveDurableEntityError; + /** + * Sets the string value of this DurableString. + * + * @param str the string value to set + * @param destroy whether to destroy the old value + * @throws OutOfHybridMemory if there is not enough memory to store the string + * @throws RetrieveDurableEntityError if an error occurs while retrieving the string + */ @DurableSetter - public abstract void setStr(String str, boolean destroy) - throws OutOfHybridMemory, RetrieveDurableEntityError; + public abstract void setStr(String str, boolean destroy) throws OutOfHybridMemory, RetrieveDurableEntityError; + + /** + * Checks if this DurableString is equal to another object. + * + * @param obj the object to compare to + * @return true if the objects are equal, false otherwise + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + DurableString that = (DurableString) obj; + return getStr().equals(that.getStr()); + } + /** + * Returns a hash code value for this object. + * + * @return a hash code value for this object + */ + @Override + public int hashCode() { + return getStr().hashCode(); + } + + /** + * Returns a string representation of the object. + * + * @return a string representation of the object + */ + @Override + public String toString() { + return getStr(); + } }