Example #1
0
        public int compareTo(Object o)
        {
            if (!(o is FormIndex))
            {
                throw new ArgumentException("Attempt to compare Object of type " + o.GetType().Name + " to a FormIndex");
            }

            FormIndex a = this;
            FormIndex b = (FormIndex)o;

            if (a.beginningOfForm)
            {
                return(b.beginningOfForm ? 0 : -1);
            }
            else if (a.endOfForm)
            {
                return(b.endOfForm ? 0 : 1);
            }
            else
            {
                //a is in form
                if (b.beginningOfForm)
                {
                    return(1);
                }
                else if (b.endOfForm)
                {
                    return(-1);
                }
            }

            if (a.localIndex != b.localIndex)
            {
                return(a.localIndex < b.localIndex ? -1 : 1);
            }
            else if (a.instanceIndex != b.instanceIndex)
            {
                return(a.instanceIndex < b.instanceIndex ? -1 : 1);
            }
            else if ((a.getNextLevel() == null) != (b.getNextLevel() == null))
            {
                return(a.getNextLevel() == null ? -1 : 1);
            }
            else if (a.getNextLevel() != null)
            {
                return(a.getNextLevel().compareTo(b.getNextLevel()));
            }
            else
            {
                return(0);
            }

            //		int comp = 0;
            //
            //		//TODO: while(true) loops freak me out, this should probably
            //		//get written more safely. -ctsims
            //		while(comp == 0) {
            //			if(index.isTerminal() != local.isTerminal() ||
            //					index.getLocalIndex() != local.getLocalIndex() ||
            //					index.getInstanceIndex() != local.getInstanceIndex()) {
            //				if(local.localIndex > index.localIndex) {
            //					return 1;
            //				} else if(local.localIndex < index.localIndex) {
            //					return -1;
            //				} else if (local.instanceIndex > index.instanceIndex) {
            //					return 1;
            //				} else if (local.instanceIndex < index.instanceIndex) {
            //					return -1;
            //				}
            //
            //				//This case is here as a fallback, but it shouldn't really
            //				//ever be the case that two references have the same chain
            //				//of indices without terminating at the same level.
            //				else if (local.isTerminal() && !index.isTerminal()) {
            //					return -1;
            //				} else {
            //					return 1;
            //				}
            //			}
            //			else if(local.isTerminal()) {
            //				break;
            //			}
            //			local = local.getNextLevel();
            //			index = index.getNextLevel();
            //		}
            //		return comp;
        }