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

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/geometric/PGlseg.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 a lseg (line segment) consisting of two points
 
9
 */
 
10
public class PGlseg extends PGobject implements Serializable, Cloneable
 
11
{
 
12
        /*
 
13
         * These are the two points.
 
14
         */
 
15
        public PGpoint point[] = new PGpoint[2];
 
16
 
 
17
        /*
 
18
         * @param x1 coordinate for first point
 
19
         * @param y1 coordinate for first point
 
20
         * @param x2 coordinate for second point
 
21
         * @param y2 coordinate for second point
 
22
         */
 
23
        public PGlseg(double x1, double y1, double x2, double y2)
 
24
        {
 
25
                this(new PGpoint(x1, y1), new PGpoint(x2, y2));
 
26
        }
 
27
 
 
28
        /*
 
29
         * @param p1 first point
 
30
         * @param p2 second point
 
31
         */
 
32
        public PGlseg(PGpoint p1, PGpoint p2)
 
33
        {
 
34
                this();
 
35
                this.point[0] = p1;
 
36
                this.point[1] = p2;
 
37
        }
 
38
 
 
39
        /*
 
40
         * @param s definition of the circle in PostgreSQL's syntax.
 
41
         * @exception SQLException on conversion failure
 
42
         */
 
43
        public PGlseg(String s) throws SQLException
 
44
        {
 
45
                this();
 
46
                setValue(s);
 
47
        }
 
48
 
 
49
        /*
 
50
         * reuired by the driver
 
51
         */
 
52
        public PGlseg()
 
53
        {
 
54
                setType("lseg");
 
55
        }
 
56
 
 
57
        /*
 
58
         * @param s Definition of the line segment in PostgreSQL's syntax
 
59
         * @exception SQLException on conversion failure
 
60
         */
 
61
        public void setValue(String s) throws SQLException
 
62
        {
 
63
                PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s), ',');
 
64
                if (t.getSize() != 2)
 
65
                        throw new PSQLException("postgresql.geo.lseg");
 
66
 
 
67
                point[0] = new PGpoint(t.getToken(0));
 
68
                point[1] = new PGpoint(t.getToken(1));
 
69
        }
 
70
 
 
71
        /*
 
72
         * @param obj Object to compare with
 
73
         * @return true if the two boxes are identical
 
74
         */
 
75
        public boolean equals(Object obj)
 
76
        {
 
77
                if (obj instanceof PGlseg)
 
78
                {
 
79
                        PGlseg p = (PGlseg)obj;
 
80
                        return (p.point[0].equals(point[0]) && p.point[1].equals(point[1])) ||
 
81
                                   (p.point[0].equals(point[1]) && p.point[1].equals(point[0]));
 
82
                }
 
83
                return false;
 
84
        }
 
85
 
 
86
        /*
 
87
         * This must be overidden to allow the object to be cloned
 
88
         */
 
89
        public Object clone()
 
90
        {
 
91
                return new PGlseg((PGpoint)point[0].clone(), (PGpoint)point[1].clone());
 
92
        }
 
93
 
 
94
        /*
 
95
         * @return the PGlseg in the syntax expected by org.postgresql
 
96
         */
 
97
        public String getValue()
 
98
        {
 
99
                return "[" + point[0] + "," + point[1] + "]";
 
100
        }
 
101
}