[New] TimeValue and its implementations are now Comparable
This commit is contained in:
parent
ff434cb285
commit
fedc2824f6
|
@ -24,7 +24,7 @@ package li.strolch.model.timevalue;
|
|||
*
|
||||
* @author Martin Smock <smock.martin@gmail.com>
|
||||
*/
|
||||
public interface IValue<T> {
|
||||
public interface IValue<T> extends Comparable<IValue<T>> {
|
||||
|
||||
/**
|
||||
* @return the type of this {@link IValue}
|
||||
|
|
|
@ -115,4 +115,9 @@ public class BooleanValue implements IValue<Boolean>, Serializable {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IValue<Boolean> o) {
|
||||
return Boolean.compare(this.value, o.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,4 +153,11 @@ public class FloatListValue implements IValue<List<Double>>, Serializable {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IValue<List<Double>> o) {
|
||||
List<Double> otherValues = o.getValue();
|
||||
if (this.value.equals(otherValues))
|
||||
return 0;
|
||||
return Integer.compare(this.value.size(), otherValues.size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,4 +125,8 @@ public class FloatValue implements IValue<Double>, Serializable {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IValue<Double> o) {
|
||||
return Double.compare(this.value, o.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,4 +116,8 @@ public class IntegerValue implements IValue<Integer>, Serializable {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IValue<Integer> o) {
|
||||
return Integer.compare(this.value, o.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,4 +116,8 @@ public class LongValue implements IValue<Long>, Serializable {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IValue<Long> o) {
|
||||
return Long.compare(this.value, o.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,4 +141,12 @@ public class StringSetValue implements IValue<Set<AString>>, Serializable {
|
|||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IValue<Set<AString>> o) {
|
||||
Set<AString> otherValues = o.getValue();
|
||||
if (this.aStrings.equals(otherValues))
|
||||
return 0;
|
||||
return Integer.compare(this.aStrings.size(), otherValues.size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,9 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
|||
|
||||
/**
|
||||
* @param time
|
||||
* the time for this value
|
||||
* @param value
|
||||
* the actual value for this value
|
||||
*/
|
||||
public TimeValue(final Long time, final T value) {
|
||||
this.time = time;
|
||||
|
@ -41,7 +43,7 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getValue() {
|
||||
return (T) this.value.getCopy();
|
||||
return this.value == null ? null : (T) this.value.getCopy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,9 +64,19 @@ public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable
|
|||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int compareTo(final ITimeValue<T> arg0) {
|
||||
return this.getTime().compareTo(arg0.getTime());
|
||||
int i = getTime().compareTo(arg0.getTime());
|
||||
if (i != 0)
|
||||
return i;
|
||||
if (this.value == null && arg0.getValue() == null)
|
||||
return 0;
|
||||
if (this.value == null)
|
||||
return -1;
|
||||
if (arg0.getValue() == null)
|
||||
return 1;
|
||||
return getValue().compareTo(arg0.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue