commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chuck Daniels" <c...@yahoo.com>
Subject RE: [lang] Equalator?
Date Wed, 12 May 2004 00:54:32 GMT
I suggest you simply implement the Comparator interface since it is a
"superset" of your suggested Equalator interface.  Therefore, I would
implement your MetaphoneEqualator as EncodingComparator.  The class name
prefix is changed from Metaphone to Encoding since you are not actually
comparing Metaphones, but rather two encodings produced by a single
Metaphone.  More generally, you are actually comparing two encodings
produced by a single Encoder:

public class EncodingComparator implements Comparator {
    private Encoder encoder;

    public EncodingComparator(Encoder encoder) {
        if (encoder == null) {
            throw new IllegalArgumentExcpetion("encoder is null");
        }

        this.encoder = encoder;
    }

    public int compare(Object a, Object b) {
        int result = 1;

        try {
            // TODO: Handle null values (inputs and outputs)?

            Object encoding1 = this.encoder.encode(a);
            Object encoding2 = this.encoder.encode(b);

            result = encoding1.equals(encoding2) ? 0 : 1;
        } catch (EncoderException e) {
            // TODO: Log this?
        }

        return result;
    }

    // TODO: implement equals and hashCode?
}

Note that the EncodingComparator effectively contains no more code than your
suggested MetaphoneEqualator.  Further, it leverages an interface that
already exists in the core API.

The only difference in the client code is that rather than using the
MetaphoneEqualator's equals method, you use the EncodingComparator's compare
method and compare the return value to zero in order to determine equality
of the encodings.

-- Chuck

> -----Original Message-----
> From: Edelson, Justin [mailto:Justin.Edelson@mtvi.com]
> Sent: Tuesday, May 11, 2004 3:32 PM
> To: Jakarta Commons Developers List
> Subject: RE: [lang] Equalator?
>
>
> That could be one implementation of the Equalator interface. Another
> trivial impelmetantion might do "return (a == b);" and be called
> IdentityEqualator
>
> The specific case I'm working on is using Metaphone (from codec). The
> impelemtatnion of MetaphoneEqualator looks like this:
>
> ...
> private Metaphone mEncoder = new Metaphone();
> ...
> public boolean equals(Object a, Object b) {
> 	try {
>             Object encoded0 = mEncoder.encode(a);
>             Object encoded1 = mEncoder.encode(b);
>             if (encoded0.equals(encoded1)) {
>                 return true;
>             } else {
>                 return false;
>             }
>         } catch (EncoderException exception) {
>             return false;
>         }
> }
>
> -----Original Message-----
> From: Hookom, Jacob [mailto:Jacob.Hookom@redline.mckhboc.com]
> Sent: Tuesday, May 11, 2004 2:47 PM
> To: 'Jakarta Commons Developers List'
> Subject: RE: [lang] Equalator?
>
>
> There's this method on Object called "equals"... I suppose you could
> write a single object called Equalator that does:
>
> Public Boolean equals(object a, object b) {
> 	Return a.equals(b);
> }
>
> -----Original Message-----
> From: Edelson, Justin [mailto:Justin.Edelson@mtvi.com]
> Sent: Tuesday, May 11, 2004 1:25 PM
> To: Jakarta Commons Developers List
> Subject: [lang] Equalator?
>
> I'm writing a few classes that currently implement Comparator, but I
> really don't care about comparisons - I just want to use an object to
> test equality, ergo Equalator. Does such an interface exist somewhere in
> lang (I can't find anything similar).
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message