- Timestamp:
- 2020-02-06T01:03:07+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r15419 r15820 18 18 import java.util.Set; 19 19 import java.util.concurrent.TimeUnit; 20 import java.util.concurrent.atomic.AtomicLong;21 20 import java.util.function.BiPredicate; 22 21 … … 31 30 */ 32 31 public abstract class AbstractPrimitive implements IPrimitive { 33 34 private static final AtomicLong idCounter = new AtomicLong(0);35 36 /**37 * Generates a new primitive unique id.38 * @return new primitive unique (negative) id39 */40 static long generateUniqueId() {41 return idCounter.decrementAndGet();42 }43 44 /**45 * Returns the current primitive unique id.46 * @return the current primitive unique (negative) id (last generated)47 * @since 1253648 */49 public static long currentUniqueId() {50 return idCounter.get();51 }52 53 /**54 * Advances the current primitive unique id to skip a range of values.55 * @param newId new unique id56 * @throws IllegalArgumentException if newId is greater than current unique id57 * @since 1253658 */59 public static void advanceUniqueId(long newId) {60 if (newId > currentUniqueId()) {61 throw new IllegalArgumentException("Cannot modify the id counter backwards");62 }63 idCounter.set(newId);64 }65 32 66 33 /** … … 284 251 public void clearOsmMetadata() { 285 252 // Not part of dataset - no lock necessary 286 this.id = ge nerateUniqueId();253 this.id = getIdGenerator().generateUniqueId(); 287 254 this.version = 0; 288 255 this.user = null; … … 293 260 this.setVisible(true); 294 261 } 262 263 /** 264 * Returns the unique identifier generator. 265 * @return the unique identifier generator 266 * @since 15820 267 */ 268 public abstract UniqueIdGenerator getIdGenerator(); 295 269 296 270 @Override -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r15449 r15820 26 26 */ 27 27 public final class Node extends OsmPrimitive implements INode { 28 29 static final UniqueIdGenerator idGenerator = new UniqueIdGenerator(); 28 30 29 31 /* … … 423 425 return false; 424 426 } 427 428 @Override 429 public UniqueIdGenerator getIdGenerator() { 430 return idGenerator; 431 } 425 432 } -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r14120 r15820 13 13 14 14 private static final long serialVersionUID = 5626323599550908773L; 15 private static final UniqueIdGenerator idGenerator = Node.idGenerator; 15 16 /* 16 17 * we "inline" lat/lon coordinates instead of using a LatLon => reduces memory footprint … … 24 25 public NodeData() { 25 26 // contents can be set later with setters 27 this(idGenerator.generateUniqueId()); 26 28 } 27 29 … … 109 111 return false; 110 112 } 113 114 @Override 115 public UniqueIdGenerator getIdGenerator() { 116 return idGenerator; 117 } 111 118 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r15588 r15820 112 112 throw new IllegalArgumentException(MessageFormat.format("Expected ID >= 0. Got {0}.", id)); 113 113 else if (id == 0) { 114 this.id = ge nerateUniqueId();114 this.id = getIdGenerator().generateUniqueId(); 115 115 } else { 116 116 this.id = id; -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java
r13766 r15820 16 16 17 17 /** Node type */ 18 NODE(marktr(/* ICON(data/) */"node"), Node.class, NodeData.class ),18 NODE(marktr(/* ICON(data/) */"node"), Node.class, NodeData.class, Node.idGenerator), 19 19 /** Way type */ 20 WAY(marktr(/* ICON(data/) */"way"), Way.class, WayData.class ),20 WAY(marktr(/* ICON(data/) */"way"), Way.class, WayData.class, Way.idGenerator), 21 21 /** Relation type */ 22 RELATION(marktr(/* ICON(data/) */"relation"), Relation.class, RelationData.class ),22 RELATION(marktr(/* ICON(data/) */"relation"), Relation.class, RelationData.class, Relation.idGenerator), 23 23 24 24 /** Closed way: only for display, no real type */ 25 CLOSEDWAY(marktr(/* ICON(data/) */"closedway"), null, WayData.class ),25 CLOSEDWAY(marktr(/* ICON(data/) */"closedway"), null, WayData.class, Way.idGenerator), 26 26 /** Multipolygon: only for display, no real type */ 27 MULTIPOLYGON(marktr(/* ICON(data/) */"multipolygon"), null, RelationData.class );27 MULTIPOLYGON(marktr(/* ICON(data/) */"multipolygon"), null, RelationData.class, Relation.idGenerator); 28 28 29 29 private static final Collection<OsmPrimitiveType> DATA_VALUES = Arrays.asList(NODE, WAY, RELATION); … … 32 32 private final Class<? extends OsmPrimitive> osmClass; 33 33 private final Class<? extends PrimitiveData> dataClass; 34 private final UniqueIdGenerator idGenerator; 34 35 35 OsmPrimitiveType(String apiTypeName, Class<? extends OsmPrimitive> osmClass, Class<? extends PrimitiveData> dataClass) { 36 OsmPrimitiveType(String apiTypeName, Class<? extends OsmPrimitive> osmClass, Class<? extends PrimitiveData> dataClass, 37 UniqueIdGenerator idGenerator) { 36 38 this.apiTypeName = apiTypeName; 37 39 this.osmClass = osmClass; 38 40 this.dataClass = dataClass; 41 this.idGenerator = idGenerator; 39 42 } 40 43 … … 154 157 } 155 158 159 /** 160 * Returns the unique identifier generator. 161 * @return the unique identifier generator 162 * @since 15820 163 */ 164 public final UniqueIdGenerator getIdGenerator() { 165 return idGenerator; 166 } 167 156 168 @Override 157 169 public String toString() { -
trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
r13808 r15820 26 26 27 27 private static final long serialVersionUID = -1044837092478109138L; 28 29 /**30 * Constructs a new {@code PrimitiveData}.31 */32 public PrimitiveData() {33 this(OsmPrimitive.generateUniqueId());34 }35 28 36 29 /** -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r15418 r15820 28 28 */ 29 29 public final class Relation extends OsmPrimitive implements IRelation<RelationMember> { 30 31 static final UniqueIdGenerator idGenerator = new UniqueIdGenerator(); 30 32 31 33 private RelationMember[] members = new RelationMember[0]; … … 550 552 .map(m -> (OsmPrimitive) m).collect(Collectors.toList()); 551 553 } 554 555 @Override 556 public UniqueIdGenerator getIdGenerator() { 557 return idGenerator; 558 } 552 559 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationData.java
r13908 r15820 14 14 15 15 private static final long serialVersionUID = 1163664954890478565L; 16 private static final UniqueIdGenerator idGenerator = Relation.idGenerator; 16 17 private List<RelationMemberData> members = new ArrayList<>(); 17 18 … … 21 22 public RelationData() { 22 23 // contents can be set later with setters 24 this(idGenerator.generateUniqueId()); 23 25 } 24 26 … … 100 102 throw new UnsupportedOperationException(); 101 103 } 104 105 @Override 106 public UniqueIdGenerator getIdGenerator() { 107 return idGenerator; 108 } 102 109 } -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r15436 r15820 28 28 */ 29 29 public final class Way extends OsmPrimitive implements IWay<Node> { 30 31 static final UniqueIdGenerator idGenerator = new UniqueIdGenerator(); 30 32 31 33 /** … … 749 751 return angles; 750 752 } 753 754 @Override 755 public UniqueIdGenerator getIdGenerator() { 756 return idGenerator; 757 } 751 758 } -
trunk/src/org/openstreetmap/josm/data/osm/WayData.java
r13922 r15820 14 14 15 15 private static final long serialVersionUID = 106944939313286415L; 16 private static final UniqueIdGenerator idGenerator = Way.idGenerator; 16 17 private List<Long> nodes = new ArrayList<>(); 17 18 … … 21 22 public WayData() { 22 23 // contents can be set later with setters 24 this(idGenerator.generateUniqueId()); 23 25 } 24 26 … … 130 132 throw new UnsupportedOperationException(); 131 133 } 134 135 @Override 136 public UniqueIdGenerator getIdGenerator() { 137 return idGenerator; 138 } 132 139 } -
trunk/src/org/openstreetmap/josm/io/AbstractReader.java
r15783 r15820 326 326 throw new IllegalDataException(e); 327 327 } finally { 328 OptionalLong minId = externalIdMap.values().stream().mapToLong(AbstractPrimitive::getUniqueId).min(); 329 synchronized (AbstractPrimitive.class) { 330 if (minId.isPresent() && minId.getAsLong() < AbstractPrimitive.currentUniqueId()) { 331 AbstractPrimitive.advanceUniqueId(minId.getAsLong()); 328 for (OsmPrimitiveType dataType : OsmPrimitiveType.dataValues()) { 329 OptionalLong minId = externalIdMap.entrySet().parallelStream() 330 .filter(e -> e.getKey().getType() == dataType) 331 .mapToLong(e -> e.getValue().getUniqueId()).min(); 332 synchronized (dataType.getDataClass()) { 333 if (minId.isPresent() && minId.getAsLong() < dataType.getIdGenerator().currentUniqueId()) { 334 dataType.getIdGenerator().advanceUniqueId(minId.getAsLong()); 335 } 332 336 } 333 337 } … … 615 619 protected OsmPrimitive buildPrimitive(PrimitiveData pd) { 616 620 OsmPrimitive p; 617 if (pd.getUniqueId() < AbstractPrimitive.currentUniqueId()) {621 if (pd.getUniqueId() < pd.getIdGenerator().currentUniqueId()) { 618 622 p = pd.getType().newInstance(pd.getUniqueId(), true); 619 AbstractPrimitive.advanceUniqueId(pd.getUniqueId());623 pd.getIdGenerator().advanceUniqueId(pd.getUniqueId()); 620 624 } else { 621 625 p = pd.getType().newVersionedInstance(pd.getId(), pd.getVersion()); … … 655 659 protected final Node parseNode(String lat, String lon, CommonReader commonReader, NodeReader nodeReader) 656 660 throws IllegalDataException { 657 NodeData nd = new NodeData( );661 NodeData nd = new NodeData(0); 658 662 LatLon ll = null; 659 663 if (areLatLonDefined(lat, lon)) {
Note:
See TracChangeset
for help on using the changeset viewer.