Changeset 8574 in josm for trunk/src/org
- Timestamp:
- 2015-07-05T22:14:49+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r8566 r8574 487 487 } 488 488 489 final Map<String, String> result = new HashMap<>( );489 final Map<String, String> result = new HashMap<>(Utils.hashMapInitialCapacity(keys.length / 2)); 490 490 for (int i = 0; i < keys.length; i += 2) { 491 491 result.put(keys[i], keys[i + 1]); … … 654 654 @Override 655 655 public final Collection<String> keySet() { 656 String[] keys = this.keys;657 if (keys == null) 656 final String[] keys = this.keys; 657 if (keys == null){ 658 658 return Collections.emptySet(); 659 Set<String> result = new HashSet<>(keys.length / 2); 659 } 660 if (keys.length == 1){ 661 return Collections.singleton(keys[0]); 662 } 663 664 final Set<String> result = new HashSet<>(Utils.hashMapInitialCapacity(keys.length / 2)); 660 665 for (int i = 0; i < keys.length; i += 2) { 661 666 result.add(keys[i]); -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r8540 r8574 439 439 String time = parser.getAttributeValue(null, "timestamp"); 440 440 if (time != null && !time.isEmpty()) { 441 current.set Timestamp(DateUtils.fromString(time));441 current.setRawTimestamp((int)(DateUtils.tsFromString(time)/1000)); 442 442 } 443 443 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r8570 r8574 1366 1366 } 1367 1367 } 1368 1369 /** 1370 * Returns the initial capacity to pass to the HashMap / HashSet constructor 1371 * when it is initialized with a known number of entries. 1372 * 1373 * When a HashMap is filled with entries, the underlying array is copied over 1374 * to a larger one multiple times. To avoid this process when the number of 1375 * entries is known in advance, the initial capacity of the array can be 1376 * given to the HashMap constructor. This method returns a suitable value 1377 * that avoids rehashing but doesn't waste memory. 1378 * @param nEntries the number of entries expected 1379 * @param loadFactor the load factor 1380 * @return the initial capacity for the HashMap constructor 1381 */ 1382 public static int hashMapInitialCapacity(int nEntries, float loadFactor) { 1383 return (int) Math.ceil(nEntries / loadFactor); 1384 } 1385 1386 /** 1387 * Returns the initial capacity to pass to the HashMap / HashSet constructor 1388 * when it is initialized with a known number of entries. 1389 * 1390 * When a HashMap is filled with entries, the underlying array is copied over 1391 * to a larger one multiple times. To avoid this process when the number of 1392 * entries is known in advance, the initial capacity of the array can be 1393 * given to the HashMap constructor. This method returns a suitable value 1394 * that avoids rehashing but doesn't waste memory. 1395 * 1396 * Assumes default load factor (0.75). 1397 * @param nEntries the number of entries expected 1398 * @return the initial capacity for the HashMap constructor 1399 */ 1400 public static int hashMapInitialCapacity(int nEntries) { 1401 return hashMapInitialCapacity(nEntries, 0.75f); 1402 } 1368 1403 } -
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r8565 r8574 66 66 */ 67 67 public static synchronized Date fromString(String str) { 68 return new Date(tsFromString(str)); 69 } 70 71 /** 72 * Parses XML date quickly, regardless of current locale. 73 * @param str The XML date as string 74 * @return The date in milliseconds since epoch 75 */ 76 public static synchronized long tsFromString(String str) { 68 77 // "2007-07-25T09:26:24{Z|{+|-}01:00}" 69 78 if (checkLayout(str, "xxxx-xx-xxTxx:xx:xxZ") || … … 83 92 int plusHr = parsePart2(str, 20); 84 93 int mul = str.charAt(19) == '+' ? -3600000 : 3600000; 85 calendar.setTimeInMillis(calendar.getTimeInMillis()+plusHr*mul);94 return calendar.getTimeInMillis()+plusHr*mul; 86 95 } 87 96 88 return calendar.getTime ();97 return calendar.getTimeInMillis(); 89 98 } else if (checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxxZ") || 90 99 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx") || … … 99 108 parsePart2(str, 17)); 100 109 long millis = parsePart3(str, 20); 101 if (str.length() == 29) 110 if (str.length() == 29){ 102 111 millis += parsePart2(str, 24) * (str.charAt(23) == '+' ? -3600000 : 3600000); 103 calendar.setTimeInMillis(calendar.getTimeInMillis()+millis);104 105 return calendar.getTime ();112 } 113 114 return calendar.getTimeInMillis() + millis; 106 115 } else { 107 116 // example date format "18-AUG-08 13:33:03" … … 109 118 Date d = f.parse(str, new ParsePosition(0)); 110 119 if (d != null) 111 return d ;120 return d.getTime(); 112 121 } 113 122 114 123 try { 115 return XML_DATE.newXMLGregorianCalendar(str).toGregorianCalendar().getTime ();124 return XML_DATE.newXMLGregorianCalendar(str).toGregorianCalendar().getTimeInMillis(); 116 125 } catch (Exception ex) { 117 return new Date();126 return System.currentTimeMillis(); 118 127 } 119 128 }
Note:
See TracChangeset
for help on using the changeset viewer.