/** Same as byteToHexString(bytes, 0, bytes.length). */ public static String byteToHexString(byte bytes[]) { return byteToHexString(bytes, 0, bytes.length); }
/** * Escape commas in the string using the default escape char * @param str a string * @return an escaped string */ public static String escapeString(String str) { return escapeString(str, ESCAPE_CHAR, COMMA); }
/** * * Given a finish and start time in long milliseconds, returns a * String in the format Xhrs, Ymins, Z sec, for the time difference between two times. * If finish time comes before start time then negative valeus of X, Y and Z wil return. * * @param finishTime finish time * @param startTime start time */ public static String formatTimeDiff(long finishTime, long startTime){ long timeDiff = finishTime - startTime; return formatTime(timeDiff); }
/** * Splits a comma separated value <code>String</code>, trimming leading and trailing whitespace on each value. * @param str a comma separated <String> with values * @return a <code>Collection</code> of <code>String</code> values */ public static Collection<String> getTrimmedStringCollection(String str){ return Arrays.asList(getTrimmedStrings(str)); }
/** * Returns an arraylist of strings. * @param str the comma seperated string values * @return the arraylist of the comma seperated string values */ public static String[] getStrings(String str){ Collection<String> values = getStringCollection(str); if(values.size() == 0) { return null; } return values.toArray(new String[values.size()]); }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s. * If no such property is specified then <code>null</code> is returned. * * @param name property name. * @return property value as an array of <code>String</code>s, * or <code>null</code>. */ public String[] getStrings(String name) { String valueString = get(name); return StringUtils.getStrings(valueString); }
/** * Set the array of string values for the <code>name</code> property as * as comma delimited values. * * @param name property name. * @param values The values */ public void setStrings(String name, String... values) { set(name, StringUtils.arrayToString(values)); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then empty <code>Collection</code> is returned. * * @param name property name. * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> */ public Collection<String> getTrimmedStringCollection(String name) { String valueString = get(name); if (null == valueString) { return Collections.emptyList(); } return StringUtils.getTrimmedStringCollection(valueString); }
/** * Formats time in ms and appends difference (finishTime - startTime) * as returned by formatTimeDiff(). * If finish time is 0, empty string is returned, if start time is 0 * then difference is not appended to return value. * @param dateFormat date format to use * @param finishTime fnish time * @param startTime start time * @return formatted value. */ public static String getFormattedTimeWithDiff(DateFormat dateFormat, long finishTime, long startTime){ StringBuilder buf = new StringBuilder(); if (0 != finishTime) { buf.append(dateFormat.format(new Date(finishTime))); if (0 != startTime){ buf.append(" (" + formatTimeDiff(finishTime , startTime) + ")"); } } return buf.toString(); }
/** * Split a string using the given separator * @param str a string that may have escaped separator * @param escapeChar a char that be used to escape the separator * @param separator a separator char * @return an array of strings */ public static String[] split( String str, char escapeChar, char separator) { if (str==null) { return null; } List<String> strList = new ArrayList<>(); StringBuilder split = new StringBuilder(); int index = 0; while ((index = findNext(str, separator, escapeChar, index, split)) >= 0) { ++index; // move over the separator for next search strList.add(split.toString()); split.setLength(0); // reset the buffer } strList.add(split.toString()); // remove trailing empty split(s) int last = strList.size(); // last split while (--last>=0 && "".equals(strList.get(last))) { strList.remove(last); } return strList.toArray(new String[strList.size()]); }
/** * Splits a comma separated value <code>String</code>, trimming leading and trailing whitespace on each value. * @param str a comma separated <String> with values * @return a <code>Collection</code> of <code>String</code> values */ public static Collection<String> getTrimmedStringCollection(String str){ return Arrays.asList(getTrimmedStrings(str)); }
/** * Returns an arraylist of strings. * @param str the comma seperated string values * @return the arraylist of the comma seperated string values */ public static String[] getStrings(String str){ Collection<String> values = getStringCollection(str); if(values.size() == 0) { return null; } return values.toArray(new String[values.size()]); }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s. * If no such property is specified then <code>null</code> is returned. * * @param name property name. * @return property value as an array of <code>String</code>s, * or <code>null</code>. */ public String[] getStrings(String name) { String valueString = get(name); return StringUtils.getStrings(valueString); }
/** * Set the array of string values for the <code>name</code> property as * as comma delimited values. * * @param name property name. * @param values The values */ public void setStrings(String name, String... values) { set(name, StringUtils.arrayToString(values)); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then empty <code>Collection</code> is returned. * * @param name property name. * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> */ public Collection<String> getTrimmedStringCollection(String name) { String valueString = get(name); if (null == valueString) { Collection<String> empty = Collections.emptyList(); return empty; } return StringUtils.getTrimmedStringCollection(valueString); }
/** * Formats time in ms and appends difference (finishTime - startTime) * as returned by formatTimeDiff(). * If finish time is 0, empty string is returned, if start time is 0 * then difference is not appended to return value. * @param dateFormat date format to use * @param finishTime fnish time * @param startTime start time * @return formatted value. */ public static String getFormattedTimeWithDiff(DateFormat dateFormat, long finishTime, long startTime){ StringBuffer buf = new StringBuffer(); if (0 != finishTime) { buf.append(dateFormat.format(new Date(finishTime))); if (0 != startTime){ buf.append(" (" + formatTimeDiff(finishTime , startTime) + ")"); } } return buf.toString(); }
/** * Split a string using the given separator * @param str a string that may have escaped separator * @param escapeChar a char that be used to escape the separator * @param separator a separator char * @return an array of strings */ public static String[] split( String str, char escapeChar, char separator) { if (str==null) { return null; } ArrayList<String> strList = new ArrayList<String>(); StringBuilder split = new StringBuilder(); int index = 0; while ((index = findNext(str, separator, escapeChar, index, split)) >= 0) { ++index; // move over the separator for next search strList.add(split.toString()); split.setLength(0); // reset the buffer } strList.add(split.toString()); // remove trailing empty split(s) int last = strList.size(); // last split while (--last>=0 && "".equals(strList.get(last))) { strList.remove(last); } return strList.toArray(new String[strList.size()]); }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s, trimmed of the leading and trailing whitespace. * If no such property is specified then an empty array is returned. * * @param name property name. * @return property value as an array of trimmed <code>String</code>s, * or empty array. */ public String[] getTrimmedStrings(String name) { String valueString = get(name); return StringUtils.getTrimmedStrings(valueString); }
/** * Get the comma delimited values of the <code>name</code> property as * a collection of <code>String</code>s. * If no such property is specified then empty collection is returned. * <p> * This is an optimized version of {@link #getStrings(String)} * * @param name property name. * @return property value as a collection of <code>String</code>s. */ public Collection<String> getStringCollection(String name) { String valueString = get(name); return StringUtils.getStringCollection(valueString); }
/** * Get the comma delimited values of the <code>name</code> property as * an array of <code>String</code>s. * If no such property is specified then default value is returned. * * @param name property name. * @param defaultValue The default value * @return property value as an array of <code>String</code>s, * or default value. */ public String[] getStrings(String name, String... defaultValue) { String valueString = get(name); if (valueString == null) { return defaultValue; } else { return StringUtils.getStrings(valueString); } }