Skip to content

Commit 4e88248

Browse files
authored
Merge pull request #88 from spinscale/remove-useless-constants
Remove hardcoded constants to improve readability
2 parents 4de60e8 + fdf0356 commit 4e88248

1 file changed

Lines changed: 15 additions & 21 deletions

File tree

src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ public class MatchRatingApproachEncoder implements StringEncoder {
3535

3636
private static final String EMPTY = "";
3737

38-
/**
39-
* Constants used mainly for the min rating value.
40-
*/
41-
private static final int ONE = 1, TWO = 2, THREE = 3, FOUR = 4, FIVE = 5, SIX = 6, SEVEN = 7,
42-
ELEVEN = 11, TWELVE = 12;
43-
4438
/**
4539
* The plain letter equivalent of the accented letters.
4640
*/
@@ -159,9 +153,9 @@ public final String encode(String name) {
159153
String getFirst3Last3(final String name) {
160154
final int nameLength = name.length();
161155

162-
if (nameLength > SIX) {
163-
final String firstThree = name.substring(0, THREE);
164-
final String lastThree = name.substring(nameLength - THREE, nameLength);
156+
if (nameLength > 6) {
157+
final String firstThree = name.substring(0, 3);
158+
final String lastThree = name.substring(nameLength - 3, nameLength);
165159
return firstThree + lastThree;
166160
}
167161
return name;
@@ -183,16 +177,16 @@ String getFirst3Last3(final String name) {
183177
int getMinRating(final int sumLength) {
184178
int minRating = 0;
185179

186-
if (sumLength <= FOUR) {
187-
minRating = FIVE;
188-
} else if (sumLength <= SEVEN) { // aready know it is at least 5
189-
minRating = FOUR;
190-
} else if (sumLength <= ELEVEN) { // aready know it is at least 8
191-
minRating = THREE;
192-
} else if (sumLength == TWELVE) {
193-
minRating = TWO;
180+
if (sumLength <= 4) {
181+
minRating = 5;
182+
} else if (sumLength <= 7) { // aready know it is at least 5
183+
minRating = 4;
184+
} else if (sumLength <= 11) { // aready know it is at least 8
185+
minRating = 3;
186+
} else if (sumLength == 12) {
187+
minRating = 2;
194188
} else {
195-
minRating = ONE; // docs said little here.
189+
minRating = 1; // docs said little here.
196190
}
197191

198192
return minRating;
@@ -243,7 +237,7 @@ public boolean isEncodeEquals(String name1, String name2) {
243237

244238
// 4. Check for length difference - if 3 or greater then no similarity
245239
// comparison is done
246-
if (Math.abs(name1.length() - name2.length()) >= THREE) {
240+
if (Math.abs(name1.length() - name2.length()) >= 3) {
247241
return false;
248242
}
249243

@@ -335,9 +329,9 @@ int leftToRightThenRightToLeftProcessing(final String name1, final String name2)
335329

336330
// Final bit - subtract longest string from 6 and return this int value
337331
if (strA.length() > strB.length()) {
338-
return Math.abs(SIX - strA.length());
332+
return Math.abs(6 - strA.length());
339333
}
340-
return Math.abs(SIX - strB.length());
334+
return Math.abs(6 - strB.length());
341335
}
342336

343337
/**

0 commit comments

Comments
 (0)