List of usage examples for java.util HashSet toArray
<T> T[] toArray(T[] a);
From source file:Main.java
private static String[] convertCursorAsStringArrayWithCloseCursor(Cursor cursor, int colIdx) { String[] result = null;/*from w w w. ja va 2 s . c o m*/ try { int resultCount = cursor.getCount(); if (resultCount > 0) { HashSet<String> phones = new HashSet<String>(resultCount); while (cursor.moveToNext()) { String phone = cursor.getString(0); phones.add(phone); } result = phones.toArray(new String[phones.size()]); } Log.d(TAG, "ConvertCursor As StringArray : found " + resultCount + " String converted from idx " + colIdx); } finally { cursor.close(); } return result; }
From source file:Main.java
public static int[] divide(int number, int number_of_parts) { HashSet<Integer> uniqueInts = new HashSet<Integer>(); uniqueInts.add(0);// w w w. ja v a 2 s.c o m uniqueInts.add(number); int array_size = number_of_parts + 1; while (uniqueInts.size() < array_size) { uniqueInts.add(1 + r.nextInt(number - 1)); } Integer[] dividers = uniqueInts.toArray(new Integer[array_size]); Arrays.sort(dividers); int[] results = new int[number_of_parts]; for (int i = 1, j = 0; i < dividers.length; ++i, ++j) { results[j] = dividers[i] - dividers[j]; } return results; }
From source file:SerialVersionUID.java
/** * Create a Map<String, ClassVersionInfo> for the jboss dist jars. * /*from www . j a v a2 s. c o m*/ * @param j2eeHome - * the j2ee ri dist root directory * @return Map<String, ClassVersionInfo> * @throws IOException */ public static Map generateRISerialVersionUIDReport(File j2eeHome) throws IOException { // Obtain the jars from the /lib HashSet jarFiles = new HashSet(); File lib = new File(j2eeHome, "lib"); buildJarSet(lib, jarFiles); URL[] cp = new URL[jarFiles.size()]; jarFiles.toArray(cp); ClassLoader parent = Thread.currentThread().getContextClassLoader(); URLClassLoader completeClasspath = new URLClassLoader(cp, parent); TreeMap classVersionMap = new TreeMap(); Iterator jarIter = jarFiles.iterator(); while (jarIter.hasNext()) { URL jar = (URL) jarIter.next(); try { generateJarSerialVersionUIDs(jar, classVersionMap, completeClasspath, "javax"); } catch (IOException e) { log.info("Failed to process jar: " + jar); } } return classVersionMap; }
From source file:fastcall.FArrayUtils.java
/** * Return sorted unique array of string/*from w w w .j a v a2 s .co m*/ * @param input * @return */ public static String[] getUniqueStringArray(String[] input) { HashSet<String> t = new HashSet(); for (int i = 0; i < input.length; i++) { t.add(input[i]); } String[] result = t.toArray(new String[t.size()]); Arrays.sort(result); return result; }
From source file:com.netcrest.pado.tools.pado.util.PadoShellUtil.java
/** * Returns an array of full paths determined by parsing all paths arguments * found in the specified commandLine. Duplicates are ignored. * /*from w ww .ja va 2s . co m*/ * @param padoShell * PadoShell instance * @param commandLine * Command line with path arguments. * @return null if paths are not found in the specified commandLine. */ @SuppressWarnings("unchecked") public final static String[] getFullPaths(PadoShell padoShell, CommandLine commandLine) { List<String> argList = (List<String>) commandLine.getArgList(); if (argList.size() <= 1) { return null; } HashSet<String> set = new HashSet<String>(argList.size()); for (int i = 1; i < argList.size(); i++) { String path = argList.get(i); set.add(padoShell.getFullPath(path)); } String fullPaths[] = set.toArray(new String[set.size()]); return fullPaths; }
From source file:org.osaf.cosmo.util.StringPropertyUtils.java
/** * Get all child keys of a parent key. For example * for the set of keys: a.b, a.c and a.d the set * of child keys of a are [b,c,d]./*from ww w. j a v a 2s.c o m*/ * @param parent parent key * @param keys keys to search * @return child keys */ public static String[] getChildKeys(String parent, String[] keys) { HashSet<String> children = new HashSet<String>(); if (!parent.endsWith(".")) parent = parent + "."; for (String key : keys) { String end = StringUtils.substringAfter(key, parent); if ("".equals(end) || end == null) continue; children.add(StringUtils.substringBefore(end, ".")); } return children.toArray(new String[0]); }
From source file:org.unitedinternet.cosmo.util.StringPropertyUtils.java
/** * Get all child keys of a parent key. For example * for the set of keys: a.b, a.c and a.d the set * of child keys of a are [b,c,d]./*from w ww . ja v a 2 s . c om*/ * @param parent parent key * @param keys keys to search * @return child keys */ public static String[] getChildKeys(String parent, String[] keys) { HashSet<String> children = new HashSet<String>(); if (!parent.endsWith(".")) { parent = parent + "."; } for (String key : keys) { String end = StringUtils.substringAfter(key, parent); if ("".equals(end) || end == null) { continue; } children.add(StringUtils.substringBefore(end, ".")); } return children.toArray(new String[children.size()]); }
From source file:org.apache.sysml.hops.codegen.opt.PlanAnalyzer.java
private static HashSet<Long> getPartitionRootNodes(CPlanMemoTable memo, HashSet<Long> partition) { //build inverted index of references entries HashSet<Long> ix = new HashSet<>(); for (Long hopID : partition) if (memo.contains(hopID)) for (MemoTableEntry me : memo.get(hopID)) { ix.add(me.input1);// www .j av a2s . co m ix.add(me.input2); ix.add(me.input3); } HashSet<Long> roots = new HashSet<>(); for (Long hopID : partition) if (!ix.contains(hopID)) roots.add(hopID); if (LOG.isTraceEnabled()) { LOG.trace("Partition root points: " + Arrays.toString(roots.toArray(new Long[0]))); } return roots; }
From source file:jp.mamesoft.mailsocketchat.Mailsocketchat.java
static void Logperse(JSONObject jsondata) { if (!jsondata.isNull("comment")) { String name = jsondata.getString("name"); String comment = jsondata.getString("comment"); String ip = jsondata.getString("ip"); String time_js = jsondata.getString("time"); Pattern time_p = Pattern.compile("([0-9]{4}).([0-9]{2}).([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})"); Matcher time_m = time_p.matcher(time_js); String time = ""; String simpletime = ""; if (time_m.find()) { int year = Integer.parseInt(time_m.group(1)); int month = Integer.parseInt(time_m.group(2)); int day = Integer.parseInt(time_m.group(3)); int hour = Integer.parseInt(time_m.group(4)); int min = Integer.parseInt(time_m.group(5)); int sec = Integer.parseInt(time_m.group(6)); hour = hour + 9;//from w w w . j a v a 2 s. co m if (hour >= 24) { hour = hour - 24; day = day + 1; } time = String.format("%1$04d", year) + "-" + String.format("%1$02d", month) + "-" + String.format("%1$02d", day) + " " + String.format("%1$02d", hour) + ":" + String.format("%1$02d", min) + ":" + String.format("%1$02d", sec); simpletime = String.format("%1$02d", hour) + ":" + String.format("%1$02d", min) + ":" + String.format("%1$02d", sec); } String channel = ""; HashMap<String, String> log = new HashMap<String, String>(); log.put("name", name); log.put("_id", jsondata.getString("_id")); log.put("comment", comment); log.put("ip", ip); log.put("time", time); log.put("simpletime", simpletime); if (!jsondata.isNull("response")) { log.put("res", jsondata.getString("response")); } else { log.put("res", ""); } if (!jsondata.isNull("channel")) { HashSet<String> channels_hash = new HashSet<String>(); for (int i = 0; i < jsondata.getJSONArray("channel").length(); i++) { channels_hash.add(jsondata.getJSONArray("channel").getString(i)); } String channels[] = (String[]) channels_hash.toArray(new String[0]); for (int i = 0; i < channels.length; i++) { channel = channel + " #" + channels[i]; } log.put("channel", channel); } if (push) { logs.add(log); Mail.Send(address, 1); } else { logs.add(log); } } }
From source file:Main.java
/** * Get all threads//from w w w .ja v a 2 s .c o m * * @return */ public static String[] getThreadNames() { ThreadGroup group = Thread.currentThread().getThreadGroup(); ThreadGroup parent = null; while ((parent = group.getParent()) != null) { group = parent; } Thread[] threads = new Thread[group.activeCount()]; group.enumerate(threads); HashSet<String> set = new HashSet<String>(); for (int i = 0; i < threads.length; ++i) { if (threads[i] != null && threads[i].isAlive()) { try { set.add(threads[i].getThreadGroup().getName() + ", " + threads[i].getName() + ", " + threads[i].getPriority() + ", " + threads[i].getState()); } catch (Throwable e) { e.printStackTrace(); } } } String[] result = (String[]) set.toArray(new String[0]); Arrays.sort(result); for (int i = 0; i < result.length; i++) { // logger.debug(result[i]); } return result; }