From 82821f8a31e5f98c27dced51f1bba0fc6637d598 Mon Sep 17 00:00:00 2001 From: Constantin Date: Mon, 14 Jun 2010 11:27:05 +0200 Subject: changed build system of java/ folder from makefile to ant (big compilation time improvement) --- java/src/rasj/RasPoint.java | 426 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 426 insertions(+) create mode 100644 java/src/rasj/RasPoint.java (limited to 'java/src/rasj/RasPoint.java') diff --git a/java/src/rasj/RasPoint.java b/java/src/rasj/RasPoint.java new file mode 100644 index 0000000..b0f3793 --- /dev/null +++ b/java/src/rasj/RasPoint.java @@ -0,0 +1,426 @@ +package rasj; + +import java.lang.*; +import java.util.*; + +/* +* This file is part of rasdaman community. +* +* Rasdaman community 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 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community 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 rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +*/ +/** *********************************************************** + *
+ *
+ * PURPOSE:
+ * This class represents an n-dimensional point vector.
+ * @version $Revision: 1.9 $
+ *
+ *
+ *
+ * COMMENTS:
+ *
+ * 
+ *********************************************************** */ + + +public class RasPoint +{ + static final String rcsid = "@(#)Package rasj, class RasPoint: $Header: /home/rasdev/CVS-repository/rasdaman/java/rasj/RasPoint.java,v 1.9 2003/12/10 21:04:23 rasdev Exp $"; + + // array holding the point coordinates + private long[] points; + // dimensionality of the point + private int dimensionality; + // number of components initialized already + private int streamInitCnt; + + /** + * Constructor getting the dimensionality for stream initialization. + * @param dim the dimensionality of this point + **/ + public RasPoint(int dim) + { + dimensionality = dim; + streamInitCnt = 0; + + points = new long[dimensionality]; + + for(int i=0; i< dimensionality; i++) + points[i] = 0; + } + + /** + * Method for stream initialization of this point. + * @param newElement a new dimension that is added to this point + **/ + public RasPoint stream(long newElement) throws RasStreamInputOverflowException + { + if(streamInitCnt >= dimensionality) + throw new RasStreamInputOverflowException(); + + points[streamInitCnt++] = newElement; + return this; + } + + /** + * constructor taking a string representation for this point (for example "[1, 2, 3]"). + * @param stringRep the string representation for this point + **/ + public RasPoint(String stringRep) + { + dimensionality = 1; + streamInitCnt = 0; + + if(stringRep.trim().charAt(0) != '[') + { + // error + dimensionality = 0; + return; + } + + // for parsing the string + StringTokenizer strTok = new StringTokenizer(stringRep.trim(), "[,]"); + String strCurTok = null; + + // calculate dimensionality + dimensionality = strTok.countTokens(); + + points = new long[dimensionality]; + + for(int i=0; i= dimensionality) + throw new RasIndexOutOfBoundsException(0, dimensionality-1, i); + + return points[i]; + } + + /** + * write access to the i-th coordinate + * @param i the coordinate that is to be accessed + * @param value the value that is to be assigned to the specified coordinate + **/ + public void setItem(int i, long value) throws RasIndexOutOfBoundsException + { + if(i < 0 || i >= dimensionality) + throw new RasIndexOutOfBoundsException(0, dimensionality-1, i); + points[i] = value; + } + + /** + * This method copies the values of the given point to the current point. All + * previously defined values of the current point will be deleted. + * @param pt the point to be copied + * @return the current point with its new values + **/ + public final RasPoint setTo(final RasPoint pt) throws RasIndexOutOfBoundsException + { + if(this != pt) + { + if((points != null) && dimensionality != pt.dimension()) + { + points = null; + } + + dimensionality = pt.dimension(); + streamInitCnt = dimensionality; + + if(points == null) + points = new long[ dimensionality ]; + + for(int i=0; i + * -2 if the points have not the same dimensionality + * -1 if the current point is "lesser" than point p. + *
In this context, "lesser" refers to the comparison of the coordinates in decreasing order + * of magnitude For example, the point (2,2,9) is "lesser" than the point (2,3,1). + * 0 if the two points have an equal value + * 1 if the current point is "greater" than point p + * ("greater" is the opposite of "lesser"). + * + **/ + public final int comparedWith(final RasPoint p) + { + if(dimensionality != p.dimensionality) + return -2; + + try { + for (int i = 0; i < dimensionality; i++) + { + if (points[i] > p.item(i)) + return 1; + if (points[i] < p.item(i)) + return -1 ; + } + return 0; + } + catch(RasIndexOutOfBoundsException e) { + // this cannot occur (theoretically) + System.out.println("Error in method RasPoint.comparedWith()."); + return -2; + } + } + + /** + * Method for testing equality of two points.
Two points are equal + * if they have the same dimensionality and identic values in each dimension. + * @param pt the point that is compared to the current point + * @return true if the two points are equal + **/ + public boolean equals(final RasPoint pt) throws RasDimensionMismatchException + { + boolean returnValue = false; + + if(dimensionality != pt.dimensionality) + { + throw new RasDimensionMismatchException(dimensionality, pt.dimensionality); + } + try { + returnValue = true; + for(int i=0; i 0) + { + for(int i=0; i