1
/*-------------------------------------------------------------------------
3
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
6
* $PostgreSQL: pgjdbc/org/postgresql/geometric/PGpolygon.java,v 1.11 2005/01/11 08:25:45 jurka Exp $
8
*-------------------------------------------------------------------------
10
package org.postgresql.geometric;
12
import org.postgresql.util.PGobject;
13
import org.postgresql.util.PGtokenizer;
14
import java.io.Serializable;
15
import java.sql.SQLException;
18
* This implements the polygon datatype within PostgreSQL.
20
public class PGpolygon extends PGobject implements Serializable, Cloneable
23
* The points defining the polygon
25
public PGpoint points[];
28
* Creates a polygon using an array of PGpoints
30
* @param points the points defining the polygon
32
public PGpolygon(PGpoint[] points)
39
* @param s definition of the polygon in PostgreSQL's syntax.
40
* @exception SQLException on conversion failure
42
public PGpolygon(String s) throws SQLException
49
* Required by the driver
57
* @param s Definition of the polygon in PostgreSQL's syntax
58
* @exception SQLException on conversion failure
60
public void setValue(String s) throws SQLException
62
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ',');
63
int npoints = t.getSize();
64
points = new PGpoint[npoints];
65
for (int p = 0;p < npoints;p++)
66
points[p] = new PGpoint(t.getToken(p));
70
* @param obj Object to compare with
71
* @return true if the two polygons are identical
73
public boolean equals(Object obj)
75
if (obj instanceof PGpolygon)
77
PGpolygon p = (PGpolygon)obj;
79
if (p.points.length != points.length)
82
for (int i = 0;i < points.length;i++)
83
if (!points[i].equals(p.points[i]))
91
public int hashCode() {
92
// XXX not very good..
94
for (int i = 0; i < points.length && i < 5; ++i)
96
hash = hash ^ points[i].hashCode();
101
public Object clone()
103
PGpoint ary[] = new PGpoint[points.length];
104
for (int i = 0;i < points.length;i++)
105
ary[i] = (PGpoint)points[i].clone();
106
return new PGpolygon(ary);
110
* @return the PGpolygon in the syntax expected by org.postgresql
112
public String getValue()
114
StringBuffer b = new StringBuffer();
116
for (int p = 0;p < points.length;p++)
120
b.append(points[p].toString());