Skip to content
Browse files

Removed external dependency for ModHex converter

  • Loading branch information...
1 parent 89e1141 commit de5a98822a53f2f8381f2ada42ca68aab99aa789 @Ratler Ratler committed Feb 4, 2012
Showing with 28 additions and 11 deletions.
  1. +0 −5 pom.xml
  2. +28 −6 src/main/java/org/unitedid/yhsm/utility/ModHex.java
View
5 pom.xml
@@ -80,11 +80,6 @@
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
</dependencies>
<build>
View
34 src/main/java/org/unitedid/yhsm/utility/ModHex.java
@@ -18,11 +18,9 @@
package org.unitedid.yhsm.utility;
-import org.apache.commons.lang.StringUtils;
-
public class ModHex {
- private static final String[] HEX = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
- private static final String[] MODHEX = {"c", "b", "d", "e", "f", "g", "h", "i", "j", "k", "l", "n", "r", "t", "u", "v"};
+ private static final String HEX = "0123456789abcdef";
+ private static final String MODHEX = "cbdefghijklnrtuv";
/**
* Encode a hex string as modHex
@@ -31,7 +29,7 @@
* @return modHex string
*/
public static String encode(String input) {
- return StringUtils.replaceEach(input, HEX, MODHEX);
+ return replaceEach(input, HEX, MODHEX);
}
/**
@@ -41,7 +39,7 @@ public static String encode(String input) {
* @return hex string
*/
public static String decode(String input) {
- return StringUtils.replaceEach(input, MODHEX, HEX);
+ return replaceEach(input, MODHEX, HEX);
}
/**
@@ -53,4 +51,28 @@ public static String decode(String input) {
public static Long toDecimal(String input) {
return Long.decode("#" + decode(input));
}
+
+ /**
+ * Replace characters in a string
+ *
+ * @param input String to replace characters in
+ * @param searchList String of characters to search for
+ * @param replacementList String of characters to replace with
+ * @return modified string
+ */
+ private static String replaceEach(String input, String searchList, String replacementList) {
+ StringBuilder buf = new StringBuilder(input.length());
+
+ for (int i = 0; i < input.length(); i++) {
+ char ch = input.charAt(i);
+ int index = searchList.indexOf(ch);
+ if (index >= 0) {
+ buf.append(replacementList.charAt(index));
+ } else {
+ buf.append(ch);
+ }
+ }
+
+ return buf.toString();
+ }
}

0 comments on commit de5a988

Please sign in to comment.
Something went wrong with that request. Please try again.