implement Comparable.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4270 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -7,7 +7,7 @@ import com.threerings.io.ObjectOutputStream;
|
|||||||
import com.threerings.io.Streamable;
|
import com.threerings.io.Streamable;
|
||||||
|
|
||||||
public class Name extends Object
|
public class Name extends Object
|
||||||
implements Hashable, Streamable
|
implements Comparable, Hashable, Streamable
|
||||||
{
|
{
|
||||||
public function Name (name :String = "")
|
public function Name (name :String = "")
|
||||||
{
|
{
|
||||||
@@ -37,14 +37,14 @@ public class Name extends Object
|
|||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Hashable
|
// from interface Hashable
|
||||||
public function equals (other :Object) :Boolean
|
public function equals (other :Object) :Boolean
|
||||||
{
|
{
|
||||||
return (other is Name) &&
|
return (other is Name) &&
|
||||||
(getNormal() === (other as Name).getNormal());
|
(getNormal() === (other as Name).getNormal());
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Hashable
|
// from interface Hashable
|
||||||
public function hashCode () :int
|
public function hashCode () :int
|
||||||
{
|
{
|
||||||
var norm :String = getNormal();
|
var norm :String = getNormal();
|
||||||
@@ -55,14 +55,30 @@ public class Name extends Object
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Streamable
|
// from interface Comparable
|
||||||
|
public function compareTo (other :Object) :int
|
||||||
|
{
|
||||||
|
var thisNormal :String = getNormal();
|
||||||
|
var thatNormal :String = (other as Name).getNormal();
|
||||||
|
if (thisNormal == thatNormal) {
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} if (thisNormal < thatNormal) {
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// from interface Streamable
|
||||||
public function writeObject (out :ObjectOutputStream) :void
|
public function writeObject (out :ObjectOutputStream) :void
|
||||||
//throws IOError
|
//throws IOError
|
||||||
{
|
{
|
||||||
out.writeField(_name);
|
out.writeField(_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface Streamable
|
// from interface Streamable
|
||||||
public function readObject (ins :ObjectInputStream) :void
|
public function readObject (ins :ObjectInputStream) :void
|
||||||
//throws IOError
|
//throws IOError
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user