From fa67a247cf66ea86f6fcc773c27cfd4698d2405a Mon Sep 17 00:00:00 2001 From: Marc G. Fournier Date: Sat, 20 Sep 1997 02:21:25 +0000 Subject: Bring in Peter's changes...finally :( --- src/interfaces/jdbc/postgresql/PGpoint.java | 96 +++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/interfaces/jdbc/postgresql/PGpoint.java (limited to 'src/interfaces/jdbc/postgresql/PGpoint.java') diff --git a/src/interfaces/jdbc/postgresql/PGpoint.java b/src/interfaces/jdbc/postgresql/PGpoint.java new file mode 100644 index 0000000000..77a61730f9 --- /dev/null +++ b/src/interfaces/jdbc/postgresql/PGpoint.java @@ -0,0 +1,96 @@ +/** + * + * This implements a version of java.awt.Point, except it uses double + * to represent the coordinates. + * + * It maps to the point datatype in postgresql. + */ + +package postgresql; + +import java.awt.Point; +import java.io.*; +import java.sql.*; + +public class PGpoint implements Serializable +{ + /** + * These are the coordinates. + * These are public, because their equivalents in java.awt.Point are + */ + public double x,y; + + public PGpoint(double x,double y) + { + this.x = x; + this.y = y; + } + + public PGpoint(PGpoint p) + { + this(p.x,p.y); + } + + /** + * This constructor is used by the driver. + */ + public PGpoint(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 SQLException("conversion of point failed - "+e.toString()); + } + } + + public boolean equals(Object obj) + { + PGpoint p = (PGpoint)obj; + return x == p.x && y == p.y; + } + + /** + * This returns the point in the syntax expected by postgresql + */ + public String toString() + { + return "("+x+","+y+")"; + } + + public void translate(int x,int y) + { + translate((double)x,(double)y); + } + + public void translate(double x,double y) + { + this.x += x; + this.y += y; + } + + public void move(int x,int y) + { + setLocation(x,y); + } + + public void move(double x,double y) + { + this.x = x; + this.y = y; + } + + // refer to java.awt.Point for description of this + public void setLocation(int x,int y) + { + move((double)x,(double)y); + } + + // refer to java.awt.Point for description of this + public void setLocation(Point p) + { + setLocation(p.x,p.y); + } + +} -- cgit v1.2.3