Skip to content

Commit fbee540

Browse files
committed
Added SortOrder Mendix project
1 parent 206b198 commit fbee540

File tree

369 files changed

+41067
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

369 files changed

+41067
-0
lines changed

SortOrder.mpr

16.6 MB
Binary file not shown.

data-snapshot.zip

24 KB
Binary file not shown.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package communitycommons;
2+
3+
import communitycommons.proxies.DatePartSelector;
4+
import static communitycommons.proxies.DatePartSelector.day;
5+
import static communitycommons.proxies.DatePartSelector.month;
6+
import static communitycommons.proxies.DatePartSelector.year;
7+
import java.util.Date;
8+
9+
import java.time.LocalDate;
10+
import java.time.Period;
11+
import java.time.ZoneId;
12+
import java.util.Calendar;
13+
14+
public class DateTime {
15+
16+
/**
17+
* @author mwe
18+
* @author res
19+
* @param firstDate The begin of the period
20+
* @param compareDate The end of the period
21+
* @return The period between the firstDate in the system default timezone, and the compareDate in the system
22+
* default timezone as a Java Period
23+
*
24+
* Code is based on http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java
25+
*
26+
* Adjusted to Java 8 APIs (April, 2019)
27+
*/
28+
public static Period periodBetween(Date firstDate, Date compareDate) {
29+
return Period.between(toLocalDate(firstDate), toLocalDate(compareDate));
30+
}
31+
32+
private static LocalDate toLocalDate(Date someDate) {
33+
return someDate.toInstant()
34+
.atZone(ZoneId.systemDefault())
35+
.toLocalDate();
36+
}
37+
38+
public static long dateTimeToInteger(Date date, DatePartSelector selectorObj) {
39+
Calendar newDate = Calendar.getInstance();
40+
newDate.setTime(date);
41+
int value = -1;
42+
switch (selectorObj) {
43+
case year:
44+
value = newDate.get(Calendar.YEAR);
45+
break;
46+
case month:
47+
value = newDate.get(Calendar.MONTH) + 1;
48+
break; // Return starts at 0
49+
case day:
50+
value = newDate.get(Calendar.DAY_OF_MONTH);
51+
break;
52+
default:
53+
break;
54+
}
55+
return value;
56+
}
57+
58+
public static long dateTimeToLong(Date date) {
59+
return date.getTime();
60+
}
61+
62+
public static Date longToDateTime(Long value) {
63+
return new Date(value);
64+
}
65+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package communitycommons;
2+
3+
import org.apache.commons.lang3.builder.HashCodeBuilder;
4+
5+
6+
public class ImmutablePair<T, U>
7+
{
8+
public static <T, U> ImmutablePair<T, U> of(T left, U right) {
9+
return new ImmutablePair<T, U>(left, right);
10+
}
11+
12+
private final T left;
13+
private final U right;
14+
15+
private ImmutablePair(T left, U right) {
16+
if (left == null)
17+
throw new IllegalArgumentException("Left is NULL");
18+
if (right == null)
19+
throw new IllegalArgumentException("Right is NULL");
20+
21+
this.left = left;
22+
this.right = right;
23+
}
24+
25+
public T getLeft() {
26+
return left;
27+
}
28+
29+
public U getRight() {
30+
return right;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return "<" + left.toString()+ "," + right.toString() + ">";
36+
}
37+
38+
@Override
39+
public boolean equals(Object other) {
40+
if (!(other instanceof ImmutablePair<?,?>))
41+
return false;
42+
43+
if (this == other)
44+
return true;
45+
46+
ImmutablePair<?,?> o = (ImmutablePair<?, ?>) other;
47+
return left.equals(o.getLeft()) && right.equals(o.getRight());
48+
}
49+
50+
@Override
51+
public int hashCode() {
52+
return new HashCodeBuilder(19, 85)
53+
.append(left)
54+
.append(right)
55+
.toHashCode();
56+
}
57+
58+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package communitycommons;
2+
3+
import com.mendix.core.Core;
4+
import com.mendix.logging.ILogNode;
5+
import communitycommons.proxies.LogLevel;
6+
import communitycommons.proxies.LogNodes;
7+
import java.util.Date;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
public class Logging {
12+
13+
private static Map<String, Long> timers = new HashMap<String, Long>();
14+
15+
public static void trace(String lognode, String message) {
16+
log(lognode, LogLevel.Trace, message, null);
17+
}
18+
19+
public static void info(String lognode, String message) {
20+
log(lognode, LogLevel.Info, message, null);
21+
}
22+
23+
public static void debug(String lognode, String message) {
24+
log(lognode, LogLevel.Debug, message, null);
25+
}
26+
27+
public static void warn(String lognode, String message, Throwable e) {
28+
log(lognode, LogLevel.Warning, message, e);
29+
}
30+
31+
public static void warn(String lognode, String message) {
32+
warn(lognode, message, null);
33+
}
34+
35+
public static void error(String lognode, String message, Throwable e) {
36+
log(lognode, LogLevel.Error, message, e);
37+
}
38+
39+
public static void error(String lognode, String message) {
40+
error(lognode, message, null);
41+
}
42+
43+
public static void critical(String lognode, String message, Throwable e) {
44+
log(lognode, LogLevel.Critical, message, e);
45+
}
46+
47+
public static void log(String lognode, LogLevel loglevel, String message, Throwable e) {
48+
ILogNode logger = createLogNode(lognode);
49+
switch (loglevel) {
50+
case Critical:
51+
logger.critical(message, e);
52+
break;
53+
case Warning:
54+
logger.warn(message, e);
55+
break;
56+
case Debug:
57+
logger.debug(message);
58+
break;
59+
case Error:
60+
logger.error(message, e);
61+
break;
62+
case Info:
63+
logger.info(message);
64+
break;
65+
case Trace:
66+
logger.trace(message);
67+
break;
68+
}
69+
}
70+
71+
public static Long measureEnd(String timerName, LogLevel loglevel,
72+
String message) {
73+
Long cur = new Date().getTime();
74+
if (!timers.containsKey(timerName)) {
75+
throw new IllegalArgumentException(String.format("Timer with key %s not found", timerName));
76+
}
77+
Long timeTaken = cur - timers.get(timerName);
78+
String time = String.format("%d", timeTaken);
79+
log(LogNodes.CommunityCommons.name(), loglevel, "Timer " + timerName + " finished in " + time + " ms. " + message, null);
80+
return timeTaken;
81+
}
82+
83+
public static void measureStart(String timerName) {
84+
timers.put(timerName, new Date().getTime());
85+
}
86+
87+
public static ILogNode createLogNode(String logNode) {
88+
return Core.getLogger(logNode);
89+
}
90+
}

0 commit comments

Comments
 (0)