First working version
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 19 Mar 2010 15:50:45 +0000 (15:50 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 19 Mar 2010 15:50:45 +0000 (15:50 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@3433 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

basic/runtime/org.argeo.basic.nodeps/.classpath
basic/runtime/org.argeo.basic.nodeps/.project
basic/runtime/org.argeo.basic.nodeps/build.properties [new file with mode: 0644]
basic/runtime/org.argeo.basic.nodeps/pom.xml
basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/Throughput.java [new file with mode: 0644]
basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/ThroughputEditor.java [new file with mode: 0644]
basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/ThroughputTest.java [new file with mode: 0644]

index 16f01e2ee7b671c44c26c453773dab706e98da1e..3bf070c69cfa5727c6f9142bb04801884d8126ec 100644 (file)
@@ -1,7 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
        <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+       <classpathentry kind="src" path="src/test/java"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
        <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry kind="output" path="target/classes"/>
 </classpath>
index e11498f944a2534b20bc829d38b98237352ebd08..e03b5033e237e1ca2be0f2d506de38f002a0a2cb 100644 (file)
                        </arguments>
                </buildCommand>
                <buildCommand>
-                       <name>org.maven.ide.eclipse.maven2Builder</name>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
-               <nature>org.maven.ide.eclipse.maven2Nature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.pde.PluginNature</nature>
        </natures>
 </projectDescription>
diff --git a/basic/runtime/org.argeo.basic.nodeps/build.properties b/basic/runtime/org.argeo.basic.nodeps/build.properties
new file mode 100644 (file)
index 0000000..0b396f9
--- /dev/null
@@ -0,0 +1,5 @@
+source.. = src/main/java/,\
+           src/test/java/
+bin.includes = META-INF/,\
+               .
+additional.bundles = com.springsource.junit
index 8cf6bdde885fb2c8bce0df6a5c2a019b26cf6f88..cd2e50c17cee4f39cf8a687a1354a40f913d7ad3 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.basic</groupId>
        <name>Commons Basic No Deps</name>
        <build>
                <plugins>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-compiler-plugin</artifactId>
-                       </plugin>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-source-plugin</artifactId>
-                       </plugin>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-jar-plugin</artifactId>
-                       </plugin>
                        <plugin>
                                <groupId>org.apache.felix</groupId>
                                <artifactId>maven-bundle-plugin</artifactId>
                </plugins>
        </build>
        <dependencies>
+               <dependency>
+                       <groupId>org.junit</groupId>
+                       <artifactId>com.springsource.junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
        </dependencies>
 </project>
diff --git a/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/Throughput.java b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/Throughput.java
new file mode 100644 (file)
index 0000000..12f6695
--- /dev/null
@@ -0,0 +1,71 @@
+package org.argeo.util;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Locale;
+
+import org.argeo.ArgeoException;
+
+public class Throughput {
+       private final static NumberFormat usNumberFormat = NumberFormat
+                       .getInstance(Locale.US);
+
+       enum Unit {
+               s, m, h, d
+       }
+
+       private final Double value;
+       private final Unit unit;
+
+       public Throughput(Double value, Unit unit) {
+               this.value = value;
+               this.unit = unit;
+       }
+
+       public Throughput(Double value, String unitStr) {
+               this(value, Unit.valueOf(unitStr));
+       }
+
+       public Throughput(String def) {
+               int index = def.indexOf('/');
+               if (def.length() < 3 || index <= 0 || index != def.length() - 2)
+                       throw new ArgeoException(def + " no a proper throughput definition"
+                                       + " (should be <value>/<unit>, e.g. 3.54/s or 1500/h");
+               String valueStr = def.substring(0, index);
+               String unitStr = def.substring(index + 1);
+               try {
+                       this.value = usNumberFormat.parse(valueStr).doubleValue();
+               } catch (ParseException e) {
+                       throw new ArgeoException("Cannot parse " + valueStr
+                                       + " as a number.", e);
+               }
+               this.unit = Unit.valueOf(unitStr);
+       }
+
+       public Long asMsPeriod() {
+               if (unit.equals(Unit.s))
+                       return Math.round(1000d / value);
+               else if (unit.equals(Unit.m))
+                       return Math.round((60d * 1000d) / value);
+               else if (unit.equals(Unit.h))
+                       return Math.round((60d * 60d * 1000d) / value);
+               else if (unit.equals(Unit.d))
+                       return Math.round((24d * 60d * 60d * 1000d) / value);
+               else
+                       throw new ArgeoException("Unsupported unit " + unit);
+       }
+
+       @Override
+       public String toString() {
+               return usNumberFormat.format(value) + '/' + unit;
+       }
+
+       public Double getValue() {
+               return value;
+       }
+
+       public Unit getUnit() {
+               return unit;
+       }
+
+}
diff --git a/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/ThroughputEditor.java b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/ThroughputEditor.java
new file mode 100644 (file)
index 0000000..396d773
--- /dev/null
@@ -0,0 +1,17 @@
+package org.argeo.util;
+
+import java.beans.PropertyEditorSupport;
+
+public class ThroughputEditor extends PropertyEditorSupport {
+
+       @Override
+       public String getAsText() {
+               return getValue().toString();
+       }
+
+       @Override
+       public void setAsText(String text) throws IllegalArgumentException {
+               setValue(new Throughput(text));
+       }
+
+}
diff --git a/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/ThroughputTest.java b/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/ThroughputTest.java
new file mode 100644 (file)
index 0000000..c44f954
--- /dev/null
@@ -0,0 +1,17 @@
+package org.argeo.util;
+
+import junit.framework.TestCase;
+
+public class ThroughputTest extends TestCase {
+       public void testParse() {
+               Throughput t;
+               t = new Throughput("3.54/s");
+               assertEquals(3.54d, t.getValue());
+               assertEquals(Throughput.Unit.s, t.getUnit());
+               assertEquals(282l, (long) t.asMsPeriod());
+
+               t = new Throughput("35698.2569/h");
+               assertEquals(Throughput.Unit.h, t.getUnit());
+               assertEquals(101l, (long) t.asMsPeriod());
+       }
+}