commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey Varszegi <j...@generalize.net>
Subject Re: [codec] Submit: codec fixes + encoder changes + hex
Date Mon, 02 Dec 2002 01:43:23 GMT
Tim,

That's great, but don't you think that the method
should return a byte array instead of a String?  Then
maybe you could include a method named
encodeToString() or something similar, as an optional
operation.   

I don't think it's a big deal to create a String from
a byte array, but to assume that all users of some
common encoding interface will be dealing with strings
might be a mistake.  What do you think?  

Jeff

--- Tim O'Brien <tobrien@transolutions.net> wrote:
> Here is a patch for codec, which includes the
> following:
> 
> 0. Added a function to Encoder - public String
> encode(byte[])
> 
> 1. Added function to all classes that implement
> encoder.
> 
> 2. Hex, encodes a byte[] to a hex string - 0xcbd342
> -> "cbd342"
> 
> 3. TestHex, a junit test for Hex class.
> 
> 4. Some files in the codec package CRLF problems,
> patch resolves this.  
> 
> --------
> Tim O'Brien 
> Transolutions, Inc.
> 18 N Waukegan Road
> Lake Bluff, Il 60044
> W 847-574-2143
> F 847-234-3471
> M 847-863-7045
> > Index:
> src/java/org/apache/commons/codec/Encoder.java
>
===================================================================
> RCS file:
>
/home/cvspublic/jakarta-commons-sandbox/codec/src/java/org/apache/commons/codec/Encoder.java,v
> retrieving revision 1.2
> diff -u -r1.2 Encoder.java
> --- src/java/org/apache/commons/codec/Encoder.java
> 18 Nov 2002 12:41:24 -0000	1.2
> +++ src/java/org/apache/commons/codec/Encoder.java	1
> Dec 2002 22:03:15 -0000
> @@ -1,4 +1,16 @@
> -/*
>
====================================================================
> * The Apache Software License, Version 1.1
 *
 *
> Copyright (c) 2002 The Apache Software Foundation. 
> All rights
 * reserved.
 *
 * Redistribution and use
> in source and binary forms, with or without
 *
> modification, are permitted provided that the
> following conditions
 * are met:
 *
 * 1.
> Redistributions of source code must retain the above
> copyright
 *    notice, this list of conditions and
> the following disclaimer.
 *
 * 2. Redistributions
> in binary form must reproduce the above copyright
> +/*
>
====================================================================
> + * The Apache Software License, Version 1.1 *
> + * Copyright (c) 2002 The Apache Software
> Foundation.  All rights
> + * reserved.
> + *
> + * Redistribution and use in source and binary
> forms, with or without
> + * modification, are permitted provided that the
> following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain
> the above copyright
> + *    notice, this list of conditions and the
> following disclaimer.
> + *
> + * 2. Redistributions in binary form must reproduce
> the above copyright
>   *    notice, this list of conditions and the
> following disclaimer in
>   *    the documentation and/or other materials
> provided with the
>   *    distribution.
> @@ -31,4 +43,25 @@
>   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> ARISING IN ANY WAY OUT
>   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE POSSIBILITY OF
>   * SUCH DAMAGE.
> - *
>
====================================================================
> *
 * This software consists of voluntary
> contributions made by many
 * individuals on behalf
> of the Apache Software Foundation.  For more
 *
> information on the Apache Software Foundation,
> please see
 * <http://www.apache.org/>.
 */
package
> org.apache.commons.codec;

/**
 * Encoder is an
> interface, which is implemented by Soundex,
 *
> Metaphone, Soundex2, etc.
 *
 * @author
> tobrien@transolutions.net
 * @version $Revision: 1.2
> $ $Date: 2002/11/18 12:41:24 $
 */
public interface
> Encoder {
    String encode(String str);
}  
> + *
>
====================================================================
> + *
> + * This software consists of voluntary
> contributions made by many
> + * individuals on behalf of the Apache Software
> Foundation.  For more
> + * information on the Apache Software Foundation,
> please see
> + * <http://www.apache.org/>.
> + */
> +package org.apache.commons.codec;
> +
> +/** 
> + * Encoder is an interface, which is implemented by
> Soundex, 
> + * Metaphone, Soundex2, etc. 
> + * 
> + * @author tobrien@transolutions.net 
> + * @version $Revision: 1.2 $ $Date: 2002/11/18
> 12:41:24 $ 
> + */
> +public interface Encoder {
> +
> +  String encode(String str);
> +  String encode(byte[] bytes);
> +
> +}
> Index:
>
src/java/org/apache/commons/codec/EncoderComparator.java
>
===================================================================
> RCS file:
>
/home/cvspublic/jakarta-commons-sandbox/codec/src/java/org/apache/commons/codec/EncoderComparator.java,v
> retrieving revision 1.2
> diff -u -r1.2 EncoderComparator.java
> ---
>
src/java/org/apache/commons/codec/EncoderComparator.java
> 18 Nov 2002 12:41:24 -0000	1.2
> +++
>
src/java/org/apache/commons/codec/EncoderComparator.java
> 1 Dec 2002 22:03:16 -0000
> @@ -1,2 +1,86 @@
> -/*
>
====================================================================
> * The Apache Software License, Version 1.1
 *
 *
> Copyright (c) 2002 The Apache Software Foundation. 
> All rights
 * reserved.
 *
 * Redistribution and use
> in source and binary forms, with or without
 *
> modification, are permitted provided that the
> following conditions
 * are met:
 *
 * 1.
> Redistributions of source code must retain the above
> copyright
 *    notice, this list of conditions and
> the following disclaimer.
 *
 * 2. Redistributions
> in binary form must reproduce the above copyright
 *
>    notice, this list of conditions and the following
> disclaimer in
 *    the documentation and/or other
> materials provided with the
 *    distribution.
 *
> * 3. The end-user documentation included with the
> redistribution,
 *    if any, must include the
> following acknowledgment:
 *       "This product
> includes software developed by the
 *        Apache
> Software Foundation (http://www.apache.org/)."
 *   
> Alternately, this acknowledgment may appear in the
> software itself,
 *    if and wherever such
> third-party acknowledgments normally appear.
 *
 *
> 4. The names "Apache" and "Apache Software
> Foundation" and
 *    "Apache Commons" must not be
> used to endorse or promote products
 *    derived
> from this software without prior written permission.
> For
 *    written permission, please contact
> apache@apache.org.
 *
 * 5. Products derived from
> this software may not be called "Apache",
 *   
> "Apache Turbine", nor may "Apache" appear in their
> name, without
 *    prior written permission of the
> Apache Software Foundation.
 *
 * THIS SOFTWARE IS
> PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 *
> WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS
> FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO
> EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS
> CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO,
> PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
> OF
 * USE, DATA, OR PROFITS; OR BUSINESS
> INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF
> LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 *
> OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
> IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN
> IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
>
====================================================================
> *
 * This software consists of voluntary
> contributions made by many
 * individuals on behalf
> of the Apache Software Foundation.  For more
 *
> information on the Apache Software Foundation,
> please see
 * <http://www.apache.org/>.
 */
package
> org.apache.commons.codec;
> -import java.util.Comparator;

/**
 * Compare using
> an Encoder.
 *
 * @author tobrien@transolutions.net
> * @version $Revision: 1.2 $ $Date: 2002/11/18
> 12:41:24 $
 */
public class EncoderComparator
> implements Comparator {

    private Encoder
> encoder;

    /**
     * Use the default soundex
> algorithm, US_ENGLISH.
     */
    public
> EncoderComparator() {
       
> this(RefinedSoundex.US_ENGLISH);
    }

    /**
    
> * Use the provided soundex algorithm.
     */
   
> public EncoderComparator(Encoder en) {
       
> this.encoder = en;
    }

    public int
> compare(Object o1, Object o2) {
        String s1 =
> encoder.encode(o1.toString());
        String s2 =
> encoder.encode(o2.toString());
        return
> s1.compareTo(s2);
    }

}
> +/*
>
====================================================================
> + * The Apache Software License, Version 1.1 *
> + * Copyright (c) 2002 The Apache Software
> Foundation.  All rights
> + * reserved.
> + *
> + * Redistribution and use in source and binary
> forms, with or without
> + * modification, are permitted provided that the
> following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain
> the above copyright
> + *    notice, this list of conditions and the
> following disclaimer.
> + *
> + * 2. Redistributions in binary form must reproduce
> the above copyright
> 
=== message truncated ===> --
> To unsubscribe, e-mail:  
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>


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


Mime
View raw message