-
Notifications
You must be signed in to change notification settings - Fork 1
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
99ba057
commit 1a9ffc3
Showing
150 changed files
with
8,853 additions
and
53 deletions.
There are no files selected for viewing
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
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
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
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
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package communitycommons; | ||
|
||
import communitycommons.proxies.DatePartSelector; | ||
import static communitycommons.proxies.DatePartSelector.day; | ||
import static communitycommons.proxies.DatePartSelector.month; | ||
import static communitycommons.proxies.DatePartSelector.year; | ||
import java.util.Date; | ||
|
||
import java.time.LocalDate; | ||
import java.time.Period; | ||
import java.time.ZoneId; | ||
import java.util.Calendar; | ||
|
||
public class DateTime { | ||
|
||
/** | ||
* @author mwe | ||
* @author res | ||
* @param firstDate The begin of the period | ||
* @param compareDate The end of the period | ||
* @return The period between the firstDate in the system default timezone, and the compareDate in the system | ||
* default timezone as a Java Period | ||
* | ||
* Code is based on http://stackoverflow.com/questions/1116123/how-do-i-calculate-someones-age-in-java | ||
* | ||
* Adjusted to Java 8 APIs (April, 2019) | ||
*/ | ||
public static Period periodBetween(Date firstDate, Date compareDate) { | ||
return Period.between(toLocalDate(firstDate), toLocalDate(compareDate)); | ||
} | ||
|
||
private static LocalDate toLocalDate(Date someDate) { | ||
return someDate.toInstant() | ||
.atZone(ZoneId.systemDefault()) | ||
.toLocalDate(); | ||
} | ||
|
||
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; | ||
} | ||
|
||
public static long dateTimeToLong(Date date) { | ||
return date.getTime(); | ||
} | ||
|
||
public static Date longToDateTime(Long value) { | ||
return new Date(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 |
---|---|---|
@@ -0,0 +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(); | ||
} | ||
|
||
} |
Oops, something went wrong.