All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.pgclient.data.Polygon Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
package io.vertx.pgclient.data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Polygon data type in Postgres represented by lists of points (the vertexes of the polygon).
 * Polygons are very similar to closed paths, but are stored differently and have their own set of support routines.
 */
public class Polygon {
  private List points;

  public Polygon() {
    this(new ArrayList<>());
  }

  public Polygon(List points) {
    this.points = points;
  }


  public List getPoints() {
    return points;
  }

  public void setPoints(List points) {
    this.points = points;
  }

  public Polygon addPoint(Point point) {
    Objects.requireNonNull(point);
    if (points == null) {
      points = new ArrayList<>();
    }
    points.add(point);
    return this;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Polygon polygon = (Polygon) o;

    return points.equals(polygon.points);
  }

  @Override
  public int hashCode() {
    return points.hashCode();
  }

  @Override
  public String toString() {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Polygon");
    stringBuilder.append("(");
    for (int i = 0; i < points.size(); i++) {
      Point point = points.get(i);
      stringBuilder.append(point.toString());
      if (i != points.size() - 1) {
        // not the last one
        stringBuilder.append(",");
      }
    }
    stringBuilder.append(")");
    return stringBuilder.toString();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy