List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:com.mindquarry.desktop.workspace.ConflictHelper.java
/** * Finds all conflicts where a remotely replaced folder conflicts with a * local modification of (in) that folder. */// w w w . j a va2s .c o m public static List<Conflict> findRemoteContainerReplacedConflicts(List<Status> remoteAndLocalChanges) { List<Conflict> conflicts = new ArrayList<Conflict>(); Iterator<Status> iter = remoteAndLocalChanges.iterator(); // remember any replaced dirs we have already handled to // avoid an endless recursion of the main while loop Set<Status> handledReplacedDirs = new HashSet<Status>(); while (iter.hasNext()) { Status status = iter.next(); // REPLACED DIRECTORIES (remotely) if (status.getReposKind() == NodeKind.dir && status.getRepositoryTextStatus() == StatusKind.replaced && !handledReplacedDirs.contains(status)) { // conflict if there is a modification inside the directory // locally Status conflictParent = status; handledReplacedDirs.add(conflictParent); List<Status> localChildren = new ArrayList<Status>(); List<Status> remoteChildren = new ArrayList<Status>(); // find all children while (iter.hasNext()) { status = iter.next(); if (FileHelper.isParent(conflictParent.getPath(), status.getPath())) { if (status.getTextStatus() != StatusKind.none && status.getTextStatus() != StatusKind.normal) { localChildren.add(status); } else { remoteChildren.add(status); } // TODO: some might have to be added to both local and // remote iter.remove(); } else { // no more children found, this conflict is done break; } } if (localChildren.size() > 0) { // also remove the deleted folder status object remoteAndLocalChanges.remove(conflictParent); conflicts.add(new ReplaceConflict(conflictParent, localChildren, remoteChildren)); } // reset global iterator for next conflict search iter = remoteAndLocalChanges.iterator(); } } return conflicts; }
From source file:com.l2jfree.util.Introspection.java
private static void deepToString(Object obj, StringBuilder dest, Set<Object> dejaVu) throws SecurityException, NoSuchMethodException { if (obj == null) { dest.append("null"); return;//from ww w .j av a 2s. c o m } if (obj.getClass().isArray()) { final int length = Array.getLength(obj); if (length == 0) { dest.append("[]"); return; } if (dejaVu == null) dejaVu = new HashSet<Object>(); dejaVu.add(obj); dest.append('['); for (int i = 0; i < length; i++) { if (i != 0) dest.append(", "); final Object element = Array.get(obj, i); if (dejaVu.contains(element)) dest.append("[...]"); else deepToString(element, dest, dejaVu); } dest.append(']'); dejaVu.remove(obj); } else { if (obj.getClass().getMethod("toString").getDeclaringClass() == Object.class) dest.append(Introspection.toString(obj)); else dest.append(obj.toString()); } }
From source file:com.frostwire.gui.library.LibraryUtils.java
private static int addToPlaylist(Playlist playlist, File[] files, boolean starred, int index, Set<File> ignore) { int count = 0; for (int i = 0; i < files.length && !playlist.isDeleted(); i++) { if (MediaPlayer.isPlayableFile(files[i]) && !ignore.contains(files[i])) { LibraryUtils.addPlaylistItem(playlist, files[i], starred, index + count); count++;/*w w w . ja va 2 s . c o m*/ } else if (files[i].isDirectory()) { count += addToPlaylist(playlist, files[i].listFiles(), starred, index + count, ignore); } } return count; }
From source file:com.ofalvai.bpinfo.ui.alertlist.AlertListPresenter.java
/** * Returns a new filtered list of Alerts matching the provided set of RouteTypes, and sorted * according to the alert list type (descending/ascending) *///from w w w . ja v a 2 s .com @NonNull private static List<Alert> filterAndSort(@Nullable Set<RouteType> types, @NonNull List<Alert> alerts, @NonNull AlertListType type) { List<Alert> sorted = new ArrayList<>(alerts); // Sort: descending by alert start time Collections.sort(sorted, new Utils.AlertStartTimestampComparator()); if (type == AlertListType.ALERTS_TODAY) { Collections.reverse(sorted); } if (types == null || types.isEmpty()) { return sorted; } List<Alert> filtered = new ArrayList<>(); for (Alert alert : sorted) { for (Route route : alert.getAffectedRoutes()) { if (types.contains(route.getType())) { filtered.add(alert); break; } } } return filtered; }
From source file:com.taobao.android.builder.tools.manifest.ManifestHelper.java
public static List<? extends AndroidLibrary> getManifestDependencies(List<AwbBundle> awbBundles, Set<String> notMergedArtifacts, org.gradle.api.logging.Logger logger) { List<AndroidLibrary> list = new ArrayList<>(); for (AwbBundle lib : awbBundles) { // get the dependencies // [vliux] respect manifestOption.notMergedBundle String cord = String.format("%s:%s", lib.getResolvedCoordinates().getGroupId(), lib.getResolvedCoordinates().getArtifactId()); if (null == notMergedArtifacts || !notMergedArtifacts.contains(cord)) { list.add(lib.getAndroidLibrary()); list.addAll(lib.getAndroidLibraries()); } else {//from w w w .j ava 2 s. co m logger.info("[NotMergedManifest] " + cord); } } return list; }
From source file:com.knowbout.epg.EPG.java
private static void updateSitemap(String sitemap) { int lastslash = sitemap.lastIndexOf('/'); String inprogress = sitemap.substring(0, lastslash) + "/inprogress-" + sitemap.substring(lastslash + 1); String marker = "<!-- EVERYTHING BELOW IS AUTOMATICALLY GENERATED -->"; String baseurl = null;/*from w w w . jav a 2s .c o m*/ try { PrintStream doc = new PrintStream(new GZIPOutputStream(new FileOutputStream(inprogress))); BufferedReader orig = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(sitemap)))); String line = orig.readLine(); while (line != null) { if ((line.indexOf("</urlset>") >= 0) || (line.indexOf(marker) >= 0)) { break; } if (baseurl == null) { if (line.indexOf("<loc>") >= 0) { int http = line.indexOf("http://"); int nextslash = line.indexOf("/", http + 7); baseurl = line.substring(http, nextslash); } } doc.println(line); line = orig.readLine(); } doc.println(marker); Set<String> teams = new HashSet<String>(); HibernateUtil.openSession(); try { ScrollableResults scroll = Program.selectAllTeams(); while (scroll.next()) { Program program = (Program) scroll.get(0); addToSitemap(doc, baseurl, program); teams.add(program.getSportName() + ":" + program.getTeamName()); } scroll = Program.selectAllShowsMoviesSports(); while (scroll.next()) { Program program = (Program) scroll.get(0); if (program.isSports()) { if (!teams.contains(program.getSportName() + ":" + program.getHomeTeamName())) { Program home = Program.selectByTeam(program.getSportName(), program.getHomeTeamName()); addToSitemap(doc, baseurl, home); teams.add(home.getSportName() + ":" + home.getTeamName()); } if (!teams.contains(program.getSportName() + ":" + program.getAwayTeamName())) { Program away = Program.selectByTeam(program.getSportName(), program.getAwayTeamName()); addToSitemap(doc, baseurl, away); teams.add(away.getSportName() + ":" + away.getTeamName()); } } else { addToSitemap(doc, baseurl, program); } } } finally { HibernateUtil.closeSession(); } doc.println("</urlset>"); doc.close(); orig.close(); File origFile = new File(sitemap); File backupFile = new File(sitemap + ".bak"); File inprogressFile = new File(inprogress); backupFile.delete(); if (!origFile.renameTo(backupFile)) { throw new IOException("Could not rename " + origFile + " to " + backupFile); } if (!inprogressFile.renameTo(origFile)) { throw new IOException("Could not rename " + inprogressFile + " to " + origFile); } } catch (FileNotFoundException e) { log.error("Could not write to " + inprogress, e); } catch (IOException e) { log.error("IO Exception for " + inprogress + " or " + sitemap, e); } }
From source file:edu.stanford.muse.util.Log4JUtils.java
/** taken from: http://stackoverflow.com/questions/3060240/how-do-you-flush-a-buffered-log4j-fileappender */ public static void flushAllLogs() { try {// www . j a v a 2 s . c om Set<FileAppender> flushedFileAppenders = new LinkedHashSet<FileAppender>(); Enumeration currentLoggers = LogManager.getLoggerRepository().getCurrentLoggers(); while (currentLoggers.hasMoreElements()) { Object nextLogger = currentLoggers.nextElement(); if (nextLogger instanceof Logger) { Logger currentLogger = (Logger) nextLogger; Enumeration allAppenders = currentLogger.getAllAppenders(); while (allAppenders.hasMoreElements()) { Object nextElement = allAppenders.nextElement(); if (nextElement instanceof FileAppender) { FileAppender fileAppender = (FileAppender) nextElement; if (!flushedFileAppenders.contains(fileAppender) && !fileAppender.getImmediateFlush()) { flushedFileAppenders.add(fileAppender); //log.info("Appender "+fileAppender.getName()+" is not doing immediateFlush "); fileAppender.setImmediateFlush(true); currentLogger .info("Flushing appender: " + fileAppender.getName() + "\n" + fileAppender); fileAppender.setImmediateFlush(false); } else { //log.info("fileAppender"+fileAppender.getName()+" is doing immediateFlush"); } } } } } } catch (RuntimeException e) { log.error("Failed flushing logs", e); } }
From source file:com.gamesalutes.utils.EncryptUtils.java
/** * Returns <code>List</code> of strings in {@link #STRONG_CIPHER_SUITES} that * are supported by the default ssl socket factory. * /*from w w w.j a va 2 s . c o m*/ * @return <code>List</code> of supported strong cipher suites */ public static List<String> getSupportedStrongCipherSuites() { Set<String> suites = new HashSet<String>( Arrays.asList(HttpsURLConnection.getDefaultSSLSocketFactory().getSupportedCipherSuites())); List<String> enabledSuites = new ArrayList<String>(); //get strong suites that are supported by the SSL factory for (String s : STRONG_CIPHER_SUITES) { if (suites.contains(s)) enabledSuites.add(s); } return enabledSuites; //convert list into comma separated string for use in System.setProperty }
From source file:com.openkm.module.db.base.BaseDocumentModule.java
/** * Check if a node is being used in a running workflow */// w w w . j a va 2s. c o m public static boolean hasWorkflowNodes(String docUuid) throws WorkflowException, PathNotFoundException, DatabaseException { Set<String> workflowNodes = new HashSet<String>(); for (ProcessDefinition procDef : CommonWorkflowModule.findAllProcessDefinitions()) { for (ProcessInstance procIns : CommonWorkflowModule.findProcessInstances(procDef.getId())) { if (procIns.getEnd() == null) { String uuid = (String) procIns.getVariables() .get(Config.WORKFLOW_PROCESS_INSTANCE_VARIABLE_UUID); workflowNodes.add(uuid); } } } if (workflowNodes.contains(docUuid)) { return true; } else { return false; } }