gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18032 - in gnunet-java: . src/org/gnunet/service src/org/g


From: gnunet
Subject: [GNUnet-SVN] r18032 - in gnunet-java: . src/org/gnunet/service src/org/gnunet/util src/org/gnunet/util/config src/org/gnunet/util/network src/org/gnunet/util/scheduler src/org/gnunet/util/time
Date: Mon, 7 Nov 2011 00:27:10 +0100

Author: dold
Date: 2011-11-07 00:27:10 +0100 (Mon, 07 Nov 2011)
New Revision: 18032

Added:
   gnunet-java/src/org/gnunet/util/AbsoluteTime.java
   gnunet-java/src/org/gnunet/util/Configuration.java
   gnunet-java/src/org/gnunet/util/RelativeTime.java
   gnunet-java/test/
Removed:
   gnunet-java/src/org/gnunet/util/config/Configuration.java
   gnunet-java/src/org/gnunet/util/time/AbsoluteTime.java
   gnunet-java/src/org/gnunet/util/time/RelativeTime.java
Modified:
   gnunet-java/src/org/gnunet/service/StatisticsService.java
   gnunet-java/src/org/gnunet/util/network/Client.java
   gnunet-java/src/org/gnunet/util/network/Connection.java
   gnunet-java/src/org/gnunet/util/scheduler/Scheduler.java
Log:
structural changes

Modified: gnunet-java/src/org/gnunet/service/StatisticsService.java
===================================================================
--- gnunet-java/src/org/gnunet/service/StatisticsService.java   2011-11-06 
23:20:06 UTC (rev 18031)
+++ gnunet-java/src/org/gnunet/service/StatisticsService.java   2011-11-06 
23:27:10 UTC (rev 18032)
@@ -9,10 +9,10 @@
 
 import java.util.LinkedList;
 
-import org.gnunet.util.config.Configuration;
+import org.gnunet.util.AbsoluteTime;
+import org.gnunet.util.Configuration;
+import org.gnunet.util.RelativeTime;
 import org.gnunet.util.network.Client;
-import org.gnunet.util.time.AbsoluteTime;
-import org.gnunet.util.time.RelativeTime;
 
 public class StatisticsService {
 

Copied: gnunet-java/src/org/gnunet/util/AbsoluteTime.java (from rev 18030, 
gnunet-java/src/org/gnunet/util/time/AbsoluteTime.java)
===================================================================
--- gnunet-java/src/org/gnunet/util/AbsoluteTime.java                           
(rev 0)
+++ gnunet-java/src/org/gnunet/util/AbsoluteTime.java   2011-11-06 23:27:10 UTC 
(rev 18032)
@@ -0,0 +1,143 @@
+package org.gnunet.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AbsoluteTime {
+    private static final Logger logger = LoggerFactory
+            .getLogger(AbsoluteTime.class);
+
+    public final static AbsoluteTime ZERO = new AbsoluteTime(0);
+    public final static AbsoluteTime FOREVER = new 
AbsoluteTime(Long.MAX_VALUE);
+
+    private static long offset = 0;
+
+    private final long abs_value;
+
+    /**
+     * Set the timestamp offset for this instance.
+     * 
+     * @param offset
+     *            the offset to skew the locale time by
+     */
+    public static void setOffset(final long offset) {
+        AbsoluteTime.offset = offset;
+    }
+
+    /**
+     * Get the current time (works just as "time", just that we use the unit of
+     * time that the cron-jobs use (and is 64 bit)).
+     * 
+     * @return the current time
+     */
+    public static AbsoluteTime now() {
+        return new AbsoluteTime(System.currentTimeMillis() + offset);
+    }
+
+    public AbsoluteTime(final long abs_value) {
+        this.abs_value = abs_value;
+    }
+
+    public long getMilliseconds() {
+        return abs_value;
+    }
+
+    /**
+     * Returns the minimum of two time values.
+     * 
+     * @param other
+     * @return min(this,other)
+     */
+    public AbsoluteTime min(final AbsoluteTime other) {
+        return (abs_value <= other.abs_value) ? this : other;
+    }
+
+    public AbsoluteTime max(final AbsoluteTime other) {
+        return (abs_value >= other.abs_value) ? this : other;
+
+    }
+
+    public RelativeTime getRemaining() {
+        if (abs_value == Long.MAX_VALUE) {
+            return RelativeTime.FOREVER;
+        }
+        final AbsoluteTime now = AbsoluteTime.now();
+        if (now.abs_value > abs_value) {
+            return RelativeTime.ZERO;
+        }
+        return new RelativeTime(abs_value - now.abs_value);
+
+    }
+
+    /**
+     * Calculate the estimate time of arrival/completion for an operation.
+     * 
+     * @param start
+     *            when did the operation start?
+     * @param finished
+     *            how much has been done?
+     * @param total
+     *            how much must be done overall (same unit as for "finished")
+     * @return remaining duration for the operation, assuming it continues at
+     *         the same speed
+     */
+    public RelativeTime calculateETA(final AbsoluteTime start, final long 
finished,
+            final long total) {
+        if (finished >= total) {
+            return RelativeTime.ZERO;
+        }
+        if (finished == 0) {
+            return RelativeTime.FOREVER;
+        }
+        final RelativeTime dur = start.getDuration();
+        final double exp = ((double) dur.getMilliseconds()) * ((double) total)
+                / finished;
+        return new RelativeTime((long) exp);
+    }
+
+    public RelativeTime getDifference(final AbsoluteTime other) {
+        if (other.abs_value == Long.MAX_VALUE) {
+            return RelativeTime.FOREVER;
+        }
+        if (other.abs_value < abs_value) {
+            return RelativeTime.ZERO;
+        }
+        return new RelativeTime(abs_value - other.abs_value);
+    }
+
+    public RelativeTime getDuration() {
+        assert abs_value != Long.MAX_VALUE;
+        return getDifference(AbsoluteTime.now());
+    }
+
+    public AbsoluteTime add(final RelativeTime duration) {
+        if (abs_value == Long.MAX_VALUE
+                || duration.getMilliseconds() == Long.MAX_VALUE) {
+            return this;
+        }
+        if (abs_value + duration.getMilliseconds() < abs_value) {
+            logger.warn("time overflow");
+            return AbsoluteTime.FOREVER;
+        }
+        return new AbsoluteTime(abs_value + duration.getMilliseconds());
+    }
+
+    public AbsoluteTime subtract(final RelativeTime duration) {
+        if (abs_value <= duration.getMilliseconds()) {
+            return AbsoluteTime.ZERO;
+        }
+        if (abs_value == Long.MAX_VALUE) {
+            return this;
+        }
+        return new AbsoluteTime(abs_value - duration.getMilliseconds());
+    }
+
+    public byte[] toNetwork() {
+        throw new UnsupportedOperationException();
+    }
+
+    static AbsoluteTime fromNetwork(final byte[] b) {
+        throw new UnsupportedOperationException();
+    }
+
+}

Copied: gnunet-java/src/org/gnunet/util/Configuration.java (from rev 18031, 
gnunet-java/src/org/gnunet/util/config/Configuration.java)
===================================================================
--- gnunet-java/src/org/gnunet/util/Configuration.java                          
(rev 0)
+++ gnunet-java/src/org/gnunet/util/Configuration.java  2011-11-06 23:27:10 UTC 
(rev 18032)
@@ -0,0 +1,207 @@
+package org.gnunet.util;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Configuration management
+ * 
+ * @author Florian Dold
+ */
+public class Configuration {
+    private static final Logger logger = LoggerFactory
+            .getLogger(Configuration.class);
+    
+    
+    private static Pattern section = Pattern.compile("\\[(.*?)\\]");
+    private static Pattern tag = Pattern.compile("(.*?) =( .*?)");
+
+    private Map<String,Map<String, String>> sections;
+
+    /**
+     * Start with an empty configuration.
+     */
+    public Configuration() {
+        sections = new HashMap<String, Map<String,String>>();
+    }
+
+    /**
+     * Parse a configuration file, add all of the options in the file to the
+     * configuration environment.
+     * 
+     * @param filename
+     *            name of the configuration file
+     * @throws FileNotFoundException 
+     */
+    public void parse(String filename) throws FileNotFoundException {
+        DataInputStream in = new DataInputStream(new 
FileInputStream(filename));
+        BufferedReader br = new BufferedReader(new InputStreamReader(in));
+        
+        String current_section = "";
+        
+        while (true) {
+            String line;
+            try {
+                line = br.readLine();
+            } catch (IOException e) {
+                logger.warn("error parsing file", e);
+                break;
+            }
+            line = line.trim();
+            if (line.charAt(0) == '#' || line.charAt(0) == '%') {
+                continue;
+            }
+            
+            Matcher m;
+            
+            m = section.matcher(line);
+            if (m.matches()) {
+                current_section = m.group(1);
+                continue;
+            }
+            
+            m = tag.matcher(line);
+            if (m.matches()) {
+                String option = m.group(1).trim();
+                String value = m.group(2).trim();
+                if (value.charAt(0) == '"') {
+                    int last = value.lastIndexOf('"', 1);
+                    if (last == -1) {
+                        logger.warn("error parsing file: incorrect quoting");
+                        continue;
+                    }
+                    value = value.substring(1, last).trim();
+                }
+                setValueString(current_section, option, value);
+            }
+            
+        }
+    }
+
+    /**
+     * Start with defaults, the parse configuration file.
+     */
+    public boolean load(String filename) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Test if there are configuration options that were changed since the last
+     * save.
+     */
+    public boolean isDirty() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Write configuration file.
+     * 
+     * @param filename
+     *            where to write the configuration
+     */
+    public void write(String filename) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Remove the given section and all options in it.
+     */
+    public void removeSection(String section) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Write only configuration entries that have been changed to configuration
+     * file.
+     * 
+     * @param cfgNew new configuration
+     * 
+     * @param filename where to write the configuration diff between default 
and
+     * new
+     */
+    public void writeDiffs(Configuration cfgNew, String filename) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setValueString(String section, String option, String value) {
+        Map<String,String> table = sections.get(section);
+        if (table == null) {
+            table = new HashMap<String, String>();
+            sections.put(section, table);
+        }
+        table.put(option, value);
+    }
+
+    public void setValueNumber(String section, String option, long value) {
+        throw new UnsupportedOperationException();
+    }
+
+    public long getValueNumer(String section, String option) {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getValueString(String section, String option) {
+        throw new UnsupportedOperationException();
+    }
+
+    public RelativeTime getValueTime(String section, String option) {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getValueChoice(String section, String option,
+            List<String> choices) {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean haveValue(String section, String option) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where
+     * either in the "PATHS" section or the environtment "FOO" is set to
+     * "DIRECTORY".
+     * 
+     * @param orig
+     *            string to $-expand
+     * @return $-expanded string
+     */
+    public String expandDollar(String orig) {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getValueFileName(String section, String option) {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean getValueYesNo(String section, String option) {
+        throw new UnsupportedOperationException();
+    }
+
+    public List<String> getValueFilenames(String section, String option) {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean appendValueFilename(String section, String option,
+            String value) {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean removeValueFilename(String section, String option,
+            String value) {
+        throw new UnsupportedOperationException();
+    }
+
+}

Copied: gnunet-java/src/org/gnunet/util/RelativeTime.java (from rev 18030, 
gnunet-java/src/org/gnunet/util/time/RelativeTime.java)
===================================================================
--- gnunet-java/src/org/gnunet/util/RelativeTime.java                           
(rev 0)
+++ gnunet-java/src/org/gnunet/util/RelativeTime.java   2011-11-06 23:27:10 UTC 
(rev 18032)
@@ -0,0 +1,149 @@
+package org.gnunet.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Florian Dold
+ */
+public final class RelativeTime {
+    private static final Logger logger = LoggerFactory
+            .getLogger(RelativeTime.class);
+
+    public static final RelativeTime MILLISECOND = new RelativeTime(1);
+    public static final RelativeTime SECOND = MILLISECOND.multiply(1000);
+    public static final RelativeTime MINUTE = SECOND.multiply(60);
+    public static final RelativeTime HOUR = MINUTE.multiply(60);
+    public static final RelativeTime DAY = HOUR.multiply(24);
+    public static final RelativeTime WEEK = DAY.multiply(7);
+    public static final RelativeTime MONTH = DAY.multiply(30);
+    public static final RelativeTime YEAR = DAY.multiply(365);
+
+    public static final RelativeTime ZERO = new RelativeTime(0);
+    public static final RelativeTime FOREVER = new 
RelativeTime(Long.MAX_VALUE);
+
+    private final long rel_value;
+
+    public RelativeTime(final long abs_value) {
+        this.rel_value = abs_value;
+    }
+
+    public long getMilliseconds() {
+        return rel_value;
+    }
+
+    /**
+     * Convert relative time to an absolute time in the future.
+     * 
+     * @return timestamp that is "rel" in the future, or FOREVER if 
rel==FOREVER
+     *         (or if we would overflow)
+     */
+    public AbsoluteTime toAbsolute() {
+        return AbsoluteTime.now().add(this);
+    }
+
+    /**
+     * Return the minimum of two relative time values.
+     * 
+     * @return the smaller time value
+     */
+    public RelativeTime min(final RelativeTime other) {
+        return (rel_value <= other.rel_value) ? this : other;
+    }
+
+    /**
+     * Return the maximum of two relative time values.
+     * 
+     * @return the bigger time value
+     */
+    public RelativeTime max(final RelativeTime other) {
+        return (rel_value >= other.rel_value) ? this : other;
+    }
+
+    /**
+     * Multiply relative time by a given factor.
+     * 
+     * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
+     */
+    public RelativeTime multiply(final int factor) {
+        if (factor == 0) {
+            return RelativeTime.ZERO;
+        }
+        final long ret = this.rel_value * factor;
+        if (ret / factor != rel_value) {
+            logger.warn("time overflow");
+            return RelativeTime.FOREVER;
+        }
+        return new RelativeTime(ret);
+    }
+
+    /**
+     * Divide relative time by a given factor.
+     * 
+     * @param rel
+     *            some duration
+     * @param factor
+     *            integer to divide by
+     * @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor
+     */
+    public RelativeTime divide(final int factor) {
+        if (factor == 0 || this.rel_value == Long.MAX_VALUE) {
+            return RelativeTime.FOREVER;
+        }
+        return new RelativeTime(this.rel_value / factor);
+    }
+
+    /**
+     * Add relative times together.
+     */
+    public RelativeTime add(final RelativeTime other) {
+        if (this.rel_value == Long.MAX_VALUE
+                || other.rel_value == Long.MAX_VALUE) {
+            return RelativeTime.FOREVER;
+        }
+        final long new_rel_value = this.rel_value + other.rel_value;
+        // check for numeric overflow
+        if (new_rel_value < this.rel_value) {
+            logger.warn("time overflow");
+            return RelativeTime.FOREVER;
+        }
+        return new RelativeTime(new_rel_value);
+    }
+
+    /**
+     * Subtract relative timestamp from the other.
+     * 
+     * @param other
+     *            second timestamp
+     * @return ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is
+     *         FOREVER, a1-a2 otherwise
+     */
+    public RelativeTime subtract(final RelativeTime other) {
+        if (this.rel_value >= other.rel_value) {
+            return RelativeTime.ZERO;
+        } else if (this.rel_value == Long.MAX_VALUE) {
+            return this;
+        } else {
+            return new RelativeTime(this.rel_value - other.rel_value);
+        }
+    }
+
+    /**
+     * Convert a relative time to a string.
+     * 
+     * @return string form of the time (as milliseconds)
+     */
+    @Override
+    public String toString() {
+        return "" + this.rel_value;
+    }
+
+    public byte[] toNetwork() {
+        throw new UnsupportedOperationException();
+    }
+
+    static RelativeTime fromNetwork(final byte[] b) {
+        throw new UnsupportedOperationException();
+    }
+
+}

Deleted: gnunet-java/src/org/gnunet/util/config/Configuration.java
===================================================================
--- gnunet-java/src/org/gnunet/util/config/Configuration.java   2011-11-06 
23:20:06 UTC (rev 18031)
+++ gnunet-java/src/org/gnunet/util/config/Configuration.java   2011-11-06 
23:27:10 UTC (rev 18032)
@@ -1,214 +0,0 @@
-package org.gnunet.util.config;
-
-import java.io.BufferedReader;
-import java.io.DataInputStream;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.gnunet.util.time.RelativeTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Configuration management
- * 
- * @author Florian Dold
- */
-public class Configuration {
-    private static final Logger logger = LoggerFactory
-            .getLogger(Configuration.class);
-    
-    
-    private static Pattern section = Pattern.compile("\\[(.*?)\\]");
-    private static Pattern tag = Pattern.compile("(.*?) =( .*?)");
-
-    private Map<String,Map<String, String>> sections;
-
-    /**
-     * Start with an empty configuration.
-     */
-    public Configuration() {
-        sections = new HashMap<String, Map<String,String>>();
-    }
-
-    /**
-     * Parse a configuration file, add all of the options in the file to the
-     * configuration environment.
-     * 
-     * @param filename
-     *            name of the configuration file
-     * @throws FileNotFoundException 
-     */
-    public void parse(String filename) throws FileNotFoundException {
-        DataInputStream in = new DataInputStream(new 
FileInputStream(filename));
-        BufferedReader br = new BufferedReader(new InputStreamReader(in));
-        
-        String current_section = "";
-        
-        while (true) {
-            String line;
-            try {
-                line = br.readLine();
-            } catch (IOException e) {
-                logger.warn("error parsing file", e);
-                break;
-            }
-            line = line.trim();
-            if (line.charAt(0) == '#' || line.charAt(0) == '%') {
-                continue;
-            }
-            
-            Matcher m;
-            
-            m = section.matcher(line);
-            if (m.matches()) {
-                current_section = m.group(1);
-                continue;
-            }
-            
-            m = tag.matcher(line);
-            if (m.matches()) {
-                String option = m.group(1).trim();
-                String value = m.group(2).trim();
-                if (value.charAt(0) == '"') {
-                    int last = value.lastIndexOf('"', 1);
-                    if (last == -1) {
-                        logger.warn("error parsing file: incorrect quoting");
-                        continue;
-                    }
-                    value = value.substring(1, last).trim();
-                }
-                setValueString(current_section, option, value);
-            }
-            
-        }
-    }
-
-    /**
-     * Start with defaults, the parse configuration file.
-     */
-    public boolean load(String filename) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Test if there are configuration options that were changed since the last
-     * save.
-     */
-    public boolean isDirty() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Write configuration file.
-     * 
-     * @param filename
-     *            where to write the configuration
-     */
-    public void write(String filename) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Remove the given section and all options in it.
-     */
-    public void removeSection(String section) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public Configuration clone() {
-        throw new UnsupportedOperationException();
-    }
-
-    /*
-     * Write only configuration entries that have been changed to configuration
-     * file
-     * 
-     * @param cfgNew new configuration
-     * 
-     * @param filename where to write the configuration diff between default 
and
-     * new
-     */
-
-    public void writeDiffs(Configuration cfgNew, String filename) {
-        throw new UnsupportedOperationException();
-    }
-
-    public void setValueString(String section, String option, String value) {
-        Map<String,String> table = sections.get(section);
-        if (table == null) {
-            table = new HashMap<String, String>();
-            sections.put(section, table);
-        }
-        table.put(option, value);
-    }
-
-    public void setValueNumber(String section, String option, long value) {
-        throw new UnsupportedOperationException();
-    }
-
-    public long getValueNumer(String section, String option) {
-        throw new UnsupportedOperationException();
-    }
-
-    public String getValueString(String section, String option) {
-        throw new UnsupportedOperationException();
-    }
-
-    public RelativeTime getValueTime(String section, String option) {
-        throw new UnsupportedOperationException();
-    }
-
-    public String getValueChoice(String section, String option,
-            List<String> choices) {
-        throw new UnsupportedOperationException();
-    }
-
-    public boolean haveValue(String section, String option) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where
-     * either in the "PATHS" section or the environtment "FOO" is set to
-     * "DIRECTORY".
-     * 
-     * @param orig
-     *            string to $-expand
-     * @return $-expanded string
-     */
-    public String expandDollar(String orig) {
-        throw new UnsupportedOperationException();
-    }
-
-    public String getValueFileName(String section, String option) {
-        throw new UnsupportedOperationException();
-    }
-
-    public boolean getValueYesNo(String section, String option) {
-        throw new UnsupportedOperationException();
-    }
-
-    public List<String> getValueFilenames(String section, String option) {
-        throw new UnsupportedOperationException();
-    }
-
-    public boolean appendValueFilename(String section, String option,
-            String value) {
-        throw new UnsupportedOperationException();
-    }
-
-    public boolean removeValueFilename(String section, String option,
-            String value) {
-        throw new UnsupportedOperationException();
-    }
-
-}

Modified: gnunet-java/src/org/gnunet/util/network/Client.java
===================================================================
--- gnunet-java/src/org/gnunet/util/network/Client.java 2011-11-06 23:20:06 UTC 
(rev 18031)
+++ gnunet-java/src/org/gnunet/util/network/Client.java 2011-11-06 23:27:10 UTC 
(rev 18032)
@@ -1,7 +1,7 @@
 package org.gnunet.util.network;
 
-import org.gnunet.util.config.Configuration;
-import org.gnunet.util.time.RelativeTime;
+import org.gnunet.util.Configuration;
+import org.gnunet.util.RelativeTime;
 
 
 

Modified: gnunet-java/src/org/gnunet/util/network/Connection.java
===================================================================
--- gnunet-java/src/org/gnunet/util/network/Connection.java     2011-11-06 
23:20:06 UTC (rev 18031)
+++ gnunet-java/src/org/gnunet/util/network/Connection.java     2011-11-06 
23:27:10 UTC (rev 18032)
@@ -2,7 +2,7 @@
 
 import java.net.*;
 
-import org.gnunet.util.time.RelativeTime;
+import org.gnunet.util.RelativeTime;
 
 public class Connection {
        public class TransmitHandle {

Modified: gnunet-java/src/org/gnunet/util/scheduler/Scheduler.java
===================================================================
--- gnunet-java/src/org/gnunet/util/scheduler/Scheduler.java    2011-11-06 
23:20:06 UTC (rev 18031)
+++ gnunet-java/src/org/gnunet/util/scheduler/Scheduler.java    2011-11-06 
23:27:10 UTC (rev 18032)
@@ -2,8 +2,8 @@
 
 package org.gnunet.util.scheduler;
 
-import org.gnunet.util.time.AbsoluteTime;
-import org.gnunet.util.time.RelativeTime;
+import org.gnunet.util.AbsoluteTime;
+import org.gnunet.util.RelativeTime;
 
 /**
  * 

Deleted: gnunet-java/src/org/gnunet/util/time/AbsoluteTime.java
===================================================================
--- gnunet-java/src/org/gnunet/util/time/AbsoluteTime.java      2011-11-06 
23:20:06 UTC (rev 18031)
+++ gnunet-java/src/org/gnunet/util/time/AbsoluteTime.java      2011-11-06 
23:27:10 UTC (rev 18032)
@@ -1,143 +0,0 @@
-package org.gnunet.util.time;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AbsoluteTime {
-    private static final Logger logger = LoggerFactory
-            .getLogger(AbsoluteTime.class);
-
-    public final static AbsoluteTime ZERO = new AbsoluteTime(0);
-    public final static AbsoluteTime FOREVER = new 
AbsoluteTime(Long.MAX_VALUE);
-
-    private static long offset = 0;
-
-    private final long abs_value;
-
-    /**
-     * Set the timestamp offset for this instance.
-     * 
-     * @param offset
-     *            the offset to skew the locale time by
-     */
-    public static void setOffset(final long offset) {
-        AbsoluteTime.offset = offset;
-    }
-
-    /**
-     * Get the current time (works just as "time", just that we use the unit of
-     * time that the cron-jobs use (and is 64 bit)).
-     * 
-     * @return the current time
-     */
-    public static AbsoluteTime now() {
-        return new AbsoluteTime(System.currentTimeMillis() + offset);
-    }
-
-    public AbsoluteTime(final long abs_value) {
-        this.abs_value = abs_value;
-    }
-
-    public long getMilliseconds() {
-        return abs_value;
-    }
-
-    /**
-     * Returns the minimum of two time values.
-     * 
-     * @param other
-     * @return min(this,other)
-     */
-    public AbsoluteTime min(final AbsoluteTime other) {
-        return (abs_value <= other.abs_value) ? this : other;
-    }
-
-    public AbsoluteTime max(final AbsoluteTime other) {
-        return (abs_value >= other.abs_value) ? this : other;
-
-    }
-
-    public RelativeTime getRemaining() {
-        if (abs_value == Long.MAX_VALUE) {
-            return RelativeTime.FOREVER;
-        }
-        final AbsoluteTime now = AbsoluteTime.now();
-        if (now.abs_value > abs_value) {
-            return RelativeTime.ZERO;
-        }
-        return new RelativeTime(abs_value - now.abs_value);
-
-    }
-
-    /**
-     * Calculate the estimate time of arrival/completion for an operation.
-     * 
-     * @param start
-     *            when did the operation start?
-     * @param finished
-     *            how much has been done?
-     * @param total
-     *            how much must be done overall (same unit as for "finished")
-     * @return remaining duration for the operation, assuming it continues at
-     *         the same speed
-     */
-    public RelativeTime calculateETA(final AbsoluteTime start, final long 
finished,
-            final long total) {
-        if (finished >= total) {
-            return RelativeTime.ZERO;
-        }
-        if (finished == 0) {
-            return RelativeTime.FOREVER;
-        }
-        final RelativeTime dur = start.getDuration();
-        final double exp = ((double) dur.getMilliseconds()) * ((double) total)
-                / finished;
-        return new RelativeTime((long) exp);
-    }
-
-    public RelativeTime getDifference(final AbsoluteTime other) {
-        if (other.abs_value == Long.MAX_VALUE) {
-            return RelativeTime.FOREVER;
-        }
-        if (other.abs_value < abs_value) {
-            return RelativeTime.ZERO;
-        }
-        return new RelativeTime(abs_value - other.abs_value);
-    }
-
-    public RelativeTime getDuration() {
-        assert abs_value != Long.MAX_VALUE;
-        return getDifference(AbsoluteTime.now());
-    }
-
-    public AbsoluteTime add(final RelativeTime duration) {
-        if (abs_value == Long.MAX_VALUE
-                || duration.getMilliseconds() == Long.MAX_VALUE) {
-            return this;
-        }
-        if (abs_value + duration.getMilliseconds() < abs_value) {
-            logger.warn("time overflow");
-            return AbsoluteTime.FOREVER;
-        }
-        return new AbsoluteTime(abs_value + duration.getMilliseconds());
-    }
-
-    public AbsoluteTime subtract(final RelativeTime duration) {
-        if (abs_value <= duration.getMilliseconds()) {
-            return AbsoluteTime.ZERO;
-        }
-        if (abs_value == Long.MAX_VALUE) {
-            return this;
-        }
-        return new AbsoluteTime(abs_value - duration.getMilliseconds());
-    }
-
-    public byte[] toNetwork() {
-        throw new UnsupportedOperationException();
-    }
-
-    static AbsoluteTime fromNetwork(final byte[] b) {
-        throw new UnsupportedOperationException();
-    }
-
-}

Deleted: gnunet-java/src/org/gnunet/util/time/RelativeTime.java
===================================================================
--- gnunet-java/src/org/gnunet/util/time/RelativeTime.java      2011-11-06 
23:20:06 UTC (rev 18031)
+++ gnunet-java/src/org/gnunet/util/time/RelativeTime.java      2011-11-06 
23:27:10 UTC (rev 18032)
@@ -1,149 +0,0 @@
-package org.gnunet.util.time;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author Florian Dold
- */
-public final class RelativeTime {
-    private static final Logger logger = LoggerFactory
-            .getLogger(RelativeTime.class);
-
-    public static final RelativeTime MILLISECOND = new RelativeTime(1);
-    public static final RelativeTime SECOND = MILLISECOND.multiply(1000);
-    public static final RelativeTime MINUTE = SECOND.multiply(60);
-    public static final RelativeTime HOUR = MINUTE.multiply(60);
-    public static final RelativeTime DAY = HOUR.multiply(24);
-    public static final RelativeTime WEEK = DAY.multiply(7);
-    public static final RelativeTime MONTH = DAY.multiply(30);
-    public static final RelativeTime YEAR = DAY.multiply(365);
-
-    public static final RelativeTime ZERO = new RelativeTime(0);
-    public static final RelativeTime FOREVER = new 
RelativeTime(Long.MAX_VALUE);
-
-    private final long rel_value;
-
-    public RelativeTime(final long abs_value) {
-        this.rel_value = abs_value;
-    }
-
-    public long getMilliseconds() {
-        return rel_value;
-    }
-
-    /**
-     * Convert relative time to an absolute time in the future.
-     * 
-     * @return timestamp that is "rel" in the future, or FOREVER if 
rel==FOREVER
-     *         (or if we would overflow)
-     */
-    public AbsoluteTime toAbsolute() {
-        return AbsoluteTime.now().add(this);
-    }
-
-    /**
-     * Return the minimum of two relative time values.
-     * 
-     * @return the smaller time value
-     */
-    public RelativeTime min(final RelativeTime other) {
-        return (rel_value <= other.rel_value) ? this : other;
-    }
-
-    /**
-     * Return the maximum of two relative time values.
-     * 
-     * @return the bigger time value
-     */
-    public RelativeTime max(final RelativeTime other) {
-        return (rel_value >= other.rel_value) ? this : other;
-    }
-
-    /**
-     * Multiply relative time by a given factor.
-     * 
-     * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
-     */
-    public RelativeTime multiply(final int factor) {
-        if (factor == 0) {
-            return RelativeTime.ZERO;
-        }
-        final long ret = this.rel_value * factor;
-        if (ret / factor != rel_value) {
-            logger.warn("time overflow");
-            return RelativeTime.FOREVER;
-        }
-        return new RelativeTime(ret);
-    }
-
-    /**
-     * Divide relative time by a given factor.
-     * 
-     * @param rel
-     *            some duration
-     * @param factor
-     *            integer to divide by
-     * @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor
-     */
-    public RelativeTime divide(final int factor) {
-        if (factor == 0 || this.rel_value == Long.MAX_VALUE) {
-            return RelativeTime.FOREVER;
-        }
-        return new RelativeTime(this.rel_value / factor);
-    }
-
-    /**
-     * Add relative times together.
-     */
-    public RelativeTime add(final RelativeTime other) {
-        if (this.rel_value == Long.MAX_VALUE
-                || other.rel_value == Long.MAX_VALUE) {
-            return RelativeTime.FOREVER;
-        }
-        final long new_rel_value = this.rel_value + other.rel_value;
-        // check for numeric overflow
-        if (new_rel_value < this.rel_value) {
-            logger.warn("time overflow");
-            return RelativeTime.FOREVER;
-        }
-        return new RelativeTime(new_rel_value);
-    }
-
-    /**
-     * Subtract relative timestamp from the other.
-     * 
-     * @param other
-     *            second timestamp
-     * @return ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is
-     *         FOREVER, a1-a2 otherwise
-     */
-    public RelativeTime subtract(final RelativeTime other) {
-        if (this.rel_value >= other.rel_value) {
-            return RelativeTime.ZERO;
-        } else if (this.rel_value == Long.MAX_VALUE) {
-            return this;
-        } else {
-            return new RelativeTime(this.rel_value - other.rel_value);
-        }
-    }
-
-    /**
-     * Convert a relative time to a string.
-     * 
-     * @return string form of the time (as milliseconds)
-     */
-    @Override
-    public String toString() {
-        return "" + this.rel_value;
-    }
-
-    public byte[] toNetwork() {
-        throw new UnsupportedOperationException();
-    }
-
-    static RelativeTime fromNetwork(final byte[] b) {
-        throw new UnsupportedOperationException();
-    }
-
-}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]