Changeset 8332 in josm


Ignore:
Timestamp:
2015-05-06T00:23:51+02:00 (9 years ago)
Author:
Don-vip
Message:

fix various issues:

  • performance - inefficient use of keySet iterator instead of entrySet iterator
  • squid:S2674: The value returned from a stream read should be checked
  • remove unused imports
  • improve javadoc
Location:
trunk/src/org/openstreetmap/josm
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java

    r8240 r8332  
    99import java.util.List;
    1010import java.util.Map;
     11import java.util.Map.Entry;
    1112import java.util.concurrent.Future;
    1213import java.util.regex.Matcher;
     
    128129        private final Map<OsmPrimitive, Date> toLoad;
    129130
    130         public HistoryLoaderAndListener(Map<OsmPrimitive, Date> toLoad) {
     131        private HistoryLoaderAndListener(Map<OsmPrimitive, Date> toLoad) {
    131132            this.toLoad = toLoad;
    132133            add(toLoad.keySet());
     
    138139        public void historyUpdated(HistoryDataSet source, PrimitiveId id) {
    139140            Map<OsmPrimitive, Date> toLoadNext = new HashMap<>();
    140             for (Iterator<OsmPrimitive> it = toLoad.keySet().iterator(); it.hasNext();) {
    141                 OsmPrimitive p = it.next();
     141            for (Iterator<Entry<OsmPrimitive, Date>> it = toLoad.entrySet().iterator(); it.hasNext();) {
     142                Entry<OsmPrimitive, Date> entry = it.next();
     143                OsmPrimitive p = entry.getKey();
    142144                History history = source.getHistory(p.getPrimitiveId());
    143                 Date date = toLoad.get(p);
     145                Date date = entry.getValue();
    144146                // If the history has been loaded and a timestamp is known
    145147                if (history != null && date != null) {
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r8285 r8332  
    573573        public boolean allElements;
    574574
     575        /**
     576         * Constructs a new {@code SearchSetting}.
     577         */
    575578        public SearchSetting() {
    576579            this("", SearchMode.replace, false /* case insensitive */,
  • trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java

    r8308 r8332  
    2727import java.util.HashMap;
    2828import java.util.List;
     29import java.util.Map;
     30
     31import org.openstreetmap.josm.Main;
    2932
    3033/**
     
    8689    }
    8790
     91    private void readBytes(InputStream in, byte[] b) throws IOException {
     92        if (in.read(b) < b.length) {
     93            Main.error("Failed to read expected amount of bytes ("+ b.length +") from stream");
     94        }
     95    }
     96
    8897    /**
    8998     * Load a Grid Shift File from an InputStream. The Grid Shift node
     
    98107     * @throws IOException
    99108     */
    100     public void loadGridShiftFile(InputStream in, boolean loadAccuracy ) throws IOException {
     109    public void loadGridShiftFile(InputStream in, boolean loadAccuracy) throws IOException {
    101110        byte[] b8 = new byte[8];
    102111        boolean bigEndian = true;
     
    104113        toEllipsoid = "";
    105114        topLevelSubGrid = null;
    106         in.read(b8);
     115        readBytes(in, b8);
    107116        String overviewHeaderCountId = new String(b8, StandardCharsets.UTF_8);
    108117        if (!"NUM_OREC".equals(overviewHeaderCountId))
    109118            throw new IllegalArgumentException("Input file is not an NTv2 grid shift file");
    110         in.read(b8);
     119        readBytes(in, b8);
    111120        overviewHeaderCount = NTV2Util.getIntBE(b8, 0);
    112121        if (overviewHeaderCount == 11) {
     
    119128                throw new IllegalArgumentException("Input file is not an NTv2 grid shift file");
    120129        }
    121         in.read(b8);
    122         in.read(b8);
     130        readBytes(in, b8);
     131        readBytes(in, b8);
    123132        subGridHeaderCount = NTV2Util.getInt(b8, bigEndian);
    124         in.read(b8);
    125         in.read(b8);
     133        readBytes(in, b8);
     134        readBytes(in, b8);
    126135        subGridCount = NTV2Util.getInt(b8, bigEndian);
    127136        NTV2SubGrid[] subGrid = new NTV2SubGrid[subGridCount];
    128         in.read(b8);
    129         in.read(b8);
     137        readBytes(in, b8);
     138        readBytes(in, b8);
    130139        shiftType = new String(b8, StandardCharsets.UTF_8);
    131         in.read(b8);
    132         in.read(b8);
     140        readBytes(in, b8);
     141        readBytes(in, b8);
    133142        version = new String(b8, StandardCharsets.UTF_8);
    134         in.read(b8);
    135         in.read(b8);
     143        readBytes(in, b8);
     144        readBytes(in, b8);
    136145        fromEllipsoid = new String(b8, StandardCharsets.UTF_8);
    137         in.read(b8);
    138         in.read(b8);
     146        readBytes(in, b8);
     147        readBytes(in, b8);
    139148        toEllipsoid = new String(b8, StandardCharsets.UTF_8);
    140         in.read(b8);
    141         in.read(b8);
     149        readBytes(in, b8);
     150        readBytes(in, b8);
    142151        fromSemiMajorAxis = NTV2Util.getDouble(b8, bigEndian);
    143         in.read(b8);
    144         in.read(b8);
     152        readBytes(in, b8);
     153        readBytes(in, b8);
    145154        fromSemiMinorAxis = NTV2Util.getDouble(b8, bigEndian);
    146         in.read(b8);
    147         in.read(b8);
     155        readBytes(in, b8);
     156        readBytes(in, b8);
    148157        toSemiMajorAxis = NTV2Util.getDouble(b8, bigEndian);
    149         in.read(b8);
    150         in.read(b8);
     158        readBytes(in, b8);
     159        readBytes(in, b8);
    151160        toSemiMinorAxis = NTV2Util.getDouble(b8, bigEndian);
    152161
     
    166175    private NTV2SubGrid[] createSubGridTree(NTV2SubGrid[] subGrid) {
    167176        int topLevelCount = 0;
    168         HashMap<String, List<NTV2SubGrid>> subGridMap = new HashMap<>();
     177        Map<String, List<NTV2SubGrid>> subGridMap = new HashMap<>();
    169178        for (int i = 0; i < subGrid.length; i++) {
    170179            if ("NONE".equalsIgnoreCase(subGrid[i].getParentSubGridName())) {
     
    321330        return toEllipsoid;
    322331    }
    323 
    324332}
  • trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2SubGrid.java

    r8308 r8332  
    7575        byte[] b4 = new byte[4];
    7676        byte[] b1 = new byte[1];
    77         in.read(b8);
    78         in.read(b8);
     77        readBytes(in, b8);
     78        readBytes(in, b8);
    7979        subGridName = new String(b8, StandardCharsets.UTF_8).trim();
    80         in.read(b8);
    81         in.read(b8);
     80        readBytes(in, b8);
     81        readBytes(in, b8);
    8282        parentSubGridName = new String(b8, StandardCharsets.UTF_8).trim();
    83         in.read(b8);
    84         in.read(b8);
     83        readBytes(in, b8);
     84        readBytes(in, b8);
    8585        created = new String(b8, StandardCharsets.UTF_8);
    86         in.read(b8);
    87         in.read(b8);
     86        readBytes(in, b8);
     87        readBytes(in, b8);
    8888        updated = new String(b8, StandardCharsets.UTF_8);
    89         in.read(b8);
    90         in.read(b8);
     89        readBytes(in, b8);
     90        readBytes(in, b8);
    9191        minLat = NTV2Util.getDouble(b8, bigEndian);
    92         in.read(b8);
    93         in.read(b8);
     92        readBytes(in, b8);
     93        readBytes(in, b8);
    9494        maxLat = NTV2Util.getDouble(b8, bigEndian);
    95         in.read(b8);
    96         in.read(b8);
     95        readBytes(in, b8);
     96        readBytes(in, b8);
    9797        minLon = NTV2Util.getDouble(b8, bigEndian);
    98         in.read(b8);
    99         in.read(b8);
     98        readBytes(in, b8);
     99        readBytes(in, b8);
    100100        maxLon = NTV2Util.getDouble(b8, bigEndian);
    101         in.read(b8);
    102         in.read(b8);
     101        readBytes(in, b8);
     102        readBytes(in, b8);
    103103        latInterval = NTV2Util.getDouble(b8, bigEndian);
    104         in.read(b8);
    105         in.read(b8);
     104        readBytes(in, b8);
     105        readBytes(in, b8);
    106106        lonInterval = NTV2Util.getDouble(b8, bigEndian);
    107107        lonColumnCount = 1 + (int)((maxLon - minLon) / lonInterval);
    108108        latRowCount = 1 + (int)((maxLat - minLat) / latInterval);
    109         in.read(b8);
    110         in.read(b8);
     109        readBytes(in, b8);
     110        readBytes(in, b8);
    111111        nodeCount = NTV2Util.getInt(b8, bigEndian);
    112112        if (nodeCount != lonColumnCount * latRowCount)
     
    123123            // certain VM which are not able to read byte blocks when the resource file is
    124124            // in a .jar file (Pieren)
    125             in.read(b1); b4[0] = b1[0];
    126             in.read(b1); b4[1] = b1[0];
    127             in.read(b1); b4[2] = b1[0];
    128             in.read(b1); b4[3] = b1[0];
     125            readBytes(in, b1); b4[0] = b1[0];
     126            readBytes(in, b1); b4[1] = b1[0];
     127            readBytes(in, b1); b4[2] = b1[0];
     128            readBytes(in, b1); b4[3] = b1[0];
    129129            latShift[i] = NTV2Util.getFloat(b4, bigEndian);
    130             in.read(b1); b4[0] = b1[0];
    131             in.read(b1); b4[1] = b1[0];
    132             in.read(b1); b4[2] = b1[0];
    133             in.read(b1); b4[3] = b1[0];
     130            readBytes(in, b1); b4[0] = b1[0];
     131            readBytes(in, b1); b4[1] = b1[0];
     132            readBytes(in, b1); b4[2] = b1[0];
     133            readBytes(in, b1); b4[3] = b1[0];
    134134            lonShift[i] = NTV2Util.getFloat(b4, bigEndian);
    135             in.read(b1); b4[0] = b1[0];
    136             in.read(b1); b4[1] = b1[0];
    137             in.read(b1); b4[2] = b1[0];
    138             in.read(b1); b4[3] = b1[0];
     135            readBytes(in, b1); b4[0] = b1[0];
     136            readBytes(in, b1); b4[1] = b1[0];
     137            readBytes(in, b1); b4[2] = b1[0];
     138            readBytes(in, b1); b4[3] = b1[0];
    139139            if (loadAccuracy) {
    140140                latAccuracy[i] = NTV2Util.getFloat(b4, bigEndian);
    141141            }
    142             in.read(b1); b4[0] = b1[0];
    143             in.read(b1); b4[1] = b1[0];
    144             in.read(b1); b4[2] = b1[0];
    145             in.read(b1); b4[3] = b1[0];
     142            readBytes(in, b1); b4[0] = b1[0];
     143            readBytes(in, b1); b4[1] = b1[0];
     144            readBytes(in, b1); b4[2] = b1[0];
     145            readBytes(in, b1); b4[3] = b1[0];
    146146            if (loadAccuracy) {
    147147                lonAccuracy[i] = NTV2Util.getFloat(b4, bigEndian);
    148148            }
     149        }
     150    }
     151
     152    private void readBytes(InputStream in, byte[] b) throws IOException {
     153        if (in.read(b) < b.length) {
     154            Main.error("Failed to read expected amount of bytes ("+ b.length +") from stream");
    149155        }
    150156    }
     
    194200     * Bi-Linear interpolation of four nearest node values as described in
    195201     * 'GDAit Software Architecture Manual' produced by the <a
    196      * href='http://www.sli.unimelb.edu.au/gda94'>Geomatics
    197      * Department of the University of Melbourne</a>
     202     * href='http://www.dtpli.vic.gov.au/property-and-land-titles/geodesy/geocentric-datum-of-australia-1994-gda94/gda94-useful-tools'>
     203     * Geomatics Department of the University of Melbourne</a>
    198204     * @param a value at the A node
    199205     * @param b value at the B node
    200206     * @param c value at the C node
    201207     * @param d value at the D node
    202      * @param X Longitude factor
    203      * @param Y Latitude factor
     208     * @param x Longitude factor
     209     * @param y Latitude factor
    204210     * @return interpolated value
    205211     */
    206     private final double interpolate(float a, float b, float c, float d, double X, double Y) {
    207         return a + (((double)b - (double)a) * X) + (((double)c - (double)a) * Y) +
    208         (((double)a + (double)d - b - c) * X * Y);
     212    private final double interpolate(float a, float b, float c, float d, double x, double y) {
     213        return a + (((double)b - (double)a) * x) + (((double)c - (double)a) * y) +
     214        (((double)a + (double)d - b - c) * x * y);
    209215    }
    210216
     
    213219     * of the GridShiftFile. The algorithm is described in
    214220     * 'GDAit Software Architecture Manual' produced by the <a
    215      * href='http://www.sli.unimelb.edu.au/gda94'>Geomatics
    216      * Department of the University of Melbourne</a>
     221     * href='http://www.dtpli.vic.gov.au/property-and-land-titles/geodesy/geocentric-datum-of-australia-1994-gda94/gda94-useful-tools'>
     222     * Geomatics Department of the University of Melbourne</a>
    217223     * <p>This method is thread safe for both memory based and file based node data.
    218224     * @param gs GridShift object containing the coordinate to shift and the shift values
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/PasteTagsConflictResolverDialog.java

    r8308 r8332  
    6868    private JPanel pnlTagResolver;
    6969
     70    /**
     71     * Constructs a new {@code PasteTagsConflictResolverDialog}.
     72     * @param owner parent component
     73     */
    7074    public PasteTagsConflictResolverDialog(Component owner) {
    7175        super(JOptionPane.getFrameForComponent(owner), ModalityType.DOCUMENT_MODAL);
     
    114118        ApplyAction applyAction = new ApplyAction();
    115119        allPrimitivesResolver.getModel().addPropertyChangeListener(applyAction);
    116         for (OsmPrimitiveType type: resolvers.keySet()) {
    117             resolvers.get(type).getModel().addPropertyChangeListener(applyAction);
     120        for (TagConflictResolver r : resolvers.values()) {
     121            r.getModel().addPropertyChangeListener(applyAction);
    118122        }
    119123        pnl.add(new SideButton(applyAction));
     
    266270    class CancelAction extends AbstractAction {
    267271
    268         public CancelAction() {
     272        private CancelAction() {
    269273            putValue(Action.SHORT_DESCRIPTION, tr("Cancel conflict resolution"));
    270274            putValue(Action.NAME, tr("Cancel"));
     
    282286    class ApplyAction extends AbstractAction implements PropertyChangeListener {
    283287
    284         public ApplyAction() {
     288        private ApplyAction() {
    285289            putValue(Action.SHORT_DESCRIPTION, tr("Apply resolved conflicts"));
    286290            putValue(Action.NAME, tr("Apply"));
     
    354358    }
    355359
    356     public static class StatisticsInfo {
     360    private static class StatisticsInfo {
    357361        public int numTags;
    358362        public Map<OsmPrimitiveType, Integer> sourceInfo;
    359363        public Map<OsmPrimitiveType, Integer> targetInfo;
    360364
    361         public StatisticsInfo() {
     365        private StatisticsInfo() {
    362366            sourceInfo = new HashMap<>();
    363367            targetInfo = new HashMap<>();
     
    366370
    367371    private static class StatisticsTableColumnModel extends DefaultTableColumnModel {
    368         public StatisticsTableColumnModel() {
     372        private StatisticsTableColumnModel() {
    369373            TableCellRenderer renderer = new StatisticsInfoRenderer();
    370374            TableColumn col = null;
     
    397401        private transient List<StatisticsInfo> data;
    398402
    399         public StatisticsTableModel() {
     403        private StatisticsTableModel() {
    400404            data = new ArrayList<>();
    401405        }
     
    516520        }
    517521
    518         public StatisticsInfoTable(StatisticsTableModel model) {
     522        private StatisticsInfoTable(StatisticsTableModel model) {
    519523            build(model);
    520524        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java

    r8285 r8332  
    99import java.util.Map;
    1010import java.util.Map.Entry;
     11import java.util.Objects;
    1112
    1213import org.openstreetmap.josm.data.osm.Relation;
     
    121122        // lookup the entry for editor and remove it
    122123        //
    123         for (DialogContext context: openDialogs.keySet()) {
    124             if (openDialogs.get(context) == editor) {
    125                 openDialogs.remove(context);
     124        for (Iterator<Entry<DialogContext, RelationEditor>> it = openDialogs.entrySet().iterator(); it.hasNext();) {
     125            Entry<DialogContext, RelationEditor> entry = it.next();
     126            if (Objects.equals(entry.getValue(), editor)) {
     127                it.remove();
    126128                break;
    127129            }
     
    215217    public void windowClosed(WindowEvent e) {
    216218        RelationEditor editor = (RelationEditor)e.getWindow();
    217         DialogContext context = null;
    218         for (DialogContext c : openDialogs.keySet()) {
    219             if (editor.equals(openDialogs.get(c))) {
    220                 context = c;
     219        for (Iterator<Entry<DialogContext, RelationEditor>> it = openDialogs.entrySet().iterator(); it.hasNext(); ) {
     220            if (editor.equals(it.next().getValue())) {
     221                it.remove();
    221222                break;
    222223            }
    223         }
    224         if (context != null) {
    225             openDialogs.remove(context);
    226224        }
    227225    }
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java

    r8285 r8332  
    99import java.util.Collection;
    1010import java.util.HashMap;
     11import java.util.Iterator;
    1112import java.util.List;
    1213import java.util.Map;
     14import java.util.Map.Entry;
     15import java.util.Objects;
    1316
    1417import javax.swing.JOptionPane;
     
    105108     */
    106109    public void hide(HistoryBrowserDialog dialog) {
    107         long id = 0;
    108         for (long i: dialogs.keySet()) {
    109             if (dialogs.get(i) == dialog) {
    110                 id = i;
     110        for (Iterator<Entry<Long, HistoryBrowserDialog>> it = dialogs.entrySet().iterator(); it.hasNext(); ) {
     111            if (Objects.equals(it.next().getValue(), dialog)) {
     112                it.remove();
     113                if (dialogs.isEmpty()) {
     114                    new WindowGeometry(dialog).remember(WINDOW_GEOMETRY_PREF);
     115                }
    111116                break;
    112             }
    113         }
    114         if (id > 0) {
    115             dialogs.remove(id);
    116             if (dialogs.isEmpty()) {
    117                 new WindowGeometry(dialog).remember(WINDOW_GEOMETRY_PREF);
    118117            }
    119118        }
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r8323 r8332  
    1111import java.awt.FlowLayout;
    1212import java.awt.GridBagLayout;
    13 import java.awt.Image;
    1413import java.awt.event.ActionEvent;
    1514import java.awt.event.KeyEvent;
     
    2827import javax.swing.BorderFactory;
    2928import javax.swing.Icon;
    30 import javax.swing.ImageIcon;
    3129import javax.swing.JButton;
    3230import javax.swing.JComponent;
  • trunk/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java

    r8308 r8332  
    2020import java.util.HashMap;
    2121import java.util.Map;
     22import java.util.Map.Entry;
    2223
    2324import javax.swing.BorderFactory;
     
    275276    protected UploadStrategy getUploadStrategy() {
    276277        UploadStrategy strategy = null;
    277         for (UploadStrategy s: rbStrategy.keySet()) {
    278             if (rbStrategy.get(s).isSelected()) {
    279                 strategy = s;
     278        for (Entry<UploadStrategy, JRadioButton> e : rbStrategy.entrySet()) {
     279            if (e.getValue().isSelected()) {
     280                strategy = e.getKey();
    280281                break;
    281282            }
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r8323 r8332  
    1212import java.awt.Graphics2D;
    1313import java.awt.GridBagLayout;
    14 import java.awt.Image;
    1514import java.awt.Point;
    1615import java.awt.Rectangle;
     
    3433import javax.swing.Action;
    3534import javax.swing.Icon;
    36 import javax.swing.ImageIcon;
    3735import javax.swing.JLabel;
    3836import javax.swing.JOptionPane;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java

    r7864 r8332  
    77import java.util.List;
    88import java.util.Map;
     9import java.util.Map.Entry;
    910import java.util.regex.Pattern;
    1011
     
    204205    public String toString() {
    205206        StringBuilder res = new StringBuilder("Cascade{ ");
    206         for (String key : prop.keySet()) {
    207             res.append(key+":");
    208             Object val = prop.get(key);
     207        for (Entry<String, Object> entry : prop.entrySet()) {
     208            res.append(entry.getKey()+":");
     209            Object val = entry.getValue();
    209210            if (val instanceof float[]) {
    210211                res.append(Arrays.toString((float[]) val));
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r8285 r8332  
    2929import java.util.List;
    3030import java.util.Map;
     31import java.util.Map.Entry;
    3132import java.util.TreeSet;
    3233
     
    11231124
    11241125            if (display != null) {
    1125                 for (String val : lhm.keySet()) {
    1126                     String k = lhm.get(val).toString();
     1126                for (Entry<String, PresetListEntry> entry : lhm.entrySet()) {
     1127                    String k = entry.getValue().toString();
    11271128                    if (k != null && k.equals(display)) {
    1128                         value = val;
     1129                        value = entry.getKey();
    11291130                        break;
    11301131                    }
  • trunk/src/org/openstreetmap/josm/io/AbstractReader.java

    r8291 r8332  
    99import java.util.List;
    1010import java.util.Map;
     11import java.util.Map.Entry;
    1112
    1213import org.openstreetmap.josm.Main;
     
    8283     */
    8384    protected void processWaysAfterParsing() throws IllegalDataException{
    84         for (Long externalWayId: ways.keySet()) {
     85        for (Entry<Long, Collection<Long>> entry : ways.entrySet()) {
     86            Long externalWayId = entry.getKey();
    8587            Way w = (Way)externalIdMap.get(new SimplePrimitiveId(externalWayId, OsmPrimitiveType.WAY));
    8688            List<Node> wayNodes = new ArrayList<>();
    87             for (long id : ways.get(externalWayId)) {
     89            for (long id : entry.getValue()) {
    8890                Node n = (Node)externalIdMap.get(new SimplePrimitiveId(id, OsmPrimitiveType.NODE));
    8991                if (n == null) {
     
    132134        }
    133135
    134         for (Long externalRelationId : relations.keySet()) {
     136        for (Entry<Long, Collection<RelationMemberData>> entry : relations.entrySet()) {
     137            Long externalRelationId = entry.getKey();
    135138            Relation relation = (Relation) externalIdMap.get(
    136139                    new SimplePrimitiveId(externalRelationId, OsmPrimitiveType.RELATION)
    137140            );
    138141            List<RelationMember> relationMembers = new ArrayList<>();
    139             for (RelationMemberData rm : relations.get(externalRelationId)) {
     142            for (RelationMemberData rm : entry.getValue()) {
    140143                OsmPrimitive primitive = null;
    141144
  • trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java

    r7434 r8332  
    1919 * use {@link RuntimeException} if no exception must be handled.
    2020 * @author xeen
    21  *
     21 * @since 1450
    2222 */
    2323public abstract class CacheCustomContent<T extends Throwable> {
    24     /**
    25      * Common intervals
    26      */
     24
     25    /** Update interval meaning an update is always needed */
    2726    public static final int INTERVAL_ALWAYS = -1;
     27    /** Update interval meaning an update is needed each hour */
    2828    public static final int INTERVAL_HOURLY = 60*60;
     29    /** Update interval meaning an update is needed each day */
    2930    public static final int INTERVAL_DAILY = INTERVAL_HOURLY * 24;
     31    /** Update interval meaning an update is needed each week */
    3032    public static final int INTERVAL_WEEKLY = INTERVAL_DAILY * 7;
     33    /** Update interval meaning an update is needed each month */
    3134    public static final int INTERVAL_MONTHLY = INTERVAL_WEEKLY * 4;
     35    /** Update interval meaning an update is never needed */
    3236    public static final int INTERVAL_NEVER = Integer.MAX_VALUE;
    3337
     
    6165
    6266    /**
    63      * This function serves as a comfort hook to perform additional checks if the cache is valid
    64      * @return True if the cached copy is still valid
    65      */
    66     protected boolean isCacheValid() {
    67         return true;
    68     }
    69 
    70     /**
    7167     * Initializes the class. Note that all read data will be stored in memory until it is flushed
    7268     * by flushData().
    73      * @param ident
    74      * @param updateInterval
     69     * @param ident ident that identifies the stored file. Includes file-ending.
     70     * @param updateInterval update interval in seconds. -1 means always
    7571     */
    7672    public CacheCustomContent(String ident, int updateInterval) {
     
    7874        this.updateInterval = updateInterval;
    7975        this.path = new File(Main.pref.getCacheDirectory(), ident);
     76    }
     77
     78    /**
     79     * This function serves as a comfort hook to perform additional checks if the cache is valid
     80     * @return True if the cached copy is still valid
     81     */
     82    protected boolean isCacheValid() {
     83        return true;
    8084    }
    8185
     
    104108     * Updates data if required
    105109     * @return Returns the data
     110     * @throws T if an error occurs
    106111     */
    107112    public byte[] updateIfRequired() throws T {
     
    114119     * Updates data if required
    115120     * @return Returns the data as string
     121     * @throws T if an error occurs
    116122     */
    117123    public String updateIfRequiredString() throws T {
     
    124130     * Executes an update regardless of updateInterval
    125131     * @return Returns the data
     132     * @throws T if an error occurs
    126133     */
    127134    public byte[] updateForce() throws T {
     
    135142     * Executes an update regardless of updateInterval
    136143     * @return Returns the data as String
     144     * @throws T if an error occurs
    137145     */
    138146    public String updateForceString() throws T {
     
    144152     * Returns the data without performing any updates
    145153     * @return the data
     154     * @throws T if an error occurs
    146155     */
    147156    public byte[] getData() throws T {
     
    155164     * Returns the data without performing any updates
    156165     * @return the data as String
     166     * @throws T if an error occurs
    157167     */
    158168    public String getDataString() throws T {
     
    170180        try (BufferedInputStream input = new BufferedInputStream(new FileInputStream(path))) {
    171181            this.data = new byte[input.available()];
    172             input.read(this.data);
     182            if (input.read(this.data) < this.data.length) {
     183                Main.error("Failed to read expected contents from "+path);
     184            }
    173185        } catch (IOException e) {
    174186            if (!isOffline()) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

    r8308 r8332  
    1515import java.util.HashSet;
    1616import java.util.Map;
     17import java.util.Map.Entry;
    1718import java.util.Set;
    1819
     
    9495
    9596        private String getToolTip() {
    96             StringBuilder sb=new StringBuilder();
     97            StringBuilder sb = new StringBuilder();
    9798            sb.append("<html>");
    9899            sb.append(tr("Old values of"));
     
    100101            sb.append(tag);
    101102            sb.append("</b><br/>");
    102             for (String k: valueCount.keySet()) {
     103            for (Entry<String, Integer> e : valueCount.entrySet()) {
    103104                sb.append("<b>");
    104                 sb.append(valueCount.get(k));
     105                sb.append(e.getValue());
    105106                sb.append(" x </b>");
    106                 sb.append(k);
     107                sb.append(e.getKey());
    107108                sb.append("<br/>");
    108109            }
    109110            sb.append("</html>");
    110111            return sb.toString();
    111 
    112112        }
    113113    }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    r8285 r8332  
    1212import java.util.List;
    1313import java.util.Map;
     14import java.util.Map.Entry;
    1415
    1516import org.openstreetmap.josm.Main;
     
    119120     * Find the node with almost the same ccords in dataset or in already added nodes
    120121     * @since 5845
    121      **/
     122     */
    122123    Node findOrCreateNode(LatLon ll,  List<Command> commands) {
    123124        Node nd = null;
     
    132133
    133134        Node prev = null;
    134         for (LatLon lOld: addedNodes.keySet()) {
     135        for (Entry<LatLon, Node> entry : addedNodes.entrySet()) {
     136            LatLon lOld = entry.getKey();
    135137            if (lOld.greatCircleDistance(ll) < Main.pref.getDouble("remotecontrol.tolerance", 0.1)) {
    136                 prev = addedNodes.get(lOld);
     138                prev = entry.getValue();
    137139                break;
    138140            }
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r7326 r8332  
    484484
    485485        layers = new ArrayList<>();
    486         for (int idx : layersMap.keySet()) {
    487             Layer layer = layersMap.get(idx);
     486        for (Entry<Integer, Layer> entry : layersMap.entrySet()) {
     487            Layer layer = entry.getValue();
    488488            if (layer == null) {
    489489                continue;
    490490            }
    491             Element el = elems.get(idx);
     491            Element el = elems.get(entry.getKey());
    492492            if (el.hasAttribute("visible")) {
    493493                layer.setVisible(Boolean.parseBoolean(el.getAttribute("visible")));
  • trunk/src/org/openstreetmap/josm/tools/MultiMap.java

    r7276 r8332  
    231231    public String toString() {
    232232        List<String> entries = new ArrayList<>(map.size());
    233         for (A key : map.keySet()) {
    234             entries.add(key + "->{" + Utils.join(",", map.get(key)) + "}");
     233        for (Entry<A, Set<B>> entry : map.entrySet()) {
     234            entries.add(entry.getKey() + "->{" + Utils.join(",", entry.getValue()) + "}");
    235235        }
    236236        return "(" + Utils.join(",", entries) + ")";
Note: See TracChangeset for help on using the changeset viewer.