Hi Jia,

isEqualTo() is used by DoubleToken and ComplexToken to
compare two tokens with an epsilon factor.

Token.isEqualTo() says:

    /** Test that the value of this Token is close to the argument
     *  Token.  In this base class, we call isEqualTo().  This method
     *  should be overridden in derived classes such as DoubleToken
     *  and ComplexToken to provide type specific actions for
     *  equality testing using an epsilon factor.
     *
     *  @see #isEqualTo
     *  @param token The token to test closeness of this token with.
     *  @return a boolean token that contains the value true if the
     *  value and units of this token are close to those of the
     *  argument token.
     *  If either this token or the argument token is a nil token, then
     *  a boolean token that contains the value false is returned.
     *  @exception IllegalActionException If the argument token is not
     *  of a type that can be compared with this token.
     */
    public final BooleanToken isCloseTo(Token token)
            throws IllegalActionException {
        return isCloseTo(token, ptolemy.math.Complex.EPSILON);
    }

It looks like gr SceneGraphToken, gr Scene2DToken and ActorToken
all look like:

    public BooleanToken isEqualTo(Token token) throws IllegalActionException {
        if (token instanceof ActorToken) {
            return new BooleanToken(this == token);
        } else {
            throw new IllegalActionException(
                    "Equality test not supported between "
                            + this.getClass().getName() + " and "
                            + token.getClass().getName() + ".");
        }
    }

In theory, isEqualTo could call equals(), but I think they are fine
as is.

So, I think we are all set here.

_Christopher

--------

    
    Hi Christopher,
    I checked through that list. I do have a questions:
    First, for classes like these:
    ptolemy/domains/gr/kernel/SceneGraphToken.java
    ptolemy/domains/gr/kernel/Scene2DToken.java
    ptolemy/data/ActorToken.java
    
    Each has a isEqualTo method (Not sure why we are not overwriting the equals
    method), but each also has a type class corresponding to the token, and the
    equals method in that type only uses ==. I'm not sure how that works?
    Thanks,
    
    Jia
    
    On Tue, Jul 8, 2008 at 4:30 PM, Jia Zou <[EMAIL PROTECTED]> wrote:
    
    > Hi Christopher,
    > Thanks for pointing that out. I'll check the rest of the types soon.
    >
    > Jia
    >
    >
    > On Tue, Jul 8, 2008 at 3:37 PM, Christopher Brooks <[EMAIL PROTECTED]
   >
    > wrote:
    >
    >> Hi Jia,
    >>
    >> Actually, the Javadoc for java.lang.Comparable says that java.
    >>  "Note that null is not an instance of any class, and e.compareTo(null)
    >>  should throw a NullPointerException even though e.equals(null)
    >>  returns false."
    >>
    >> So, equals(null) should return false and compareTo(null) should throw
    >> an NPE.
    >>
    >> See
    >> http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html
    >> for details about natural ordering
    >>
    >>
    >> There were no unit tests for ptolemy.actor.util.Time.
    >>
    >> I created a unit test for this bug and fixed Time.java.
    >>
    >> One way around this is to do an instanceof check because null is not
    >> an instance of a class.  So, you'll see equals implemented like:
    >>
    >>    public boolean equals(Object time) {
    >>        if (time instanceof Time) {
    >>            return this.compareTo(time) == 0;
    >>        }
    >>        return false;
    >>    }
    >>
    >> In Ptolemy, the classes have equals() methods.  I checked the classes
    >> upto DEEvent, could you take a look at the classes below DEEvent?
    >>
    >> doc/tutorial/LeftRightDirector.java
    >> com/JLex/Main.java
    >> com/jgoodies/forms/layout/ConstantSize.java
    >> com/jgoodies/forms/layout/BoundedSize.java
    >> ptolemy/kernel/attributes/VersionAttribute.java
    >> ptolemy/backtrack/eclipse/ast/Type.java
    >>
    >> # No need to check these, they are used for back tracking
    >> ptolemy/backtrack/util/java/util/AbstractList.java
    >> ptolemy/backtrack/util/java/util/AbstractMap.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/Collections.java
    >> ptolemy/backtrack/util/java/util/AbstractSet.java
    >> ptolemy/backtrack/util/java/util/WeakHashMap.java
    >> ptolemy/backtrack/util/java/util/WeakHashMap.java
    >> ptolemy/backtrack/util/java/util/Hashtable.java
    >>
    >> # I checked these
    >> ptolemy/math/FixPoint.java
    >> ptolemy/math/Overflow.java
    >> ptolemy/math/Fraction.java
    >> ptolemy/math/FixPointQuantization.java
    >> ptolemy/math/Quantization.java
    >> ptolemy/math/Precision.java
    >> ptolemy/math/Rounding.java
    >> ptolemy/domains/fsm/kernel/ia/StatePair.java
    >> ptolemy/domains/csp/demo/DiningPhilosophers/Coordinate.java
    >> ptolemy/domains/de/kernel/DEEvent.java
    >>
    >> # Start checking here
    >> ptolemy/domains/gr/kernel/SceneGraphToken.java
    >> ptolemy/domains/gr/kernel/Scene2DToken.java
    >> ptolemy/graph/mapping/MapMapping.java
    >> ptolemy/graph/Graph.java
    >> ptolemy/graph/Inequality.java
    >> ptolemy/graph/LabeledList.java
    >> ptolemy/component/data/type/TupleType.java
    >> ptolemy/component/data/TupleToken.java
    >> ptolemy/apps/cacheAwareScheduler/kernel/MemoryAddress.java
    >> ptolemy/codegen/kernel/CodeGeneratorHelper.java
    >> ptolemy/codegen/kernel/CodeStream.java
    >> ptolemy/caltrop/ddi/util/DataflowActorInterpreter.java
    >> ptolemy/caltrop/ddi/DataflowWithRates.java
    >> ptolemy/moml/unit/Unit.java
    >> ptolemy/actor/gt/GraphAnalyzer.java
    >> ptolemy/actor/gt/GraphAnalyzer.java
    >> ptolemy/actor/util/Time.java
    >> ptolemy/data/type/MatrixType.java
    >> ptolemy/data/type/ObjectType.java
    >> ptolemy/data/type/BaseType.java
    >> ptolemy/data/type/RecordType.java
    >> ptolemy/data/type/ArrayType.java
    >> ptolemy/data/type/Type.java
    >> ptolemy/data/type/FunctionType.java
    >> ptolemy/data/type/FixType.java
    >> ptolemy/data/type/UnionType.java
    >> ptolemy/data/type/TypeConstant.java
    >> ptolemy/data/expr/CachedMethod.java
    >> ptolemy/data/properties/token/PropertyToken.java
    >> ptolemy/data/properties/PropertyHelper.java
    >> ptolemy/data/ShortToken.java
    >> ptolemy/data/LongToken.java
    >> ptolemy/data/UnsignedByteToken.java
    >> ptolemy/data/FloatToken.java
    >> ptolemy/data/StringToken.java
    >> ptolemy/data/ObjectToken.java
    >> ptolemy/data/ComplexToken.java
    >> ptolemy/data/ArrayToken.java
    >> ptolemy/data/IntMatrixToken.java
    >> ptolemy/data/UnionToken.java
    >> ptolemy/data/PetiteToken.java
    >> ptolemy/data/IntToken.java
    >> ptolemy/data/DoubleMatrixToken.java
    >> ptolemy/data/BooleanMatrixToken.java
    >> ptolemy/data/ActorToken.java
    >> ptolemy/data/DoubleToken.java
    >> ptolemy/data/FixMatrixToken.java
    >> ptolemy/data/RecordToken.java
    >> ptolemy/data/BooleanToken.java
    >> ptolemy/data/EventToken.java
    >> ptolemy/data/LongMatrixToken.java
    >> ptolemy/data/FixToken.java
    >> ptolemy/data/ComplexMatrixToken.java
    >> ptolemy/copernicus/kernel/SideEffectAnalysis.java
    >>
    >> _Christopher
    >>
    >> --------
    >>
    >>
    >>    It's because when you are comparing one time object with another, bot
   h
    >> of
    >>    them have to be actual objects, and null is not an object. You should
    >>    probably have a:
    >>    if (a != null && b !=null) when you are using the equals method.
    >>
    >>    Jia
    >>
    >>    On Sun, Jul 6, 2008 at 3:54 PM, Richard Ware <[EMAIL PROTECTED]>
    >> wrote:
    >>
    >>    >  When I do this,
    >>    >
    >>    >    Time a = ourDirector.getModelTime();
    >>    >    Time b = null;
    >>    >    boolean comparison = a.equals( b );
    >>    >
    >>    > I get a NullPointerException.
    >>    >
    >>    >  That isn't what the equals() method of a Java object is supposed t
   o
    >> do.
    >>    >  If
    >>    > given null as the argument, it's supposed to calmly return the
    >> boolean
    >>    > value "false".
    >>    >
    >>    >
    >>    >
    >>    >
    >>    >
    >> ------------------------------------------------------------------------
   -
    >>   ---
    >>    > Posted to the ptolemy-hackers mailing list.  Please send
    >> administrative
    >>    > mail for this list to:
    >> [EMAIL PROTECTED]
    >>    >
    >>

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to