Ticket #20793: 20793.gpx-memory.diff
| File 20793.gpx-memory.diff, 14.0 KB (added by , 5 years ago) |
|---|
-
src/org/openstreetmap/josm/data/gpx/GpxExtensionCollection.java
22 22 23 23 private static final long serialVersionUID = 1L; 24 24 25 private final Stack<GpxExtension> childStack = new Stack<>();25 private Stack<GpxExtension> childStack; 26 26 private IWithAttributes parent; 27 27 28 28 /** … … 46 46 * @param atts the attributes 47 47 */ 48 48 public void openChild(String namespaceURI, String qName, Attributes atts) { 49 if (childStack == null) { 50 childStack = new Stack<>(); 51 } 49 52 GpxExtension child = new GpxExtension(namespaceURI, qName, atts); 50 53 if (!childStack.isEmpty()) { 51 54 childStack.lastElement().getExtensions().add(child); … … 62 65 * @param value the value 63 66 */ 64 67 public void closeChild(String qName, String value) { 65 if (childStack .isEmpty())68 if (childStack == null || childStack.isEmpty()) 66 69 throw new InvalidArgumentException("Can't close child " + qName + ", no element in stack."); 67 70 68 71 GpxExtension child = childStack.pop(); … … 258 261 259 262 @Override 260 263 public void clear() { 261 childStack.clear(); 264 if (childStack != null) { 265 childStack.clear(); 266 childStack = null; 267 } 262 268 super.clear(); 263 269 } 264 270 -
src/org/openstreetmap/josm/data/gpx/GpxTrack.java
104 104 } 105 105 106 106 private Color getColorFromExtension() { 107 GpxExtension gpxd = getExtensions().find("gpxd", "color"); 108 if (gpxd != null) { 109 colorFormat = ColorFormat.GPXD; 110 String cs = gpxd.getValue(); 111 try { 112 return Color.decode(cs); 113 } catch (NumberFormatException ex) { 114 Logging.warn("Could not read gpxd color: " + cs); 115 } 116 } else { 117 GpxExtension gpxx = getExtensions().find("gpxx", "DisplayColor"); 118 if (gpxx != null) { 119 colorFormat = ColorFormat.GPXX; 120 String cs = gpxx.getValue(); 121 if (cs != null) { 122 Color cc = GARMIN_COLORS.get(cs); 123 if (cc != null) { 124 return cc; 107 if (hasExtensions()) { 108 GpxExtension gpxd = getExtensions().find("gpxd", "color"); 109 if (gpxd != null) { 110 colorFormat = ColorFormat.GPXD; 111 String cs = gpxd.getValue(); 112 try { 113 return Color.decode(cs); 114 } catch (NumberFormatException ex) { 115 Logging.warn("Could not read gpxd color: " + cs); 116 } 117 } else { 118 GpxExtension gpxx = getExtensions().find("gpxx", "DisplayColor"); 119 if (gpxx != null) { 120 colorFormat = ColorFormat.GPXX; 121 String cs = gpxx.getValue(); 122 if (cs != null) { 123 Color cc = GARMIN_COLORS.get(cs); 124 if (cc != null) { 125 return cc; 126 } 125 127 } 128 Logging.warn("Could not read garmin color: " + cs); 126 129 } 127 Logging.warn("Could not read garmin color: " + cs);128 130 } 129 131 } 130 132 return null; -
src/org/openstreetmap/josm/data/gpx/IWithAttributes.java
57 57 Map<String, Object> getAttributes(); 58 58 59 59 /** 60 * Returns whether the {@link GpxExtensionCollection} instance has been created yet, should be overridden. 61 * The instance will usually be created on first call of {@link #getExtensions()}. 62 * @return whether the {@link GpxExtensionCollection} instance has been created yet 63 */ 64 default boolean hasExtensions() { 65 return getExtensions() != null; 66 } 67 68 /** 60 69 * Returns the extensions 61 70 * @return the extensions 62 71 */ -
src/org/openstreetmap/josm/data/gpx/WithAttributes.java
24 24 /** 25 25 * The "exts" collection contains all extensions. 26 26 */ 27 private final GpxExtensionCollection exts = new GpxExtensionCollection(this);27 private GpxExtensionCollection exts; 28 28 29 29 /** 30 30 * Returns the Object value to which the specified key is mapped, … … 86 86 } 87 87 88 88 @Override 89 public boolean hasExtensions() { 90 return exts != null; 91 } 92 93 @Override 89 94 public GpxExtensionCollection getExtensions() { 95 if (exts == null) { 96 exts = new GpxExtensionCollection(this); 97 } 90 98 return exts; 91 99 } 92 100 -
src/org/openstreetmap/josm/io/GpxReader.java
506 506 currentState = states.pop(); 507 507 if (!currentTrackSeg.isEmpty()) { 508 508 GpxTrackSegment seg = new GpxTrackSegment(currentTrackSeg); 509 seg.getExtensions().addAll(currentExtensionCollection); 509 if (!currentExtensionCollection.isEmpty()) { 510 seg.getExtensions().addAll(currentExtensionCollection); 511 } 510 512 currentTrack.add(seg); 511 513 } 512 514 currentExtensionCollection.clear(); … … 518 520 currentState = states.pop(); 519 521 convertUrlToLink(currentTrackAttr); 520 522 GpxTrack trk = new GpxTrack(new ArrayList<>(currentTrack), currentTrackAttr); 521 trk.getExtensions().addAll(currentTrackExtensionCollection); 523 if (!currentTrackExtensionCollection.isEmpty()) { 524 trk.getExtensions().addAll(currentTrackExtensionCollection); 525 } 522 526 data.addTrack(trk); 523 527 currentTrackExtensionCollection.clear(); 524 528 break;
