Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java
r18808 r18811 172 172 * 173 173 * @param name the name without the nodes count 174 * @param primitive the primitive174 * @param way the way 175 175 * @since 18808 176 176 */ 177 protected void decorateNameWithNodes(StringBuilder name, IWay way) { 177 protected void decorateNameWithNodes(StringBuilder name, IWay<?> way) { 178 178 char mark; 179 179 // If current language is left-to-right (almost all languages) … … 559 559 * Decorates the name of primitive with its id, if the preference 560 560 * <code>osm-primitives.showid</code> is set. 561 * 562 * The id is append to the {@link StringBuilder} passed in <code>name</code>. 561 * <p> 562 * The id is appended to the {@link StringBuilder} passed in <code>name</code>. 563 563 * 564 564 * @param name the name without the id -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r18801 r18811 76 76 77 77 /** Pattern matching white spaces */ 78 public static final Pattern WHITE_SPACES_PATTERN = Pattern.compile("\\s+"); 78 public static final Pattern WHITE_SPACES_PATTERN = Pattern.compile("\\s+", Pattern.UNICODE_CHARACTER_CLASS); 79 79 80 80 private static final long MILLIS_OF_SECOND = TimeUnit.SECONDS.toMillis(1); … … 105 105 106 106 private static Method mapOfEntriesMethod() { 107 try { 108 return Map.class.getMethod("ofEntries", Map.Entry[].class); 109 } catch (NoSuchMethodException e) { 110 return null; 111 } 107 if (getJavaVersion() >= 9) { 108 try { 109 return Map.class.getMethod("ofEntries", Map.Entry[].class); 110 } catch (NoSuchMethodException noSuchMethodException) { 111 Logging.trace(noSuchMethodException); 112 } 113 } 114 return null; 112 115 } 113 116 … … 197 200 * empty string 198 201 * @return null if values is null. The joined string otherwise. 199 * @deprecated use {@link String#join} or {@link Collectors#joining} 202 * @deprecated since 15718, use {@link String#join} or {@link Collectors#joining} 200 203 */ 201 204 @Deprecated … … 521 524 522 525 char[] hexChars = new char[len * 2]; 523 for (int i = 0,j = 0;i < len; i++) {524 = bytes[i];526 int j = 0; 527 for (final int v : bytes) { 525 528 hexChars[j++] = HEX_ARRAY[(v & 0xf0) >> 4]; 526 529 hexChars[j++] = HEX_ARRAY[v & 0xf]; … … 682 685 try { 683 686 // Java 9: use Map.ofEntries(...) 684 return (Map<K, V>) mapOfEntries.invoke(null, new Object[]{map.entrySet().toArray(new Map.Entry[0])});685 } catch (Exception ignore) {686 Logging.trace( ignore);687 return (Map<K, V>) mapOfEntries.invoke(null, (Object) map.entrySet().toArray(new Map.Entry[0])); 688 } catch (ReflectiveOperationException toLog) { 689 Logging.trace(toLog); 687 690 } 688 691 } … … 1520 1523 return new byte[0]; 1521 1524 } 1522 try { // NOPMD 1523 ByteArrayOutputStream bout = new ByteArrayOutputStream(stream.available()); 1525 try (ByteArrayOutputStream bout = new ByteArrayOutputStream(stream.available())) { 1524 1526 byte[] buffer = new byte[8192]; 1525 1527 boolean finished = false; … … 1543 1545 * Returns the initial capacity to pass to the HashMap / HashSet constructor 1544 1546 * when it is initialized with a known number of entries. 1545 * 1547 * <p> 1546 1548 * When a HashMap is filled with entries, the underlying array is copied over 1547 1549 * to a larger one multiple times. To avoid this process when the number of … … 1560 1562 * Returns the initial capacity to pass to the HashMap / HashSet constructor 1561 1563 * when it is initialized with a known number of entries. 1562 * 1564 * <p> 1563 1565 * When a HashMap is filled with entries, the underlying array is copied over 1564 1566 * to a larger one multiple times. To avoid this process when the number of … … 1566 1568 * given to the HashMap constructor. This method returns a suitable value 1567 1569 * that avoids rehashing but doesn't waste memory. 1568 * 1570 * <p> 1569 1571 * Assumes default load factor (0.75). 1570 1572 * @param nEntries the number of entries expected … … 1640 1642 */ 1641 1643 public static double clamp(double val, double min, double max) { 1644 // Switch to Math.clamp when we move to Java 21 1642 1645 if (min > max) { 1643 1646 throw new IllegalArgumentException(MessageFormat.format("Parameter min ({0}) cannot be greater than max ({1})", min, max)); … … 1674 1677 /** 1675 1678 * Convert angle from radians to degrees. 1676 * 1679 * <p> 1677 1680 * Replacement for {@link Math#toDegrees(double)} to match the Java 9 1678 1681 * version of that method. (Can be removed when JOSM support for Java 8 ends.) … … 1689 1692 /** 1690 1693 * Convert angle from degrees to radians. 1691 * 1694 * <p> 1692 1695 * Replacement for {@link Math#toRadians(double)} to match the Java 9 1693 1696 * version of that method. (Can be removed when JOSM support for Java 8 ends.) … … 1708 1711 */ 1709 1712 public static int getJavaVersion() { 1710 String version = getSystemProperty("java.version"); 1713 // Switch to Runtime.version() once we move past Java 8 1714 String version = Objects.requireNonNull(getSystemProperty("java.version")); 1711 1715 if (version.startsWith("1.")) { 1712 1716 version = version.substring(2); … … 1729 1733 */ 1730 1734 public static int getJavaUpdate() { 1731 String version = getSystemProperty("java.version"); 1735 // Switch to Runtime.version() once we move past Java 8 1736 String version = Objects.requireNonNull(getSystemProperty("java.version")); 1732 1737 if (version.startsWith("1.")) { 1733 1738 version = version.substring(2); … … 1738 1743 // 9 1739 1744 // 9.0.1 1745 // 17.0.4.1+1-LTS 1746 // $MAJOR.$MINOR.$SECURITY.$PATCH 1740 1747 int undePos = version.indexOf('_'); 1741 1748 int dashPos = version.indexOf('-'); … … 1745 1752 } 1746 1753 int firstDotPos = version.indexOf('.'); 1747 int lastDotPos = version.lastIndexOf('.');1748 if (firstDotPos == lastDotPos) {1754 int secondDotPos = version.indexOf('.', firstDotPos + 1); 1755 if (firstDotPos == secondDotPos) { 1749 1756 return 0; 1750 1757 } 1751 1758 return firstDotPos > -1 ? Integer.parseInt(version.substring(firstDotPos + 1, 1752 lastDotPos > -1 ?lastDotPos : version.length())) : 0;1759 secondDotPos > -1 ? secondDotPos : version.length())) : 0; 1753 1760 } 1754 1761 … … 1759 1766 */ 1760 1767 public static int getJavaBuild() { 1761 String version = getSystemProperty("java.runtime.version"); 1768 // Switch to Runtime.version() once we move past Java 8 1769 String version = Objects.requireNonNull(getSystemProperty("java.runtime.version")); 1762 1770 int bPos = version.indexOf('b'); 1763 1771 int pPos = version.indexOf('+'); … … 2041 2049 public static String stripHtml(String rawString) { 2042 2050 // remove HTML tags 2043 rawString = rawString.replaceAll("< .*?>", " ");2051 rawString = rawString.replaceAll("<[^>]+>", " "); 2044 2052 // consolidate multiple spaces between a word to a single space 2045 rawString = rawString.replaceAll("\\b\\s{2,}\\b", " "); 2053 rawString = rawString.replaceAll("(?U)\\b\\s{2,}\\b", " "); 2046 2054 // remove extra whitespaces 2047 2055 return rawString.trim(); -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r18553 r18811 312 312 System.setProperty("java.version", "9.1.2"); 313 313 assertEquals(1, Utils.getJavaUpdate()); 314 315 System.setProperty("java.version", "17.0.4.1+1-LTS"); 316 assertEquals(0, Utils.getJavaUpdate()); 314 317 } finally { 315 318 System.setProperty("java.version", javaVersion);
Note:
See TracChangeset
for help on using the changeset viewer.