Skip to content

Commit

Permalink
Merge pull request #388 from katarinaking/828
Browse files Browse the repository at this point in the history
MNEMONIC-828: DurableString Enhancements
  • Loading branch information
katarinaking committed May 30, 2024
2 parents 056bf72 + 16c7123 commit f2f246a
Showing 1 changed file with 82 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DurableString> {

/**
* 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();
}
}

0 comments on commit f2f246a

Please sign in to comment.