public int compareTo( final Value o )
{
if ( !( o instanceof Value ) )
{
throw new ClassCastException();
}
Value it = (Value) o;
if ( this.type == DataTypes.BOOLEAN_TYPE || this.type == DataTypes.INT_TYPE )
{
return this.contentLong < it.contentLong ? -1 : this.contentLong == it.contentLong ? 0 : 1;
}
if ( this.type == DataTypes.FLOAT_TYPE )
{
return Double.compare(
Double.longBitsToDouble( this.contentLong ),
Double.longBitsToDouble( it.contentLong ) );
}
if ( this.contentString != null && it.contentString != null )
{
return this.contentString.compareToIgnoreCase( it.contentString );
}
return -1;
}
public int compareTo( final Value o )
{
if ( !( o instanceof Value ) )
{
throw new ClassCastException();
}
Value it = (Value) o;
if ( this.type == DataTypes.BOOLEAN_TYPE || this.type == DataTypes.INT_TYPE )
{
return this.contentLong < it.contentLong ? -1 : this.contentLong == it.contentLong ? 0 : 1;
}
if ( this.type == DataTypes.FLOAT_TYPE )
{
return Double.compare(
Double.longBitsToDouble( this.contentLong ),
Double.longBitsToDouble( it.contentLong ) );
}
if (this.type == DataTypes.ITEM_TYPE)
{
return (this.getType().getType() - it.getType().getType());
}
if (this.type == DataTypes.EFFECT_TYPE)
{
return (this.getType().getType() - it.getType().getType());
}
if ( this.contentString != null && it.contentString != null )
{
return this.contentString.compareToIgnoreCase( it.contentString );
}
return -1;
}
if ( this.type == DataTypes.BOOLEAN_TYPE || this.type == DataTypes.INT_TYPE || this.type == DataTypes.ITEM_TYPE || this.type == DataTypes.EFFECT_TYPE)
{
return this.contentLong < it.contentLong ? -1 : this.contentLong == it.contentLong ? 0 : 1;
}
The method returns an int and the difference between two longs can overflow an int. Java gives an error about "possible loss of precision" if you try it.I am not sure why that isn't just implemented as this.contentLong - it.contentLong.
if ( this.type == DataTypes.MONSTER_TYPE )
{
// If we know the monster ID, compare it
if ( this.contentLong != 0 && it.contentLong != 0 )
{
return this.contentLong < it.contentLong ? -1 : this.contentLong == it.contentLong ? 0 : 1;
}
// Otherwise, must compare names
}
if ( this.contentLong != 0 && it.contentLong != 0 )
if ( this.contentLong != 0 || it.contentLong != 0 )