Package | org.as3utils |
Class | public final class EquatableUtil |
Inheritance | EquatableUtil Object |
org.as3coreaddendum.system.IEquatable
.
Method | Defined By | ||
---|---|---|---|
NumberUtil is a static class and shouldn't be instantiated. | EquatableUtil | ||
areEqual(o1:*, o2:*):Boolean [static]
Checks if objects are equal. | EquatableUtil |
EquatableUtil | () | Constructor |
public function EquatableUtil()
NumberUtil is a static class and shouldn't be instantiated.
IllegalOperationError — NumberUtil is a static class and shouldn't be instantiated.
|
areEqual | () | method |
public static function areEqual(o1:*, o2:*):Boolean
Checks if objects are equal.
First thi method compare objects using o1 == o2
.
If it returns true then the method returns true.
Otherwise it will be checked if both objects implement org.as3coreaddendum.system.IEquatable
interface and then use o1.equals(o2)
.
Parameters
o1:* — a Number object to evaluate.
| |
o2:* |
Boolean — true if the value is NaN (not a number) and false otherwise.
|
package test { import org.as3coreaddendum.system.IEquatable; import org.as3utils.ReflectionUtil; public class EquatableObject implements IEquatable { private var _id:String; public function get id(): String { return _id; } public function EquatableObject(id:String) { _id = id; } public function equals(other:: Boolean { if (!other) return false; if (!ReflectionUtil.classPathEquals(this, other)) return false; return id == (other as EquatableObject).id; } } }
import test.EquatableObject; import org.as3coreaddendum.system.IEquatable; trace(EquatableUtil.areEqual(1, 1)) // false trace(EquatableUtil.areEqual("test1", 99)) // false var equatableObject1A:EquatableObject = new EquatableObject("object-1"); var equatableObject1B:EquatableObject = new EquatableObject("object-1"); var equatableObject2:EquatableObject = new EquatableObject("object-2"); trace(EquatableUtil.areEqual(equatableObject1A, equatableObject1B)) // true trace(EquatableUtil.areEqual(equatableObject1A, equatableObject2)) // false