[Schmitzm-commits] r1938 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Wed Apr 4 23:26:53 CEST 2012
Author: mojays
Date: 2012-04-04 23:26:53 +0200 (Wed, 04 Apr 2012)
New Revision: 1938
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:
LangUtil: combineDate(.) by Date and day millis.
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-04-04 15:43:10 UTC (rev 1937)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-04-04 21:26:53 UTC (rev 1938)
@@ -359,7 +359,25 @@
return combinedDateCal.getTime();
}
- /**
+ /**
+ * Returns a new date which combines the date and time information of several date objects.
+ *
+ * @param date
+ * date the date information is taken from
+ * @param time
+ * time in milliseconds of day
+ */
+ public static Date combineDate(Date date, long timeMillis) {
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.set(Calendar.HOUR_OF_DAY, (int)(timeMillis/LangUtil.HOUR_MILLIS) );
+ cal.set(Calendar.MINUTE, (int)((timeMillis%LangUtil.HOUR_MILLIS)/LangUtil.MIN_MILLIS) );
+ cal.set(Calendar.SECOND, (int)((timeMillis%LangUtil.MIN_MILLIS)/LangUtil.SEC_MILLIS) );
+ cal.set(Calendar.MILLISECOND, (int)(timeMillis%LangUtil.SEC_MILLIS) );
+ Date time = cal.getTime();
+ return combineDate(date, time);
+ }
+
+ /**
* Returns a {@link Date} which represents the given day and time in GMT time zone.<br>
* <b>For example:</b><br>
* The given date is 01.01.2011, 00:00 (in CET). Then this method returns 01.01.2011, 01:00, because the timezone
@@ -827,7 +845,31 @@
return destMap;
}
- /**
+ /**
+ * Transforms map keys according to a mapping.
+ * @param sourceMap source map
+ * @param mapping mapping from destination key to source key (if mapping contains
+ * no value for a key of source map, the value is irgnored)
+ * @param destMap destination map to put the values in (if {@code null} a new
+ * {@link HashMap} is created)
+ * @return {@code sourceMap} if mapping is {@code null}
+ */
+ public static <K,V> Map<K,V> transformMapKeysInverted(Map<K,V> sourceMap, Map<K,K> mapping, Map<K,V> destMap) {
+ if ( mapping == null )
+ return sourceMap;
+ if ( destMap == null )
+ destMap = new HashMap<K,V>();
+ for (K destKey : mapping.keySet()) {
+ K sourceKey = mapping.get(destKey);
+ if ( sourceKey != null ) {
+ V value = sourceMap.get(sourceKey);
+ destMap.put(destKey,value);
+ }
+ }
+ return destMap;
+ }
+
+ /**
* Erzeugt einen vorbelegten Array.
*
* @param count
More information about the Schmitzm-commits
mailing list