From: Mathieu Baudier Date: Fri, 19 Mar 2010 15:50:45 +0000 (+0000) Subject: First working version X-Git-Tag: argeo-commons-2.1.30~1638 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=73d1fdb44aea0dc6c291f60dbcf4ab8501a26cf2;p=lgpl%2Fargeo-commons.git First working version git-svn-id: https://svn.argeo.org/commons/trunk@3433 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/basic/runtime/org.argeo.basic.nodeps/.classpath b/basic/runtime/org.argeo.basic.nodeps/.classpath index 16f01e2ee..3bf070c69 100644 --- a/basic/runtime/org.argeo.basic.nodeps/.classpath +++ b/basic/runtime/org.argeo.basic.nodeps/.classpath @@ -1,7 +1,9 @@ + + diff --git a/basic/runtime/org.argeo.basic.nodeps/.project b/basic/runtime/org.argeo.basic.nodeps/.project index e11498f94..e03b5033e 100644 --- a/basic/runtime/org.argeo.basic.nodeps/.project +++ b/basic/runtime/org.argeo.basic.nodeps/.project @@ -11,13 +11,18 @@ - org.maven.ide.eclipse.maven2Builder + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder - org.maven.ide.eclipse.maven2Nature org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature diff --git a/basic/runtime/org.argeo.basic.nodeps/build.properties b/basic/runtime/org.argeo.basic.nodeps/build.properties new file mode 100644 index 000000000..0b396f912 --- /dev/null +++ b/basic/runtime/org.argeo.basic.nodeps/build.properties @@ -0,0 +1,5 @@ +source.. = src/main/java/,\ + src/test/java/ +bin.includes = META-INF/,\ + . +additional.bundles = com.springsource.junit diff --git a/basic/runtime/org.argeo.basic.nodeps/pom.xml b/basic/runtime/org.argeo.basic.nodeps/pom.xml index 8cf6bdde8..cd2e50c17 100644 --- a/basic/runtime/org.argeo.basic.nodeps/pom.xml +++ b/basic/runtime/org.argeo.basic.nodeps/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.argeo.commons.basic @@ -10,18 +11,6 @@ Commons Basic No Deps - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - org.apache.felix maven-bundle-plugin @@ -37,5 +26,10 @@ + + org.junit + com.springsource.junit + test + 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 index 000000000..12f669505 --- /dev/null +++ b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/Throughput.java @@ -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 /, 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 index 000000000..396d773ad --- /dev/null +++ b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/ThroughputEditor.java @@ -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 index 000000000..c44f9544a --- /dev/null +++ b/basic/runtime/org.argeo.basic.nodeps/src/test/java/org/argeo/util/ThroughputTest.java @@ -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()); + } +}