- Timestamp:
- 2015-12-29T23:51:37+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r9216 r9217 310 310 @Override 311 311 public boolean equalVal(List<String> otherVal) { 312 return equalCollection(value, otherVal); 313 } 314 315 public static boolean equalCollection(Collection<String> a, Collection<String> b) { 316 if (a == null) return b == null; 317 if (b == null) return false; 318 if (a.size() != b.size()) return false; 319 Iterator<String> itA = a.iterator(); 320 Iterator<String> itB = b.iterator(); 321 while (itA.hasNext()) { 322 String aStr = itA.next(); 323 String bStr = itB.next(); 324 if (!Objects.equals(aStr, bStr)) return false; 325 } 326 return true; 312 return Utils.equalCollection(value, otherVal); 327 313 } 328 314 … … 392 378 Iterator<List<String>> itB = otherVal.iterator(); 393 379 while (itA.hasNext()) { 394 if (! ListSetting.equalCollection(itA.next(), itB.next())) return false;380 if (!Utils.equalCollection(itA.next(), itB.next())) return false; 395 381 } 396 382 return true; … … 518 504 } 519 505 506 /** 507 * Event triggered when a preference entry value changes. 508 */ 520 509 public interface PreferenceChangeEvent { 510 /** 511 * Returns the preference key. 512 * @return the preference key 513 */ 521 514 String getKey(); 522 515 516 /** 517 * Returns the old preference value. 518 * @return the old preference value 519 */ 523 520 Setting<?> getOldValue(); 524 521 522 /** 523 * Returns the new preference value. 524 * @return the new preference value 525 */ 525 526 Setting<?> getNewValue(); 526 527 } 527 528 529 /** 530 * Listener to preference change events. 531 */ 528 532 public interface PreferenceChangedListener { 533 /** 534 * Trigerred when a preference entry value changes. 535 * @param e the preference change event 536 */ 529 537 void preferenceChanged(PreferenceChangeEvent e); 530 538 } … … 897 905 * @throws XMLStreamException if an XML error occurs while parsing the file (after validation) 898 906 */ 899 p ublicvoid load() throws IOException, SAXException, XMLStreamException {907 protected void load() throws IOException, SAXException, XMLStreamException { 900 908 settingsMap.clear(); 901 909 File pref = getPreferenceFile(); … … 1293 1301 * Indicates that a certain field should be considered in the conversion 1294 1302 * process. Otherwise it is ignored. 1295 * 1303 * 1296 1304 * @see #serializeStruct(java.lang.Object, java.lang.Class) 1297 * @see #deserializeStruct(java.util.Map, java.lang.Class) 1305 * @see #deserializeStruct(java.util.Map, java.lang.Class) 1298 1306 */ 1299 1307 @Retention(RetentionPolicy.RUNTIME) // keep annotation at runtime … … 1304 1312 * Indicates that a certain field should be written to the map, even if 1305 1313 * the value is the same as the default value. 1306 * 1314 * 1307 1315 * @see #serializeStruct(java.lang.Object, java.lang.Class) 1308 1316 */ … … 1347 1355 * Convenience method that saves a MapListSetting which is provided as a 1348 1356 * Collection of objects. 1349 * 1357 * 1350 1358 * Each object is converted to a <code>Map<String, String></code> using 1351 1359 * the fields with {@link pref} annotation. The field name is the key and 1352 1360 * the value will be converted to a string. 1353 * 1361 * 1354 1362 * Considers only fields that have the @pref annotation. 1355 1363 * In addition it does not write fields with null values. (Thus they are cleared) … … 1358 1366 * Fields equal to the default value are not written unless the field has 1359 1367 * the @writeExplicitly annotation. 1360 * @param <T> the class, 1368 * @param <T> the class, 1361 1369 * @param key main preference key 1362 1370 * @param val the list that is supposed to be saved … … 1417 1425 * Convert an object to a String Map, by using field names and values as map 1418 1426 * key and value. 1419 * 1427 * 1420 1428 * The field value is converted to a String. 1421 * 1429 * 1422 1430 * Only fields with annotation {@link pref} are taken into account. 1423 * 1431 * 1424 1432 * Fields will not be written to the map if the value is null or unchanged 1425 1433 * (compared to an object created with the no-arg-constructor). 1426 1434 * The {@link writeExplicitly} annotation overrides this behavior, i.e. the 1427 1435 * default value will also be written. 1428 * 1436 * 1429 1437 * @param <T> the class of the object <code>struct</code> 1430 1438 * @param struct the object to be converted … … 1470 1478 * map keys to field names of the class and assigning map values to the 1471 1479 * corresponding fields. 1472 * 1480 * 1473 1481 * The map value (a String) is converted to the field type. Supported 1474 1482 * types are: boolean, Boolean, int, Integer, double, Double, String and 1475 1483 * Map<String, String>. 1476 * 1484 * 1477 1485 * Only fields with annotation {@link pref} are taken into account. 1478 1486 * @param <T> the class … … 1625 1633 protected XMLStreamReader parser; 1626 1634 1627 public void validateXML(Reader in) throws IOException, SAXException {1635 public static void validateXML(Reader in) throws IOException, SAXException { 1628 1636 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 1629 1637 try (InputStream xsdStream = new CachedFile("resource://data/preferences.xsd").getInputStream()) { … … 1634 1642 } 1635 1643 1636 p ublicvoid fromXML(Reader in) throws XMLStreamException {1644 protected void fromXML(Reader in) throws XMLStreamException { 1637 1645 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in); 1638 1646 this.parser = parser; … … 1640 1648 } 1641 1649 1642 p ublicvoid parse() throws XMLStreamException {1650 private void parse() throws XMLStreamException { 1643 1651 int event = parser.getEventType(); 1644 1652 while (true) { 1645 1653 if (event == XMLStreamConstants.START_ELEMENT) { 1646 try 1647 { 1648 loadedVersion = Integer.parseInt(parser.getAttributeValue(null, "version")); 1649 } catch (Exception e) { 1654 try { 1655 loadedVersion = Integer.parseInt(parser.getAttributeValue(null, "version")); 1656 } catch (NumberFormatException e) { 1657 if (Main.isDebugEnabled()) { 1658 Main.debug(e.getMessage()); 1659 } 1650 1660 } 1651 1661 parseRoot(); … … 1662 1672 } 1663 1673 1664 p ublicvoid parseRoot() throws XMLStreamException {1674 private void parseRoot() throws XMLStreamException { 1665 1675 while (true) { 1666 1676 int event = parser.next(); … … 1698 1708 } 1699 1709 1700 pr otectedvoid parseToplevelList() throws XMLStreamException {1710 private void parseToplevelList() throws XMLStreamException { 1701 1711 String key = parser.getAttributeValue(null, "key"); 1702 1712 String name = parser.getLocalName(); … … 1753 1763 } 1754 1764 1755 pr otectedList<String> parseInnerList() throws XMLStreamException {1765 private List<String> parseInnerList() throws XMLStreamException { 1756 1766 List<String> entries = new ArrayList<>(); 1757 1767 while (true) { … … 1771 1781 } 1772 1782 1773 pr otectedMap<String, String> parseMap() throws XMLStreamException {1783 private Map<String, String> parseMap() throws XMLStreamException { 1774 1784 Map<String, String> map = new LinkedHashMap<>(); 1775 1785 while (true) { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9196 r9217 48 48 import java.util.List; 49 49 import java.util.Locale; 50 import java.util.Objects; 50 51 import java.util.concurrent.ExecutorService; 51 52 import java.util.concurrent.Executors; … … 515 516 public static boolean equalsEpsilon(double a, double b) { 516 517 return Math.abs(a - b) <= EPSILON; 518 } 519 520 /** 521 * Determines if two collections are equal. 522 * @param a first collection 523 * @param b second collection 524 * @return {@code true} if collections are equal, {@code false} otherwise 525 * @since 9217 526 */ 527 public static boolean equalCollection(Collection<?> a, Collection<?> b) { 528 if (a == null) return b == null; 529 if (b == null) return false; 530 if (a.size() != b.size()) return false; 531 Iterator<?> itA = a.iterator(); 532 Iterator<?> itB = b.iterator(); 533 while (itA.hasNext()) { 534 if (!Objects.equals(itA.next(), itB.next())) 535 return false; 536 } 537 return true; 517 538 } 518 539
Note:
See TracChangeset
for help on using the changeset viewer.