[MOBY-guts] biomoby commit
Paul Gordon
gordonp at pub.open-bio.org
Mon Apr 4 17:42:17 UTC 2005
gordonp
Mon Apr 4 13:42:17 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory pub.open-bio.org:/tmp/cvs-serv19762/org/biomoby/shared
Modified Files:
MobyDataSimpleInstance.java
Log Message:
Added 'equals' method at request of Sophie Durand, as well as implementing Comparable interface
moby-live/Java/src/main/org/biomoby/shared MobyDataSimpleInstance.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataSimpleInstance.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataSimpleInstance.java 2005/02/09 17:20:38 1.4
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataSimpleInstance.java 2005/04/04 17:42:17 1.5
@@ -22,9 +22,11 @@
* Having both modes is useful because the data instance created from a previous call can be
* passed to a service search template by switching the XML mode. By default the object is in
* SERVICE_XML_MODE.
+ *
+ * @author Paul Gordon (gordonp at ucalgary.ca)
*/
-public class MobyDataSimpleInstance extends MobyPrimaryDataSimple implements MobyDataInstance, Cloneable{
+public class MobyDataSimpleInstance extends MobyPrimaryDataSimple implements MobyDataInstance, Cloneable, Comparable{
public static final int CENTRAL_XML_MODE = 124;
public static final int SERVICE_XML_MODE = 891;
protected int xmlMode = SERVICE_XML_MODE;
@@ -93,6 +95,57 @@
}
/**
+ * Used to see if two objects are equivalent.
+ * If the passed in object is a MobyDataSimpleInstance, its getObject() value
+ * will be used for the comparison. The namespace and ID are ignored,
+ * only the value is compared (such as a MobyDataInteger or Integer or
+ * BigInteger vs. a MobyDataInteger).
+ */
+ public boolean equals(Object passedInObject){
+ Object ourObject = getObject();
+ if(passedInObject != null && passedInObject instanceof MobyDataSimpleInstance){
+ passedInObject = ((MobyDataSimpleInstance) passedInObject).getObject();
+ }
+ return ourObject == passedInObject;
+ }
+
+ /**
+ * This method lexically compares in the order of value, ID, name if passed in object is a MobyDataSimpleInstance.
+ * Otherwise it returns -1 (null fields get pushed to the end of the list).
+ *
+ * Child classes are encouraged to override this method for numerical comparison, etc. where
+ * appropriate, falling back to this method if the result is 0.
+ */
+ public int compareTo(Object o){
+ if(o == null || !(o instanceof MobyDataSimpleInstance)){
+ return -1;
+ }
+ MobyDataSimpleInstance mdsi = (MobyDataSimpleInstance) o;
+ if(getValue() == null && mdsi.getValue() != null){
+ return 1;
+ }
+ else if(getValue() != null && getValue().compareTo(mdsi.getValue()) != 0){
+ return getValue().compareTo(mdsi.getValue());
+ }
+ else if(getId() == null && mdsi.getId() != null){
+ return 1;
+ }
+ else if(getId() != null && getId().compareTo(mdsi.getId()) != 0){
+ return getId().compareTo(mdsi.getId());
+ }
+ else if(getName() == null && mdsi.getName() != null){
+ return 1;
+ }
+ else if(getName() != null){
+ return getName().compareTo(mdsi.getName());
+ }
+ // Equivalent in all three fields if we got to this point
+ else{
+ return 0;
+ }
+ }
+
+ /**
* Determined whether toXML will return a Central template value or a service call instance value.
*
* @param mode one of CENTRAL_XML_MODE or SERVICE_XML_MODE
More information about the MOBY-guts
mailing list