/** * limit string size to 32. * * @param value the value * @return the string */ public static String checkSize(byte[] value) { return checkSize(value, 32); }
/** * limit string size to 32. * * @param value the value * @param defaultValue the default value * @return the string */ public static String checkSize(Object value, String defaultValue) { return checkSize(value, VIEW_SIZE, defaultValue); }
/** * limit string size to 32. * * @param value the value * @return the string */ public static String checkSize(Object value) { return checkSize(value, VIEW_SIZE, null); }
/** * limit string size to 32. * * @param value the value * @return the string */ public static String checkSize(Object value) { return checkSize(value, VIEW_SIZE, null); }
/** * limit string size to 32. * * @param value the value * @param defaultValue the default value * @return the string */ public static String checkSize(Object value, String defaultValue) { return checkSize(value, VIEW_SIZE, defaultValue); }
/** * limit string size to 32. * * @param value the value * @return the string */ public static String checkSize(byte[] value) { return checkSize(value, 32); }
/** * limit string size. * * @param value the value * @param limitSize the limit size * @param defaultValue the default value * @return the string */ public static String checkSize(Object value, int limitSize, String defaultValue) { if (value != null) { if (byte[].class.getSimpleName().equals(value.getClass().getSimpleName())) { return checkSize((byte[]) value, limitSize/2); } String str = value.toString(); if (str.length() > limitSize) { return str.substring(0, limitSize - 3) + "..."; } else return str; } else return defaultValue; }
/** * format as sql parameter. If value is not null, method will return * 'value'. If value is not null, delimiter will be used to delimit return * value. Otherwise, defaultValue will be returned, without delimiter. * * @param value the value * @param delimiter the delimiter * @return the string */ public static String formatParam(Object value, String delimiter) { if (value != null) { if (byte[].class.getSimpleName().equals(value.getClass().getSimpleName())) { return checkSize((byte[]) value, VIEW_SIZE); } String str = value.toString(); if (str.length() > VIEW_SIZE) { return delimiter + str.substring(0, VIEW_SIZE - 3) + "..." + delimiter; } else return delimiter + str + delimiter; } else return "<undefined>"; }
/** * limit string size. * * @param value the value * @param limitSize the limit size * @param defaultValue the default value * @return the string */ public static String checkSize(Object value, int limitSize, String defaultValue) { if (value != null) { if (byte[].class.getSimpleName().equals(value.getClass().getSimpleName())) { return checkSize((byte[]) value, limitSize/2); } String str = value.toString(); if (str.length() > limitSize) { return str.substring(0, limitSize - 3) + "..."; } else return str; } else return defaultValue; }
/** * format as sql parameter. If value is not null, method will return * 'value'. If value is not null, delimiter will be used to delimit return * value. Otherwise, defaultValue will be returned, without delimiter. * * @param value the value * @param delimiter the delimiter * @return the string */ public static String formatParam(Object value, String delimiter) { if (value != null) { if (byte[].class.getSimpleName().equals(value.getClass().getSimpleName())) { return checkSize((byte[]) value, VIEW_SIZE); } String str = value.toString(); if (str.length() > VIEW_SIZE) { return delimiter + str.substring(0, VIEW_SIZE - 3) + "..." + delimiter; } else return delimiter + str + delimiter; } else return "<undefined>"; }