Changeset 3671 in josm for trunk/src/org/openstreetmap/josm/data/validation/util
- Timestamp:
- 2010-11-25T09:45:38+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/validation/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/util/AgregatePrimitivesVisitor.java
r3669 r3671 19 19 * @author frsantos 20 20 */ 21 public class AgregatePrimitivesVisitor extends AbstractVisitor 22 { 21 public class AgregatePrimitivesVisitor extends AbstractVisitor { 23 22 /** Aggregated data */ 24 23 final Collection<OsmPrimitive> aggregatedData = new HashSet<OsmPrimitive>(); … … 29 28 * @return The aggregated primitives 30 29 */ 31 public Collection<OsmPrimitive> visit(Collection<OsmPrimitive> data) 32 { 33 for (OsmPrimitive osm : data) 34 { 30 public Collection<OsmPrimitive> visit(Collection<OsmPrimitive> data) { 31 for (OsmPrimitive osm : data) { 35 32 osm.visit(this); 36 33 } … … 39 36 } 40 37 41 public void visit(Node n)42 {43 if (!aggregatedData.contains(n))38 @Override 39 public void visit(Node n) { 40 if (!aggregatedData.contains(n)) { 44 41 aggregatedData.add(n); 45 }46 47 public void visit(Way w)48 {49 if(!aggregatedData.contains(w))50 {51 aggregatedData.add(w);52 for (Node n : w.getNodes())53 visit(n);54 42 } 55 43 } 56 44 45 @Override 46 public void visit(Way w) { 47 if (!aggregatedData.contains(w)) { 48 aggregatedData.add(w); 49 for (Node n : w.getNodes()) { 50 visit(n); 51 } 52 } 53 } 54 55 @Override 57 56 public void visit(Relation r) { 58 57 if (!aggregatedData.contains(r)) { -
trunk/src/org/openstreetmap/josm/data/validation/util/MultipleNameVisitor.java
r3669 r3671 31 31 * @param data The collection of primitives 32 32 */ 33 public void visit(Collection<? extends OsmPrimitive> data) 34 { 33 public void visit(Collection<? extends OsmPrimitive> data) { 35 34 String multipleName = null; 36 35 String multiplePluralClassname = null; … … 40 39 41 40 multipleClassname = null; 42 for (OsmPrimitive osm : data) 43 { 41 for (OsmPrimitive osm : data) { 44 42 String name = osm.get("name"); 45 if(name == null) name = osm.get("ref"); 46 if(!initializedname) 47 { 43 if (name == null) { 44 name = osm.get("ref"); 45 } 46 if (!initializedname) { 48 47 multipleName = name; initializedname = true; 49 } 50 else if(multipleName != null && (name == null || !name.equals(multipleName))) 51 { 48 } else if (multipleName != null && (name == null || !name.equals(multipleName))) { 52 49 multipleName = null; 53 50 } 54 51 55 if (firstName == null && name != null)52 if (firstName == null && name != null) { 56 53 firstName = name; 54 } 57 55 osm.visit(this); 58 if (multipleClassname == null) 59 { 56 if (multipleClassname == null) { 60 57 multipleClassname = className; 61 58 multiplePluralClassname = classNamePlural; 62 } 63 else if (!multipleClassname.equals(className)) 64 { 59 } else if (!multipleClassname.equals(className)) { 65 60 multipleClassname = "object"; 66 61 multiplePluralClassname = trn("object", "objects", 2); … … 68 63 } 69 64 70 if ( size == 1 )65 if (size == 1) { 71 66 displayName = name; 72 else if(multipleName != null)67 } else if (multipleName != null) { 73 68 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size) + ": " + multipleName; 74 else if(firstName != null)69 } else if (firstName != null) { 75 70 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size) + ": " + tr("{0}, ...", firstName); 76 else71 } else { 77 72 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size); 73 } 78 74 } 79 75 80 76 @Override 81 public JLabel toLabel() 82 { 77 public JLabel toLabel() { 83 78 return new JLabel(getText(), getIcon(), JLabel.HORIZONTAL); 84 79 } … … 88 83 * @return the name of the items 89 84 */ 90 public String getText() 91 { 85 public String getText() { 92 86 return displayName; 93 87 } … … 97 91 * @return the icon of the items 98 92 */ 99 public Icon getIcon() 100 { 101 if( size == 1 ) 93 public Icon getIcon() { 94 if (size == 1) 102 95 return icon; 103 96 else -
trunk/src/org/openstreetmap/josm/data/validation/util/NameVisitor.java
r3669 r3671 43 43 * is displayed. 44 44 */ 45 @Override 45 46 public void visit(Node n) { 46 47 name = n.getDisplayName(DefaultNameFormatter.getInstance()); … … 55 56 * is displayed with x being the number of nodes in the way. 56 57 */ 58 @Override 57 59 public void visit(Way w) { 58 60 name = w.getDisplayName(DefaultNameFormatter.getInstance()); … … 65 67 /** 66 68 */ 69 @Override 67 70 public void visit(Relation e) { 68 71 name = e.getDisplayName(DefaultNameFormatter.getInstance()); … … 77 80 } 78 81 79 80 82 private void addId(OsmPrimitive osm) { 81 if (Main.pref.getBoolean("osm-primitives.showid")) 83 if (Main.pref.getBoolean("osm-primitives.showid")) { 82 84 name += tr(" [id: {0}]", osm.getId()); 85 } 83 86 } 84 87 } -
trunk/src/org/openstreetmap/josm/data/validation/util/ValUtil.java
r3670 r3671 38 38 * @return A list with all the cells the way starts or ends 39 39 */ 40 public static List<List<Way>> getWaysInCell(Way w, Map<Point2D,List<Way>> cellWays) 41 { 40 public static List<List<Way>> getWaysInCell(Way w, Map<Point2D,List<Way>> cellWays) { 42 41 if (w.getNodesCount() == 0) 43 42 return Collections.emptyList(); … … 59 58 cell = new Point2D.Double(x0, y0); 60 59 cellNodes.add(cell); 61 List<Way> ways = cellWays.get( cell ); 62 if( ways == null ) 63 { 60 List<Way> ways = cellWays.get(cell); 61 if (ways == null) { 64 62 ways = new ArrayList<Way>(); 65 63 cellWays.put(cell, ways); … … 69 67 // End of the way 70 68 cell = new Point2D.Double(x1, y1); 71 if( !cellNodes.contains(cell) ) 72 { 69 if (!cellNodes.contains(cell)) { 73 70 cellNodes.add(cell); 74 71 ways = cellWays.get( cell ); 75 if( ways == null ) 76 { 72 if (ways == null) { 77 73 ways = new ArrayList<Way>(); 78 74 cellWays.put(cell, ways); … … 82 78 83 79 // Then floor coordinates, in case the way is in the border of the cell. 84 x0 = (long) Math.floor(n1.getEastNorth().east() * OsmValidator.griddetail);85 y0 = (long) Math.floor(n1.getEastNorth().north() * OsmValidator.griddetail);86 x1 = (long) Math.floor(n2.getEastNorth().east() * OsmValidator.griddetail);87 y1 = (long) Math.floor(n2.getEastNorth().north() * OsmValidator.griddetail);80 x0 = (long) Math.floor(n1.getEastNorth().east() * OsmValidator.griddetail); 81 y0 = (long) Math.floor(n1.getEastNorth().north() * OsmValidator.griddetail); 82 x1 = (long) Math.floor(n2.getEastNorth().east() * OsmValidator.griddetail); 83 y1 = (long) Math.floor(n2.getEastNorth().north() * OsmValidator.griddetail); 88 84 89 85 // Start of the way 90 86 cell = new Point2D.Double(x0, y0); 91 if( !cellNodes.contains(cell) ) 92 { 87 if (!cellNodes.contains(cell)) { 93 88 cellNodes.add(cell); 94 ways = cellWays.get( cell ); 95 if( ways == null ) 96 { 89 ways = cellWays.get(cell); 90 if (ways == null) { 97 91 ways = new ArrayList<Way>(); 98 92 cellWays.put(cell, ways); … … 103 97 // End of the way 104 98 cell = new Point2D.Double(x1, y1); 105 if( !cellNodes.contains(cell) ) 106 { 99 if (!cellNodes.contains(cell)) { 107 100 cellNodes.add(cell); 108 ways = cellWays.get( cell ); 109 if( ways == null ) 110 { 101 ways = cellWays.get(cell); 102 if (ways == null) { 111 103 ways = new ArrayList<Way>(); 112 104 cellWays.put(cell, ways); … … 114 106 cells.add(ways); 115 107 } 116 117 108 return cells; 118 109 } … … 128 119 * @return A list with the coordinates of all cells 129 120 */ 130 public static List<Point2D> getSegmentCells(Node n1, Node n2, double gridDetail) 131 { 121 public static List<Point2D> getSegmentCells(Node n1, Node n2, double gridDetail) { 132 122 List<Point2D> cells = new ArrayList<Point2D>(); 133 123 double x0 = n1.getEastNorth().east() * gridDetail; … … 136 126 double y1 = n2.getEastNorth().north() * gridDetail + 1; 137 127 138 if( x0 > x1 ) 139 { 128 if (x0 > x1) { 140 129 // Move to 1st-4th cuadrants 141 130 double aux; … … 147 136 double dy = y1 - y0; 148 137 long stepY = y0 <= y1 ? 1 : -1; 149 long gridX0 = (long) Math.floor(x0);150 long gridX1 = (long) Math.floor(x1);151 long gridY0 = (long) Math.floor(y0);152 long gridY1 = (long) Math.floor(y1);138 long gridX0 = (long) Math.floor(x0); 139 long gridX1 = (long) Math.floor(x1); 140 long gridY0 = (long) Math.floor(y0); 141 long gridY1 = (long) Math.floor(y1); 153 142 154 143 long maxSteps = (gridX1 - gridX0) + Math.abs(gridY1 - gridY0) + 1; 155 while( (gridX0 <= gridX1 && (gridY0 - gridY1)*stepY <= 0) && maxSteps-- > 0) 156 { 157 cells.add( new Point2D.Double(gridX0, gridY0) ); 144 while ((gridX0 <= gridX1 && (gridY0 - gridY1)*stepY <= 0) && maxSteps-- > 0) { 145 cells.add( new Point2D.Double(gridX0, gridY0)); 158 146 159 147 // Is the cross between the segment and next vertical line nearer than the cross with next horizontal line? … … 166 154 double distY = Math.pow(scanX - x0, 2) + Math.pow(gridY0 + stepY - y0, 2); 167 155 168 if ( distX < distY)156 if (distX < distY) { 169 157 gridX0 += 1; 170 else158 } else { 171 159 gridY0 += stepY; 160 } 172 161 } 173 174 162 return cells; 175 163 }
Note: See TracChangeset
for help on using the changeset viewer.