commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1063395 - /commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/ColognePhonetic.java
Date Tue, 25 Jan 2011 18:40:36 GMT
Author: ggregory
Date: Tue Jan 25 18:40:36 2011
New Revision: 1063395

URL: http://svn.apache.org/viewvc?rev=1063395&view=rev
Log:
This refactoring changes method names from "put" and "drop" to "add" and "remove". The names
"put" would have been OK if used with a key like an index or map key. Here we just add one
char with one call.

Modified:
    commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/ColognePhonetic.java

Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/ColognePhonetic.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/ColognePhonetic.java?rev=1063395&r1=1063394&r2=1063395&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/ColognePhonetic.java
(original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/ColognePhonetic.java
Tue Jan 25 18:40:36 2011
@@ -183,6 +183,7 @@ public class ColognePhonetic implements 
     private abstract class CologneBuffer {
 
         protected final char[] data;
+        
         protected int length = 0;
 
         public CologneBuffer(char[] data) {
@@ -212,16 +213,16 @@ public class ColognePhonetic implements 
             super(buffSize);
         }
 
+        public void addRight(char chr) {
+            data[length] = chr;
+            length++;
+        }
+
         protected char[] copyData(int start, final int length) {
             char[] retData = new char[length];
             System.arraycopy(data, start, retData, 0, length);
             return retData;
         }
-
-        public void putRight(char chr) {
-            data[length] = chr;
-            length++;
-        }
     }
 
     private class CologneRightBuffer extends CologneBuffer {
@@ -230,25 +231,29 @@ public class ColognePhonetic implements 
             super(data);
         }
 
+        public void addLeft(char ch) {
+            length++;
+            data[getNextPos()] = ch;
+        }
+
         protected char[] copyData(int start, final int length) {
             char[] newData = new char[length];
             System.arraycopy(data, data.length - this.length + start, newData, 0, length);
             return newData;
         }
 
-        public char dropNext() {
-            char ch = data[data.length - length];
-            length--;
-            return ch;
+        public char getNextChar() {
+            return data[getNextPos()];
         }
 
-        public char getNext() {
-            return data[data.length - length];
+        protected int getNextPos() {
+            return data.length - length;
         }
         
-        public void putLeft(char ch) {
-            length++;
-            data[data.length - length] = ch;
+        public char removeNext() {
+            char ch = getNextChar();
+            length--;
+            return ch;
         }
     }
 
@@ -259,16 +264,15 @@ public class ColognePhonetic implements 
             new char[] { '\u00DF', 'S' }      // ß
     };
 
-    public Object encode(Object pObject) throws EncoderException {
-        if (!(pObject instanceof String)) {
+    public Object encode(Object object) throws EncoderException {
+        if (!(object instanceof String)) {
             throw new EncoderException(
                     "This method’s parameter was expected to be of the type "
                             + String.class.getName()
                             + ". But actually it was of the type "
-                            + pObject.getClass().getName() + ".");
+                            + object.getClass().getName() + ".");
         }
-
-        return encode((String) pObject);
+        return encode((String) object);
     }
 
     public String encode(String text) {
@@ -309,10 +313,10 @@ public class ColognePhonetic implements 
         int rightLength = right.length();
 
         while (rightLength > 0) {
-            chr = right.dropNext();
+            chr = right.removeNext();
 
             if ((rightLength = right.length()) > 0) {
-                nextChar = right.getNext();
+                nextChar = right.getNextChar();
             } else {
                 nextChar = '-';
             }
@@ -336,7 +340,7 @@ public class ColognePhonetic implements 
             } else if (chr == 'X'
                     && !arrayContains(new char[] { 'C', 'K', 'Q' }, lastChar)) {
                 code = '4';
-                right.putLeft('S');
+                right.addLeft('S');
                 rightLength++;
             } else if (chr == 'S' || chr == 'Z') {
                 code = '8';
@@ -372,7 +376,7 @@ public class ColognePhonetic implements 
             if (code != '-'
                     && (lastCode != code && (code != '0' || lastCode == '/')
                             || code < '0' || code > '8')) {
-                left.putRight(code);
+                left.addRight(code);
             }
 
             lastChar = chr;



Mime
View raw message