public static String formatStrings(String separator, String ... items) { if (items == null) return ""; return formatPart(null, separator, 0, items.length, items); }
@Override public Object parseObject(String source, ParsePosition pos) { String[] result = parse(source, separator, String.class); pos.setIndex(source.length()); return result; }
@SuppressWarnings("null") public static void equals(byte[] a1, byte[] a2) { if (a1 == null && a2 == null) return; else if ((a1 == null && a2 != null) || (a1 != null && a2 == null)) throw new AssertionError("Arrays are not equal, one of them is null"); else if (a1.length != a2.length) throw new AssertionError("Arrays are not equal, the size differs: [" + ArrayFormat.formatBytes(",", a1) + "] vs. [" + ArrayFormat.formatBytes(",", a2) + ']'); else if (!Arrays.equals(a1, a2)) throw new AssertionError("Arrays are not equal, content differs: [" + ArrayFormat.formatBytes(",", a1) + "] vs. [" + ArrayFormat.formatBytes(",", a2) + ']'); }
private Converter<?, String> createToStringConverter(Class<?> sourceType) throws ConversionException { if (sourceType.isArray()) { Class<?> componentType = sourceType.getComponentType(); if (componentType == byte.class) return new ByteArrayToBase64Converter(); else if (componentType == char.class) return new CharArray2StringConverter(); else return new FormatFormatConverter(sourceType, new ArrayFormat(), true); } else if (sourceType == Time.class) { return new FormatFormatConverter<Time>(Time.class, new SimpleDateFormat(Patterns.DEFAULT_TIME_PATTERN), false); } else if (sourceType == Timestamp.class) { return new TimestampFormatter(); } else if (sourceType == Date.class) { return new FormatFormatConverter<Time>(Time.class, new SimpleDateFormat(Patterns.DEFAULT_DATETIME_PATTERN), false); } else if (sourceType == Class.class) { return new Class2StringConverter(); } else if (Enum.class.isAssignableFrom(sourceType)) { return new Enum2StringConverter(sourceType); } else { Converter<?, String> result = tryToCreateFactoryConverter(sourceType, String.class); if (result != null) return result; else return new ToStringMethodInvoker(sourceType); } }
@Override public String toString() { return "(" + ArrayFormat.format(" " + symbol + " ", terms) + ")"; }
public static <T> String format(String separator, T ... items) { if (items == null) return ""; return formatPart(null, separator, 0, items.length, items); }
@Override public Object convert(String sourceValue) throws ConversionException { return ConverterManager.convertAll(ArrayFormat.parse(sourceValue, ",", String.class), realConverter, targetComponentType); }
@Override public String toString() { return "(" + ArrayFormat.format(" " + symbol + " ", terms) + ")"; }
public static <T> String format(Converter<Object,String> formatter, String separator, T ... items) { return formatPart(formatter, separator, 0, items.length, items); }
@Override public String getDescription() { return "Identity definition by unique key: " + ArrayFormat.format(columnNames); }
public static <T> String formatPart(int offset, int length, T ... items) { return formatPart(null, DEFAULT_SEPARATOR, offset, length, items); }
public static String renderColumnNames(String[] columnNames) { return '(' + ArrayFormat.format(columnNames) + ')'; }
public static <T> String formatPart(String separator, int offset, int length, T ... items) { return formatPart(null, separator, offset, length, items); }
public static <T> String format(T ... items) { return format(", ", items); }
@Override public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { return formatPart(toAppendTo, itemFormatter, separator, 0, Array.getLength(obj), obj); }
@Override public String toString() { return ArrayFormat.format(elements); }
public static <T> String formatPart(Converter<Object,String> formatter, String separator, int offset, int length, T ... items) { if (items.length == 0) return ""; return formatPart(new StringBuilder(), formatter, separator, offset, length, items).toString(); }
@Override public String toString() { return "min(" + ArrayFormat.format(terms) + ')'; }
/** * Maps the locale code to a locale, e.g. de_DE to Locale.GERMANY. * @param code the locale colde to map * @return a locale instance the represents the code */ public static Locale getLocale(String code) { if (StringUtil.isEmpty(code)) throw new IllegalArgumentException("code is empty"); String[] path = StringUtil.tokenize(code, '_'); switch (path.length) { case 1 : return new Locale(path[0]); case 2 : return new Locale(path[0], path[1]); case 3 : return new Locale(path[0], path[1], path[2]); default : return new Locale(path[0], path[1], ArrayFormat.formatPart("_", 2, path.length - 2, path)); } }