Changeset 9217 in josm


Ignore:
Timestamp:
2015-12-29T23:51:37+01:00 (9 years ago)
Author:
Don-vip
Message:

checkstyle, code cleanup

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r9216 r9217  
    310310        @Override
    311311        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);
    327313        }
    328314
     
    392378            Iterator<List<String>> itB = otherVal.iterator();
    393379            while (itA.hasNext()) {
    394                 if (!ListSetting.equalCollection(itA.next(), itB.next())) return false;
     380                if (!Utils.equalCollection(itA.next(), itB.next())) return false;
    395381            }
    396382            return true;
     
    518504    }
    519505
     506    /**
     507     * Event triggered when a preference entry value changes.
     508     */
    520509    public interface PreferenceChangeEvent {
     510        /**
     511         * Returns the preference key.
     512         * @return the preference key
     513         */
    521514        String getKey();
    522515
     516        /**
     517         * Returns the old preference value.
     518         * @return the old preference value
     519         */
    523520        Setting<?> getOldValue();
    524521
     522        /**
     523         * Returns the new preference value.
     524         * @return the new preference value
     525         */
    525526        Setting<?> getNewValue();
    526527    }
    527528
     529    /**
     530     * Listener to preference change events.
     531     */
    528532    public interface PreferenceChangedListener {
     533        /**
     534         * Trigerred when a preference entry value changes.
     535         * @param e the preference change event
     536         */
    529537        void preferenceChanged(PreferenceChangeEvent e);
    530538    }
     
    897905     * @throws XMLStreamException if an XML error occurs while parsing the file (after validation)
    898906     */
    899     public void load() throws IOException, SAXException, XMLStreamException {
     907    protected void load() throws IOException, SAXException, XMLStreamException {
    900908        settingsMap.clear();
    901909        File pref = getPreferenceFile();
     
    12931301     * Indicates that a certain field should be considered in the conversion
    12941302     * process. Otherwise it is ignored.
    1295      * 
     1303     *
    12961304     * @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)
    12981306     */
    12991307    @Retention(RetentionPolicy.RUNTIME) // keep annotation at runtime
     
    13041312     * Indicates that a certain field should be written to the map, even if
    13051313     * the value is the same as the default value.
    1306      * 
     1314     *
    13071315     * @see #serializeStruct(java.lang.Object, java.lang.Class)
    13081316     */
     
    13471355     * Convenience method that saves a MapListSetting which is provided as a
    13481356     * Collection of objects.
    1349      * 
     1357     *
    13501358     * Each object is converted to a <code>Map&lt;String, String&gt;</code> using
    13511359     * the fields with {@link pref} annotation. The field name is the key and
    13521360     * the value will be converted to a string.
    1353      * 
     1361     *
    13541362     * Considers only fields that have the @pref annotation.
    13551363     * In addition it does not write fields with null values. (Thus they are cleared)
     
    13581366     * Fields equal to the default value are not written unless the field has
    13591367     * the @writeExplicitly annotation.
    1360      * @param <T> the class, 
     1368     * @param <T> the class,
    13611369     * @param key main preference key
    13621370     * @param val the list that is supposed to be saved
     
    14171425     * Convert an object to a String Map, by using field names and values as map
    14181426     * key and value.
    1419      * 
     1427     *
    14201428     * The field value is converted to a String.
    1421      * 
     1429     *
    14221430     * Only fields with annotation {@link pref} are taken into account.
    1423      * 
     1431     *
    14241432     * Fields will not be written to the map if the value is null or unchanged
    14251433     * (compared to an object created with the no-arg-constructor).
    14261434     * The {@link writeExplicitly} annotation overrides this behavior, i.e. the
    14271435     * default value will also be written.
    1428      * 
     1436     *
    14291437     * @param <T> the class of the object <code>struct</code>
    14301438     * @param struct the object to be converted
     
    14701478     * map keys to field names of the class and assigning map values to the
    14711479     * corresponding fields.
    1472      * 
     1480     *
    14731481     * The map value (a String) is converted to the field type. Supported
    14741482     * types are: boolean, Boolean, int, Integer, double, Double, String and
    14751483     * Map&lt;String, String&gt;.
    1476      * 
     1484     *
    14771485     * Only fields with annotation {@link pref} are taken into account.
    14781486     * @param <T> the class
     
    16251633    protected XMLStreamReader parser;
    16261634
    1627     public void validateXML(Reader in) throws IOException, SAXException {
     1635    public static void validateXML(Reader in) throws IOException, SAXException {
    16281636        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    16291637        try (InputStream xsdStream = new CachedFile("resource://data/preferences.xsd").getInputStream()) {
     
    16341642    }
    16351643
    1636     public void fromXML(Reader in) throws XMLStreamException {
     1644    protected void fromXML(Reader in) throws XMLStreamException {
    16371645        XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
    16381646        this.parser = parser;
     
    16401648    }
    16411649
    1642     public void parse() throws XMLStreamException {
     1650    private void parse() throws XMLStreamException {
    16431651        int event = parser.getEventType();
    16441652        while (true) {
    16451653            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                    }
    16501660                }
    16511661                parseRoot();
     
    16621672    }
    16631673
    1664     public void parseRoot() throws XMLStreamException {
     1674    private void parseRoot() throws XMLStreamException {
    16651675        while (true) {
    16661676            int event = parser.next();
     
    16981708    }
    16991709
    1700     protected void parseToplevelList() throws XMLStreamException {
     1710    private void parseToplevelList() throws XMLStreamException {
    17011711        String key = parser.getAttributeValue(null, "key");
    17021712        String name = parser.getLocalName();
     
    17531763    }
    17541764
    1755     protected List<String> parseInnerList() throws XMLStreamException {
     1765    private List<String> parseInnerList() throws XMLStreamException {
    17561766        List<String> entries = new ArrayList<>();
    17571767        while (true) {
     
    17711781    }
    17721782
    1773     protected Map<String, String> parseMap() throws XMLStreamException {
     1783    private Map<String, String> parseMap() throws XMLStreamException {
    17741784        Map<String, String> map = new LinkedHashMap<>();
    17751785        while (true) {
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r9196 r9217  
    4848import java.util.List;
    4949import java.util.Locale;
     50import java.util.Objects;
    5051import java.util.concurrent.ExecutorService;
    5152import java.util.concurrent.Executors;
     
    515516    public static boolean equalsEpsilon(double a, double b) {
    516517        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;
    517538    }
    518539
Note: See TracChangeset for help on using the changeset viewer.