@Test(expected=ConversionException.class) public void normalizeLeadingHexZeroesNullValue() throws Exception { NumberRadixUtil.normalizeLeadingHexZeroes(null, 2); }
static public String normalizeLeadingHexZeroes(String v, int length) throws ConversionException { if (v == null || v.length() == 0) { throw new ConversionException("Empty or null value detected; unable to convert"); } else if (v.length() == length) { return v; } else if (v.length() < length) { int prepend = (length - v.length()); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < prepend; i++) { sb.append('0'); } sb.append(v); return sb.toString(); } else { int remove = (v.length() - length); for (int i = 0; i < remove; i++) { if (v.charAt(i) != '0') { throw new ConversionOverflowException("Overflow of value detected; unable to trim value [" + v + "] to length " + length); } } return v.substring(remove); } }
NumberRadixUtil { static public String normalizeLeadingHexZeroes(String v, int length) throws ConversionException { if (v == null || v.length() == 0) { throw new ConversionException("Empty or null value detected; unable to convert"); } else if (v.length() == length) { return v; } else if (v.length() < length) { int prepend = (length - v.length()); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < prepend; i++) { sb.append('0'); } sb.append(v); return sb.toString(); } else { int remove = (v.length() - length); for (int i = 0; i < remove; i++) { if (v.charAt(i) != '0') { throw new ConversionOverflowException("Overflow of value detected; unable to trim value [" + v + "] to length " + length); } } return v.substring(remove); } } }
NumberRadixUtil { static public String normalizeLeadingHexZeroes(String v, int length) throws ConversionException { if (v == null || v.length() == 0) { throw new ConversionException("Empty or null value detected; unable to convert"); } else if (v.length() == length) { return v; } else if (v.length() < length) { int prepend = (length - v.length()); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < prepend; i++) { sb.append('0'); } sb.append(v); return sb.toString(); } else { int remove = (v.length() - length); for (int i = 0; i < remove; i++) { if (v.charAt(i) != '0') { throw new ConversionOverflowException("Overflow of value detected; unable to trim value [" + v + "] to length " + length); } } return v.substring(remove); } }  }
NumberRadixUtil { static public String normalizeLeadingHexZeroes(String v, int length) throws ConversionException { if (v == null || v.length() == 0) { throw new ConversionException("Empty or null value detected; unable to convert"); } else if (v.length() == length) { return v; } else if (v.length() < length) { int prepend = (length - v.length()); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < prepend; i++) { sb.append('0'); } sb.append(v); return sb.toString(); } else { int remove = (v.length() - length); for (int i = 0; i < remove; i++) { if (v.charAt(i) != '0') { throw new ConversionOverflowException("Overflow of value detected; unable to trim value [" + v + "] to length " + length); } } return v.substring(remove); } }  static NumberRadixResult parseNumberRadix(String number); static String normalizeLeadingHexZeroes(String v, int length); }
NumberRadixUtil { static public String normalizeLeadingHexZeroes(String v, int length) throws ConversionException { if (v == null || v.length() == 0) { throw new ConversionException("Empty or null value detected; unable to convert"); } else if (v.length() == length) { return v; } else if (v.length() < length) { int prepend = (length - v.length()); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < prepend; i++) { sb.append('0'); } sb.append(v); return sb.toString(); } else { int remove = (v.length() - length); for (int i = 0; i < remove; i++) { if (v.charAt(i) != '0') { throw new ConversionOverflowException("Overflow of value detected; unable to trim value [" + v + "] to length " + length); } } return v.substring(remove); } }  static NumberRadixResult parseNumberRadix(String number); static String normalizeLeadingHexZeroes(String v, int length);  }