[Schmitzm-commits] r2292 - in trunk: schmitzm-core/src/main/java/de/schmitzm/data schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales schmitzm-core/src/test/java/de/schmitzm/data schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Apr 18 17:26:48 CEST 2013


Author: mojays
Date: 2013-04-18 17:26:48 +0200 (Thu, 18 Apr 2013)
New Revision: 2292

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/data/DurationUnit.java
Modified:
   trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle.properties
   trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle_de.properties
   trunk/schmitzm-core/src/test/java/de/schmitzm/data/UnitConversionTest.java
   trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/DatabaseEntityTable.java
Log:
new DurationUnit (e.g. "hours per day")

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/data/DurationUnit.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/data/DurationUnit.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/data/DurationUnit.java	2013-04-18 15:26:48 UTC (rev 2292)
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+
+package de.schmitzm.data;
+
+
+/**
+ * This enum represents duration units and provides several utility
+ * function for conversion.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public enum DurationUnit implements Unit<DurationUnit> {
+  /** Hours per day */
+  HOURS_DAY,
+  /** Minutes per day */
+  MIN_DAY,
+  /** Seconds per day */
+  SEC_DAY,
+  /** Milliseconds per day */
+  MS_DAY,
+  /** Minutes per hour */
+  MIN_HOUR,
+  /** Seconds per hour */
+  SEC_HOUR,
+  /** Milliseconds per hour  */
+  MS_HOUR,
+  /** Seconds per minute */
+  SEC_MIN,
+  /** Milliseconds per minute  */
+  MS_MIN,
+  /** Milliseconds per second  */
+  MS_SEC;
+
+  /**
+   * Returns a short abbreviation for the unit.
+   */
+  @Override
+  public String getAbbreviation() {
+    return RESOURCE.getString("DurationUnit."+this+".Abb");
+  }
+
+  /**
+   * Returns a title for the unit.
+   */
+  @Override
+  public String getTitle() {
+    return RESOURCE.getString("DurationUnit."+this);
+  }
+
+  /**
+   * Returns the factor to convert 1 in "this" unit to another unit.<br>
+   * {@code x = A.getConversionFactor(B) <=> 1 A = x B}
+   * @param unit destination unit
+   */
+  @Override
+  public double getConversionFactor(DurationUnit unit) {
+    if ( this.equals(unit) )
+      return 1.0;
+    switch ( this ) {
+      case HOURS_DAY: switch (unit) {
+                        case MIN_DAY:   return TimeUnit.HOUR.getConversionFactor(TimeUnit.MIN);
+                        case SEC_DAY:   return TimeUnit.HOUR.getConversionFactor(TimeUnit.SEC);
+                        case MS_DAY:    return TimeUnit.HOUR.getConversionFactor(TimeUnit.MS);
+                        case MIN_HOUR:  return TimeUnit.HOUR.getConversionFactor(TimeUnit.MIN)
+                                             / TimeUnit.DAY.getConversionFactor(TimeUnit.HOUR);
+                        case SEC_HOUR:  return TimeUnit.HOUR.getConversionFactor(TimeUnit.SEC)
+                                             / TimeUnit.DAY.getConversionFactor(TimeUnit.HOUR);
+                        case MS_HOUR:   return TimeUnit.HOUR.getConversionFactor(TimeUnit.MS)
+                                             / TimeUnit.DAY.getConversionFactor(TimeUnit.HOUR);
+                        case SEC_MIN:   return TimeUnit.HOUR.getConversionFactor(TimeUnit.SEC)
+                                             / TimeUnit.DAY.getConversionFactor(TimeUnit.MIN);
+                        case MS_MIN:    return TimeUnit.HOUR.getConversionFactor(TimeUnit.MS)
+                                             / TimeUnit.DAY.getConversionFactor(TimeUnit.MIN);
+                        case MS_SEC:    return TimeUnit.HOUR.getConversionFactor(TimeUnit.MS)
+                                             / TimeUnit.DAY.getConversionFactor(TimeUnit.SEC);
+                      }
+                      break;
+      case MIN_DAY:   return HOURS_DAY.getConversionFactor(unit) / TimeUnit.HOUR.getConversionFactor(TimeUnit.MIN); 
+      case SEC_DAY:   return HOURS_DAY.getConversionFactor(unit) / TimeUnit.HOUR.getConversionFactor(TimeUnit.SEC);
+      case MS_DAY:    return HOURS_DAY.getConversionFactor(unit) / TimeUnit.HOUR.getConversionFactor(TimeUnit.MS);
+      case MIN_HOUR:  return MIN_DAY.getConversionFactor(unit) / TimeUnit.HOUR.getConversionFactor(TimeUnit.DAY);
+      case SEC_HOUR:  return SEC_DAY.getConversionFactor(unit) / TimeUnit.HOUR.getConversionFactor(TimeUnit.DAY);
+      case MS_HOUR:   return MS_DAY.getConversionFactor(unit)  / TimeUnit.HOUR.getConversionFactor(TimeUnit.DAY);
+      case SEC_MIN:   return SEC_DAY.getConversionFactor(unit) / TimeUnit.MIN.getConversionFactor(TimeUnit.DAY);
+      case MS_MIN:    return MS_DAY.getConversionFactor(unit)  / TimeUnit.MIN.getConversionFactor(TimeUnit.DAY);
+      case MS_SEC:    return MS_DAY.getConversionFactor(unit)  / TimeUnit.SEC.getConversionFactor(TimeUnit.DAY);
+    }
+    throw new UnsupportedOperationException("Can not convert "+this+" to "+unit+".");
+  }
+
+  /**
+   * Converts a value to another unit. 
+   * @param unit unit to convert the value to
+   * @param value value to convert
+   */
+  @Override
+  public double convertTo(DurationUnit unit, double value) {
+    return value * getConversionFactor(unit);
+  }
+
+}
\ No newline at end of file

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle.properties	2013-04-01 19:27:13 UTC (rev 2291)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle.properties	2013-04-18 15:26:48 UTC (rev 2292)
@@ -82,6 +82,28 @@
 TimeUnit.SEC.Abb=s
 TimeUnit.MS.Abb=ms
 
+DurationUnit.HOURS_DAY=hours per day
+DurationUnit.MIN_DAY=minutes per day
+DurationUnit.SEC_DAY=seconds per day
+DurationUnit.MS_DAY=milliseconds per day
+DurationUnit.MIN_HOUR=minutes per hour
+DurationUnit.SEC_HOUR=seconds per hour
+DurationUnit.MS_HOUR=milliseconds per hour
+DurationUnit.SEC_MIN=seconds per minute
+DurationUnit.MS_MIN=milliseconds per minute
+DurationUnit.MS_SEC=milliseconds per second
+
+DurationUnit.HOURS_DAY.Abb=h/day
+DurationUnit.MIN_DAY.Abb=min/day
+DurationUnit.SEC_DAY.Abb=s/day
+DurationUnit.MS_DAY.Abb=ms/day
+DurationUnit.MIN_HOUR.Abb=min/h
+DurationUnit.SEC_HOUR.Abb=s/h
+DurationUnit.MS_HOUR.Abb=ms/h
+DurationUnit.SEC_MIN.Abb=s/min
+DurationUnit.MS_MIN.Abb=ms/min
+DurationUnit.MS_SEC.Abb=ms/s
+
 SpeedUnit.KM_H=kilometers per hour
 SpeedUnit.M_S=meters per second
 SpeedUnit.MI_H=miles per hour

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle_de.properties	2013-04-01 19:27:13 UTC (rev 2291)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/data/resource/locales/DataResourceBundle_de.properties	2013-04-18 15:26:48 UTC (rev 2292)
@@ -70,6 +70,28 @@
 TimeUnit.SEC=Sekunden
 TimeUnit.MS=Millisekunden
 
+DurationUnit.HOURS_DAY=Stunden pro Tag
+DurationUnit.MIN_DAY=Minuten pro Tag
+DurationUnit.SEC_DAY=Sekunden pro Tag
+DurationUnit.MS_DAY=Millisekunden pro Tag
+DurationUnit.MIN_HOUR=Minuten pro Stunde
+DurationUnit.SEC_HOUR=Sekunden pro Stunde
+DurationUnit.MS_HOUR=Millisekunden pro Stunde
+DurationUnit.SEC_MIN=Sekunden pro Minute
+DurationUnit.MS_MIN=Millisekunden pro Minute
+DurationUnit.MS_SEC=Millisekunden pro Sekunde
+
+DurationUnit.HOURS_DAY.Abb=h/tag
+DurationUnit.MIN_DAY.Abb=min/tag
+DurationUnit.SEC_DAY.Abb=s/tag
+DurationUnit.MS_DAY.Abb=ms/tag
+DurationUnit.MIN_HOUR.Abb=min/h
+DurationUnit.SEC_HOUR.Abb=s/h
+DurationUnit.MS_HOUR.Abb=ms/h
+DurationUnit.SEC_MIN.Abb=s/min
+DurationUnit.MS_MIN.Abb=ms/min
+DurationUnit.MS_SEC.Abb=ms/s
+
 SpeedUnit.KM_H=Kilometer pro Stunde
 SpeedUnit.M_S=Meter pro Sekunde
 SpeedUnit.MI_H=Meilen pro Stunde

Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/data/UnitConversionTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/data/UnitConversionTest.java	2013-04-01 19:27:13 UTC (rev 2291)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/data/UnitConversionTest.java	2013-04-18 15:26:48 UTC (rev 2292)
@@ -2,6 +2,7 @@
 
 import static org.junit.Assert.*;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 import de.schmitzm.testing.TestingClass;
@@ -84,6 +85,120 @@
     checkAllCombinations(TemperatureUnit.values());
   }
 
+  @Test
+  public void testUnitConversion_Duration() {
+    assertEquals(1.0,DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.HOURS_DAY),0.0);
+    assertEquals(60.0,DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.MIN_DAY),0.0);
+    assertEquals(60.0*60.0,DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.SEC_DAY),0.0);
+    assertEquals(60.0*60.0*1000.0,DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.MS_DAY),0.0);
+    assertEquals(60.0/24.0,DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.MIN_HOUR),0.0);
+    assertEquals(60.0*60.0/24.0,DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.SEC_HOUR),0.0);
+    assertEquals(60.0*60.0*1000.0/24.0,DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.MS_HOUR),0.0);
+    assertEquals(60.0*60.0/(24.0*60.0),DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.SEC_MIN),0.0);
+    assertEquals(60.0*60.0*1000.0/(24.0*60.0),DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.MS_MIN),0.0);
+    assertEquals(60.0*60.0*1000.0/(24.0*60.0*60.0),DurationUnit.HOURS_DAY.getConversionFactor(DurationUnit.MS_SEC),0.0);
+      
+    assertEquals(1.0/60.0,DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.HOURS_DAY),0.0);
+    assertEquals(1.0,DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.MIN_DAY),0.0);
+    assertEquals(60.0,DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.SEC_DAY),0.0);
+    assertEquals(60.0*1000.0,DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.MS_DAY),0.0);
+    assertEquals(1.0/24.0,DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.MIN_HOUR),0.0);
+    assertEquals(60.0/24.0,DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.SEC_HOUR),0.0);
+    assertEquals(60.0*1000.0/24.0,DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.MS_HOUR),0.0);
+    assertEquals(60.0/(24.0*60.0),DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.SEC_MIN),0.0);
+    assertEquals(60.0*1000.0/(24.0*60.0),DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.MS_MIN),0.0);
+    assertEquals(60.0*1000.0/(24.0*60.0*60.0),DurationUnit.MIN_DAY.getConversionFactor(DurationUnit.MS_SEC),0.0);
+
+    assertEquals(1.0/(60.0*60.0),DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.HOURS_DAY),0.0);
+    assertEquals(1.0/60.0,DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.MIN_DAY),0.0);
+    assertEquals(1.0,DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.SEC_DAY),0.0);
+    assertEquals(1000.0,DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.MS_DAY),0.0);
+    assertEquals(1.0/(24.0*60.0),DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.MIN_HOUR),0.0);
+    assertEquals(1.0/24.0,DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.SEC_HOUR),0.0);
+    assertEquals(1000.0/24.0,DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.MS_HOUR),0.0);
+    assertEquals(1.0/(24.0*60.0),DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.SEC_MIN),0.0);
+    assertEquals(1000.0/(24.0*60.0),DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.MS_MIN),0.0);
+    assertEquals(1000.0/(24.0*60.0*60.0),DurationUnit.SEC_DAY.getConversionFactor(DurationUnit.MS_SEC),0.0);
+    
+    assertEquals(1.0/(60.0*60.0*1000.0),DurationUnit.MS_DAY.getConversionFactor(DurationUnit.HOURS_DAY),0.0);
+    assertEquals(1.0/(60.0*1000.0),DurationUnit.MS_DAY.getConversionFactor(DurationUnit.MIN_DAY),0.0);
+    assertEquals(1.0/1000.0,DurationUnit.MS_DAY.getConversionFactor(DurationUnit.SEC_DAY),0.0);
+    assertEquals(1.0,DurationUnit.MS_DAY.getConversionFactor(DurationUnit.MS_DAY),0.0);
+    assertEquals(1.0/(24.0*60.0*1000.0),DurationUnit.MS_DAY.getConversionFactor(DurationUnit.MIN_HOUR),0.0);
+    assertEquals(1.0/(24.0*1000.0),DurationUnit.MS_DAY.getConversionFactor(DurationUnit.SEC_HOUR),0.0);
+    assertEquals(1.0/24.0,DurationUnit.MS_DAY.getConversionFactor(DurationUnit.MS_HOUR),0.0);
+    assertEquals(1.0/(24.0*60.0*1000.0),DurationUnit.MS_DAY.getConversionFactor(DurationUnit.SEC_MIN),0.0);
+    assertEquals(1.0/(24.0*60.0),DurationUnit.MS_DAY.getConversionFactor(DurationUnit.MS_MIN),0.0);
+    assertEquals(1.0/(24.0*60.0*60.0),DurationUnit.MS_DAY.getConversionFactor(DurationUnit.MS_SEC),0.0);
+    
+    assertEquals(24.0/60.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.HOURS_DAY),0.0);
+    assertEquals(24.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.MIN_DAY),0.0);
+    assertEquals(24.0*60.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.SEC_DAY),0.0);
+    assertEquals(24.0*60.0*1000.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.MS_DAY),0.0);
+    assertEquals(1.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.MIN_HOUR),0.0);
+    assertEquals(60.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.SEC_HOUR),0.0);
+    assertEquals(60.0*1000.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.MS_HOUR),0.0);
+    assertEquals(1.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.SEC_MIN),0.0);
+    assertEquals(1000.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.MS_MIN),0.0);
+    assertEquals(1000.0/60.0,DurationUnit.MIN_HOUR.getConversionFactor(DurationUnit.MS_SEC),0.0);
+
+    assertEquals(24.0/(60.0*60.0),DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.HOURS_DAY),0.00001);
+    assertEquals(24.0/60.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.MIN_DAY),0.00001);
+    assertEquals(24.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.SEC_DAY),0.00001);
+    assertEquals(24.0*1000.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.MS_DAY),0.00001);
+    assertEquals(1.0/60.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.MIN_HOUR),0.00001);
+    assertEquals(1.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.SEC_HOUR),0.00001);
+    assertEquals(1000.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.MS_HOUR),0.00001);
+    assertEquals(1.0/60.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.SEC_MIN),0.00001);
+    assertEquals(1000.0/60.0,DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.MS_MIN),0.00001);
+    assertEquals(1000.0/(60.0*60.0),DurationUnit.SEC_HOUR.getConversionFactor(DurationUnit.MS_SEC),0.00001);
+    
+    assertEquals(24.0/(60.0*60.0*1000.0),DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.HOURS_DAY),0.00001);
+    assertEquals(24.0/(60.0*1000.0),DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.MIN_DAY),0.00001);
+    assertEquals(24.0/1000.0,DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.SEC_DAY),0.00001);
+    assertEquals(24.0,DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.MS_DAY),0.00001);
+    assertEquals(1.0/(60.0*1000.0),DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.MIN_HOUR),0.00001);
+    assertEquals(1.0/1000.0,DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.SEC_HOUR),0.00001);
+    assertEquals(1.0,DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.MS_HOUR),0.00001);
+    assertEquals(1.0/(60.0*1000.0),DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.SEC_MIN),0.00001);
+    assertEquals(1.0/60.0,DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.MS_MIN),0.00001);
+    assertEquals(1.0/(60.0*60.0),DurationUnit.MS_HOUR.getConversionFactor(DurationUnit.MS_SEC),0.00001);
+    
+    assertEquals(24.0/60.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.HOURS_DAY),0.00001);
+    assertEquals(24.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.MIN_DAY),0.00001);
+    assertEquals(24.0*60.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.SEC_DAY),0.00001);
+    assertEquals(24.0*60.0*1000.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.MS_DAY),0.00001);
+    assertEquals(1.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.MIN_HOUR),0.00001);
+    assertEquals(1.0*60.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.SEC_HOUR),0.00001);
+    assertEquals(1000.0*60.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.MS_HOUR),0.00001);
+    assertEquals(1.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.SEC_MIN),0.00001);
+    assertEquals(1000.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.MS_MIN),0.00001);
+    assertEquals(1000.0/60.0,DurationUnit.SEC_MIN.getConversionFactor(DurationUnit.MS_SEC),0.00001);
+
+    assertEquals(24.0/(60.0*1000.0),DurationUnit.MS_MIN.getConversionFactor(DurationUnit.HOURS_DAY),0.00001);
+    assertEquals(24.0/1000.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.MIN_DAY),0.00001);
+    assertEquals(24.0*60.0/1000.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.SEC_DAY),0.00001);
+    assertEquals(24.0*60.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.MS_DAY),0.00001);
+    assertEquals(1.0/1000.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.MIN_HOUR),0.00001);
+    assertEquals(1.0*60.0/1000.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.SEC_HOUR),0.00001);
+    assertEquals(60.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.MS_HOUR),0.00001);
+    assertEquals(1.0/1000.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.SEC_MIN),0.00001);
+    assertEquals(1.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.MS_MIN),0.00001);
+    assertEquals(1.0/60.0,DurationUnit.MS_MIN.getConversionFactor(DurationUnit.MS_SEC),0.00001);
+    
+    assertEquals(24.0/1000.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.HOURS_DAY),0.00001);
+    assertEquals(24.0*60.0/1000.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.MIN_DAY),0.00001);
+    assertEquals(24.0*60.0*60.0/1000.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.SEC_DAY),0.00001);
+    assertEquals(24.0*60.0*60.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.MS_DAY),0.00001);
+    assertEquals(60.0/1000.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.MIN_HOUR),0.00001);
+    assertEquals(60.0*60.0/1000.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.SEC_HOUR),0.00001);
+    assertEquals(60.0*60.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.MS_HOUR),0.00001);
+    assertEquals(60.0/1000.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.SEC_MIN),0.00001);
+    assertEquals(60.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.MS_MIN),0.00001);
+    assertEquals(1.0,DurationUnit.MS_SEC.getConversionFactor(DurationUnit.MS_SEC),0.00001);
+
+    checkAllCombinations(DurationUnit.values());
+  }
   
   private <U extends Unit<?>> void checkAllCombinations(U[] units) {
     // check if conversion to same unit equals 1.0 and if
@@ -93,7 +208,11 @@
         if ( u1.equals(u2) )
           assertEquals(1.0, u1.convertTo(u2, 1.0), 0.0);
         else
-          assertFalse(u1.convertTo(u2, 1.0) == 1.0);
+// This condition is not correct for all conversions:
+// e.g. although sec/min not equals min/hour, 1sec/min = 1 min/hour!! 
+//          assertFalse(u1.convertTo(u2, 1.0) == 1.0);
+// instead we check the reciprocal          
+          assertEquals(u1.convertTo(u2, 1.0), 1.0/u2.convertTo(u1, 1.0),0.000001);
       }
   }
 

Modified: trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/DatabaseEntityTable.java
===================================================================
--- trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/DatabaseEntityTable.java	2013-04-01 19:27:13 UTC (rev 2291)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/gui/DatabaseEntityTable.java	2013-04-18 15:26:48 UTC (rev 2292)
@@ -84,7 +84,7 @@
    * This method does nothing. Sub-classes can override this method
    * to implement a special functionality.
    */
-  protected void performEntitySelection(E kontakt) {
+  protected void performEntitySelection(E entity) {
   }
 
 }
\ No newline at end of file



More information about the Schmitzm-commits mailing list