aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/postgresql/PGlseg.java
blob: d073b46b20b28862ba3f0121c86fed91abcec40f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 *
 * This implements a lseg (line segment) consisting of two points
 *
 */

package postgresql;

import java.io.*;
import java.sql.*;

public class PGlseg implements Serializable
{
  /**
   * These are the two points.
   */
  public PGpoint point[] = new PGpoint[2];
  
  public PGlseg(double x1,double y1,double x2,double y2)
  {
    this.point[0] = new PGpoint(x1,y1);
    this.point[1] = new PGpoint(x2,y2);
  }
  
  public PGlseg(PGpoint p1,PGpoint p2)
  {
    this.point[0] = p1;
    this.point[1] = p2;
  }
  
  /**
   * This constructor is used by the driver.
   */
  public PGlseg(String s) throws SQLException
  {
    PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s),',');
    if(t.getSize() != 2)
      throw new SQLException("conversion of lseg failed - "+s);
    
    point[0] = new PGpoint(t.getToken(0));
    point[1] = new PGpoint(t.getToken(1));
  }
  
  public boolean equals(Object obj)
  {
    PGlseg p = (PGlseg)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]));
  }
  
  /**
   * This returns the lseg in the syntax expected by postgresql
   */
  public String toString()
  {
    return "["+point[0]+","+point[1]+"]";
  }
}