Commit 41238d17 authored by gmantele's avatar gmantele Committed by Grégory Mantelet
Browse files

[ADQL] BOX+CIRCLE+POLYGON : make coord. sys. optional and allow POINT values

parent 36113a04
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -372,10 +372,20 @@ public class ADQLQueryFactory {
		return new BoxFunction(coordinateSystem, firstCoord, secondCoord, boxWidth, boxHeight);
	}

	/** @since 2.0 */
	public BoxFunction createBox(ADQLOperand coordinateSystem, GeometryValue<GeometryFunction> center, ADQLOperand boxWidth, ADQLOperand boxHeight) throws Exception {
		return new BoxFunction(coordinateSystem, center, boxWidth, boxHeight);
	}

	public CircleFunction createCircle(ADQLOperand coordSys, ADQLOperand coord1, ADQLOperand coord2, ADQLOperand radius) throws Exception {
		return new CircleFunction(coordSys, coord1, coord2, radius);
	}

	/** @since 2.0 */
	public CircleFunction createCircle(ADQLOperand coordSys, GeometryValue<GeometryFunction> center, ADQLOperand radius) throws Exception {
		return new CircleFunction(coordSys, center, radius);
	}

	public CentroidFunction createCentroid(GeometryFunction param) throws Exception {
		return new CentroidFunction(new GeometryValue<GeometryFunction>(param));
	}
+136 −91
Original line number Diff line number Diff line
@@ -1305,34 +1305,30 @@ DistanceFunction DistanceFunction(): { Token fct=null, end=null; DistanceFunctio
	}
}

DistanceFunction DistanceFunction2(): { Token fct=null, end=null; DistanceFunction gf; GeometryValue<GeometryFunction> gvp1, gvp2; GeometryFunction p1=null, p2=null; ADQLColumn col1=null, col2=null; UserDefinedFunction udf1=null, udf2=null; } {
	try {
		fct=<DISTANCE> <LEFT_PAR>
		(p1=Point()|p1=Centroid()|LOOKAHEAD(2) udf1=UserDefinedFunction()|col1=Column()) 
		{
			if (p1 != null)
				gvp1 = new GeometryValue<GeometryFunction>(p1);
			else if (udf1 != null){
			  	udf1.setExpectedType('G');
				gvp1 = new GeometryValue<GeometryFunction>(udf1);
GeometryValue<GeometryFunction> PointValue(): { GeometryFunction p=null; ADQLColumn col=null; UserDefinedFunction udf=null; } {
	( p=Point()
	| p=Centroid()
	| LOOKAHEAD(2) udf=UserDefinedFunction()
	| col=Column() )
	{
		if (p != null)
			return new GeometryValue<GeometryFunction>(p);
		else if (udf != null){
		  	udf.setExpectedType('G');
			return new GeometryValue<GeometryFunction>(udf);
		}else{
				col1.setExpectedType('G');
				gvp1 = new GeometryValue<GeometryFunction>(col1);
			}
			col.setExpectedType('G');
			return new GeometryValue<GeometryFunction>(col);
		}
		<COMMA>
		(p2=Point()|p2=Centroid()|LOOKAHEAD(2) udf2=UserDefinedFunction()|col2=Column())
		{
			if (p2 != null)
				gvp2 = new GeometryValue<GeometryFunction>(p2);
			else if (udf2 != null){
			  	udf2.setExpectedType('G');
				gvp2 = new GeometryValue<GeometryFunction>(udf2);
			}else{
				col2.setExpectedType('G');
				gvp2 = new GeometryValue<GeometryFunction>(col2);
	}
}

DistanceFunction DistanceFunction2(): { Token fct=null, end=null; DistanceFunction gf; GeometryValue<GeometryFunction> gvp1, gvp2; GeometryFunction p1=null, p2=null; ADQLColumn col1=null, col2=null; UserDefinedFunction udf1=null, udf2=null; } {
	try {
		fct=<DISTANCE> <LEFT_PAR>
		gvp1=PointValue() 
		<COMMA>
		gvp2=PointValue()
		end=<RIGHT_PAR>
		{
			gf = queryFactory.createDistance(gvp1, gvp2);
@@ -1349,45 +1345,23 @@ ADQLOperand CoordinateSystem(): { ADQLOperand coordSys=null;}{
	{ return coordSys; }
}

GeometryFunction GeometryValueFunction(): {Token fct=null, end=null; ADQLOperand width, height; ADQLOperand[] coords, tmp; Vector<ADQLOperand> vCoords; ADQLOperand op=null; GeometryValue<GeometryFunction> gvf = null; GeometryFunction gf = null;} {
GeometryFunction GeometryValueFunction(): {Token fct=null, end=null; ADQLOperand coordSys, width, height; ADQLOperand[] coords = null, tmp; Vector<ADQLOperand> vCoords; ADQLOperand op=null; GeometryValue<GeometryFunction> gvf = null, gvp = null; GeometryFunction gf = null;} {
	try{
	  
		// BOX (deprecated since ADQL-2.1)
		(LOOKAHEAD(BoxWithCooSys()) gf=BoxWithCooSys()

		// BOX:
		| (fct=<BOX> <LEFT_PAR> // coord_sys
				coords=Coordinates() // coordinates
				<COMMA> width=NumericExpression() <COMMA> height=NumericExpression() end=<RIGHT_PAR>)
		 {gf = queryFactory.createBox(null, coords[0], coords[1], width, height);}
		(gf=Box()
		
		// CENTROID:
		| gf=Centroid()

		// CIRCLE (deprecated since ADQL-2.1)
		| LOOKAHEAD(CircleWithCooSys()) gf=CircleWithCooSys()
		
		// CIRCLE:
		| (fct=<CIRCLE> <LEFT_PAR>
				coords=Coordinates() // coordinates
				<COMMA> width=NumericExpression() end=<RIGHT_PAR>) // radius
		 {gf = queryFactory.createCircle(null, coords[0], coords[1], width);}
		| gf=Circle()
		
		// POINT: 
		| gf=Point()

		// POLYGON (deprecated since ADQL-2.1)
		| LOOKAHEAD(PolygonWithCooSys()) gf=PolygonWithCooSys()
		
		// POLYGON:
		| (fct=<POLYGON> <LEFT_PAR>
				{ vCoords = new Vector<ADQLOperand>(); } // coordinates
				tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
				<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
				<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
				(<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);})*
				end=<RIGHT_PAR>)
		  { gf = queryFactory.createPolygon(null, vCoords); }
		| gf=Polygon()
		  
		/* // REGION (REMOVED SINCE 2.1):
		| (fct=<REGION> <LEFT_PAR> op=StringExpression() end=<RIGHT_PAR>) {gf = queryFactory.createRegion(op);}*/
@@ -1403,10 +1377,41 @@ GeometryFunction GeometryValueFunction(): {Token fct=null, end=null; ADQLOperand
	}
}

GeometryFunction BoxWithCooSys(): { Token fct=null, end=null; ADQLOperand coordSys; ADQLOperand width, height; ADQLOperand[] coords; } {
	fct=<BOX> <LEFT_PAR> coordSys=CoordinateSystem() // coord_sys
			<COMMA> coords=Coordinates() // coordinates
			<COMMA> width=NumericExpression() <COMMA> height=NumericExpression() end=<RIGHT_PAR>
GeometryFunction Box(): { GeometryFunction gf; } {
	(
		LOOKAHEAD(BoxWithPoint())
		gf=BoxWithPoint()
	|
		gf=BoxWithCoords()
	)
	{ return gf; }
}

GeometryFunction BoxWithPoint(): { Token fct=null, end=null; ADQLOperand coordSys=null; ADQLOperand width, height; GeometryValue<GeometryFunction> center = null; } {
	fct=<BOX> <LEFT_PAR>
		[ coordSys=CoordinateSystem() <COMMA> ] // coord_sys (deprecated since ADQL-2.1)
		center=PointValue()                     // center point
		<COMMA> width=NumericExpression()       // width
		<COMMA> height=NumericExpression()      // height
	end=<RIGHT_PAR>
	{
		try {
			GeometryFunction gf = queryFactory.createBox(coordSys, center, width, height);
			gf.setPosition(new TextPosition(fct, end));
			return gf;	
		}catch(Exception ex){
			throw generateParseException(ex);
		}
	}
}

GeometryFunction BoxWithCoords(): { Token fct=null, end=null; ADQLOperand coordSys=null; ADQLOperand width, height; ADQLOperand[] coords = null; } {
	fct=<BOX> <LEFT_PAR>
		[ coordSys=CoordinateSystem() <COMMA> ] // coord_sys (deprecated since ADQL-2.1)
		coords=Coordinates()                    // center coordinates
		<COMMA> width=NumericExpression()       // width
		<COMMA> height=NumericExpression()      // height
	end=<RIGHT_PAR>
	{
		try {
			GeometryFunction gf = queryFactory.createBox(coordSys, coords[0], coords[1], width, height);
@@ -1418,10 +1423,38 @@ GeometryFunction BoxWithCooSys(): { Token fct=null, end=null; ADQLOperand coordS
	}
}

GeometryFunction CircleWithCooSys(): { Token fct=null, end=null; ADQLOperand coordSys; ADQLOperand width; ADQLOperand[] coords; } {
	fct=<CIRCLE> <LEFT_PAR> coordSys=CoordinateSystem() <COMMA> // coord_sys
			coords=Coordinates() // coordinates
			<COMMA> width=NumericExpression() end=<RIGHT_PAR> // radius
GeometryFunction Circle(): { GeometryFunction gf; } {
	(
		LOOKAHEAD(CircleWithPoint())
		gf=CircleWithPoint()
	|
		gf=CircleWithCoords()
	)
	{ return gf; }
}

GeometryFunction CircleWithPoint(): { Token fct=null, end=null; ADQLOperand coordSys=null; ADQLOperand width; GeometryValue<GeometryFunction> center = null; } {
	fct=<CIRCLE> <LEFT_PAR>
		[ coordSys=CoordinateSystem() <COMMA> ] // coord_sys (deprecated since ADQL-2.1)
		center=PointValue()                     // center coordinates
		<COMMA> width=NumericExpression()       // radius
	end=<RIGHT_PAR>
	{
		try {
			GeometryFunction gf = queryFactory.createCircle(coordSys, center, width);
			gf.setPosition(new TextPosition(fct, end));
			return gf;	
		}catch(Exception ex){
			throw generateParseException(ex);
		}
	}
}

GeometryFunction CircleWithCoords(): { Token fct=null, end=null; ADQLOperand coordSys=null; ADQLOperand width; ADQLOperand[] coords = null; } {
	fct=<CIRCLE> <LEFT_PAR>
		[ coordSys=CoordinateSystem() <COMMA> ] // coord_sys (deprecated since ADQL-2.1)
		coords=Coordinates()                    // center coordinates
		<COMMA> width=NumericExpression()       // radius
	end=<RIGHT_PAR>
	{
		try {
			GeometryFunction gf = queryFactory.createCircle(coordSys, coords[0], coords[1], width);
@@ -1444,45 +1477,57 @@ CentroidFunction Centroid(): {Token fct=null, end=null; GeometryValue<GeometryFu
	}
}

PointFunction Point(): {Token start, end; ADQLOperand[] coords; PointFunction pf;} {
	// POINT (depecrated since ADQL-2.1)
	(LOOKAHEAD(PointWithCooSys())
		pf=PointWithCooSys()
		{ return pf; }
	
	// POINT (last version - >= ADQL-2.1)
	|
		start=<POINT> <LEFT_PAR> coords=Coordinates() end=<RIGHT_PAR> // coordinates
PointFunction Point(): {Token start, end; ADQLOperand coordSys=null; ADQLOperand[] coords; PointFunction pf;} {
	start=<POINT> <LEFT_PAR>
		[ coordSys=CoordinateSystem() <COMMA> ] // coord_sys (deprecated since ADQL-2.1)
		coords=Coordinates()                    // coordinates
	end=<RIGHT_PAR>
	{
		try{
				pf = queryFactory.createPoint(null, coords[0], coords[1]);
			pf = queryFactory.createPoint(coordSys, coords[0], coords[1]);
			pf.setPosition(new TextPosition(start, end));
			return pf;
		}catch(Exception ex){
			throw generateParseException(ex);
		}
	}
}

GeometryFunction Polygon(): { GeometryFunction gf; } {
	(
		LOOKAHEAD(PolygonWithPoints())
		gf=PolygonWithPoints()
	|
		gf=PolygonWithCoords()
	)
	{ return gf; }
}

PointFunction PointWithCooSys(): {Token start, end; ADQLOperand coordSys; ADQLOperand[] coords;} {
	start=<POINT> <LEFT_PAR> coordSys=CoordinateSystem() <COMMA> // coord_sys
			coords=Coordinates() end=<RIGHT_PAR> // coordinates
GeometryFunction PolygonWithPoints(): { Token fct=null, end=null; ADQLOperand coordSys=null; GeometryValue<GeometryFunction> tmp; Vector<ADQLOperand> vCoords; } {
	fct=<POLYGON> <LEFT_PAR>
		[ coordSys=CoordinateSystem() <COMMA> ]  // coord_sys (deprecated since ADQL-2.1)
		{ vCoords = new Vector<ADQLOperand>(); } // points (min. 3)
		 tmp=PointValue() {vCoords.add(tmp);}
		 <COMMA> tmp=PointValue() {vCoords.add(tmp);}
		 <COMMA> tmp=PointValue() {vCoords.add(tmp);}
		(<COMMA> tmp=PointValue() {vCoords.add(tmp);})*
	end=<RIGHT_PAR>
	{
		try {
			PointFunction pf = queryFactory.createPoint(coordSys, coords[0], coords[1]);
			pf.setPosition(new TextPosition(start, end));
			return pf;
			GeometryFunction gf = queryFactory.createPolygon(coordSys, vCoords);
			gf.setPosition(new TextPosition(fct, end));
			return gf;
		}catch(Exception ex){
			throw generateParseException(ex);
		}
	}
}

GeometryFunction PolygonWithCooSys(): { Token fct=null, end=null; ADQLOperand coordSys; ADQLOperand[] coords, tmp; Vector<ADQLOperand> vCoords; } {
	fct=<POLYGON> <LEFT_PAR> coordSys=CoordinateSystem() // coord_sys
			{ vCoords = new Vector<ADQLOperand>(); } // coordinates
			<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
GeometryFunction PolygonWithCoords(): { Token fct=null, end=null; ADQLOperand coordSys=null; ADQLOperand[] coords, tmp; Vector<ADQLOperand> vCoords; } {
	fct=<POLYGON> <LEFT_PAR>
		[ coordSys=CoordinateSystem() <COMMA> ]  // coord_sys (deprecated since ADQL-2.1)
		{ vCoords = new Vector<ADQLOperand>(); } // coordinates (min. 3 pairs)
		 tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
		 <COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
		 <COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
		(<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);})*
+180 −45
Original line number Diff line number Diff line
@@ -16,13 +16,15 @@ package adql.query.operand.function.geometry;
 * You should have received a copy of the GNU Lesser General Public License
 * along with ADQLLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2012-2019 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2020 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

import adql.parser.feature.LanguageFeature;
import adql.query.ADQLObject;
import adql.query.operand.ADQLColumn;
import adql.query.operand.ADQLOperand;
import adql.query.operand.function.UserDefinedFunction;

/**
 * It represents the box function of the ADQL language.
@@ -66,8 +68,7 @@ import adql.query.operand.ADQLOperand;
 *
 * <p>
 * 	The function arguments may be literal values, as above, or they may be
 * 	column references, functions or expressions that returns the appropriate
 * 	datatypes.
 * 	column references, functions or expressions that returns a POINT value.
 * </p>
 *
 * <i>
@@ -87,7 +88,7 @@ import adql.query.operand.ADQLOperand;
 * </p>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (07/2019)
 * @version 2.0 (06/2020)
 */
public class BoxFunction extends GeometryFunction {

@@ -95,10 +96,23 @@ public class BoxFunction extends GeometryFunction {
	 * @since 2.0 */
	public static final LanguageFeature FEATURE = new LanguageFeature(LanguageFeature.TYPE_ADQL_GEO, "BOX", true, "Express a box on the sky.");

	/** The first coordinate of the center of this box. */
	/** Center position.
	 * <p><i><b>Note:</b>
	 * 	NULL, if both {@link #coord1} and {@link #coord2} are provided.
	 * </i></p>
	 * @since 2.0 */
	private GeometryValue<GeometryFunction> centerPoint;

	/** The first coordinate of the center of this box.
	 * <p><i><b>Note:</b>
	 * 	NULL, if {@link #centerPoint} is provided.
	 * </i></p> */
	private ADQLOperand coord1;

	/** The second coordinate of the center of this box. */
	/** The second coordinate of the center of this box.
	 * <p><i><b>Note:</b>
	 * 	NULL, if {@link #centerPoint} is provided.
	 * </i></p> */
	private ADQLOperand coord2;

	/** The width of this box (in degrees). */
@@ -118,9 +132,11 @@ public class BoxFunction extends GeometryFunction {
	 *                   			box.
	 * @param boxWidth				The width of this box (in degrees).
	 * @param boxHeight				The height of this box (in degrees).
	 *
	 * @throws NullPointerException	If one parameter is NULL.
	 * @throws Exception 			If there is another error.
	 */
	@SuppressWarnings("deprecation")
	public BoxFunction(ADQLOperand coordinateSystem, ADQLOperand firstCoord, ADQLOperand secondCoord, ADQLOperand boxWidth, ADQLOperand boxHeight) throws NullPointerException, Exception {
		super(coordinateSystem);

@@ -131,6 +147,35 @@ public class BoxFunction extends GeometryFunction {
		coord2 = secondCoord;
		width = boxWidth;
		height = boxHeight;
		centerPoint = null;
	}

	/**
	 * Builds a BOX function.
	 *
	 * @param coordinateSystem		The coordinate system of the center
	 *                        		position.
	 * @param center				The center position.
	 * @param boxWidth				The width of this box (in degrees).
	 * @param boxHeight				The height of this box (in degrees).
	 *
	 * @throws NullPointerException	If one parameter is NULL.
	 * @throws Exception 			If there is another error.
	 *
	 * @since 2.0
	 */
	@SuppressWarnings("deprecation")
	public BoxFunction(ADQLOperand coordinateSystem, GeometryValue<GeometryFunction> center, ADQLOperand boxWidth, ADQLOperand boxHeight) throws NullPointerException, Exception {
		super(coordinateSystem);

		if (center == null || boxWidth == null || boxHeight == null)
			throw new NullPointerException("All the parameters of the BOX function must be different from NULL!");

		coord1 = null;
		coord2 = null;
		width = boxWidth;
		height = boxHeight;
		centerPoint = center;
	}

	/**
@@ -139,12 +184,14 @@ public class BoxFunction extends GeometryFunction {
	 * @param toCopy		The BOX function to copy.
	 * @throws Exception	If there is an error during the copy.
	 */
	@SuppressWarnings("unchecked")
	public BoxFunction(BoxFunction toCopy) throws Exception {
		super(toCopy);
		coord1 = (ADQLOperand)(toCopy.coord1.getCopy());
		coord2 = (ADQLOperand)(toCopy.coord2.getCopy());
		width = (ADQLOperand)(toCopy.width.getCopy());
		height = (ADQLOperand)(toCopy.height.getCopy());
		centerPoint = (GeometryValue<GeometryFunction>)(toCopy.centerPoint.getCopy());
	}

	@Override
@@ -177,6 +224,42 @@ public class BoxFunction extends GeometryFunction {
		return true;
	}

	/**
	 * Gets the center point, exactly as provided.
	 *
	 * <p><b>IMPORTANT NOTE:</b>
	 * 	If this {@link BoxFunction} has been initialized with a pair of
	 * 	coordinates, this function will return NULL.
	 * </p>
	 *
	 * @return	The center point of the represented box,
	 *        	or NULL if created with a pair of coordinates.
	 *
	 * @since 2.0
	 */
	public final GeometryValue<GeometryFunction> getCenter() {
		return centerPoint;
	}

	/**
	 * Sets the center point.
	 *
	 * <p><b>WARNING:</b>
	 * 	Calling this function will erase the single coordinates already set:
	 * 	{@link #getCoord1()} and {@link #getCoord2()} will both return NULL.
	 * </p>
	 *
	 * @param newCenter	The new center point of the represented box.
	 *
	 * @since 2.0
	 */
	public final void setCenter(final GeometryValue<GeometryFunction> newCenter) {
		centerPoint = newCenter;
		coord1 = null;
		coord2 = null;
		setPosition(null);
	}

	/**
	 * Gets the first coordinate (i.e. right ascension).
	 *
@@ -254,17 +337,23 @@ public class BoxFunction extends GeometryFunction {
	}

	@Override
	@SuppressWarnings("deprecation")
	public ADQLOperand[] getParameters() {
		if (centerPoint == null)
			return new ADQLOperand[]{ coordSys, coord1, coord2, width, height };
		else
			return new ADQLOperand[]{ coordSys, centerPoint.getValue(), width, height };
	}

	@Override
	public int getNbParameters() {
		return 5;
		return (centerPoint == null ? 5 : 4);
	}

	@Override
	@SuppressWarnings("deprecation")
	public ADQLOperand getParameter(int index) throws ArrayIndexOutOfBoundsException {
		if (centerPoint == null) {
			switch(index) {
				case 0:
					return coordSys;
@@ -279,9 +368,24 @@ public class BoxFunction extends GeometryFunction {
				default:
					throw new ArrayIndexOutOfBoundsException("No " + index + "-th parameter for the function \"" + getName() + "\"!");
			}
		} else {
			switch(index) {
				case 0:
					return coordSys;
				case 1:
					return centerPoint.getValue();
				case 2:
					return width;
				case 3:
					return height;
				default:
					throw new ArrayIndexOutOfBoundsException("No " + index + "-th parameter for the function \"" + getName() + "\"!");
			}
		}
	}

	@Override
	@SuppressWarnings({ "unchecked", "deprecation" })
	public ADQLOperand setParameter(int index, ADQLOperand replacer) throws ArrayIndexOutOfBoundsException, NullPointerException, Exception {
		if (replacer == null)
			throw new NullPointerException("Impossible to remove one parameter from a " + getName() + " function!");
@@ -289,6 +393,7 @@ public class BoxFunction extends GeometryFunction {
			throw new Exception("Impossible to replace an ADQLOperand by a " + replacer.getClass().getName() + " (" + replacer.toADQL() + ")!");

		ADQLOperand replaced = null;
		if (centerPoint == null) {
			switch(index) {
				case 0:
					replaced = coordSys;
@@ -296,24 +401,54 @@ public class BoxFunction extends GeometryFunction {
					break;
				case 1:
					replaced = coord1;
				coord1 = replacer;
					setCoord1(replacer);
					break;
				case 2:
					replaced = coord2;
				coord2 = replacer;
					setCoord2(replacer);
					break;
				case 3:
					replaced = width;
				width = replacer;
					setWidth(replacer);
					break;
				case 4:
					replaced = height;
				height = replacer;
					setHeight(replacer);
					break;
				default:
					throw new ArrayIndexOutOfBoundsException("No " + index + "-th parameter for the function \"" + getName() + "\"!");
			}
		setPosition(null);
		} else {
			switch(index) {
				case 0:
					replaced = coordSys;
					setCoordinateSystem(replacer);
					break;
				case 1:
					replaced = centerPoint;
					if (replacer instanceof GeometryValue)
						setCenter((GeometryValue<GeometryFunction>)replacer);
					else if (replaced instanceof ADQLColumn)
						centerPoint.setColumn((ADQLColumn)replaced);
					else if (replaced instanceof GeometryFunction)
						centerPoint.setGeometry((GeometryFunction)replaced);
					else if (replaced instanceof UserDefinedFunction)
						centerPoint.setUDF((UserDefinedFunction)replaced);
					else
						throw new Exception("Impossible to replace a GeometryValue/Column/GeometryFunction/UDF by " + replacer.getClass().getName() + " (" + replacer.toADQL() + ")!");
					break;
				case 2:
					replaced = width;
					setWidth(replacer);
					break;
				case 3:
					replaced = height;
					setHeight(replacer);
					break;
				default:
					throw new ArrayIndexOutOfBoundsException("No " + index + "-th parameter for the function \"" + getName() + "\"!");
			}
		}
		return replaced;
	}

+172 −38

File changed.

Preview size limit exceeded, changes collapsed.

+7 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import adql.parser.feature.LanguageFeature;
import adql.query.ADQLObject;
import adql.query.operand.ADQLColumn;
import adql.query.operand.ADQLOperand;
import adql.query.operand.function.UserDefinedFunction;

/**
 * It represents the DISTANCE function of the ADQL language.
@@ -231,9 +232,9 @@ public class DistanceFunction extends GeometryFunction {
	public ADQLOperand getParameter(int index) throws ArrayIndexOutOfBoundsException {
		switch(index) {
			case 0:
				return p1.getValue();
				return p1;
			case 1:
				return p2.getValue();
				return p2;
			default:
				throw new ArrayIndexOutOfBoundsException("No " + index + "-th parameter for the function \"" + getName() + "\"!");
		}
@@ -244,8 +245,8 @@ public class DistanceFunction extends GeometryFunction {
	public ADQLOperand setParameter(int index, ADQLOperand replacer) throws ArrayIndexOutOfBoundsException, NullPointerException, Exception {
		if (replacer == null)
			throw new NullPointerException("Impossible to remove a parameter from the function " + getName() + "!");
		else if (!(replacer instanceof GeometryValue || replacer instanceof ADQLColumn || replacer instanceof GeometryFunction))
			throw new Exception("Impossible to replace a GeometryValue/Column/GeometryFunction by " + replacer.getClass().getName() + " (" + replacer.toADQL() + ")!");
		else if (!(replacer instanceof GeometryValue || replacer instanceof ADQLColumn || replacer instanceof GeometryFunction || replacer instanceof UserDefinedFunction))
			throw new Exception("Impossible to replace a GeometryValue/Column/GeometryFunction/UDF by " + replacer.getClass().getName() + " (" + replacer.toADQL() + ")!");

		ADQLOperand replaced = null;
		GeometryValue<GeometryFunction> toUpdate = null;
@@ -273,6 +274,8 @@ public class DistanceFunction extends GeometryFunction {
				toUpdate.setColumn((ADQLColumn)replacer);
			else if (replacer instanceof GeometryFunction)
				toUpdate.setGeometry((GeometryFunction)replacer);
			else if (replacer instanceof UserDefinedFunction)
				toUpdate.setUDF((UserDefinedFunction)replacer);
		}

		setPosition(null);
Loading