Changeset 13453 in josm for trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
- Timestamp:
- 2018-02-24T18:58:28+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r13434 r13453 104 104 * @author imi 105 105 */ 106 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, ReadOnly { 106 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, Lockable { 107 108 /** 109 * Download policy. 110 * 111 * Determines if download from the OSM server is intended, discouraged, or disabled / blocked. 112 * @see UploadPolicy 113 * @since 13453 114 */ 115 public enum DownloadPolicy { 116 /** 117 * Normal dataset, download intended. 118 */ 119 NORMAL("true"), 120 /** 121 * Download blocked. 122 * Download options completely disabled. Intended for private layers, see #8039. 123 */ 124 BLOCKED("never"); 125 126 final String xmlFlag; 127 128 DownloadPolicy(String xmlFlag) { 129 this.xmlFlag = xmlFlag; 130 } 131 132 /** 133 * Get the corresponding value of the <code>upload='...'</code> XML-attribute 134 * in the .osm file. 135 * @return value of the <code>download</code> attribute 136 */ 137 public String getXmlFlag() { 138 return xmlFlag; 139 } 140 141 /** 142 * Returns the {@code DownloadPolicy} for the given <code>upload='...'</code> XML-attribute 143 * @param xmlFlag <code>download='...'</code> XML-attribute to convert 144 * @return {@code DownloadPolicy} value 145 * @throws IllegalArgumentException for invalid values 146 */ 147 public static DownloadPolicy of(String xmlFlag) { 148 for (DownloadPolicy policy : values()) { 149 if (policy.getXmlFlag().equalsIgnoreCase(xmlFlag)) { 150 return policy; 151 } 152 } 153 throw new IllegalArgumentException(xmlFlag); 154 } 155 } 107 156 108 157 /** 109 158 * Upload policy. 110 159 * 111 * Determines if upload to the OSM server is intended, discouraged, or 112 * disabled / blocked.160 * Determines if upload to the OSM server is intended, discouraged, or disabled / blocked. 161 * @see DownloadPolicy 113 162 */ 114 163 public enum UploadPolicy { … … 173 222 174 223 private final Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true); 175 private final Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new Storage.PrimitiveIdHash()); 224 private final Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives 225 .foreignKey(new Storage.PrimitiveIdHash()); 176 226 private final CopyOnWriteArrayList<DataSetListener> listeners = new CopyOnWriteArrayList<>(); 177 227 … … 187 237 188 238 private String name; 239 private DownloadPolicy downloadPolicy; 189 240 private UploadPolicy uploadPolicy; 190 241 /** Flag used to know if the dataset should not be editable */ … … 250 301 primMap.put(w, newWay); 251 302 List<Node> newNodes = new ArrayList<>(); 252 for (Node n : w.getNodes()) {303 for (Node n : w.getNodes()) { 253 304 newNodes.add((Node) primMap.get(n)); 254 305 } … … 268 319 Relation newRelation = (Relation) primMap.get(r); 269 320 List<RelationMember> newMembers = new ArrayList<>(); 270 for (RelationMember rm : r.getMembers()) {321 for (RelationMember rm : r.getMembers()) { 271 322 newMembers.add(new RelationMember(rm.getRole(), primMap.get(rm.getMember()))); 272 323 } … … 378 429 checkModifiable(); 379 430 this.version = version; 431 } 432 433 /** 434 * Get the download policy. 435 * @return the download policy 436 * @see #setDownloadPolicy(DownloadPolicy) 437 * @since 13453 438 */ 439 public DownloadPolicy getDownloadPolicy() { 440 return this.downloadPolicy; 441 } 442 443 /** 444 * Sets the download policy. 445 * @param downloadPolicy the download policy 446 * @see #getUploadPolicy() 447 * @since 13453 448 */ 449 public void setDownloadPolicy(DownloadPolicy downloadPolicy) { 450 this.downloadPolicy = downloadPolicy; 380 451 } 381 452 … … 529 600 */ 530 601 public Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives() { 531 return getPrimitives(primitive -> !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation)); 602 return getPrimitives( 603 primitive -> !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation)); 532 604 } 533 605 … … 565 637 if (getPrimitiveById(primitive) != null) 566 638 throw new DataIntegrityProblemException( 567 tr("Unable to add primitive {0} to the dataset because it is already included", primitive.toString())); 639 tr("Unable to add primitive {0} to the dataset because it is already included", 640 primitive.toString())); 568 641 569 642 allPrimitives.add(primitive); … … 690 763 */ 691 764 public Collection<OsmPrimitive> getSelectedNodesAndWays() { 692 return new SubclassFilteredCollection<>(getSelected(), primitive -> primitive instanceof Node || primitive instanceof Way); 765 return new SubclassFilteredCollection<>(getSelected(), 766 primitive -> primitive instanceof Node || primitive instanceof Way); 693 767 } 694 768 … … 1006 1080 OsmPrimitive result = getPrimitiveById(primitiveId); 1007 1081 if (result == null && primitiveId != null) { 1008 Logging.warn(tr("JOSM expected to find primitive [{0} {1}] in dataset but it is not there. Please report this " 1009 + "at {2}. This is not a critical error, it should be safe to continue in your work.", 1082 Logging.warn(tr( 1083 "JOSM expected to find primitive [{0} {1}] in dataset but it is not there. Please report this " 1084 + "at {2}. This is not a critical error, it should be safe to continue in your work.", 1010 1085 primitiveId.getType(), Long.toString(primitiveId.getUniqueId()), Main.getJOSMWebsite())); 1011 1086 Logging.error(new Exception()); … … 1115 1190 */ 1116 1191 public boolean isModified() { 1117 for (OsmPrimitive p : allPrimitives) {1192 for (OsmPrimitive p : allPrimitives) { 1118 1193 if (p.isModified()) 1119 1194 return true; … … 1128 1203 */ 1129 1204 public boolean requiresUploadToServer() { 1130 for (OsmPrimitive p : allPrimitives) {1205 for (OsmPrimitive p : allPrimitives) { 1131 1206 if (APIOperation.of(p) != null) 1132 1207 return true; … … 1199 1274 try { 1200 1275 if (eventsToFire.size() < MAX_SINGLE_EVENTS) { 1201 for (AbstractDatasetChangedEvent event : eventsToFire) {1276 for (AbstractDatasetChangedEvent event : eventsToFire) { 1202 1277 fireEventToListeners(event); 1203 1278 } … … 1219 1294 1220 1295 private void fireEventToListeners(AbstractDatasetChangedEvent event) { 1221 for (DataSetListener listener : listeners) {1296 for (DataSetListener listener : listeners) { 1222 1297 event.fire(listener); 1223 1298 } … … 1260 1335 1261 1336 void fireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, int newChangesetId) { 1262 fireEvent(new ChangesetIdChangedEvent(this, Collections.singletonList(primitive), oldChangesetId, newChangesetId)); 1337 fireEvent(new ChangesetIdChangedEvent(this, Collections.singletonList(primitive), oldChangesetId, 1338 newChangesetId)); 1263 1339 } 1264 1340 … … 1283 1359 */ 1284 1360 public void invalidateEastNorthCache() { 1285 if (Main.getProjection() == null) return; // sanity check 1361 if (Main.getProjection() == null) 1362 return; // sanity check 1286 1363 beginUpdate(); 1287 1364 try { 1288 for (Node n : getNodes()) {1365 for (Node n : getNodes()) { 1289 1366 n.invalidateEastNorthCache(); 1290 1367 } … … 1326 1403 try { 1327 1404 clearSelection(); 1328 for (OsmPrimitive primitive :allPrimitives) {1405 for (OsmPrimitive primitive : allPrimitives) { 1329 1406 primitive.setDataset(null); 1330 1407 } … … 1343 1420 public void deleteInvisible() { 1344 1421 checkModifiable(); 1345 for (OsmPrimitive primitive :allPrimitives) {1422 for (OsmPrimitive primitive : allPrimitives) { 1346 1423 if (!primitive.isVisible()) { 1347 1424 primitive.setDeleted(true); … … 1454 1531 1455 1532 @Override 1456 public void setReadOnly() {1533 public void lock() { 1457 1534 if (!isReadOnly.compareAndSet(false, true)) { 1458 1535 Logging.warn("Trying to set readOnly flag on a readOnly dataset ", getName()); … … 1461 1538 1462 1539 @Override 1463 public void un setReadOnly() {1540 public void unlock() { 1464 1541 if (!isReadOnly.compareAndSet(true, false)) { 1465 1542 Logging.warn("Trying to unset readOnly flag on a non-readOnly dataset ", getName()); … … 1468 1545 1469 1546 @Override 1470 public boolean is ReadOnly() {1547 public boolean isLocked() { 1471 1548 return isReadOnly.get(); 1472 1549 } … … 1477 1554 */ 1478 1555 private void checkModifiable() { 1479 if (is ReadOnly()) {1556 if (isLocked()) { 1480 1557 throw new IllegalStateException("DataSet is read-only"); 1481 1558 }
Note:
See TracChangeset
for help on using the changeset viewer.