/** * Split a string into an array of strings using the given separator. A null string will result in * a null array, and an empty string in a zero element array. * * @param s the string to split * @param separatorChar the separator character * @param trim whether each element should be trimmed * @return the array list */ public static String[] arraySplit(String s, char separatorChar, boolean trim) { if (s == null) { return null; } int length = s.length(); if (length == 0) { return new String[0]; } ArrayList<String> list = New.arrayList(); StringBuilder buff = new StringBuilder(length); for (int i = 0; i < length; i++) { char c = s.charAt(i); if (c == separatorChar) { String e = buff.toString(); list.add(trim ? e.trim() : e); buff.setLength(0); } else if (c == '\\' && i < length - 1) { buff.append(s.charAt(++i)); } else { buff.append(c); } } String e = buff.toString(); list.add(trim ? e.trim() : e); String[] array = new String[list.size()]; list.toArray(array); return array; }
/** * Get the list of keys. * * @return all keys */ public ArrayList<Value> keys() { ArrayList<Value> list = New.arrayList(size); for (Value k : keys) { if (k != null && k != ValueNull.DELETED) { list.add(k); } } return list; }
/** * Get the list of values. * * @return all values */ public ArrayList<V> values() { ArrayList<V> list = New.arrayList(size); int len = keys.length; for (int i = 0; i < len; i++) { Value k = keys[i]; if (k != null && k != ValueNull.DELETED) { list.add(values[i]); } } return list; }
/** Delete all registered temp files. */ public void deleteAll() { for (String tempFile : New.arrayList(refMap.values())) { deleteFile(null, tempFile); } deleteUnused(); }