-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9179579
commit 259507e
Showing
62 changed files
with
3,039 additions
and
3,213 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
package communitycommons; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import communitycommons.proxies.DatePartSelector; | ||
|
||
public class DateTime | ||
{ | ||
/** | ||
* @author mwe | ||
* Berekent aantal jaar sinds een bepaalde datum. Als einddatum == null, het huidige tijdstip wordt gebruikt | ||
* Code is gebaseerd op http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java | ||
*/ | ||
public static long yearsBetween(Date birthdate, Date comparedate) { | ||
if (birthdate == null) | ||
return -1L; | ||
|
||
Calendar now = Calendar.getInstance(); | ||
if (comparedate != null) | ||
now.setTime(comparedate); | ||
Calendar dob = Calendar.getInstance(); | ||
dob.setTime(birthdate); | ||
if (dob.after(now)) | ||
return -1L; | ||
|
||
int year1 = now.get(Calendar.YEAR); | ||
int year2 = dob.get(Calendar.YEAR); | ||
long age = year1 - year2; | ||
int month1 = now.get(Calendar.MONTH); | ||
int month2 = dob.get(Calendar.MONTH); | ||
if (month2 > month1) { | ||
age--; | ||
} else if (month1 == month2) { | ||
int day1 = now.get(Calendar.DAY_OF_MONTH); | ||
int day2 = dob.get(Calendar.DAY_OF_MONTH); | ||
if (day2 > day1) { | ||
age--; | ||
} | ||
} | ||
return age; | ||
} | ||
|
||
public static long dateTimeToLong(Date date) | ||
{ | ||
return date.getTime(); | ||
} | ||
|
||
public static Date longToDateTime(Long value) | ||
{ | ||
return new Date(value); | ||
} | ||
|
||
public static long dateTimeToInteger(Date date, DatePartSelector selectorObj) | ||
{ | ||
Calendar newDate = Calendar.getInstance(); | ||
newDate.setTime(date); | ||
int value = -1; | ||
switch (selectorObj) { | ||
case year : value = newDate.get(Calendar.YEAR); break; | ||
case month : value = newDate.get(Calendar.MONTH)+1; break; // Return starts at 0 | ||
case day : value = newDate.get(Calendar.DAY_OF_MONTH); break; | ||
default : break; | ||
} | ||
return value; | ||
} | ||
|
||
} | ||
package communitycommons; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import communitycommons.proxies.DatePartSelector; | ||
|
||
public class DateTime | ||
{ | ||
/** | ||
* @author mwe | ||
* Berekent aantal jaar sinds een bepaalde datum. Als einddatum == null, het huidige tijdstip wordt gebruikt | ||
* Code is gebaseerd op http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java | ||
*/ | ||
public static long yearsBetween(Date birthdate, Date comparedate) { | ||
if (birthdate == null) | ||
return -1L; | ||
|
||
Calendar now = Calendar.getInstance(); | ||
if (comparedate != null) | ||
now.setTime(comparedate); | ||
Calendar dob = Calendar.getInstance(); | ||
dob.setTime(birthdate); | ||
if (dob.after(now)) | ||
return -1L; | ||
|
||
int year1 = now.get(Calendar.YEAR); | ||
int year2 = dob.get(Calendar.YEAR); | ||
long age = year1 - year2; | ||
int month1 = now.get(Calendar.MONTH); | ||
int month2 = dob.get(Calendar.MONTH); | ||
if (month2 > month1) { | ||
age--; | ||
} else if (month1 == month2) { | ||
int day1 = now.get(Calendar.DAY_OF_MONTH); | ||
int day2 = dob.get(Calendar.DAY_OF_MONTH); | ||
if (day2 > day1) { | ||
age--; | ||
} | ||
} | ||
return age; | ||
} | ||
|
||
public static long dateTimeToLong(Date date) | ||
{ | ||
return date.getTime(); | ||
} | ||
|
||
public static Date longToDateTime(Long value) | ||
{ | ||
return new Date(value); | ||
} | ||
|
||
public static long dateTimeToInteger(Date date, DatePartSelector selectorObj) | ||
{ | ||
Calendar newDate = Calendar.getInstance(); | ||
newDate.setTime(date); | ||
int value = -1; | ||
switch (selectorObj) { | ||
case year : value = newDate.get(Calendar.YEAR); break; | ||
case month : value = newDate.get(Calendar.MONTH)+1; break; // Return starts at 0 | ||
case day : value = newDate.get(Calendar.DAY_OF_MONTH); break; | ||
default : break; | ||
} | ||
return value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
package communitycommons; | ||
|
||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
|
||
public class ImmutablePair<T, U> | ||
{ | ||
public static <T, U> ImmutablePair<T, U> of(T left, U right) { | ||
return new ImmutablePair<T, U>(left, right); | ||
} | ||
|
||
private final T left; | ||
private final U right; | ||
|
||
private ImmutablePair(T left, U right) { | ||
if (left == null) | ||
throw new IllegalArgumentException("Left is NULL"); | ||
if (right == null) | ||
throw new IllegalArgumentException("Right is NULL"); | ||
|
||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
public T getLeft() { | ||
return left; | ||
} | ||
|
||
public U getRight() { | ||
return right; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "<" + left.toString()+ "," + right.toString() + ">"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (!(other instanceof ImmutablePair<?,?>)) | ||
return false; | ||
|
||
if (this == other) | ||
return true; | ||
|
||
ImmutablePair<?,?> o = (ImmutablePair<?, ?>) other; | ||
return left.equals(o.getLeft()) && right.equals(o.getRight()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder(19, 85) | ||
.append(left) | ||
.append(right) | ||
.toHashCode(); | ||
} | ||
|
||
} | ||
package communitycommons; | ||
|
||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
|
||
public class ImmutablePair<T, U> | ||
{ | ||
public static <T, U> ImmutablePair<T, U> of(T left, U right) { | ||
return new ImmutablePair<T, U>(left, right); | ||
} | ||
|
||
private final T left; | ||
private final U right; | ||
|
||
private ImmutablePair(T left, U right) { | ||
if (left == null) | ||
throw new IllegalArgumentException("Left is NULL"); | ||
if (right == null) | ||
throw new IllegalArgumentException("Right is NULL"); | ||
|
||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
public T getLeft() { | ||
return left; | ||
} | ||
|
||
public U getRight() { | ||
return right; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "<" + left.toString()+ "," + right.toString() + ">"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (!(other instanceof ImmutablePair<?,?>)) | ||
return false; | ||
|
||
if (this == other) | ||
return true; | ||
|
||
ImmutablePair<?,?> o = (ImmutablePair<?, ?>) other; | ||
return left.equals(o.getLeft()) && right.equals(o.getRight()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder(19, 85) | ||
.append(left) | ||
.append(right) | ||
.toHashCode(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,69 @@ | ||
package communitycommons; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.mendix.core.Core; | ||
import com.mendix.logging.ILogNode; | ||
import communitycommons.proxies.LogLevel; | ||
|
||
public class Logging | ||
{ | ||
private static Map<String, Long> timers = new HashMap<String, Long>(); | ||
|
||
public static void log(String lognode, LogLevel loglevel, String message) | ||
{ | ||
log(lognode, loglevel, message, null); | ||
} | ||
|
||
public static void log(String lognode, LogLevel loglevel, String message, Throwable e) { | ||
ILogNode logger = Core.getLogger(lognode); | ||
switch (loglevel) { | ||
case Critical: | ||
logger.critical(message,e); | ||
break; | ||
case Warning: | ||
logger.warn(message,e); | ||
break; | ||
case Debug: | ||
logger.debug(message); | ||
break; | ||
case Error: | ||
logger.error(message,e); | ||
break; | ||
case Info: | ||
logger.info(message); | ||
break; | ||
case Trace: | ||
logger.trace(message); | ||
break; | ||
} | ||
} | ||
|
||
public static void simpleLog(String message) | ||
{ | ||
Core.getLogger("Community_Commons").info(message); | ||
} | ||
|
||
|
||
public static Long measureEnd(String timerName, LogLevel loglevel, | ||
String message) | ||
{ | ||
Long cur = new Date().getTime(); | ||
if (!timers.containsKey(timerName)) | ||
throw new IllegalArgumentException(); | ||
String time = String.format("%d", cur - timers.get(timerName)); | ||
log("Utility_log", loglevel, "Timer " + timerName + " finished in " + time + " ms. " + message); | ||
return timers.get(timerName); | ||
} | ||
|
||
public static void measureStart(String timerName) | ||
{ | ||
timers.put(timerName, new Date().getTime()); | ||
} | ||
} | ||
package communitycommons; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.mendix.core.Core; | ||
import com.mendix.logging.ILogNode; | ||
import communitycommons.proxies.LogLevel; | ||
|
||
public class Logging | ||
{ | ||
private static Map<String, Long> timers = new HashMap<String, Long>(); | ||
|
||
public static void log(String lognode, LogLevel loglevel, String message) | ||
{ | ||
log(lognode, loglevel, message, null); | ||
} | ||
|
||
public static void log(String lognode, LogLevel loglevel, String message, Throwable e) { | ||
ILogNode logger = Core.getLogger(lognode); | ||
switch (loglevel) { | ||
case Critical: | ||
logger.critical(message,e); | ||
break; | ||
case Warning: | ||
logger.warn(message,e); | ||
break; | ||
case Debug: | ||
logger.debug(message); | ||
break; | ||
case Error: | ||
logger.error(message,e); | ||
break; | ||
case Info: | ||
logger.info(message); | ||
break; | ||
case Trace: | ||
logger.trace(message); | ||
break; | ||
} | ||
} | ||
|
||
public static void simpleLog(String message) | ||
{ | ||
Core.getLogger("Community_Commons").info(message); | ||
} | ||
|
||
|
||
public static Long measureEnd(String timerName, LogLevel loglevel, | ||
String message) | ||
{ | ||
Long cur = new Date().getTime(); | ||
if (!timers.containsKey(timerName)) | ||
throw new IllegalArgumentException(); | ||
String time = String.format("%d", cur - timers.get(timerName)); | ||
log("Utility_log", loglevel, "Timer " + timerName + " finished in " + time + " ms. " + message); | ||
return timers.get(timerName); | ||
} | ||
|
||
public static void measureStart(String timerName) | ||
{ | ||
timers.put(timerName, new Date().getTime()); | ||
} | ||
|
||
public static void createLogNode(String logNode) { | ||
Core.getLogger(logNode); | ||
} | ||
} |
Oops, something went wrong.