Util { public static String justify(String str, String value, Map<String, ConversionOptionBO> options, int length) { if (value == null) { value = "both"; } boolean justifyLeft = false; boolean justifyRight = false; if (value.equalsIgnoreCase("left")) { justifyLeft = true; } if (value.equalsIgnoreCase("right")) { justifyRight = true; } if (value.equalsIgnoreCase("both")) { justifyLeft = true; justifyRight = true; } String strPadChar = " "; String arg = getValue(options, "pad-character"); if (arg != null) { strPadChar = arg; } if (0 == length) { if (justifyLeft) { int i; for (i = str.length() - 1; i > -1 && isPadChar(str.charAt(i), strPadChar); i--) ; if (i != str.length() - 1) { str = str.substring(0, i + 1); } } if (justifyRight) { int i; for (i = 0; i < str.length() && isPadChar(str.charAt(i), strPadChar); i++) ; if (i != 0) { str = str.substring(i, str.length()); } } } else { strPadChar = strPadChar.substring(0, 1); if (str.length() < length) { int lenDiff = length - str.length(); String padding = ""; for (int i = 0; i < lenDiff; i++) padding = padding + strPadChar; if (justifyLeft) { str = str + padding; } if (justifyRight) { str = padding + str; } } } return str; }  static List<LineToken> split(String str, char chrSplit, char chrQuote); static String formatDate(Date date, String defaultDateFormat,
                                    Map<String, ConversionOptionBO> options); static String justify(String str, String value, Map<String, ConversionOptionBO> options,
                                 int length); static String strip(String str, String value, Map<String, ConversionOptionBO> options); static String substring(String str, String value, Map<String, ConversionOptionBO> options); static String defaultValue(String str, String value, Map<String, ConversionOptionBO> options); static String getValue(Map<String, ConversionOptionBO> options, String key); static Integer tryParseInt(String value); static Boolean tryParseBoolean(String value); static Boolean tryParseBoolean(String value, boolean defaultValue); static Class<?> getActualFieldType(Field field); static List<Class<?>> findRecordAnnotatedClasses(Collection<String> packageNames, Class<? extends Annotation> annotationClass); static List<Class<?>> findClassesInPackage(String packageName); static List<Class<?>> findRecordAnnotatedClasses(String packageName, Class<? extends Annotation> annotationClass); static void findRecordAnnotatedClasses(File directory, String packageName, List<Class<?>> classes, Predicate<Class<?>> predicate);  }
@Test public void testRemoveBlanks() { Map<String, ConversionOptionBO> options = new HashMap<>(); assertEquals("foo", Util.justify("foo ", "both", options, 0)); assertEquals("foo", Util.justify("foo ", "both", options, 0)); assertEquals("foo", Util.justify(" foo", "both", options, 0)); assertEquals("foo", Util.justify(" foo", "both", options, 0)); assertEquals(" foo", Util.justify(" foo ", "left", options, 0)); assertEquals("foo ", Util.justify(" foo ", "right", options, 0)); }
@Test public void testMultiplePadCharacters() { Map<String, ConversionOptionBO> options = new HashMap<>(); options.put("pad-character", new ConversionOptionBO("pad-character", "0Oo")); assertEquals("f", Util.justify("foo", "both", options, 0)); assertEquals("f", Util.justify("fooOO00", "both", options, 0)); assertEquals("f", Util.justify("oofoo", "both", options, 0)); assertEquals("f", Util.justify("oo00OOfooOO00", "both", options, 0)); assertEquals("oof", Util.justify("oofoo", "left", options, 0)); assertEquals("foo", Util.justify("oofoo", "right", options, 0)); }