Skip to content

Commit

Permalink
Improved: Remove unused ‘StringUtil#convertChar’ method
Browse files Browse the repository at this point in the history
(OFBIZ-11014)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1859927 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed May 25, 2019
1 parent c79b063 commit ad9fc62
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,6 @@ public static byte[] fromHexString(String str) {
}

private static char[] hexChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
public static int convertChar(char c) {
if ('0' <= c && c <= '9') {
return c - '0' ;
} else if ('a' <= c && c <= 'f') {
return c - 'a' + 0xa ;
} else if ('A' <= c && c <= 'F') {
return c - 'A' + 0xa ;
} else {
throw new IllegalArgumentException("Invalid hex character: [" + c + "]");
}
}

public static char[] encodeInt(int i, int j, char digestChars[]) {
if (i < 16) {
digestChars[j] = '0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ofbiz.base.lang.Appender;
import org.apache.ofbiz.base.lang.SourceMonitored;
Expand Down Expand Up @@ -186,32 +184,6 @@ public void testFromHexString() {
}
}

public void testConvertChar() {
Map<Character, Integer> conversions = new HashMap<>();
conversions.put('0', 0); conversions.put('1', 1); conversions.put('2', 2); conversions.put('3', 3);
conversions.put('4', 4); conversions.put('5', 5); conversions.put('6', 6); conversions.put('7', 7);
conversions.put('8', 8); conversions.put('9', 9);
conversions.put('a', 10); conversions.put('b', 11); conversions.put('c', 12);
conversions.put('d', 13); conversions.put('e', 14); conversions.put('f', 15);
conversions.put('A', 10); conversions.put('B', 11); conversions.put('C', 12);
conversions.put('D', 13); conversions.put('E', 14); conversions.put('F', 15);
for (int i = 0; i < 256; i++) {
Integer wanted = conversions.get((char) i);
if (wanted == null) {
Exception caught = null;
try {
StringUtil.convertChar((char) i);
} catch (Exception e) {
caught = e;
} finally {
assertNotNull(Integer.toString(i), caught);
}
} else {
assertEquals(Integer.toString(i), wanted.intValue(), StringUtil.convertChar((char) i));
}
}
}

public void testEncodeInt() {
assertEquals("one octet", new char[] {'0', '5'}, StringUtil.encodeInt(5, 0, new char[2]));
assertEquals("two octets", new char[] {'1', '5'}, StringUtil.encodeInt(21, 0, new char[2]));
Expand Down

0 comments on commit ad9fc62

Please sign in to comment.