~ubuntu-branches/ubuntu/feisty/libpgjava/feisty

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/geometric/PGpolygon.java

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-06 23:43:06 UTC
  • Revision ID: james.westby@ubuntu.com-20020206234306-hsg7suqr8q56qg40
Tags: upstream-7.2
ImportĀ upstreamĀ versionĀ 7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.postgresql.geometric;
 
2
 
 
3
import java.io.*;
 
4
import java.sql.*;
 
5
import org.postgresql.util.*;
 
6
 
 
7
/*
 
8
 * This implements the polygon datatype within PostgreSQL.
 
9
 */
 
10
public class PGpolygon extends PGobject implements Serializable, Cloneable
 
11
{
 
12
        /*
 
13
         * The points defining the polygon
 
14
         */
 
15
        public PGpoint points[];
 
16
 
 
17
        /*
 
18
         * Creates a polygon using an array of PGpoints
 
19
         *
 
20
         * @param points the points defining the polygon
 
21
         */
 
22
        public PGpolygon(PGpoint[] points)
 
23
        {
 
24
                this();
 
25
                this.points = points;
 
26
        }
 
27
 
 
28
        /*
 
29
         * @param s definition of the circle in PostgreSQL's syntax.
 
30
         * @exception SQLException on conversion failure
 
31
         */
 
32
        public PGpolygon(String s) throws SQLException
 
33
        {
 
34
                this();
 
35
                setValue(s);
 
36
        }
 
37
 
 
38
        /*
 
39
         * Required by the driver
 
40
         */
 
41
        public PGpolygon()
 
42
        {
 
43
                setType("polygon");
 
44
        }
 
45
 
 
46
        /*
 
47
         * @param s Definition of the polygon in PostgreSQL's syntax
 
48
         * @exception SQLException on conversion failure
 
49
         */
 
50
        public void setValue(String s) throws SQLException
 
51
        {
 
52
                PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ',');
 
53
                int npoints = t.getSize();
 
54
                points = new PGpoint[npoints];
 
55
                for (int p = 0;p < npoints;p++)
 
56
                        points[p] = new PGpoint(t.getToken(p));
 
57
        }
 
58
 
 
59
        /*
 
60
         * @param obj Object to compare with
 
61
         * @return true if the two boxes are identical
 
62
         */
 
63
        public boolean equals(Object obj)
 
64
        {
 
65
                if (obj instanceof PGpolygon)
 
66
                {
 
67
                        PGpolygon p = (PGpolygon)obj;
 
68
 
 
69
                        if (p.points.length != points.length)
 
70
                                return false;
 
71
 
 
72
                        for (int i = 0;i < points.length;i++)
 
73
                                if (!points[i].equals(p.points[i]))
 
74
                                        return false;
 
75
 
 
76
                        return true;
 
77
                }
 
78
                return false;
 
79
        }
 
80
 
 
81
        /*
 
82
         * This must be overidden to allow the object to be cloned
 
83
         */
 
84
        public Object clone()
 
85
        {
 
86
                PGpoint ary[] = new PGpoint[points.length];
 
87
                for (int i = 0;i < points.length;i++)
 
88
                        ary[i] = (PGpoint)points[i].clone();
 
89
                return new PGpolygon(ary);
 
90
        }
 
91
 
 
92
        /*
 
93
         * @return the PGpolygon in the syntax expected by org.postgresql
 
94
         */
 
95
        public String getValue()
 
96
        {
 
97
                StringBuffer b = new StringBuffer();
 
98
                b.append("(");
 
99
                for (int p = 0;p < points.length;p++)
 
100
                {
 
101
                        if (p > 0)
 
102
                                b.append(",");
 
103
                        b.append(points[p].toString());
 
104
                }
 
105
                b.append(")");
 
106
                return b.toString();
 
107
        }
 
108
}