Skip to content

Commit

Permalink
Upgraded to community commons 6.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
joostverhoog committed Sep 10, 2018
1 parent 9179579 commit 259507e
Show file tree
Hide file tree
Showing 62 changed files with 3,039 additions and 3,213 deletions.
Binary file added DIST/RestServices_mx6_3.2.0.mpk
Binary file not shown.
Binary file modified RestServices.mpr
Binary file not shown.
471 changes: 0 additions & 471 deletions javasource/communitycommons/ConversationLog.java

This file was deleted.

136 changes: 68 additions & 68 deletions javasource/communitycommons/DateTime.java
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;
}

}
116 changes: 58 additions & 58 deletions javasource/communitycommons/ImmutablePair.java
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();
}

}
134 changes: 69 additions & 65 deletions javasource/communitycommons/Logging.java
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);
}
}
Loading

0 comments on commit 259507e

Please sign in to comment.