Skip to content
Snippets Groups Projects
Commit 623b82dd authored by Daniel Felipe  GONZALEZ OBANDO's avatar Daniel Felipe GONZALEZ OBANDO
Browse files

Fixed number comparisons throwing warning

- Happened on type referencing with different number type
parent 632b0a85
No related branches found
No related tags found
No related merge requests found
......@@ -808,7 +808,7 @@ public class Var<T> implements XMLPersistent, VarListener<T>
if (newValue == null)
changed = false;
}
else if (referenceValue.equals(newValue))
else if (areValuesEqual(referenceValue, newValue))
changed = false;
// value changed beside we are liked to a reference ?? --> shouldn't arrive
......@@ -828,6 +828,11 @@ public class Var<T> implements XMLPersistent, VarListener<T>
fireVariableChanged(oldValue, newValue);
}
protected boolean areValuesEqual(final T a, final Object b)
{
return a.equals(b);
}
@Override
public String toString()
{
......
......@@ -14,9 +14,8 @@ public class VarFloat extends VarNumber<Float>
{
this(name, defaultValue == null ? 0f : defaultValue.floatValue());
}
/**
*
* @param name
* @param defaultValue
*/
......@@ -24,46 +23,45 @@ public class VarFloat extends VarNumber<Float>
{
this(name, defaultValue, null);
}
/**
*
* @param name
* @param defaultValue
* @param defaultListener
* A listener to add to this variable immediately after creation
* A listener to add to this variable immediately after creation
*/
public VarFloat(String name, float defaultValue, VarListener<Float> defaultListener)
{
super(name, Float.TYPE, defaultValue, defaultListener);
}
@Override
public Float parse(String s)
{
return Float.parseFloat(s);
}
@Override
public int compareTo(Float f)
{
return getValue().compareTo(f);
}
@Override
public Float getValue()
{
return getValue(false);
}
/**
* Returns a Float representing the variable value.<br>
* NOTE: if the current variable references a variable of different (wider) type, truncation
* will occur
*/
public Float getValue(boolean forbidNull)
{
Number number = super.getValue(forbidNull);
return number == null ? null : number.floatValue();
}
@Override
public Float parse(String s)
{
return Float.parseFloat(s);
}
@Override
public int compareTo(Float f)
{
return getValue().compareTo(f);
}
@Override
public Float getValue()
{
return getValue(false);
}
/**
* Returns a Float representing the variable value.<br>
* NOTE: if the current variable references a variable of different (wider) type, truncation
* will occur
*/
public Float getValue(boolean forbidNull)
{
Number number = super.getValue(forbidNull);
return number == null ? null : number.floatValue();
}
}
......@@ -54,4 +54,14 @@ public class VarLong extends VarNumber<Long>
return result == null ? null : result;
}
@Override
protected boolean areValuesEqual(Long a, Object b)
{
if (b instanceof Number)
{
return super.areValuesEqual(a, ((Number) b).longValue());
}
return false;
}
}
......@@ -74,4 +74,14 @@ public abstract class VarNumber<N extends Number> extends Var<N> implements Comp
return super.createVarEditor();
}
@Override
protected boolean areValuesEqual(Number a, Object b)
{
if (b instanceof Number) {
return Double.compare(a.doubleValue(), ((Number)b).doubleValue()) == 0;
}
return false;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment