Changeset 35353 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2020-03-08T22:08:39+01:00 (5 years ago)
Author:
simon04
Message:

jmapviewer/Coordinate: unwrap Point2D to reduce memory consumption from 48 to 32 - see #josm18896

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Coordinate.java

    r35341 r35353  
    22package org.openstreetmap.gui.jmapviewer;
    33
    4 import java.awt.geom.Point2D;
    54import java.io.IOException;
    65import java.io.ObjectInputStream;
     
    2019public class Coordinate implements ICoordinate, Serializable {
    2120    private static final long serialVersionUID = 1L;
    22     private transient Point2D.Double data;
     21    private double x;
     22    private double y;
    2323
    2424    /**
     
    2828     */
    2929    public Coordinate(double lat, double lon) {
    30         data = new Point2D.Double(lon, lat);
     30        setLat(lat);
     31        setLon(lon);
    3132    }
    3233
    3334    @Override
    3435    public double getLat() {
    35         return data.y;
     36        return y;
    3637    }
    3738
    3839    @Override
    3940    public void setLat(double lat) {
    40         data.y = lat;
     41        y = lat;
    4142    }
    4243
    4344    @Override
    4445    public double getLon() {
    45         return data.x;
     46        return x;
    4647    }
    4748
    4849    @Override
    4950    public void setLon(double lon) {
    50         data.x = lon;
     51        x = lon;
    5152    }
    5253
    5354    private void writeObject(ObjectOutputStream out) throws IOException {
    54         out.writeObject(data.x);
    55         out.writeObject(data.y);
     55        out.writeObject(x);
     56        out.writeObject(y);
    5657    }
    5758
    5859    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    59         data = new Point2D.Double();
    60         data.x = (Double) in.readObject();
    61         data.y = (Double) in.readObject();
     60        x = (Double) in.readObject();
     61        y = (Double) in.readObject();
    6262    }
    6363
    6464    @Override
    6565    public String toString() {
    66         return "Coordinate[" + data.y + ", " + data.x + ']';
     66        return "Coordinate[" + y + ", " + x + ']';
    6767    }
    6868
    6969    @Override
    7070    public int hashCode() {
    71         return Objects.hashCode(data);
     71        return Objects.hash(x, y);
    7272    }
    7373
    7474    @Override
    75     public boolean equals(Object obj) {
    76         if (this == obj)
    77             return true;
    78         if (!(obj instanceof Coordinate))
    79             return false;
    80         final Coordinate other = (Coordinate) obj;
    81         return Objects.equals(data, other.data);
     75    public boolean equals(Object o) {
     76        if (this == o) return true;
     77        if (o == null || getClass() != o.getClass()) return false;
     78        Coordinate that = (Coordinate) o;
     79        return Double.compare(that.x, x) == 0 && Double.compare(that.y, y) == 0;
    8280    }
    8381}
Note: See TracChangeset for help on using the changeset viewer.