/*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2009 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package omero.gateway.model;
import java.util.Comparator;
/**
* Defines a plane.
*
*
* @author Jean-Marie Burel
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @author Donald MacDonald
* <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
* @version 3.0
* @since 3.0-Beta4
*/
public class ROICoordinate
implements Comparator
{
/**
* Offset for z in calculating Hashcode. This currently splits z and t
* range into 16384 z-sections, and 262144 t sections.
*/
private final static int ZTBITSPLIT = 18;
/** The timepoint. */
private int t;
/** The z-section. */
private int z;
/** Creates a default instance. */
public ROICoordinate()
{
this(0, 0);
}
/**
* Creates a new instance.
*
* @param z The z-section.
* @param t The timepoint.
*/
public ROICoordinate(int z, int t)
{
this.z = z;
this.t = t;
}
/**
* Returns the timepoint.
*
* @return See above.
*/
public int getTimePoint() { return t; }
/**
* Returns the z-section.
*
* @return See above.
*/
public int getZSection() { return z; }
/**
* Implemented as specified by the {@link Comparator} I/F.
* @see Comparator#compare(Object, Object)
* If any attribute == -1 it is not included in comparison.
*/
public int compare(Object o1, Object o2)
{
if (!(o1 instanceof ROICoordinate) || !(o2 instanceof ROICoordinate))
return -1;
ROICoordinate a = (ROICoordinate) o1;
ROICoordinate b = (ROICoordinate) o2;
if (a.t < b.t) return -1;
else if (a.t > b.t) return 1;
else if (a.z < b.z) return -1;
else if (a.z > b.z) return 1;
else return 0;
}
/**
* Overridden to control if the passed object equals the current one.
* If any attribute == -1 it is not included in comparison.
* @see java.lang.Object#equals(Object)
*/
public boolean equals(Object obj)
{
if (!(obj instanceof ROICoordinate)) return false;
ROICoordinate comp = (ROICoordinate) obj;
return (comp.t == this.t && comp.z == this.z);
}
/**
* Calculate the hashCode for the data, The hashcode is generated by
* bitshifting z by ZTBITSPLIT bits and adding t.
*
* @return See above.
*/
public int hashCode()
{
return z<<ZTBITSPLIT+t;
}
/**
* Returns the string of the coordinates.
*
* @see java.lang.Object#toString()
*/
public String toString() { return "T: " + t + " Z: " + z; }
}