List of usage examples for java.util Set toString
public String toString()
From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java
/** * Finds all a processes children, kills the process then recursively calls this on the children. * // ww w .j a v a 2 s . c om * @param pid * @param kill_signal * @return * @throws IOException */ private static boolean killProcessAndChildren(final String pid, final Optional<Integer> kill_signal) throws IOException { //first find any children via pgrep -P pid final ProcessBuilder pb_children = new ProcessBuilder("pgrep", "-P", pid.toString()); final BufferedReader br = new BufferedReader(new InputStreamReader(pb_children.start().getInputStream())); final Set<String> child_pids = new HashSet<String>(); String line; while ((line = br.readLine()) != null) { child_pids.add(line); } logger.debug("children of pid: " + pid + " are: " + child_pids.toString()); //kill pid w/ signal killProcess(pid, kill_signal); //if still alive kill with -9, give it 5s to try and die the old way for (int i = 0; i < 5; i++) { try { Thread.sleep(1000L); } catch (Exception e) { } if (!isProcessRunning(pid)) { break; } } if (isProcessRunning(pid)) { killProcess(pid, Optional.of(9)); } //call this on all children return !child_pids.stream().filter(child_pid -> { try { return killProcessAndChildren(child_pid, kill_signal); } catch (Exception ex) { return false; } }).anyMatch(result -> false); }
From source file:de.citec.sc.matoll.utils.visualizeSPARQL.java
private static String findRoot(List<List<String>> relations) { String head = ""; Set<String> subj_list = new HashSet<>(); Set<String> obj_list = new HashSet<>(); relations.stream().map((list) -> { subj_list.add(list.get(0));// w ww.j a va 2 s . c om return list; }).forEach((list) -> { obj_list.add(list.get(1)); }); obj_list.removeAll(subj_list); if (obj_list.size() == 1) { return obj_list.toString().replace("[", "").replace("]", ""); } else { return null; } }
From source file:Main.java
/** * Finds a set of constant static byte field declarations in the class that have the given value * and whose name match the given pattern * @param cl class to search in// ww w . jav a2 s .c o m * @param value value of constant static byte field declarations to match * @param regexPattern pattern to match against the name of the field * @return a set of the names of fields, expressed as a string */ private static String findConstByteInClass(Class<?> cl, byte value, String regexPattern) { Field[] fields = cl.getDeclaredFields(); Set<String> fieldSet = new HashSet<String>(); for (Field f : fields) { try { if (f.getType() == Byte.TYPE && (f.getModifiers() & Modifier.STATIC) != 0 && f.getName().matches(regexPattern) && f.getByte(null) == value) { fieldSet.add(f.getName()); } } catch (IllegalArgumentException e) { // ignore } catch (IllegalAccessException e) { // ignore } } return fieldSet.toString(); }
From source file:org.apache.camel.maven.DocumentGeneratorMojo.java
private static String convertSetToString(Set<String> values) { if (values != null && !values.isEmpty()) { final String result = values.toString(); return result.substring(1, result.length() - 1); } else {// w w w . ja v a 2 s. co m return ""; } }
From source file:org.talend.designer.hdfsbrowse.manager.HadoopServerUtil.java
/** * DOC ycbai Comment method "testConnection". * /*from w ww . ja v a 2 s . co m*/ * Test whether can connect to HDFS. * * @return */ public static ConnectionStatus testConnection(HDFSConnectionBean connection) { ConnectionStatus connectionStatus = new ConnectionStatus(); connectionStatus.setResult(false); String errorMsg = "Cannot connect to HDFS \"" + connection.getNameNodeURI() + "\". Please check the connection parameters. "; Object dfs = null; ClassLoader oldClassLoaderLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader classLoader = getClassLoader(connection); Thread.currentThread().setContextClassLoader(classLoader); dfs = getDFS(connection, classLoader); if (dfs != null) { // Check if we can access the HDFS file content. Object pathObj = ReflectionUtils.newInstance("org.apache.hadoop.fs.Path", classLoader, new Object[] { ROOT_PATH }); ReflectionUtils.invokeMethod(dfs, "listStatus", new Object[] { pathObj }); connectionStatus.setResult(true); connectionStatus.setMessageException("Connection successful"); } else { connectionStatus.setMessageException(errorMsg); } } catch (Exception e) { Set<String> jars = getMissingJars(connection); String missJarMsg = ""; if (jars.size() > 0) { missJarMsg = "Missing jars:" + jars.toString() + "; " + "Need to check them in modules view."; connectionStatus.setMessageException(missJarMsg); } else { connectionStatus.setMessageException(ExceptionUtils.getFullStackTrace(e)); } ExceptionHandler.process(e); } finally { if (dfs != null) { try { ReflectionUtils.invokeMethod(dfs, "close", new Object[0]); } catch (Exception e) { } } Thread.currentThread().setContextClassLoader(oldClassLoaderLoader); } return connectionStatus; }
From source file:org.apache.hadoop.mapreduce.lib.input.TestFileInputFormat.java
public static void verifyFileStatuses(List<Path> expectedPaths, List<FileStatus> fetchedStatuses, final FileSystem localFs) { Assert.assertEquals(expectedPaths.size(), fetchedStatuses.size()); Iterable<Path> fqExpectedPaths = Iterables.transform(expectedPaths, new Function<Path, Path>() { @Override/*from ww w .ja v a2 s. co m*/ public Path apply(Path input) { return localFs.makeQualified(input); } }); Set<Path> expectedPathSet = Sets.newHashSet(fqExpectedPaths); for (FileStatus fileStatus : fetchedStatuses) { if (!expectedPathSet.remove(localFs.makeQualified(fileStatus.getPath()))) { Assert.fail("Found extra fetched status: " + fileStatus.getPath()); } } Assert.assertEquals("Not all expectedPaths matched: " + expectedPathSet.toString(), 0, expectedPathSet.size()); }
From source file:edu.umass.cs.utils.Util.java
public static Object getOtherThanString(Set<?> set, Object exclude) { return new Object() { public String toString() { @SuppressWarnings({ "rawtypes", "unchecked" }) Set<?> copy = new HashSet(set); copy.remove(exclude);/*from ww w . j ava 2s . co m*/ return copy.toString(); } }; }
From source file:Main.java
static <E> Set<E> ungrowableSet(final Set<E> s) { return new Set<E>() { @Override//from w w w . j a v a2 s.c o m public int size() { return s.size(); } @Override public boolean isEmpty() { return s.isEmpty(); } @Override public boolean contains(Object o) { return s.contains(o); } @Override public Object[] toArray() { return s.toArray(); } @Override public <T> T[] toArray(T[] a) { return s.toArray(a); } @Override public String toString() { return s.toString(); } @Override public Iterator<E> iterator() { return s.iterator(); } @Override public boolean equals(Object o) { return s.equals(o); } @Override public int hashCode() { return s.hashCode(); } @Override public void clear() { s.clear(); } @Override public boolean remove(Object o) { return s.remove(o); } @Override public boolean containsAll(Collection<?> coll) { return s.containsAll(coll); } @Override public boolean removeAll(Collection<?> coll) { return s.removeAll(coll); } @Override public boolean retainAll(Collection<?> coll) { return s.retainAll(coll); } @Override public boolean add(E o) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> coll) { throw new UnsupportedOperationException(); } }; }
From source file:moan.moan.controller.CallController.java
@RequestMapping(method = RequestMethod.GET) public Set<Call> getCalls() { SessionFactory sf = getSessionFactory(); Session s = sf.openSession();/* ww w.j a va 2 s. co m*/ Transaction tx = s.beginTransaction(); Criteria criteria = s.createCriteria(Call.class); List calls = criteria.list(); Set<Call> allCalls = new HashSet<>(calls); System.out.println("Llamadas---->" + allCalls.toString()); return allCalls; }
From source file:pl.itrack.client.local.dal.UserSettingsDao.java
public void storeFavouriteCameras(Set<Integer> cameraIds) { String cameraIdsString = cameraIds.toString(); UserSettings settings = createOrUpdateCamerasSettings(cameraIdsString); entityManager.persist(settings);//from w w w . j a va 2 s.c om entityManager.flush(); // TODO: could be flushed once in different place on page transition or leaving... }