You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2011/11/13 22:57:16 UTC
svn commit: r1201529 - in
/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec:
binary/Base64.java language/Caverphone.java language/Soundex.java
net/URLCodec.java
Author: ggregory
Date: Sun Nov 13 21:57:16 2011
New Revision: 1201529
URL: http://svn.apache.org/viewvc?rev=1201529&view=rev
Log:
Add back code for 1.6 to keep binary compatibility.
Added:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Caverphone.java
Modified:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Soundex.java
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java?rev=1201529&r1=1201528&r2=1201529&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/Base64.java Sun Nov 13 21:57:16 2011
@@ -468,6 +468,20 @@ public class Base64 extends BaseNCodec {
}
/**
+ * Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the
+ * method treats whitespace as valid.
+ *
+ * @param arrayOctet
+ * byte array to test
+ * @return <code>true</code> if all bytes are valid characters in the Base64 alphabet or if the byte array is empty;
+ * <code>false</code>, otherwise
+ * @deprecated 1.5 Use {@link #isBase64(byte[])}, will be removed in 2.0.
+ */
+ public static boolean isArrayByteBase64(byte[] arrayOctet) {
+ return isBase64(arrayOctet);
+ }
+
+ /**
* Returns whether or not the <code>octet</code> is in the base 64 alphabet.
*
* @param octet
Added: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Caverphone.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Caverphone.java?rev=1201529&view=auto
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Caverphone.java (added)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Caverphone.java Sun Nov 13 21:57:16 2011
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.codec.language;
+
+import org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.StringEncoder;
+
+/**
+ * Encodes a string into a Caverphone 2.0 value. Delegate to a {@link Caverphone2} instance.
+ *
+ * This is an algorithm created by the Caversham Project at the University of Otago. It implements the Caverphone 2.0
+ * algorithm:
+ *
+ * @author Apache Software Foundation
+ * @version $Id: Caverphone.java 1079535 2011-03-08 20:54:37Z ggregory $
+ * @see <a href="http://en.wikipedia.org/wiki/Caverphone">Wikipedia - Caverphone</a>
+ * @see <a href="http://caversham.otago.ac.nz/files/working/ctp150804.pdf">Caverphone 2.0 specification</a>
+ * @since 1.4
+ * @deprecated 1.5 Replaced by {@link Caverphone2}, will be removed in 2.0.
+ */
+public class Caverphone implements StringEncoder {
+
+ /**
+ * Delegate to a {@link Caverphone2} instance to avoid code duplication.
+ */
+ final private Caverphone2 encoder = new Caverphone2();
+
+ /**
+ * Creates an instance of the Caverphone encoder
+ */
+ public Caverphone() {
+ super();
+ }
+
+ /**
+ * Encodes the given String into a Caverphone value.
+ *
+ * @param source
+ * String the source string
+ * @return A caverphone code for the given String
+ */
+ public String caverphone(String source) {
+ return this.encoder.encode(source);
+ }
+
+ /**
+ * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of
+ * the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String.
+ *
+ * @param pObject
+ * Object to encode
+ * @return An object (or type java.lang.String) containing the caverphone code which corresponds to the String
+ * supplied.
+ * @throws EncoderException
+ * if the parameter supplied is not of type java.lang.String
+ */
+ public Object encode(Object pObject) throws EncoderException {
+ if (!(pObject instanceof String)) {
+ throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String");
+ }
+ return this.caverphone((String) pObject);
+ }
+
+ /**
+ * Encodes a String using the Caverphone algorithm.
+ *
+ * @param pString
+ * String object to encode
+ * @return The caverphone code corresponding to the String supplied
+ */
+ public String encode(String pString) {
+ return this.caverphone(pString);
+ }
+
+ /**
+ * Tests if the caverphones of two strings are identical.
+ *
+ * @param str1
+ * First of two strings to compare
+ * @param str2
+ * Second of two strings to compare
+ * @return <code>true</code> if the caverphones of these strings are identical, <code>false</code> otherwise.
+ */
+ public boolean isCaverphoneEqual(String str1, String str2) {
+ return this.caverphone(str1).equals(this.caverphone(str2));
+ }
+
+}
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Soundex.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Soundex.java?rev=1201529&r1=1201528&r2=1201529&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Soundex.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/Soundex.java Sun Nov 13 21:57:16 2011
@@ -56,29 +56,12 @@ public class Soundex implements StringEn
*/
public static final Soundex US_ENGLISH = new Soundex();
-
/**
- * Encodes the Strings and returns the number of characters in the two encoded Strings that are the same. This
- * return value ranges from 0 through 4: 0 indicates little or no similarity, and 4 indicates strong similarity or
- * identical values.
- *
- * @param s1
- * A String that will be encoded and compared.
- * @param s2
- * A String that will be encoded and compared.
- * @return The number of characters in the two encoded Strings that are the same from 0 to 4.
- *
- * @see SoundexUtils#difference(StringEncoder,String,String)
- * @see <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp"> MS
- * T-SQL DIFFERENCE </a>
+ * The maximum length of a Soundex code - Soundex codes are only four characters by definition.
*
- * @throws EncoderException
- * if an error occurs encoding one of the strings
- * @since 1.3
+ * @deprecated This feature is not needed since the encoding size must be constant. Will be removed in 2.0.
*/
- public int difference(String s1, String s2) throws EncoderException {
- return SoundexUtils.difference(this, s1, s2);
- }
+ private int maxLength = 4;
/**
* Every letter of the alphabet is "mapped" to a numerical value. This char array holds the values to which each
@@ -124,6 +107,29 @@ public class Soundex implements StringEn
}
/**
+ * Encodes the Strings and returns the number of characters in the two encoded Strings that are the same. This
+ * return value ranges from 0 through 4: 0 indicates little or no similarity, and 4 indicates strong similarity or
+ * identical values.
+ *
+ * @param s1
+ * A String that will be encoded and compared.
+ * @param s2
+ * A String that will be encoded and compared.
+ * @return The number of characters in the two encoded Strings that are the same from 0 to 4.
+ *
+ * @see SoundexUtils#difference(StringEncoder,String,String)
+ * @see <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp"> MS
+ * T-SQL DIFFERENCE </a>
+ *
+ * @throws EncoderException
+ * if an error occurs encoding one of the strings
+ * @since 1.3
+ */
+ public int difference(String s1, String s2) throws EncoderException {
+ return SoundexUtils.difference(this, s1, s2);
+ }
+
+ /**
* Encodes an Object using the soundex algorithm. This method is provided in order to satisfy the requirements of
* the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String.
*
@@ -187,6 +193,16 @@ public class Soundex implements StringEn
}
/**
+ * Returns the maxLength. Standard Soundex
+ *
+ * @deprecated This feature is not needed since the encoding size must be constant. Will be removed in 2.0.
+ * @return int
+ */
+ public int getMaxLength() {
+ return this.maxLength;
+ }
+
+ /**
* Returns the soundex mapping.
*
* @return soundexMapping.
@@ -213,6 +229,17 @@ public class Soundex implements StringEn
}
/**
+ * Sets the maxLength.
+ *
+ * @deprecated This feature is not needed since the encoding size must be constant. Will be removed in 2.0.
+ * @param maxLength
+ * The maxLength to set
+ */
+ public void setMaxLength(int maxLength) {
+ this.maxLength = maxLength;
+ }
+
+ /**
* Retrieves the Soundex code for a given String object.
*
* @param str
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java?rev=1201529&r1=1201528&r2=1201529&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/net/URLCodec.java Sun Nov 13 21:57:16 2011
@@ -59,8 +59,10 @@ public class URLCodec implements BinaryE
/**
* The default charset used for string decoding and encoding.
+ *
+ * TODO: This field will be final in 2.0.
*/
- protected final String charset;
+ protected String charset;
/**
* Release 1.5 made this field final.
@@ -346,4 +348,15 @@ public class URLCodec implements BinaryE
return this.charset;
}
+ /**
+ * The <code>String</code> encoding used for decoding and encoding.
+ *
+ * @return Returns the encoding.
+ *
+ * @deprecated Use {@link #getDefaultCharset()}, will be removed in 2.0.
+ */
+ public String getEncoding() {
+ return this.charset;
+ }
+
}