Skip to content

Commit 9c9e36e

Browse files
committed
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.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1063395 13f79535-47bb-0310-9956-ffa450edef68
1 parent 727d922 commit 9c9e36e

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

src/java/org/apache/commons/codec/language/ColognePhonetic.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public class ColognePhonetic implements StringEncoder {
183183
private abstract class CologneBuffer {
184184

185185
protected final char[] data;
186+
186187
protected int length = 0;
187188

188189
public CologneBuffer(char[] data) {
@@ -212,16 +213,16 @@ public CologneLeftBuffer(int buffSize) {
212213
super(buffSize);
213214
}
214215

216+
public void addRight(char chr) {
217+
data[length] = chr;
218+
length++;
219+
}
220+
215221
protected char[] copyData(int start, final int length) {
216222
char[] retData = new char[length];
217223
System.arraycopy(data, start, retData, 0, length);
218224
return retData;
219225
}
220-
221-
public void putRight(char chr) {
222-
data[length] = chr;
223-
length++;
224-
}
225226
}
226227

227228
private class CologneRightBuffer extends CologneBuffer {
@@ -230,25 +231,29 @@ public CologneRightBuffer(char[] data) {
230231
super(data);
231232
}
232233

234+
public void addLeft(char ch) {
235+
length++;
236+
data[getNextPos()] = ch;
237+
}
238+
233239
protected char[] copyData(int start, final int length) {
234240
char[] newData = new char[length];
235241
System.arraycopy(data, data.length - this.length + start, newData, 0, length);
236242
return newData;
237243
}
238244

239-
public char dropNext() {
240-
char ch = data[data.length - length];
241-
length--;
242-
return ch;
245+
public char getNextChar() {
246+
return data[getNextPos()];
243247
}
244248

245-
public char getNext() {
246-
return data[data.length - length];
249+
protected int getNextPos() {
250+
return data.length - length;
247251
}
248252

249-
public void putLeft(char ch) {
250-
length++;
251-
data[data.length - length] = ch;
253+
public char removeNext() {
254+
char ch = getNextChar();
255+
length--;
256+
return ch;
252257
}
253258
}
254259

@@ -259,16 +264,15 @@ public void putLeft(char ch) {
259264
new char[] { '\u00DF', 'S' } // ß
260265
};
261266

262-
public Object encode(Object pObject) throws EncoderException {
263-
if (!(pObject instanceof String)) {
267+
public Object encode(Object object) throws EncoderException {
268+
if (!(object instanceof String)) {
264269
throw new EncoderException(
265270
"This method’s parameter was expected to be of the type "
266271
+ String.class.getName()
267272
+ ". But actually it was of the type "
268-
+ pObject.getClass().getName() + ".");
273+
+ object.getClass().getName() + ".");
269274
}
270-
271-
return encode((String) pObject);
275+
return encode((String) object);
272276
}
273277

274278
public String encode(String text) {
@@ -309,10 +313,10 @@ public String colognePhonetic(String text) {
309313
int rightLength = right.length();
310314

311315
while (rightLength > 0) {
312-
chr = right.dropNext();
316+
chr = right.removeNext();
313317

314318
if ((rightLength = right.length()) > 0) {
315-
nextChar = right.getNext();
319+
nextChar = right.getNextChar();
316320
} else {
317321
nextChar = '-';
318322
}
@@ -336,7 +340,7 @@ public String colognePhonetic(String text) {
336340
} else if (chr == 'X'
337341
&& !arrayContains(new char[] { 'C', 'K', 'Q' }, lastChar)) {
338342
code = '4';
339-
right.putLeft('S');
343+
right.addLeft('S');
340344
rightLength++;
341345
} else if (chr == 'S' || chr == 'Z') {
342346
code = '8';
@@ -372,7 +376,7 @@ public String colognePhonetic(String text) {
372376
if (code != '-'
373377
&& (lastCode != code && (code != '0' || lastCode == '/')
374378
|| code < '0' || code > '8')) {
375-
left.putRight(code);
379+
left.addRight(code);
376380
}
377381

378382
lastChar = chr;

0 commit comments

Comments
 (0)