-
-
Save stickfigure/10789351 to your computer and use it in GitHub Desktop.
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
/* | |
*/ | |
package st.voo.tick.entity.util; | |
import com.googlecode.objectify.Key; | |
import com.googlecode.objectify.Ref; | |
/** | |
* A simple way to remove some boilerplate from some entity. | |
*/ | |
abstract public class AbstractHasKey<T extends HasKey<T>> implements HasKey<T> | |
{ | |
/* (non-Javadoc) | |
* @see st.voo.tick.entity.util.HasKey#getRef() | |
*/ | |
@Override | |
public Ref<T> getRef() { | |
return Ref.create(getKey()); | |
} | |
/* (non-Javadoc) | |
* @see st.voo.tick.entity.util.HasKey#equivalent(com.googlecode.objectify.Key) | |
*/ | |
@Override | |
public boolean equivalent(Key<T> key) { | |
return getKey().equals(key); | |
} | |
/* (non-Javadoc) | |
* @see st.voo.tick.entity.util.HasKey#equivalent(com.googlecode.objectify.Ref) | |
*/ | |
@Override | |
public boolean equivalent(Ref<T> ref) { | |
return getKey().equivalent(ref); | |
} | |
} |
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
/* | |
*/ | |
package st.voo.tick.entity.util; | |
import com.googlecode.objectify.Key; | |
import com.googlecode.objectify.Ref; | |
/** | |
* Defines a common interface for entities to expose their key | |
*/ | |
public interface HasKey<T extends HasKey<T>> | |
{ | |
/** Gets the key for the entity, duh */ | |
Key<T> getKey(); | |
/** Gets the ref version. Might need to rename this to ref() to avoid javabeans signature. */ | |
Ref<T> getRef(); | |
/** @return true if this entity is key-equivalent */ | |
boolean equivalent(Key<T> key); | |
/** @return true if this entity is key-equivalent */ | |
boolean equivalent(Ref<T> ref); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment