Minor utilities and fixes

This commit is contained in:
Olof Larsson 2013-03-07 12:55:20 +01:00
parent 8c5c35c725
commit 8dbb8f793d
3 changed files with 22 additions and 1 deletions

View File

@ -46,7 +46,7 @@ public abstract class Entity<E extends Entity<E, L>, L extends Comparable<? supe
public boolean attached()
{
return this.getColl() != null;
return this.getColl() != null && this.getId() != null;
}
public boolean detached()

View File

@ -381,6 +381,14 @@ public class MUtil
return herp.equals(derp);
}
public static <T> int compare(Comparable<T> herp, T derp)
{
if (herp == null && derp == null) return 0;
if (herp == null) return -1;
if (derp == null) return +1;
return herp.compareTo(derp);
}
// -------------------------------------------- //
// SORTING
// -------------------------------------------- //

View File

@ -36,6 +36,19 @@ public class TimeUnit implements Comparable<TimeUnit>
private static final TreeSet<TimeUnit> all = new TreeSet<TimeUnit>();
public static TreeSet<TimeUnit> getAll() { return new TreeSet<TimeUnit>(all); }
public static TreeSet<TimeUnit> getAllButMillis()
{
TreeSet<TimeUnit> ret = new TreeSet<TimeUnit>(all);
ret.remove(MILLISECOND);
return ret;
}
public static TreeSet<TimeUnit> getAllButMillisAndSeconds()
{
TreeSet<TimeUnit> ret = new TreeSet<TimeUnit>(all);
ret.remove(MILLISECOND);
ret.remove(SECOND);
return ret;
}
public static TimeUnit get(String timeUnitString)
{