diff options
| author | Peter Mount <peter@retep.org.uk> | 2000-04-17 20:07:56 +0000 |
|---|---|---|
| committer | Peter Mount <peter@retep.org.uk> | 2000-04-17 20:07:56 +0000 |
| commit | 25dadc85140b1f688a4cf0c2de8b961a07b10f11 (patch) | |
| tree | 14c91b7e37ca13fba1a4880687cf02bd2dad2de2 /src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java | |
| parent | aafff4af162dcf2be91fcd67db6881d6cf166565 (diff) | |
| download | postgresql-25dadc85140b1f688a4cf0c2de8b961a07b10f11.tar.gz | |
Another attempt at 7.0
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java')
| -rw-r--r-- | src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java b/src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java new file mode 100644 index 0000000000..eeb71b2773 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/geometric/PGpoint.java @@ -0,0 +1,167 @@ +package org.postgresql.geometric; + +import java.awt.Point; +import java.io.*; +import java.sql.*; + +import org.postgresql.util.*; + +/** + * This implements a version of java.awt.Point, except it uses double + * to represent the coordinates. + * + * <p>It maps to the point datatype in org.postgresql. + */ +public class PGpoint extends PGobject implements Serializable,Cloneable +{ + /** + * The X coordinate of the point + */ + public double x; + + /** + * The Y coordinate of the point + */ + public double y; + + /** + * @param x coordinate + * @param y coordinate + */ + public PGpoint(double x,double y) + { + this(); + this.x = x; + this.y = y; + } + + /** + * This is called mainly from the other geometric types, when a + * point is imbeded within their definition. + * + * @param value Definition of this point in PostgreSQL's syntax + */ + public PGpoint(String value) throws SQLException + { + this(); + setValue(value); + } + + /** + * Required by the driver + */ + public PGpoint() + { + setType("point"); + } + + /** + * @param s Definition of this point in PostgreSQL's syntax + * @exception SQLException on conversion failure + */ + public void setValue(String s) throws SQLException + { + PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s),','); + try { + x = Double.valueOf(t.getToken(0)).doubleValue(); + y = Double.valueOf(t.getToken(1)).doubleValue(); + } catch(NumberFormatException e) { + throw new PSQLException("postgresql.geo.point",e.toString()); + } + } + + /** + * @param obj Object to compare with + * @return true if the two boxes are identical + */ + public boolean equals(Object obj) + { + if(obj instanceof PGpoint) { + PGpoint p = (PGpoint)obj; + return x == p.x && y == p.y; + } + return false; + } + + /** + * This must be overidden to allow the object to be cloned + */ + public Object clone() + { + return new PGpoint(x,y); + } + + /** + * @return the PGpoint in the syntax expected by org.postgresql + */ + public String getValue() + { + return "("+x+","+y+")"; + } + + /** + * Translate the point with the supplied amount. + * @param x integer amount to add on the x axis + * @param y integer amount to add on the y axis + */ + public void translate(int x,int y) + { + translate((double)x,(double)y); + } + + /** + * Translate the point with the supplied amount. + * @param x double amount to add on the x axis + * @param y double amount to add on the y axis + */ + public void translate(double x,double y) + { + this.x += x; + this.y += y; + } + + /** + * Moves the point to the supplied coordinates. + * @param x integer coordinate + * @param y integer coordinate + */ + public void move(int x,int y) + { + setLocation(x,y); + } + + /** + * Moves the point to the supplied coordinates. + * @param x double coordinate + * @param y double coordinate + */ + public void move(double x,double y) + { + this.x = x; + this.y = y; + } + + /** + * Moves the point to the supplied coordinates. + * refer to java.awt.Point for description of this + * @param x integer coordinate + * @param y integer coordinate + * @see java.awt.Point + */ + public void setLocation(int x,int y) + { + move((double)x,(double)y); + } + + /** + * Moves the point to the supplied java.awt.Point + * refer to java.awt.Point for description of this + * @param p Point to move to + * @see java.awt.Point + */ + public void setLocation(Point p) + { + setLocation(p.x,p.y); + } + +} |
