Ignore:
Timestamp:
2016-11-20T17:33:33+01:00 (3 years ago)
Author:
simon04
Message:

see #13376 - Use TimeUnit instead of combinations of 1000/60/60/24

Location:
trunk/src/org/openstreetmap/josm/io
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java

    r10627 r11288  
    99import java.io.IOException;
    1010import java.nio.charset.StandardCharsets;
     11import java.util.concurrent.TimeUnit;
    1112
    1213import org.openstreetmap.josm.Main;
     
    2526    public static final int INTERVAL_ALWAYS = -1;
    2627    /** Update interval meaning an update is needed each hour */
    27     public static final int INTERVAL_HOURLY = 60*60;
     28    public static final int INTERVAL_HOURLY = (int) TimeUnit.HOURS.toSeconds(1);
    2829    /** Update interval meaning an update is needed each day */
    29     public static final int INTERVAL_DAILY = INTERVAL_HOURLY * 24;
     30    public static final int INTERVAL_DAILY = (int) TimeUnit.DAYS.toSeconds(1);
    3031    /** Update interval meaning an update is needed each week */
    31     public static final int INTERVAL_WEEKLY = INTERVAL_DAILY * 7;
     32    public static final int INTERVAL_WEEKLY = (int) TimeUnit.DAYS.toSeconds(7);
    3233    /** Update interval meaning an update is needed each month */
    33     public static final int INTERVAL_MONTHLY = INTERVAL_WEEKLY * 4;
     34    public static final int INTERVAL_MONTHLY = (int) TimeUnit.DAYS.toSeconds(28);
    3435    /** Update interval meaning an update is never needed */
    3536    public static final int INTERVAL_NEVER = Integer.MAX_VALUE;
     
    8889            return false;
    8990        }
    90         return Main.pref.getInteger("cache." + ident, 0) + updateInterval < System.currentTimeMillis()/1000
     91        return Main.pref.getInteger("cache." + ident, 0) + updateInterval < TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
    9192                || !isCacheValid();
    9293    }
     
    136137        this.data = updateData();
    137138        saveToDisk();
    138         Main.pref.putInteger("cache." + ident, (int) (System.currentTimeMillis()/1000));
     139        Main.pref.putInteger("cache." + ident, (int) (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
    139140        return data;
    140141    }
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r11195 r11288  
    2424import java.util.Map;
    2525import java.util.concurrent.ConcurrentHashMap;
     26import java.util.concurrent.TimeUnit;
    2627import java.util.zip.ZipEntry;
    2728import java.util.zip.ZipFile;
     
    7677
    7778    public static final long DEFAULT_MAXTIME = -1L;
    78     public static final long DAYS = 24L*60L*60L; // factor to get caching time in days
     79    public static final long DAYS = TimeUnit.DAYS.toSeconds(1); // factor to get caching time in days
    7980
    8081    private final Map<String, String> httpHeaders = new ConcurrentHashMap<>();
     
    417418        String urlStr = url.toExternalForm();
    418419        long age = 0L;
    419         long lMaxAge = maxAge;
     420        long maxAgeMillis = maxAge;
    420421        Long ifModifiedSince = null;
    421422        File localFile = null;
     
    436437                        || maxAge <= 0 // arbitrary value <= 0 is deprecated
    437438                ) {
    438                     lMaxAge = Main.pref.getInteger("mirror.maxtime", 7*24*60*60); // one week
     439                    maxAgeMillis = TimeUnit.SECONDS.toMillis(Main.pref.getLong("mirror.maxtime", TimeUnit.DAYS.toSeconds(7)));
    439440                }
    440441                age = System.currentTimeMillis() - Long.parseLong(localPathEntry.get(0));
    441                 if (offline || age < lMaxAge*1000) {
     442                if (offline || age < maxAgeMillis) {
    442443                    return localFile;
    443444                }
     
    498499            }
    499500        } catch (IOException e) {
    500             if (age >= lMaxAge*1000 && age < lMaxAge*1000*2) {
     501            if (age >= maxAgeMillis && age < maxAgeMillis*2) {
    501502                Main.warn(tr("Failed to load {0}, use cached file and retry next time: {1}", urlStr, e));
    502503                return localFile;
  • trunk/src/org/openstreetmap/josm/io/MessageNotifier.java

    r10627 r11288  
    9393            Main.info(tr("{0} not available (offline mode)", tr("Message notifier")));
    9494        } else if (!isRunning() && interval > 0 && isUserEnoughIdentified()) {
    95             task = EXECUTOR.scheduleAtFixedRate(WORKER, 0, interval * 60L, TimeUnit.SECONDS);
     95            task = EXECUTOR.scheduleAtFixedRate(WORKER, 0, TimeUnit.MINUTES.toSeconds(interval), TimeUnit.SECONDS);
    9696            Main.info("Message notifier active (checks every "+interval+" minute"+(interval > 1 ? "s" : "")+')');
    9797        }
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r10217 r11288  
    1111import java.util.LinkedList;
    1212import java.util.List;
     13import java.util.concurrent.TimeUnit;
    1314
    1415import org.openstreetmap.josm.data.osm.Changeset;
     
    6465    private boolean canceled;
    6566
    66     private static final int MSECS_PER_SECOND = 1000;
    67     private static final int SECONDS_PER_MINUTE = 60;
    68     private static final int MSECS_PER_MINUTE = MSECS_PER_SECOND * SECONDS_PER_MINUTE;
    69 
    7067    private long uploadStartTime;
    7168
     
    7976        double uploadsLeft = (double) listSize - progress;
    8077        long msLeft = (long) (uploadsLeft / uploadsPerMs);
    81         long minutesLeft = msLeft / MSECS_PER_MINUTE;
    82         long secondsLeft = (msLeft / MSECS_PER_SECOND) % SECONDS_PER_MINUTE;
     78        long minutesLeft = msLeft / TimeUnit.MINUTES.toMillis(1);
     79        long secondsLeft = (msLeft / TimeUnit.SECONDS.toMillis(1)) % TimeUnit.MINUTES.toSeconds(1);
    8380        StringBuilder timeLeftStr = new StringBuilder().append(minutesLeft).append(':');
    8481        if (secondsLeft < 10) {
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r11048 r11288  
    99import java.util.List;
    1010import java.util.NoSuchElementException;
     11import java.util.concurrent.TimeUnit;
    1112import java.util.regex.Matcher;
    1213import java.util.regex.Pattern;
     
    132133        final int timeout;
    133134        if (timeoutMatcher.find()) {
    134             timeout = 1000 * Integer.parseInt(timeoutMatcher.group(1));
     135            timeout = (int) TimeUnit.SECONDS.toMillis(Integer.parseInt(timeoutMatcher.group(1)));
    135136        } else {
    136             timeout = 180_000;
     137            timeout = (int) TimeUnit.MINUTES.toMillis(3);
    137138        }
    138139        request.setConnectTimeout(timeout);
Note: See TracChangeset for help on using the changeset viewer.