/** * <p>Centers a String in a larger String of size <code>size</code> * using the space character (' ').<p> * * <p>If the size is less than the String length, the String is returned. * A <code>null</code> String returns <code>null</code>. * A negative size is treated as zero.</p> * * <p>Equivalent to <code>center(str, size, " ")</code>.</p> * * <pre> * StringUtils.center(null, *) = null * StringUtils.center("", 4) = " " * StringUtils.center("ab", -1) = "ab" * StringUtils.center("ab", 4) = " ab " * StringUtils.center("abcd", 2) = "abcd" * StringUtils.center("a", 4) = " a " * </pre> * * @param str the String to center, may be null * @param size the int size of new String, negative treated as zero * @return centered String, <code>null</code> if null String input */ public static String center(String str, int size) { return center(str, size, ' '); }
@Override public String align(String text, int size) { return StringUtils.center(text, size); } };
/** * <p>Centers a String in a larger String of size <code>size</code> * using the space character (' ').<p> * * <p>If the size is less than the String length, the String is returned. * A <code>null</code> String returns <code>null</code>. * A negative size is treated as zero.</p> * * <p>Equivalent to <code>center(str, size, " ")</code>.</p> * * <pre> * StringUtils.center(null, *) = null * StringUtils.center("", 4) = " " * StringUtils.center("ab", -1) = "ab" * StringUtils.center("ab", 4) = " ab " * StringUtils.center("abcd", 2) = "abcd" * StringUtils.center("a", 4) = " a " * </pre> * * @param str the String to center, may be null * @param size the int size of new String, negative treated as zero * @return centered String, <code>null</code> if null String input */ public static String center(String str, int size) { return center(str, size, ' '); }
/** * <p>Centers a String in a larger String of size <code>size</code> * using the space character (' ').<p> * * <p>If the size is less than the String length, the String is returned. * A <code>null</code> String returns <code>null</code>. * A negative size is treated as zero.</p> * * <p>Equivalent to <code>center(str, size, " ")</code>.</p> * * <pre> * StringUtils.center(null, *) = null * StringUtils.center("", 4) = " " * StringUtils.center("ab", -1) = "ab" * StringUtils.center("ab", 4) = " ab " * StringUtils.center("abcd", 2) = "abcd" * StringUtils.center("a", 4) = " a " * </pre> * * @param str the String to center, may be null * @param size the int size of new String, negative treated as zero * @return centered String, <code>null</code> if null String input */ public static String center(String str, int size) { return center(str, size, ' '); }
/** * <p>Centers a String in a larger String of size <code>size</code> * using the space character (' ').<p> * * <p>If the size is less than the String length, the String is returned. * A <code>null</code> String returns <code>null</code>. * A negative size is treated as zero.</p> * * <p>Equivalent to <code>center(str, size, " ")</code>.</p> * * <pre> * StringUtils.center(null, *) = null * StringUtils.center("", 4) = " " * StringUtils.center("ab", -1) = "ab" * StringUtils.center("ab", 4) = " ab " * StringUtils.center("abcd", 2) = "abcd" * StringUtils.center("a", 4) = " a " * </pre> * * @param str the String to center, may be null * @param size the int size of new String, negative treated as zero * @return centered String, <code>null</code> if null String input */ public static String center(String str, int size) { return center(str, size, ' '); }
/** * <p>Centers a String in a larger String of size <code>size</code> * using the space character (' ').<p> * * <p>If the size is less than the String length, the String is returned. * A <code>null</code> String returns <code>null</code>. * A negative size is treated as zero.</p> * * <p>Equivalent to <code>center(str, size, " ")</code>.</p> * * <pre> * StringUtils.center(null, *) = null * StringUtils.center("", 4) = " " * StringUtils.center("ab", -1) = "ab" * StringUtils.center("ab", 4) = " ab " * StringUtils.center("abcd", 2) = "abcd" * StringUtils.center("a", 4) = " a " * </pre> * * @param str the String to center, may be null * @param size the int size of new String, negative treated as zero * @return centered String, <code>null</code> if null String input */ public static String center(String str, int size) { return center(str, size, ' '); }
/** * <p>Centers a String in a larger String of size <code>size</code> * using the space character (' ').<p> * * <p>If the size is less than the String length, the String is returned. * A <code>null</code> String returns <code>null</code>. * A negative size is treated as zero.</p> * * <p>Equivalent to <code>center(str, size, " ")</code>.</p> * * <pre> * StringUtils.center(null, *) = null * StringUtils.center("", 4) = " " * StringUtils.center("ab", -1) = "ab" * StringUtils.center("ab", 4) = " ab " * StringUtils.center("abcd", 2) = "abcd" * StringUtils.center("a", 4) = " a " * </pre> * * @param str the String to center, may be null * @param size the int size of new String, negative treated as zero * @return centered String, <code>null</code> if null String input */ public static String center(String str, int size) { return center(str, size, ' '); }
/** * Gets the output separator with the provided text. * @param message The provided text. * @return A string containing the output separator with the provided text. */ public static String displayOutputSeparator(String message) { return StringUtils.center(" ".concat(message).concat(" "), getWidth(), "-"); }
public String formatEffectiveTime(Date effectiveTime, boolean canceled) { final SimpleDateFormat timeFormat = new SimpleDateFormat(TIME_FORMAT); final SimpleDateFormat canceledTimeFormat = new SimpleDateFormat("HH'x'mm"); final String result; if (effectiveTime != null) { result = StringUtils.rightPad((canceled ? canceledTimeFormat : timeFormat).format(effectiveTime), TIME_FORMAT.length()); } else { result = StringUtils.center(canceled ? "x" : "", TIME_FORMAT.length()); } return result; }
public static String injectVersion( String text, String version ) { Pattern pat = Pattern.compile( "#{2,}" ); Matcher mat = pat.matcher( text ); StringBuilder ret = new StringBuilder(); int off = 0; while ( mat.find( off ) ) { ret.append( text.substring( off, mat.start() ) ); String repl = mat.group(); ret.append( StringUtils.center( version, repl.length() ) ); off = mat.end(); } ret.append( text.substring( off ) ); return ret.toString(); }
public static String injectVersion( String text, String version ) { Pattern pat = Pattern.compile( "#{2,}" ); Matcher mat = pat.matcher( text ); StringBuilder ret = new StringBuilder(); int off = 0; while ( mat.find( off ) ) { ret.append( text.substring( off, mat.start() ) ); String repl = mat.group(); ret.append( StringUtils.center( version, repl.length() ) ); off = mat.end(); } ret.append( text.substring( off ) ); return ret.toString(); }
public static void main(String[] args) { System.out.println(StringUtils.center(" demoBidiMap ",40,"=")); BidiMap bidiMap = new DualHashBidiMap(); bidiMap.put("BJ","Beijing"); System.out.println(StringUtils.center( " demoMultiMap " , 40, "=" )); MultiMap multiMap = new MultiHashMap(); multiMap.put( "Sean" , "C/C++" ); System.out.println(StringUtils.repeat( "=" , 40)); System.out.println(StringUtils.center( " demoLazyMap " , 40, "=" ));
public static void demoBagUsage() { System.out.println("demoBagUsage:"+StringUtils.center( " demoBagUsage " , 50, "=" ));