<?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>
</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>
--- /dev/null
+source.. = src/main/java/,\
+ src/test/java/
+bin.includes = META-INF/,\
+ .
+additional.bundles = com.springsource.junit
-<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>
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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));
+ }
+
+}
--- /dev/null
+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());
+ }
+}