Changeset 6906 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-03-10T02:33:20+01:00 (10 years ago)
Author:
Don-vip
Message:

refactor duplicated code - impacts some plugins (reverter, roadsigns, cmdline)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
1 deleted
12 edited

Legend:

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

    r6380 r6906  
    113113    }
    114114
    115     @Override
    116     public int hashCode() {
     115    protected final int computeHashCode(int init) {
    117116        final int prime = 31;
    118         int result = 1;
     117        int result = init;
    119118        long temp;
    120119        temp = java.lang.Double.doubleToLongBits(x);
     
    123122        result = prime * result + (int) (temp ^ (temp >>> 32));
    124123        return result;
     124    }
     125
     126    @Override
     127    public int hashCode() {
     128        return computeHashCode(1);
    125129    }
    126130
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r6883 r6906  
    410410    @Override
    411411    public int hashCode() {
    412         final int prime = 31;
    413         int result = super.hashCode();
    414         long temp;
    415         temp = java.lang.Double.doubleToLongBits(x);
    416         result = prime * result + (int) (temp ^ (temp >>> 32));
    417         temp = java.lang.Double.doubleToLongBits(y);
    418         result = prime * result + (int) (temp ^ (temp >>> 32));
    419         return result;
     412        return computeHashCode(super.hashCode());
    420413    }
    421414
  • trunk/src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java

    r6643 r6906  
    2525import org.openstreetmap.josm.gui.help.HelpUtil;
    2626import org.openstreetmap.josm.io.OsmApiException;
    27 import org.openstreetmap.josm.io.OsmDataParsingException;
    2827import org.openstreetmap.josm.io.OsmServerUserInfoReader;
    2928import org.openstreetmap.josm.io.OsmTransferException;
     
    3130import org.openstreetmap.josm.tools.CheckParameterUtil;
    3231import org.openstreetmap.josm.tools.Utils;
     32import org.openstreetmap.josm.tools.XmlParsingException;
    3333import org.w3c.dom.Document;
    3434import org.xml.sax.SAXException;
     
    9898    }
    9999
    100     protected UserInfo getUserDetails() throws OsmOAuthAuthorizationException, OsmDataParsingException,OsmTransferException {
     100    protected UserInfo getUserDetails() throws OsmOAuthAuthorizationException, XmlParsingException, OsmTransferException {
    101101        boolean authenticatorEnabled = true;
    102102        try {
     
    124124            return OsmServerUserInfoReader.buildFromXML(d);
    125125        } catch(SAXException e) {
    126             throw new OsmDataParsingException(e);
     126            throw new XmlParsingException(e);
    127127        } catch(ParserConfigurationException e){
    128             throw new OsmDataParsingException(e);
     128            throw new XmlParsingException(e);
    129129        } catch(MalformedURLException e) {
    130130            throw new OsmTransferException(e);
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r6733 r6906  
    7171            availablePlugins.addAll(available);
    7272        }
     73        availablePluginsModified();
     74    }
     75
     76    protected final void availablePluginsModified() {
    7377        sort();
    7478        filterDisplayedPlugins(filterExpression);
     
    8690    }
    8791
    88     protected  void updateAvailablePlugin(PluginInformation other) {
     92    protected void updateAvailablePlugin(PluginInformation other) {
    8993        if (other == null) return;
    9094        PluginInformation pi = getPluginInformation(other.name);
     
    106110            updateAvailablePlugin(other);
    107111        }
    108         sort();
    109         filterDisplayedPlugins(filterExpression);
    110         Set<String> activePlugins = new HashSet<String>();
    111         activePlugins.addAll(Main.pref.getCollection("plugins", activePlugins));
    112         for (PluginInformation pi: availablePlugins) {
    113             if (selectedPluginsMap.get(pi) == null) {
    114                 if (activePlugins.contains(pi.name)) {
    115                     selectedPluginsMap.put(pi, true);
    116                 }
    117             }
    118         }
    119         clearChanged();
    120         notifyObservers();
     112        availablePluginsModified();
    121113    }
    122114
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r6889 r6906  
    2424import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2525import org.openstreetmap.josm.tools.CheckParameterUtil;
     26import org.openstreetmap.josm.tools.XmlParsingException;
    2627import org.xml.sax.Attributes;
    2728import org.xml.sax.InputSource;
     
    7172     * @param diffUploadResponse the response. Must not be null.
    7273     * @param progressMonitor a progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null
    73      * @throws IllegalArgumentException thrown if diffUploadRequest is null
    74      * @throws OsmDataParsingException thrown if the diffUploadRequest can't be parsed successfully
     74     * @throws IllegalArgumentException if diffUploadRequest is null
     75     * @throws XmlParsingException if the diffUploadRequest can't be parsed successfully
    7576     *
    7677     */
    77     public  void parse(String diffUploadResponse, ProgressMonitor progressMonitor) throws OsmDataParsingException {
     78    public  void parse(String diffUploadResponse, ProgressMonitor progressMonitor) throws XmlParsingException {
    7879        if (progressMonitor == null) {
    7980            progressMonitor = NullProgressMonitor.INSTANCE;
     
    8586            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser());
    8687        } catch(IOException e) {
    87             throw new OsmDataParsingException(e);
     88            throw new XmlParsingException(e);
    8889        } catch(ParserConfigurationException e) {
    89             throw new OsmDataParsingException(e);
    90         } catch(OsmDataParsingException e) {
     90            throw new XmlParsingException(e);
     91        } catch(XmlParsingException e) {
    9192            throw e;
    9293        } catch(SAXException e) {
    93             throw new OsmDataParsingException(e);
     94            throw new XmlParsingException(e);
    9495        } finally {
    9596            progressMonitor.finishTask();
     
    147148        }
    148149
    149         protected void throwException(String msg) throws OsmDataParsingException{
    150             throw new OsmDataParsingException(msg).rememberLocation(locator);
     150        protected void throwException(String msg) throws XmlParsingException {
     151            throw new XmlParsingException(msg).rememberLocation(locator);
    151152        }
    152153
     
    173174                }
    174175            } catch (NumberFormatException e) {
    175                 throw new OsmDataParsingException(e).rememberLocation(locator);
     176                throw new XmlParsingException(e).rememberLocation(locator);
    176177            }
    177178        }
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r6889 r6906  
    3939import org.openstreetmap.josm.tools.CheckParameterUtil;
    4040import org.openstreetmap.josm.tools.Utils;
     41import org.openstreetmap.josm.tools.XmlParsingException;
    4142import org.xml.sax.Attributes;
    4243import org.xml.sax.InputSource;
     
    535536        } catch(OsmTransferException e) {
    536537            throw e;
    537         } catch(OsmDataParsingException e) {
     538        } catch(XmlParsingException e) {
    538539            throw new OsmTransferException(e);
    539540        } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java

    r6552 r6906  
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
    2020import org.openstreetmap.josm.tools.Utils;
     21import org.openstreetmap.josm.tools.XmlParsingException;
    2122import org.xml.sax.Attributes;
    2223import org.xml.sax.InputSource;
     
    3839        private ChangesetDataSet.ChangesetModificationType currentModificationType;
    3940
    40         protected void throwException(String message) throws OsmDataParsingException {
    41             throw new OsmDataParsingException(message).rememberLocation(locator);
     41        protected void throwException(String message) throws XmlParsingException {
     42            throw new XmlParsingException(message).rememberLocation(locator);
    4243        }
    4344
    44         protected void throwException(Exception e) throws OsmDataParsingException {
    45             throw new OsmDataParsingException(e).rememberLocation(locator);
     45        protected void throwException(Exception e) throws XmlParsingException {
     46            throw new XmlParsingException(e).rememberLocation(locator);
    4647        }
    4748
     
    128129     * @param progressMonitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null
    129130     * @return the parsed data
    130      * @throws OsmDataParsingException thrown if something went wrong. Check for chained
     131     * @throws XmlParsingException if something went wrong. Check for chained
    131132     * exceptions.
    132133     */
    133     public ChangesetDataSet parse(ProgressMonitor progressMonitor) throws OsmDataParsingException {
     134    public ChangesetDataSet parse(ProgressMonitor progressMonitor) throws XmlParsingException {
    134135        if (progressMonitor == null) {
    135136            progressMonitor = NullProgressMonitor.INSTANCE;
     
    139140            progressMonitor.indeterminateSubTask(tr("Parsing changeset content ..."));
    140141            SAXParserFactory.newInstance().newSAXParser().parse(source, new Parser());
    141         } catch(OsmDataParsingException e){
     142        } catch(XmlParsingException e) {
    142143            throw e;
    143144        } catch (ParserConfigurationException e) {
    144             throw new OsmDataParsingException(e);
     145            throw new XmlParsingException(e);
    145146        } catch(SAXException e) {
    146             throw new OsmDataParsingException(e);
     147            throw new XmlParsingException(e);
    147148        } catch(IOException e) {
    148             throw new OsmDataParsingException(e);
     149            throw new XmlParsingException(e);
    149150        } finally {
    150151            progressMonitor.finishTask();
     
    157158     *
    158159     * @return the parsed data
    159      * @throws OsmDataParsingException thrown if something went wrong. Check for chained
     160     * @throws XmlParsingException if something went wrong. Check for chained
    160161     * exceptions.
    161162     */
    162     public ChangesetDataSet parse() throws OsmDataParsingException {
     163    public ChangesetDataSet parse() throws XmlParsingException {
    163164        return parse(null);
    164165    }
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r6787 r6906  
    1919import org.openstreetmap.josm.tools.DateUtils;
    2020import org.openstreetmap.josm.tools.Utils;
     21import org.openstreetmap.josm.tools.XmlParsingException;
    2122import org.xml.sax.Attributes;
    2223import org.xml.sax.InputSource;
     
    4647    }
    4748
     49    /**
     50     * Returns the parsed changesets.
     51     * @return the parsed changesets
     52     */
    4853    public List<Changeset> getChangesets() {
    4954        return changesets;
     
    5863        }
    5964
    60         protected void throwException(String msg) throws OsmDataParsingException{
    61             throw new OsmDataParsingException(msg).rememberLocation(locator);
    62         }
    63         /**
    64          * The current changeset
    65          */
     65        protected void throwException(String msg) throws XmlParsingException {
     66            throw new XmlParsingException(msg).rememberLocation(locator);
     67        }
     68
     69        /** The current changeset */
    6670        private Changeset current = null;
    6771
    68         protected void parseChangesetAttributes(Changeset cs, Attributes atts) throws OsmDataParsingException {
     72        protected void parseChangesetAttributes(Changeset cs, Attributes atts) throws XmlParsingException {
    6973            // -- id
    7074            String value = atts.getValue("id");
     
    186190        }
    187191
    188         protected User createUser(String uid, String name) throws OsmDataParsingException {
     192        protected User createUser(String uid, String name) throws XmlParsingException {
    189193            if (uid == null) {
    190194                if (name == null)
  • trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java

    r6830 r6906  
    1818import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
     20import org.openstreetmap.josm.tools.XmlParsingException;
    2021
    2122/**
     
    182183            OsmChangesetContentParser parser = new OsmChangesetContentParser(in);
    183184            return parser.parse(monitor.createSubTaskMonitor(1, true));
    184         } catch(OsmDataParsingException e) {
     185        } catch(XmlParsingException e) {
    185186            throw new OsmTransferException(e);
    186187        } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r6889 r6906  
    1919import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2020import org.openstreetmap.josm.tools.DateUtils;
     21import org.openstreetmap.josm.tools.XmlParsingException;
    2122import org.w3c.dom.Document;
    2223import org.w3c.dom.Node;
     
    3334     * @param document The XML contents
    3435     * @return The user info
    35      * @throws OsmDataParsingException if parsing goes wrong
     36     * @throws XmlParsingException if parsing goes wrong
    3637     */
    37     public static UserInfo buildFromXML(Document document) throws OsmDataParsingException {
     38    public static UserInfo buildFromXML(Document document) throws XmlParsingException {
    3839        try {
    3940            XPathFactory factory = XPathFactory.newInstance();
     
    4243            Node xmlNode = (Node)xpath.compile("/osm/user[1]").evaluate(document, XPathConstants.NODE);
    4344            if ( xmlNode== null)
    44                 throw new OsmDataParsingException(tr("XML tag <user> is missing."));
     45                throw new XmlParsingException(tr("XML tag <user> is missing."));
    4546
    4647            // -- id
    4748            String v = getAttribute(xmlNode, "id");
    4849            if (v == null)
    49                 throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "id", "user"));
     50                throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "id", "user"));
    5051            try {
    5152                userInfo.setId(Integer.parseInt(v));
    5253            } catch(NumberFormatException e) {
    53                 throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "id", "user", v));
     54                throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "id", "user", v));
    5455            }
    5556            // -- display name
     
    7172                v = getAttribute(xmlNode, "lat");
    7273                if (v == null)
    73                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lat", "home"));
     74                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lat", "home"));
    7475                double lat;
    7576                try {
    7677                    lat = Double.parseDouble(v);
    7778                } catch(NumberFormatException e) {
    78                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lat", "home", v));
     79                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lat", "home", v));
    7980                }
    8081
    8182                v = getAttribute(xmlNode, "lon");
    8283                if (v == null)
    83                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lon", "home"));
     84                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "lon", "home"));
    8485                double lon;
    8586                try {
    8687                    lon = Double.parseDouble(v);
    8788                } catch(NumberFormatException e) {
    88                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lon", "home", v));
     89                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "lon", "home", v));
    8990                }
    9091
    9192                v = getAttribute(xmlNode, "zoom");
    9293                if (v == null)
    93                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "zoom", "home"));
     94                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "zoom", "home"));
    9495                int zoom;
    9596                try {
    9697                    zoom = Integer.parseInt(v);
    9798                } catch(NumberFormatException e) {
    98                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "zoom", "home", v));
     99                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "zoom", "home", v));
    99100                }
    100101                userInfo.setHome(new LatLon(lat,lon));
     
    117118                v = getAttribute(xmlNode, "unread");
    118119                if (v == null)
    119                     throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "unread", "received"));
     120                    throw new XmlParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "unread", "received"));
    120121                try {
    121122                    userInfo.setUnreadMessages(Integer.parseInt(v));
    122123                } catch(NumberFormatException e) {
    123                     throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v), e);
     124                    throw new XmlParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v), e);
    124125                }
    125126            }
     
    127128            return userInfo;
    128129        } catch(XPathException e) {
    129             throw new OsmDataParsingException(e);
     130            throw new XmlParsingException(e);
    130131        }
    131132    }
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r6643 r6906  
    4040    private boolean canceled;
    4141
     42    /**
     43     * Constructs a new {@code ReadLocalPluginInformationTask}.
     44     */
    4245    public ReadLocalPluginInformationTask() {
    4346        super(tr("Reading local plugin information.."), false);
     
    7275    }
    7376
    74     protected void scanSiteCacheFiles(ProgressMonitor monitor, File pluginsDirectory) {
    75         File[] siteCacheFiles = pluginsDirectory.listFiles(
     77    private File[] listFiles(File pluginsDirectory, final String regex) {
     78        return pluginsDirectory.listFiles(
    7679                new FilenameFilter() {
    7780                    @Override
    7881                    public boolean accept(File dir, String name) {
    79                         return name.matches("^([0-9]+-)?site.*\\.txt$");
     82                        return name.matches(regex);
    8083                    }
    8184                }
    8285        );
     86    }
     87
     88    protected void scanSiteCacheFiles(ProgressMonitor monitor, File pluginsDirectory) {
     89        File[] siteCacheFiles = listFiles(pluginsDirectory, "^([0-9]+-)?site.*\\.txt$");
    8390        if (siteCacheFiles == null || siteCacheFiles.length == 0)
    8491            return;
     
    97104        }
    98105    }
    99 
    100106    protected void scanIconCacheFiles(ProgressMonitor monitor, File pluginsDirectory) {
    101         File[] siteCacheFiles = pluginsDirectory.listFiles(
    102                 new FilenameFilter() {
    103                     @Override
    104                     public boolean accept(File dir, String name) {
    105                         return name.matches("^([0-9]+-)?site.*plugin-icons\\.zip$");
    106                     }
    107                 }
    108         );
     107        File[] siteCacheFiles = listFiles(pluginsDirectory, "^([0-9]+-)?site.*plugin-icons\\.zip$");
    109108        if (siteCacheFiles == null || siteCacheFiles.length == 0)
    110109            return;
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r6643 r6906  
    4343 */
    4444public class XmlObjectParser implements Iterable<Object> {
    45     public static class PresetParsingException extends SAXException {
    46         private int columnNumber;
    47         private int lineNumber;
    48 
    49         /**
    50          * Constructs a new {@code PresetParsingException}.
    51          */
    52         public PresetParsingException() {
    53             super();
    54         }
    55 
    56         public PresetParsingException(Exception e) {
    57             super(e);
    58         }
    59 
    60         public PresetParsingException(String message, Exception e) {
    61             super(message, e);
    62         }
    63 
    64         public PresetParsingException(String message) {
    65             super(message);
    66         }
    67 
    68         public PresetParsingException rememberLocation(Locator locator) {
    69             if (locator == null) return this;
    70             this.columnNumber = locator.getColumnNumber();
    71             this.lineNumber = locator.getLineNumber();
    72             return this;
    73         }
    74 
    75         @Override
    76         public String getMessage() {
    77             String msg = super.getMessage();
    78             if (lineNumber == 0 && columnNumber == 0)
    79                 return msg;
    80             if (msg == null) {
    81                 msg = getClass().getName();
    82             }
    83             msg = msg + " " + tr("(at line {0}, column {1})", lineNumber, columnNumber);
    84             return msg;
    85         }
    86 
    87         public int getColumnNumber() {
    88             return columnNumber;
    89         }
    90 
    91         public int getLineNumber() {
    92             return lineNumber;
    93         }
    94     }
    95 
    9645    public static final String lang = LanguageInfo.getLanguageCodeXML();
    9746
     
    12776        }
    12877
    129         protected void throwException(Exception e) throws PresetParsingException{
    130             throw new PresetParsingException(e).rememberLocation(locator);
    131         }
    132 
    133         @Override public void startElement(String ns, String lname, String qname, Attributes a) throws SAXException {
     78        protected void throwException(Exception e) throws XmlParsingException {
     79            throw new XmlParsingException(e).rememberLocation(locator);
     80        }
     81
     82        @Override
     83        public void startElement(String ns, String lname, String qname, Attributes a) throws SAXException {
    13484            if (mapping.containsKey(qname)) {
    13585                Class<?> klass = mapping.get(qname).klass;
     
    150100            }
    151101        }
    152         @Override public void endElement(String ns, String lname, String qname) throws SAXException {
     102
     103        @Override
     104        public void endElement(String ns, String lname, String qname) throws SAXException {
    153105            if (mapping.containsKey(qname) && !mapping.get(qname).onStart) {
    154106                report();
     
    158110            }
    159111        }
    160         @Override public void characters(char[] ch, int start, int length) {
     112
     113        @Override
     114        public void characters(char[] ch, int start, int length) {
    161115            characters.append(ch, start, length);
    162116        }
     
    281235    private Iterator<Object> queueIterator = null;
    282236
     237    /**
     238     * Constructs a new {@code XmlObjectParser}.
     239     */
    283240    public XmlObjectParser() {
    284241        parser = new Parser();
Note: See TracChangeset for help on using the changeset viewer.