summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/postgresql/geometric/PGline.java
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>1998-09-03 02:29:45 +0000
committerBruce Momjian <bruce@momjian.us>1998-09-03 02:29:45 +0000
commitc37adac74e7aced5eb3e562e2fa05b4f07da41e0 (patch)
tree1a1ca154747bdbd9b4f1a8fe9c2cf4c07661447a /src/interfaces/jdbc/postgresql/geometric/PGline.java
parentd318315200e31b886b57caeeb4d4ea81112730aa (diff)
New stuff for 6.4 jdbc.
Peter mount
Diffstat (limited to 'src/interfaces/jdbc/postgresql/geometric/PGline.java')
-rw-r--r--src/interfaces/jdbc/postgresql/geometric/PGline.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/postgresql/geometric/PGline.java b/src/interfaces/jdbc/postgresql/geometric/PGline.java
new file mode 100644
index 00000000000..a419ffb5a18
--- /dev/null
+++ b/src/interfaces/jdbc/postgresql/geometric/PGline.java
@@ -0,0 +1,103 @@
+package postgresql.geometric;
+
+import java.io.*;
+import java.sql.*;
+import postgresql.util.*;
+
+/**
+ * This implements a line consisting of two points.
+ *
+ * Currently line is not yet implemented in the backend, but this class
+ * ensures that when it's done were ready for it.
+ */
+public class PGline extends PGobject implements Serializable,Cloneable
+{
+ /**
+ * These are the two points.
+ */
+ public PGpoint point[] = new PGpoint[2];
+
+ /**
+ * @param x1 coordinate for first point
+ * @param y1 coordinate for first point
+ * @param x2 coordinate for second point
+ * @param y2 coordinate for second point
+ */
+ public PGline(double x1,double y1,double x2,double y2)
+ {
+ this(new PGpoint(x1,y1),new PGpoint(x2,y2));
+ }
+
+ /**
+ * @param p1 first point
+ * @param p2 second point
+ */
+ public PGline(PGpoint p1,PGpoint p2)
+ {
+ this();
+ this.point[0] = p1;
+ this.point[1] = p2;
+ }
+
+ /**
+ * @param s definition of the circle in PostgreSQL's syntax.
+ * @exception SQLException on conversion failure
+ */
+ public PGline(String s) throws SQLException
+ {
+ this();
+ setValue(s);
+ }
+
+ /**
+ * reuired by the driver
+ */
+ public PGline()
+ {
+ setType("line");
+ }
+
+ /**
+ * @param s Definition of the line segment in PostgreSQL's syntax
+ * @exception SQLException on conversion failure
+ */
+ public void setValue(String s) throws SQLException
+ {
+ PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s),',');
+ if(t.getSize() != 2)
+ throw new SQLException("conversion of line failed - "+s);
+
+ point[0] = new PGpoint(t.getToken(0));
+ point[1] = new PGpoint(t.getToken(1));
+ }
+
+ /**
+ * @param obj Object to compare with
+ * @return true if the two boxes are identical
+ */
+ public boolean equals(Object obj)
+ {
+ if(obj instanceof PGline) {
+ PGline p = (PGline)obj;
+ return (p.point[0].equals(point[0]) && p.point[1].equals(point[1])) ||
+ (p.point[0].equals(point[1]) && p.point[1].equals(point[0]));
+ }
+ return false;
+ }
+
+ /**
+ * This must be overidden to allow the object to be cloned
+ */
+ public Object clone()
+ {
+ return new PGline((PGpoint)point[0].clone(),(PGpoint)point[1].clone());
+ }
+
+ /**
+ * @return the PGline in the syntax expected by postgresql
+ */
+ public String getValue()
+ {
+ return "["+point[0]+","+point[1]+"]";
+ }
+}