Subversion Repositories display

Rev

Rev 140 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package test.display;

/**
 * User: steve Date: Dec 25, 2007 Time: 3:52:09 PM
 */

public class Offset implements Comparable<Offset> {
        private final int offset;

        // The point of the origin is to show where the offset was obtained from,
        // this is useful when there are several possibilities and you want to
        // know which ones make the most sense.
        private String origin;

        public Offset(int sectoff, String origin) {
                this.offset = sectoff;
                this.origin = origin;
        }

        /**
         * Compares this object with the specified object for order.  Returns a
         * negative integer, zero, or a positive integer as this object is less than,
         * equal to, or greater than the specified object.<p>
         *
         * @param o the Object to be compared.
         * @return a negative integer, zero, or a positive integer as this object is
         *         less than, equal to, or greater than the specified object.
         * @throws ClassCastException if the specified object's type prevents it from
         * being compared to this Object.
         */

        public int compareTo(Offset o) {
                if (offset > o.offset)
                        return 1;
                else if (offset < o.offset)
                        return -1;
                else
                        return 0;
        }

        /**
         * Indicates whether some other object is "equal to" this one.
         * @param obj the reference object with which to compare.
         * @return <code>true</code> if this object is the same as the obj argument;
         *         <code>false</code> otherwise.
         * @see #hashCode()
         */

        public boolean equals(Object obj) {
                if (obj instanceof Offset) {
                        Offset os = (Offset) obj;
                        if (offset == os.offset)
                                return true;
                }
                return false;
        }

        /**
         * Returns a hash code value for the object.
         * @return a hash code value for this object.
         * @see Object#equals(Object)
         */

        public int hashCode() {
                return offset;
        }

        public void appendOrigin(String more) {
                this.origin = this.origin + ", " + more;
        }

        public int getOffset() {
                return offset;
        }
}