source: josm/trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java@ 9950

Last change on this file since 9950 was 8846, checked in by Don-vip, 9 years ago

sonar - fb-contrib - minor performance improvements:

  • Method passes constant String of length 1 to character overridden method
  • Method needlessly boxes a boolean constant
  • Method uses iterator().next() on a List to get the first item
  • Method converts String to boxed primitive using excessive boxing
  • Method converts String to primitive using excessive boxing
  • Method creates array using constants
  • Class defines List based fields but uses them like Sets
  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.coor;
3
4import org.openstreetmap.josm.Main;
5import org.openstreetmap.josm.data.projection.Projection;
6
7/**
8 * LatLon class that maintains a cache of projected EastNorth coordinates.
9 *
10 * This class is convenient to use, but has relatively high memory costs.
11 * It keeps a pointer to the last known projection in order to detect projection changes.
12 *
13 * Node and WayPoint have another, optimized, cache for projected coordinates.
14 */
15public class CachedLatLon extends LatLon {
16
17 private static final long serialVersionUID = 1L;
18
19 private EastNorth eastNorth;
20 private transient Projection proj;
21
22 /**
23 * Constructs a new {@code CachedLatLon}.
24 * @param lat latitude
25 * @param lon longitude
26 */
27 public CachedLatLon(double lat, double lon) {
28 super(lat, lon);
29 }
30
31 /**
32 * Constructs a new {@code CachedLatLon}.
33 * @param coor lat/lon
34 */
35 public CachedLatLon(LatLon coor) {
36 super(coor.lat(), coor.lon());
37 proj = null;
38 }
39
40 /**
41 * Constructs a new {@code CachedLatLon}.
42 * @param eastNorth easting/northing
43 */
44 public CachedLatLon(EastNorth eastNorth) {
45 super(Main.getProjection().eastNorth2latlon(eastNorth));
46 proj = Main.getProjection();
47 this.eastNorth = eastNorth;
48 }
49
50 /**
51 * Replies the projected east/north coordinates.
52 *
53 * @return the internally cached east/north coordinates. null, if the globally defined projection is null
54 */
55 public final EastNorth getEastNorth() {
56 if (proj != Main.getProjection()) {
57 proj = Main.getProjection();
58 eastNorth = proj.latlon2eastNorth(this);
59 }
60 return eastNorth;
61 }
62
63 @Override
64 public String toString() {
65 return "CachedLatLon[lat="+lat()+",lon="+lon()+']';
66 }
67}
Note: See TracBrowser for help on using the repository browser.