Files
narya/src/as/com/threerings/util/Integer.as
T
Michael Bayne 0267c4b5c5 Added Integer.compare(). I wish Java had such a method (that worked on int
values rather than Integer values).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4500 542714f4-19e9-0310-aa3c-eee0fc999fb1
2007-01-06 03:32:00 +00:00

47 lines
1.1 KiB
ActionScript

package com.threerings.util {
/**
* Equivalent to java.lang.Integer.
*/
// Unfortunately, I think this is necessary.
// I was going to remove this class and just make the streaming stuff
// autotranslate between int <--> java.lang.Integer and
// Number <--> java.lang.Double. However, a Number object that refers
// to an integer value is actually an int. Yes, it's totally fucked.
public class Integer
implements Equalable, Wrapped
{
public var value :int;
public static function valueOf (val :int) :Integer
{
return new Integer(val);
}
public function Integer (value :int)
{
this.value = value;
}
// from Equalable
public function equals (other :Object) :Boolean
{
return (other is Integer) && (value === (other as Integer).value);
}
// from Wrapped
public function unwrap () :Object
{
return value;
}
/**
* Compares to int values in an overflow safe manner.
*/
public static function compare (val1 :int, val2 :int) :int
{
return (val1 > val2) ? 1 : (val1 == val2 ? 0 : -1);
}
}
}