- Timestamp:
- 2011-05-29T21:04:54+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/APIDataSet.java
r3530 r4100 24 24 import org.openstreetmap.josm.data.osm.RelationMember; 25 25 import org.openstreetmap.josm.data.osm.Way; 26 import org.openstreetmap.josm.tools.Utils; 26 27 27 28 /** … … 286 287 public void adjustRelationUploadOrder() throws CyclicUploadDependencyException{ 287 288 LinkedList<OsmPrimitive> newToAdd = new LinkedList<OsmPrimitive>(); 288 newToAdd.addAll( OsmPrimitive.getFilteredList(toAdd, Node.class));289 newToAdd.addAll( OsmPrimitive.getFilteredList(toAdd, Way.class));290 291 List<Relation> relationsToAdd = OsmPrimitive.getFilteredList(toAdd, Relation.class);289 newToAdd.addAll(Utils.filteredCollection(toAdd, Node.class)); 290 newToAdd.addAll(Utils.filteredCollection(toAdd, Way.class)); 291 292 List<Relation> relationsToAdd = new ArrayList<Relation>(Utils.filteredCollection(toAdd, Relation.class)); 292 293 List<Relation> noProblemRelations = filterRelationsNotReferringToNewRelations(relationsToAdd); 293 294 newToAdd.addAll(noProblemRelations); -
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r4099 r4100 10 10 import java.util.HashMap; 11 11 import java.util.HashSet; 12 import java.util.Locale; 12 13 import java.util.Map; 13 14 import java.util.Map.Entry; … … 163 164 * @see #isUndeleted() 164 165 */ 166 @Override 165 167 public boolean isNewOrUndeleted() { 166 168 return (id <= 0) || ((flags & (FLAG_VISIBLE + FLAG_DELETED)) == 0); … … 261 263 * @return the unique primitive id for this primitive 262 264 */ 265 @Override 263 266 public PrimitiveId getPrimitiveId() { 264 267 return new SimplePrimitiveId(getUniqueId(), getType()); … … 638 641 abstract protected void keysChangedImpl(Map<String, String> originalKeys); 639 642 643 /** 644 * Replies the name of this primitive. The default implementation replies the value 645 * of the tag <tt>name</tt> or null, if this tag is not present. 646 * 647 * @return the name of this primitive 648 */ 649 @Override 650 public String getName() { 651 return get("name"); 652 } 653 654 /** 655 * Replies the a localized name for this primitive given by the value of the tags (in this order) 656 * <ul> 657 * <li>name:lang_COUNTRY_Variant of the current locale</li> 658 * <li>name:lang_COUNTRY of the current locale</li> 659 * <li>name:lang of the current locale</li> 660 * <li>name of the current locale</li> 661 * </ul> 662 * 663 * null, if no such tag exists 664 * 665 * @return the name of this primitive 666 */ 667 @Override 668 public String getLocalName() { 669 String key = "name:" + Locale.getDefault().toString(); 670 if (get(key) != null) 671 return get(key); 672 key = "name:" + Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry(); 673 if (get(key) != null) 674 return get(key); 675 key = "name:" + Locale.getDefault().getLanguage(); 676 if (get(key) != null) 677 return get(key); 678 return getName(); 679 } 680 681 /** 682 * Replies the display name of a primitive formatted by <code>formatter</code> 683 * 684 * @return the display name 685 */ 686 @Override 687 public abstract String getDisplayName(NameFormatter formatter); 688 640 689 } -
trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java
r4098 r4100 3 3 4 4 import java.util.Date; 5 6 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 5 7 6 8 /** … … 16 18 void setDeleted(boolean deleted); 17 19 boolean isIncomplete(); 20 boolean isNewOrUndeleted(); 18 21 long getId(); 22 PrimitiveId getPrimitiveId(); 19 23 int getVersion(); 20 24 void setOsmId(long id, int version); … … 26 30 int getChangesetId(); 27 31 void setChangesetId(int changesetId); 32 33 void visit(PrimitiveVisitor visitor); 34 String getName(); 35 String getLocalName(); 36 String getDisplayName(NameFormatter formatter); 28 37 29 38 } -
trunk/src/org/openstreetmap/josm/data/osm/IWay.java
r4098 r4100 6 6 int getNodesCount(); 7 7 long getNodeId(int idx); 8 8 boolean isClosed(); 9 9 10 } -
trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java
r4070 r4100 5 5 6 6 public interface NameFormatter { 7 String format( Node node);8 String format( Way way);9 String format( Relation relation);7 String format(INode node); 8 String format(IWay way); 9 String format(IRelation relation); 10 10 String format(Changeset changeset); 11 11 -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r4098 r4100 5 5 import org.openstreetmap.josm.data.coor.EastNorth; 6 6 import org.openstreetmap.josm.data.coor.LatLon; 7 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 7 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 8 9 … … 138 139 139 140 @Override public void visit(Visitor visitor) { 141 visitor.visit(this); 142 } 143 144 @Override public void visit(PrimitiveVisitor visitor) { 140 145 visitor.visit(this); 141 146 } -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r4099 r4100 5 5 import org.openstreetmap.josm.data.coor.EastNorth; 6 6 import org.openstreetmap.josm.data.coor.LatLon; 7 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 7 8 8 9 public class NodeData extends PrimitiveData implements INode { … … 53 54 return OsmPrimitiveType.NODE; 54 55 } 56 57 @Override 58 public void visit(PrimitiveVisitor visitor) { 59 visitor.visit(this); 60 } 61 62 @Override 63 public String getDisplayName(NameFormatter formatter) { 64 return formatter.format(this); 65 } 66 55 67 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r4099 r4100 14 14 import java.util.LinkedList; 15 15 import java.util.List; 16 import java.util.Locale;17 16 import java.util.Map; 18 17 import java.util.Set; … … 1013 1012 1014 1013 /** 1015 * Replies the name of this primitive. The default implementation replies the value1016 * of the tag <tt>name</tt> or null, if this tag is not present.1017 *1018 * @return the name of this primitive1019 */1020 public String getName() {1021 return get("name");1022 }1023 1024 /**1025 * Replies the a localized name for this primitive given by the value of the tags (in this order)1026 * <ul>1027 * <li>name:lang_COUNTRY_Variant of the current locale</li>1028 * <li>name:lang_COUNTRY of the current locale</li>1029 * <li>name:lang of the current locale</li>1030 * <li>name of the current locale</li>1031 * </ul>1032 *1033 * null, if no such tag exists1034 *1035 * @return the name of this primitive1036 */1037 public String getLocalName() {1038 String key = "name:" + Locale.getDefault().toString();1039 if (get(key) != null)1040 return get(key);1041 key = "name:" + Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry();1042 if (get(key) != null)1043 return get(key);1044 key = "name:" + Locale.getDefault().getLanguage();1045 if (get(key) != null)1046 return get(key);1047 return getName();1048 }1049 1050 /**1051 * Replies the display name of a primitive formatted by <code>formatter</code>1052 *1053 * @return the display name1054 */1055 public abstract String getDisplayName(NameFormatter formatter);1056 1057 /**1058 1014 * Loads (clone) this primitive from provided PrimitiveData 1059 1015 * @param data -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java
r3905 r4100 45 45 } 46 46 47 public static OsmPrimitiveType from(OsmPrimitive obj) { 48 return from(obj.getClass()); 49 } 50 51 public static OsmPrimitiveType from(Class<? extends OsmPrimitive> cls) { 52 if (cls.equals(Node.class)) return NODE; 53 if (cls.equals(Way.class)) return WAY; 54 if (cls.equals(Relation.class)) return RELATION; 55 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' is not an acceptable class. Got ''{1}''.", "cls", cls.toString())); 56 } 57 58 public static OsmPrimitiveType fromData(Class<? extends PrimitiveData> cls) { 59 if (cls.equals(NodeData.class)) return NODE; 60 if (cls.equals(WayData.class)) return WAY; 61 if (cls.equals(RelationData.class)) return RELATION; 62 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' is not an acceptable class. Got ''{1}''.", "cls", cls.toString())); 63 } 64 65 public static OsmPrimitiveType fromData(PrimitiveData data) { 66 return fromData(data.getClass()); 47 public static OsmPrimitiveType from(IPrimitive obj) { 48 if (obj instanceof INode) return NODE; 49 if (obj instanceof IWay) return WAY; 50 if (obj instanceof IRelation) return RELATION; 51 throw new IllegalArgumentException(); 67 52 } 68 53 -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r4098 r4100 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 12 13 import org.openstreetmap.josm.data.osm.visitor.Visitor; 13 14 import org.openstreetmap.josm.tools.CopyList; … … 162 163 163 164 @Override public void visit(Visitor visitor) { 165 visitor.visit(this); 166 } 167 168 @Override public void visit(PrimitiveVisitor visitor) { 164 169 visitor.visit(this); 165 170 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationData.java
r4098 r4100 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 7 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 6 8 7 9 public class RelationData extends PrimitiveData implements IRelation { … … 60 62 return OsmPrimitiveType.RELATION; 61 63 } 64 65 @Override 66 public void visit(PrimitiveVisitor visitor) { 67 visitor.visit(this); 68 } 69 70 @Override 71 public String getDisplayName(NameFormatter formatter) { 72 return formatter.format(this); 73 } 74 62 75 } -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r4098 r4100 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 12 13 import org.openstreetmap.josm.data.osm.visitor.Visitor; 13 14 import org.openstreetmap.josm.tools.CopyList; … … 160 161 visitor.visit(this); 161 162 } 163 164 @Override public void visit(PrimitiveVisitor visitor) { 165 visitor.visit(this); 166 } 162 167 163 168 protected Way(long id, boolean allowNegative) { … … 409 414 } 410 415 416 @Override 411 417 public boolean isClosed() { 412 418 if (isIncomplete()) return false; -
trunk/src/org/openstreetmap/josm/data/osm/WayData.java
r4098 r4100 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 6 7 7 8 public class WayData extends PrimitiveData implements IWay { … … 32 33 } 33 34 35 @Override 36 public boolean isClosed() { 37 if (isIncomplete()) return false; 38 return nodes.get(0).equals(nodes.get(nodes.size() - 1)); 39 } 40 34 41 public void setNodes(List<Long> nodes) { 35 42 this.nodes = new ArrayList<Long>(nodes); … … 50 57 return OsmPrimitiveType.WAY; 51 58 } 59 60 @Override 61 public void visit(PrimitiveVisitor visitor) { 62 visitor.visit(this); 63 } 64 65 @Override 66 public String getDisplayName(NameFormatter formatter) { 67 return formatter.format(this); 68 } 69 52 70 } -
trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java
r4070 r4100 17 17 import org.openstreetmap.josm.data.coor.CoordinateFormat; 18 18 import org.openstreetmap.josm.data.osm.Changeset; 19 import org.openstreetmap.josm.data.osm.INode; 20 import org.openstreetmap.josm.data.osm.IPrimitive; 21 import org.openstreetmap.josm.data.osm.IRelation; 22 import org.openstreetmap.josm.data.osm.IWay; 19 23 import org.openstreetmap.josm.data.osm.NameFormatter; 20 24 import org.openstreetmap.josm.data.osm.Node; … … 83 87 * @return the decorated name 84 88 */ 85 protected String decorateNameWithId(String name, OsmPrimitive primitive) {89 protected String decorateNameWithId(String name, IPrimitive primitive) { 86 90 if (Main.pref.getBoolean("osm-primitives.showid")) 87 91 if (Main.pref.getBoolean("osm-primitives.showid.new-primitives")) … … 99 103 * @return the name 100 104 */ 101 public String format( Node node) {105 public String format(INode node) { 102 106 String name = ""; 103 107 if (node.isIncomplete()) { … … 157 161 * @return the name 158 162 */ 159 public String format( Way way) {163 public String format(IWay way) { 160 164 String name = ""; 161 165 if (way.isIncomplete()) { … … 233 237 * @return the name 234 238 */ 235 public String format( Relation relation) {239 public String format(IRelation relation) { 236 240 String name; 237 241 if (relation.isIncomplete()) { … … 250 254 name += trn("{0} member", "{0} members", mbno, mbno); 251 255 252 if (relationHasIncompleteMember(relation)) { 253 name += ", "+tr("incomplete"); 256 if (relation instanceof Relation) { 257 if (relationHasIncompleteMember((Relation) relation)) { 258 name += ", "+tr("incomplete"); 259 } 254 260 } 255 261 … … 325 331 } 326 332 327 private String getRelationTypeName( Relation relation) {333 private String getRelationTypeName(IRelation relation) { 328 334 String name = trc("Relation type", relation.get("type")); 329 335 if (name == null) { … … 353 359 } 354 360 355 private String getNameTagValue( Relation relation, String nameTag) {361 private String getNameTagValue(IRelation relation, String nameTag) { 356 362 if (nameTag.equals("name")) { 357 363 if (Main.pref.getBoolean("osm-primitives.localize-name", true)) … … 369 375 } 370 376 371 private String getRelationName( Relation relation) {377 private String getRelationName(IRelation relation) { 372 378 String nameTag = null; 373 379 for (String n : getNamingtagsForRelations()) { … … 403 409 * @return the tooltip text 404 410 */ 405 public String buildDefaultToolTip( OsmPrimitive primitive) {411 public String buildDefaultToolTip(IPrimitive primitive) { 406 412 StringBuilder sb = new StringBuilder(); 407 413 sb.append("<html>"); -
trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java
r3995 r4100 93 93 // 94 94 System.out.println(tr("Warning: object ''{0}'' is already deleted on the server. Skipping this object and retrying to upload.", p.getDisplayName(DefaultNameFormatter.getInstance()))); 95 processedPrimitives.addAll( writer.getProcessedPrimitives());95 processedPrimitives.addAll((Collection) writer.getProcessedPrimitives()); 96 96 processedPrimitives.add(p); 97 97 toUpload.removeAll(processedPrimitives); … … 124 124 if (isCancelled()) return; 125 125 writer.uploadOsm(strategy, toUpload, changeset, m); 126 processedPrimitives.addAll( writer.getProcessedPrimitives());126 processedPrimitives.addAll((Collection) writer.getProcessedPrimitives()); // OsmPrimitive in => OsmPrimitive out 127 127 break; 128 128 } catch(OsmApiPrimitiveGoneException e) { -
trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java
r3757 r4100 9 9 import java.io.IOException; 10 10 import java.lang.reflect.InvocationTargetException; 11 import java.util.Collection; 11 12 import java.util.HashSet; 12 13 import java.util.logging.Logger; … … 194 195 System.out.println(tr("Warning: object ''{0}'' is already deleted on the server. Skipping this object and retrying to upload.", p.getDisplayName(DefaultNameFormatter.getInstance()))); 195 196 monitor.appendLogMessage(tr("Object ''{0}'' is already deleted. Skipping object in upload.",p.getDisplayName(DefaultNameFormatter.getInstance()))); 196 processedPrimitives.addAll( writer.getProcessedPrimitives());197 processedPrimitives.addAll((Collection) writer.getProcessedPrimitives()); 197 198 processedPrimitives.add(p); 198 199 toUpload.removeProcessed(processedPrimitives); … … 248 249 recoverFromGoneOnServer(e, getProgressMonitor()); 249 250 } catch(ChangesetClosedException e) { 250 processedPrimitives.addAll( writer.getProcessedPrimitives());251 processedPrimitives.addAll((Collection) writer.getProcessedPrimitives()); // OsmPrimitive in => OsmPrimitive out 251 252 changeset.setOpen(false); 252 253 switch(e.getSource()) { … … 273 274 } finally { 274 275 if (writer != null) { 275 processedPrimitives.addAll( writer.getProcessedPrimitives());276 processedPrimitives.addAll((Collection) writer.getProcessedPrimitives()); 276 277 } 277 278 synchronized(this) { -
trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java
r3422 r4100 17 17 18 18 import org.openstreetmap.josm.data.osm.Changeset; 19 import org.openstreetmap.josm.data.osm. OsmPrimitive;19 import org.openstreetmap.josm.data.osm.IPrimitive; 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 21 21 import org.openstreetmap.josm.data.osm.PrimitiveId; … … 46 46 * is set 47 47 */ 48 private Set< OsmPrimitive> processed;48 private Set<IPrimitive> processed; 49 49 /** 50 50 * the collection of primitives being uploaded 51 51 */ 52 private Collection< OsmPrimitive> primitives;52 private Collection<? extends IPrimitive> primitives; 53 53 54 54 /** … … 58 58 * assumes an empty collection. 59 59 */ 60 public DiffResultProcessor(Collection< OsmPrimitive> primitives) {60 public DiffResultProcessor(Collection<? extends IPrimitive> primitives) { 61 61 if (primitives == null) { 62 62 primitives = Collections.emptyList(); 63 63 } 64 64 this.primitives = primitives; 65 this.processed = new HashSet< OsmPrimitive>();65 this.processed = new HashSet<IPrimitive>(); 66 66 } 67 67 … … 108 108 * @return the collection of processed primitives 109 109 */ 110 protected Set< OsmPrimitive> postProcess(Changeset cs,ProgressMonitor monitor) {110 protected Set<IPrimitive> postProcess(Changeset cs, ProgressMonitor monitor) { 111 111 if (monitor == null) { 112 112 monitor = NullProgressMonitor.INSTANCE; … … 116 116 monitor.setTicksCount(primitives.size()); 117 117 monitor.setTicks(0); 118 for ( OsmPrimitive p: primitives) {118 for (IPrimitive p : primitives) { 119 119 monitor.worked(1); 120 120 DiffResultEntry entry = diffResults.get(p.getPrimitiveId()); -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r3993 r4100 30 30 import org.openstreetmap.josm.Main; 31 31 import org.openstreetmap.josm.data.osm.Changeset; 32 import org.openstreetmap.josm.data.osm. OsmPrimitive;32 import org.openstreetmap.josm.data.osm.IPrimitive; 33 33 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 34 34 import org.openstreetmap.josm.gui.layer.Layer; … … 230 230 * @return XML string 231 231 */ 232 private String toXml( OsmPrimitive o, boolean addBody) {232 private String toXml(IPrimitive o, boolean addBody) { 233 233 swriter.getBuffer().setLength(0); 234 234 osmWriter.setWithBody(addBody); … … 250 250 swriter.getBuffer().setLength(0); 251 251 osmWriter.header(); 252 s.visit(osmWriter);252 osmWriter.visit(s); 253 253 osmWriter.footer(); 254 254 osmWriter.out.flush(); … … 280 280 * @throws OsmTransferException if something goes wrong 281 281 */ 282 public void createPrimitive( OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {282 public void createPrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 283 283 String ret = ""; 284 284 try { … … 300 300 * @throws OsmTransferException if something goes wrong 301 301 */ 302 public void modifyPrimitive( OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {302 public void modifyPrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 303 303 String ret = null; 304 304 try { … … 320 320 * @throws OsmTransferException if something goes wrong 321 321 */ 322 public void deletePrimitive( OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {322 public void deletePrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException { 323 323 ensureValidChangeset(); 324 324 initialize(monitor); … … 440 440 * @throws OsmTransferException if something is wrong 441 441 */ 442 public Collection< OsmPrimitive> uploadDiff(Collection<OsmPrimitive> list, ProgressMonitor monitor) throws OsmTransferException {442 public Collection<IPrimitive> uploadDiff(Collection<? extends IPrimitive> list, ProgressMonitor monitor) throws OsmTransferException { 443 443 try { 444 444 monitor.beginTask("", list.size() * 2); -
trunk/src/org/openstreetmap/josm/io/OsmChangeBuilder.java
r3366 r4100 9 9 10 10 import org.openstreetmap.josm.data.osm.Changeset; 11 import org.openstreetmap.josm.data.osm. OsmPrimitive;11 import org.openstreetmap.josm.data.osm.IPrimitive; 12 12 13 13 /** … … 38 38 } 39 39 40 protected void write( OsmPrimitive p) {40 protected void write(IPrimitive p) { 41 41 if (p.isDeleted()) { 42 42 switchMode("delete"); … … 81 81 82 82 /** 83 * Appends a collection of {@see OsmPrimitive}s to the OsmChange document.83 * Appends a collection of Primitives to the OsmChange document. 84 84 * 85 85 * @param primitives the collection of primitives. Ignored if null. 86 86 * @throws IllegalStateException thrown if the prologs has not been written yet 87 87 * @see #start() 88 * @see #append( OsmPrimitive)88 * @see #append(IPrimitive) 89 89 */ 90 public void append(Collection< OsmPrimitive> primitives) throws IllegalStateException{90 public void append(Collection<? extends IPrimitive> primitives) throws IllegalStateException{ 91 91 if (primitives == null) return; 92 92 if (!prologWritten) 93 93 throw new IllegalStateException(tr("Prolog of OsmChange document not written yet. Please write frst.")); 94 for ( OsmPrimitive p : primitives) {94 for (IPrimitive p : primitives) { 95 95 write(p); 96 96 } … … 98 98 99 99 /** 100 * Appends an {@see OsmPrimitive}to the OsmChange document.100 * Appends an Primitive to the OsmChange document. 101 101 * 102 102 * @param p the primitive. Ignored if null. … … 106 106 107 107 */ 108 public void append( OsmPrimitive p) {108 public void append(IPrimitive p) { 109 109 if (p == null) return; 110 110 if (!prologWritten) -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r2990 r4100 14 14 15 15 import org.openstreetmap.josm.data.osm.Changeset; 16 import org.openstreetmap.josm.data.osm. OsmPrimitive;16 import org.openstreetmap.josm.data.osm.IPrimitive; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 18 18 import org.openstreetmap.josm.gui.io.UploadStrategySpecification; … … 39 39 * than where passed in the list to upload*. 40 40 */ 41 private Collection< OsmPrimitive> processed;41 private Collection<IPrimitive> processed; 42 42 43 43 private OsmApi api = OsmApi.getOsmApi(); … … 76 76 * @throws OsmTransferException thrown if an exception occurs 77 77 */ 78 protected void uploadChangesIndividually(Collection< OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {78 protected void uploadChangesIndividually(Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 79 79 try { 80 80 progressMonitor.beginTask(tr("Starting to upload with one request per primitive ...")); 81 81 progressMonitor.setTicksCount(primitives.size()); 82 82 uploadStartTime = System.currentTimeMillis(); 83 for ( OsmPrimitive osm : primitives) {83 for (IPrimitive osm : primitives) { 84 84 int progress = progressMonitor.getTicks(); 85 85 String time_left_str = timeLeft(progress, primitives.size()); … … 118 118 * @throws OsmTransferException thrown if an exception occurs 119 119 */ 120 protected void uploadChangesAsDiffUpload(Collection< OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {120 protected void uploadChangesAsDiffUpload(Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 121 121 try { 122 122 progressMonitor.beginTask(tr("Starting to upload in one request ...")); … … 138 138 * @throws OsmTransferException thrown if an exception occurs 139 139 */ 140 protected void uploadChangesInChunks(Collection< OsmPrimitive> primitives, ProgressMonitor progressMonitor, int chunkSize) throws OsmTransferException, IllegalArgumentException {140 protected void uploadChangesInChunks(Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor, int chunkSize) throws OsmTransferException, IllegalArgumentException { 141 141 if (chunkSize <=0) 142 142 throw new IllegalArgumentException(tr("Value >0 expected for parameter ''{0}'', got {1}", "chunkSize", chunkSize)); 143 143 try { 144 144 progressMonitor.beginTask(tr("Starting to upload in chunks...")); 145 List< OsmPrimitive> chunk = new ArrayList<OsmPrimitive>(chunkSize);146 Iterator< OsmPrimitive> it = primitives.iterator();145 List<IPrimitive> chunk = new ArrayList<IPrimitive>(chunkSize); 146 Iterator<? extends IPrimitive> it = primitives.iterator(); 147 147 int numChunks = (int)Math.ceil((double)primitives.size() / (double)chunkSize); 148 148 int i= 0; … … 181 181 * @throws OsmTransferException thrown if something goes wrong 182 182 */ 183 public void uploadOsm(UploadStrategySpecification strategy, Collection< OsmPrimitive> primitives, Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {183 public void uploadOsm(UploadStrategySpecification strategy, Collection<? extends IPrimitive> primitives, Changeset changeset, ProgressMonitor monitor) throws OsmTransferException { 184 184 CheckParameterUtil.ensureParameterNotNull(changeset, "changeset"); 185 processed = new LinkedList< OsmPrimitive>();185 processed = new LinkedList<IPrimitive>(); 186 186 monitor = monitor == null ? NullProgressMonitor.INSTANCE : monitor; 187 187 monitor.beginTask(tr("Uploading data ...")); … … 214 214 } 215 215 216 void makeApiRequest( OsmPrimitive osm, ProgressMonitor progressMonitor) throws OsmTransferException {216 void makeApiRequest(IPrimitive osm, ProgressMonitor progressMonitor) throws OsmTransferException { 217 217 if (osm.isDeleted()) { 218 218 api.deletePrimitive(osm, progressMonitor); … … 236 236 * @return the collection of successfully processed primitives 237 237 */ 238 public Collection< OsmPrimitive> getProcessedPrimitives() {238 public Collection<IPrimitive> getProcessedPrimitives() { 239 239 return processed; 240 240 } -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r3336 r4100 16 16 import org.openstreetmap.josm.data.osm.DataSet; 17 17 import org.openstreetmap.josm.data.osm.DataSource; 18 import org.openstreetmap.josm.data.osm.INode; 19 import org.openstreetmap.josm.data.osm.IPrimitive; 20 import org.openstreetmap.josm.data.osm.IRelation; 21 import org.openstreetmap.josm.data.osm.IWay; 18 22 import org.openstreetmap.josm.data.osm.Node; 19 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;21 24 import org.openstreetmap.josm.data.osm.Relation; 22 import org.openstreetmap.josm.data.osm.RelationMember;23 25 import org.openstreetmap.josm.data.osm.Tagged; 24 26 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.data.osm.visitor. Visitor;27 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 26 28 import org.openstreetmap.josm.tools.DateUtils; 27 29 … … 31 33 * @author imi 32 34 */ 33 public class OsmWriter extends XmlWriter implements Visitor {35 public class OsmWriter extends XmlWriter implements PrimitiveVisitor { 34 36 35 37 public static final String DEFAULT_API_VERSION = "0.6"; … … 67 69 68 70 private static final Comparator<OsmPrimitive> byIdComparator = new Comparator<OsmPrimitive>() { 69 public int compare(OsmPrimitive o1, OsmPrimitive o2) {71 @Override public int compare(OsmPrimitive o1, OsmPrimitive o2) { 70 72 return (o1.getUniqueId()<o2.getUniqueId() ? -1 : (o1.getUniqueId()==o2.getUniqueId() ? 0 : 1)); 71 73 } … … 112 114 } 113 115 114 public void visit(Node n) { 116 @Override 117 public void visit(INode n) { 115 118 if (n.isIncomplete()) return; 116 119 addCommon(n, "node"); … … 123 126 } 124 127 125 public void visit(Way w) { 128 @Override 129 public void visit(IWay w) { 126 130 if (w.isIncomplete()) return; 127 131 addCommon(w, "way"); … … 130 134 } else { 131 135 out.println(">"); 132 for ( Node n : w.getNodes()) {133 out.println(" <nd ref='"+ n.getUniqueId()+"' />");136 for (int i=0; i<w.getNodesCount(); ++i) { 137 out.println(" <nd ref='"+w.getNodeId(i) +"' />"); 134 138 } 135 139 addTags(w, "way", false); … … 137 141 } 138 142 139 public void visit(Relation e) { 143 @Override 144 public void visit(IRelation e) { 140 145 if (e.isIncomplete()) return; 141 146 addCommon(e, "relation"); … … 144 149 } else { 145 150 out.println(">"); 146 for ( RelationMember em : e.getMembers()) {151 for (int i=0; i<e.getMembersCount(); ++i) { 147 152 out.print(" <member type='"); 148 out.print( OsmPrimitiveType.from(em.getMember()).getAPIName());149 out.println("' ref='"+e m.getMember().getUniqueId()+"' role='" +150 XmlWriter.encode(e m.getRole()) + "' />");153 out.print(e.getMemberType(i)); 154 out.println("' ref='"+e.getMemberId(i)+"' role='" + 155 XmlWriter.encode(e.getRole(i)) + "' />"); 151 156 } 152 157 addTags(e, "relation", false); … … 181 186 182 187 private static final Comparator<Entry<String, String>> byKeyComparator = new Comparator<Entry<String,String>>() { 183 public int compare(Entry<String, String> o1, Entry<String, String> o2) {188 @Override public int compare(Entry<String, String> o1, Entry<String, String> o2) { 184 189 return o1.getKey().compareTo(o2.getKey()); 185 190 } … … 211 216 * id, action, user, and visible. 212 217 */ 213 private void addCommon( OsmPrimitive osm, String tagname) {218 private void addCommon(IPrimitive osm, String tagname) { 214 219 out.print(" <"+tagname); 215 220 if (osm.getUniqueId() != 0) { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r4087 r4100 47 47 } 48 48 return null; 49 } 50 51 /** 52 * Filter a collection by (sub)class. 53 * This is an efficient read-only implementation. 54 */ 55 public static <S, T extends S> SubclassFilteredCollection<S, T> filteredCollection(Collection<S> collection, final Class<T> klass) { 56 return new SubclassFilteredCollection<S, T>(collection, new Predicate<S>() { 57 @Override 58 public boolean evaluate(S o) { 59 return klass.isInstance(o); 60 } 61 }); 49 62 } 50 63
Note:
See TracChangeset
for help on using the changeset viewer.