Changeset 9203 in josm
- Timestamp:
- 2015-12-28T19:15:45+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java
r8510 r9203 4 4 import java.util.Comparator; 5 5 6 /** 7 * Formats a name for a {@link OsmPrimitive}. 8 * @since 1990 9 */ 6 10 public interface NameFormatter { 11 12 /** 13 * Formats a name for a {@link Node}. 14 * 15 * @param node the node 16 * @return the name 17 */ 7 18 String format(Node node); 8 19 20 /** 21 * Formats a name for a {@link Way}. 22 * 23 * @param way the way 24 * @return the name 25 */ 9 26 String format(Way way); 10 27 28 /** 29 * Formats a name for a {@link Relation}. 30 * 31 * @param relation the relation 32 * @return the name 33 */ 11 34 String format(Relation relation); 12 35 36 /** 37 * Formats a name for a {@link Changeset}. 38 * 39 * @param changeset the changeset 40 * @return the name 41 */ 13 42 String format(Changeset changeset); 14 43 -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNameFormatter.java
r8510 r9203 2 2 package org.openstreetmap.josm.data.osm.history; 3 3 4 /** 5 * Formats a name for a {@link HistoryOsmPrimitive}. 6 * @since 2686 7 */ 4 8 public interface HistoryNameFormatter { 9 10 /** 11 * Formats a name for a {@link HistoryNode}. 12 * 13 * @param node the node 14 * @return the name 15 */ 5 16 String format(HistoryNode node); 6 17 7 String format(HistoryWay node); 18 /** 19 * Formats a name for a {@link HistoryWay}. 20 * 21 * @param way the way 22 * @return the name 23 */ 24 String format(HistoryWay way); 8 25 9 String format(HistoryRelation node); 26 /** 27 * Formats a name for a {@link HistoryRelation}. 28 * 29 * @param relation the relation 30 * @return the name 31 */ 32 String format(HistoryRelation relation); 10 33 } -
trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java
r8882 r9203 45 45 46 46 /** 47 * This is the default implementation of a {@link NameFormatter} for names of {@link OsmPrimitive}s. 48 * 47 * This is the default implementation of a {@link NameFormatter} for names of {@link OsmPrimitive}s 48 * and {@link HistoryOsmPrimitive}s. 49 * @since 1990 49 50 */ 50 51 public class DefaultNameFormatter implements NameFormatter, HistoryNameFormatter { … … 135 136 } 136 137 137 /**138 * Formats a name for a node139 *140 * @param node the node141 * @return the name142 */143 138 @Override 144 139 public String format(Node node) { … … 211 206 } 212 207 213 214 /**215 * Formats a name for a way216 *217 * @param way the way218 * @return the name219 */220 208 @Override 221 209 public String format(Way way) { … … 249 237 } 250 238 if (n == null) { 251 n = 252 253 254 239 n = (way.get("highway") != null) ? tr("highway") : 240 (way.get("railway") != null) ? tr("railway") : 241 (way.get("waterway") != null) ? tr("waterway") : 242 (way.get("landuse") != null) ? tr("landuse") : null; 255 243 } 256 244 if (n == null) { … … 313 301 } 314 302 315 316 /**317 * Formats a name for a relation318 *319 * @param relation the relation320 * @return the name321 */322 303 @Override 323 304 public String format(Relation relation) { … … 488 469 } 489 470 490 /**491 * Formats a name for a changeset492 *493 * @param changeset the changeset494 * @return the name495 */496 471 @Override 497 472 public String format(Changeset changeset) { … … 554 529 } 555 530 556 /**557 * Formats a name for a history node558 *559 * @param node the node560 * @return the name561 */562 531 @Override 563 532 public String format(HistoryNode node) { … … 586 555 } 587 556 588 /**589 * Formats a name for a way590 *591 * @param way the way592 * @return the name593 */594 557 @Override 595 558 public String format(HistoryWay way) { … … 628 591 } 629 592 630 /**631 * Formats a name for a {@link HistoryRelation})632 *633 * @param relation the relation634 * @return the name635 */636 593 @Override 637 594 public String format(HistoryRelation relation) { … … 684 641 } 685 642 643 /** 644 * Formats the given collection of primitives as an HTML unordered list. 645 * @param primitives collection of primitives to format 646 * @return HTML unordered list 647 */ 686 648 public String formatAsHtmlUnorderedList(Collection<? extends OsmPrimitive> primitives) { 687 649 return Utils.joinAsHtmlUnorderedList(Utils.transform(primitives, new Function<OsmPrimitive, String>() { … … 694 656 } 695 657 658 /** 659 * Formats the given primitive(s) as an HTML unordered list. 660 * @param primitives primitive(s) to format 661 * @return HTML unordered list 662 */ 696 663 public String formatAsHtmlUnorderedList(OsmPrimitive... primitives) { 697 664 return formatAsHtmlUnorderedList(Arrays.asList(primitives)); -
trunk/test/unit/org/openstreetmap/josm/data/osm/history/HistoryNodeTest.java
r8857 r9203 6 6 7 7 import java.util.Date; 8 import java.util.HashMap; 9 import java.util.Map; 8 10 11 import org.junit.BeforeClass; 9 12 import org.junit.Test; 13 import org.openstreetmap.josm.JOSMFixture; 10 14 import org.openstreetmap.josm.data.coor.LatLon; 15 import org.openstreetmap.josm.data.osm.Node; 11 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 17 import org.openstreetmap.josm.data.osm.User; 18 import org.openstreetmap.josm.gui.DefaultNameFormatter; 13 19 14 20 /** … … 17 23 public class HistoryNodeTest { 18 24 19 @Test 20 public void historyNode() { 21 Date d = new Date(); 22 HistoryNode node = new HistoryNode( 23 1L, 24 2L, 25 true, 25 /** 26 * Setup test. 27 */ 28 @BeforeClass 29 public static void init() { 30 JOSMFixture.createUnitTestFixture().init(); 31 } 32 33 private static HistoryNode create(Date d) { 34 return new HistoryNode( 35 1L, // id 36 2L, // version 37 true, // visible 26 38 User.createOsmUser(3, "testuser"), 27 4L, 28 d, 39 4L, // changesetId 40 d, // timestamp 29 41 new LatLon(0, 0) 30 42 ); 43 } 44 45 /** 46 * Unit test for {@link HistoryNode#HistoryNode}. 47 */ 48 @Test 49 public void testHistoryNode() { 50 Date d = new Date(); 51 HistoryNode node = create(d); 31 52 32 53 assertEquals(1, node.getId()); … … 39 60 } 40 61 62 /** 63 * Unit test for {@link HistoryNode#getType}. 64 */ 41 65 @Test 42 public void getType() { 43 Date d = new Date(); 44 HistoryNode node = new HistoryNode( 45 1, 46 2, 47 true, 48 User.createOsmUser(3, "testuser"), 49 4, 50 d, 51 new LatLon(0, 0) 52 ); 66 public void testGetType() { 67 assertEquals(OsmPrimitiveType.NODE, create(new Date()).getType()); 68 } 53 69 54 assertEquals(OsmPrimitiveType.NODE, node.getType()); 70 /** 71 * Unit test for {@link HistoryNode#getCoords}. 72 */ 73 @Test 74 public void testGetCoords() { 75 Node n = new Node(new LatLon(45, 0)); 76 n.setOsmId(1, 2); 77 n.setUser(User.createOsmUser(3, "testuser")); 78 n.setChangesetId(4); 79 assertEquals(n.getCoor(), new HistoryNode(n).getCoords()); 80 } 81 82 /** 83 * Unit test for {@link HistoryNode#getDisplayName}. 84 */ 85 @Test 86 public void testGetDisplayName() { 87 HistoryNode node = create(new Date()); 88 HistoryNameFormatter hnf = DefaultNameFormatter.getInstance(); 89 assertEquals("1 (0.0, 0.0)", node.getDisplayName(hnf)); 90 LatLon ll = node.getCoords(); 91 node.setCoords(null); 92 assertEquals("1", node.getDisplayName(hnf)); 93 node.setCoords(ll); 94 Map<String, String> map = new HashMap<>(); 95 map.put("name", "NodeName"); 96 node.setTags(map); 97 assertEquals("NodeName (0.0, 0.0)", node.getDisplayName(hnf)); 98 node.setCoords(null); 99 assertEquals("NodeName", node.getDisplayName(hnf)); 55 100 } 56 101 } -
trunk/test/unit/org/openstreetmap/josm/data/osm/history/HistoryWayTest.java
r8857 r9203 8 8 import java.util.ArrayList; 9 9 import java.util.Date; 10 import java.util.HashMap; 11 import java.util.Map; 10 12 13 import org.junit.BeforeClass; 11 14 import org.junit.Test; 15 import org.openstreetmap.josm.JOSMFixture; 12 16 import org.openstreetmap.josm.Main; 13 17 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 14 18 import org.openstreetmap.josm.data.osm.User; 19 import org.openstreetmap.josm.gui.DefaultNameFormatter; 15 20 16 21 /** … … 19 24 public class HistoryWayTest { 20 25 26 /** 27 * Setup test. 28 */ 29 @BeforeClass 30 public static void init() { 31 JOSMFixture.createUnitTestFixture().init(); 32 } 33 34 private static HistoryWay create(Date d) { 35 return new HistoryWay( 36 1, // id 37 2, // version 38 true, // visible 39 User.createOsmUser(3, "testuser"), 40 4, // changesetId 41 d // timestamp 42 ); 43 } 44 45 /** 46 * Unit test for {@link HistoryWay#HistoryWay}. 47 */ 21 48 @Test 22 public void wayTest() {49 public void testHistoryWay() { 23 50 Date d = new Date(); 24 HistoryWay way = new HistoryWay( 25 1, 26 2, 27 true, 28 User.createOsmUser(3, "testuser"), 29 4, 30 d 31 ); 51 HistoryWay way = create(d); 32 52 33 53 assertEquals(1, way.getId()); … … 42 62 } 43 63 64 /** 65 * Unit test for {@link HistoryWay#getType}. 66 */ 44 67 @Test 45 public void getType() { 46 Date d = new Date(); 47 HistoryWay way = new HistoryWay( 48 1, 49 2, 50 true, 51 User.createOsmUser(3, "testuser"), 52 4, 53 d 54 ); 55 56 assertEquals(OsmPrimitiveType.WAY, way.getType()); 68 public void testGetType() { 69 assertEquals(OsmPrimitiveType.WAY, create(new Date()).getType()); 57 70 } 58 71 59 72 @Test 60 public void nodeManipulation() { 61 Date d = new Date(); 62 HistoryWay way = new HistoryWay( 63 1, 64 2, 65 true, 66 User.createOsmUser(3, "testuser"), 67 4, 68 d 69 ); 73 public void testNodeManipulation() { 74 HistoryWay way = create(new Date()); 70 75 71 76 way.addNode(1); … … 88 93 89 94 @Test 90 public void iterating() { 91 Date d = new Date(); 92 HistoryWay way = new HistoryWay( 93 1, 94 2, 95 true, 96 User.createOsmUser(3, "testuser"), 97 4, 98 d 99 ); 95 public void testIterating() { 96 HistoryWay way = create(new Date()); 100 97 101 98 way.addNode(1); … … 110 107 assertEquals(2, (long) ids.get(1)); 111 108 } 109 110 /** 111 * Unit test for {@link HistoryWay#getDisplayName}. 112 */ 113 @Test 114 public void testGetDisplayName() { 115 HistoryNameFormatter hnf = DefaultNameFormatter.getInstance(); 116 HistoryWay way0 = create(new Date()); // no node 117 HistoryWay way1 = create(new Date()); // 1 node 118 HistoryWay way2 = create(new Date()); // 2 nodes 119 120 way1.addNode(1); 121 way2.addNode(1); 122 way2.addNode(2); 123 124 assertEquals("1 (0 nodes)", way0.getDisplayName(hnf)); 125 assertEquals("1 (1 node)", way1.getDisplayName(hnf)); 126 assertEquals("1 (2 nodes)", way2.getDisplayName(hnf)); 127 128 Map<String, String> map = new HashMap<>(); 129 map.put("name", "WayName"); 130 131 way0.setTags(map); 132 way1.setTags(map); 133 way2.setTags(map); 134 135 assertEquals("WayName (0 nodes)", way0.getDisplayName(hnf)); 136 assertEquals("WayName (1 node)", way1.getDisplayName(hnf)); 137 assertEquals("WayName (2 nodes)", way2.getDisplayName(hnf)); 138 } 112 139 }
Note:
See TracChangeset
for help on using the changeset viewer.