List of usage examples for java.util HashSet contains
public boolean contains(Object o)
From source file:blusunrize.immersiveengineering.api.ApiUtils.java
private static boolean handlePos(Vec3d pos, BlockPos posB, HashMap<BlockPos, Vec3d> halfScanned, HashSet<BlockPos> done, Predicate<Triple<BlockPos, Vec3d, Vec3d>> shouldStop, HashSet<Triple<BlockPos, Vec3d, Vec3d>> near) { final double DELTA_NEAR = .3; if (!done.contains(posB)) { if (halfScanned.containsKey(posB) && !pos.equals(halfScanned.get(posB))) { Triple<BlockPos, Vec3d, Vec3d> added = new ImmutableTriple<>(posB, halfScanned.get(posB), pos); boolean stop = shouldStop.test(added); done.add(posB);/* w w w . j ava2 s . com*/ halfScanned.remove(posB); near.removeIf((t) -> t.getLeft().equals(posB)); if (stop) return true; for (int i = 0; i < 3; i++) { double coord = getDim(pos, i); double diff = coord - Math.floor(coord); if (diff < DELTA_NEAR) near.add( new ImmutableTriple<>(offsetDim(posB, i, -1), added.getMiddle(), added.getRight())); diff = Math.ceil(coord) - coord; if (diff < DELTA_NEAR) near.add(new ImmutableTriple<>(offsetDim(posB, i, 1), added.getMiddle(), added.getRight())); } } else { halfScanned.put(posB, pos); } } return false; }
From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java
public static void removeFromInstallQueue(Context context, HashSet<String> packageNames, UserHandleCompat user) {//from ww w.j av a 2s. c o m if (packageNames.isEmpty()) { return; } SharedPreferences sp = Utilities.getPrefs(context); synchronized (sLock) { Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null); if (DBG) { Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames); } if (strings != null) { Set<String> newStrings = new HashSet<String>(strings); Iterator<String> newStringsIter = newStrings.iterator(); while (newStringsIter.hasNext()) { String encoded = newStringsIter.next(); PendingInstallShortcutInfo info = decode(encoded, context); if (info == null || (packageNames.contains(info.getTargetPackage()) && user.equals(info.user))) { newStringsIter.remove(); } } sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).apply(); } } }
From source file:com.fstx.stdlib.author.old.AuthorizationManagerTest.java
public void testRemoveAuthorizationBean() throws AuthorizationException { AuthorizationBean ab = AuthorizationManager.singleton.getAuthorizationBean("Nicholas"); HashSet myRights = ab.getRights(); assertEquals(myRights.size(), 4);//from w ww . ja v a 2 s . c om assertTrue(myRights.contains("right1")); assertTrue(myRights.contains("right2")); assertTrue(myRights.contains("right3")); assertTrue(myRights.contains("Otherright2")); assertTrue(AuthorizationManager.singleton.removeAuthorizationBean("Nicholas")); // Should be getting from the builder again. AuthorizationBean ab2 = AuthorizationManager.singleton.getAuthorizationBean("Nicholas"); HashSet myRights2 = ab2.getRights(); assertEquals(myRights2.size(), 4); assertTrue(myRights2.contains("right1")); assertTrue(myRights2.contains("right2")); assertTrue(myRights2.contains("right3")); assertTrue(myRights2.contains("Otherright2")); }
From source file:com.clustercontrol.jobmanagement.util.MonitorJobWorker.java
/** * //from w w w . j a v a 2s . c o m * @param sessionId ID */ public static void removeInfoBySessionId(String sessionId) { if (sessionId == null || sessionId.isEmpty()) { return; } /** */ List<RunInstructionInfo> runInstructionInfoList = RunHistoryUtil.findRunHistoryBySessionId(sessionId); for (RunInstructionInfo runInstructionInfo : runInstructionInfoList) { try { deleteSchedule(runInstructionInfo); } catch (HinemosUnknown e) { // ???? m_log.debug("schedule is not found."); } } /** */ HashSet<String> keySet = new HashSet<>(); for (Map.Entry<String, ConcurrentHashMap<RunInstructionInfo, MonitorInfo>> entry : monitorJobMap .entrySet()) { for (Map.Entry<RunInstructionInfo, MonitorInfo> childEntry : entry.getValue().entrySet()) { if (sessionId.equals(childEntry.getKey().getSessionId())) { monitorJobMap.get(childEntry.getValue().getMonitorTypeId()).remove(childEntry.getKey()); keySet.add(childEntry.getValue().getMonitorTypeId()); } } } // ?HinemosAgent?? if (keySet.contains(HinemosModuleConstant.MONITOR_LOGFILE)) { // SettingUpdateInfo.getInstance().setLogFileMonitorUpdateTime(HinemosTime.currentTimeMillis()); LogfileManagerUtil.broadcastConfigured(); } else if (keySet.contains(HinemosModuleConstant.MONITOR_WINEVENT)) { // Windows SettingUpdateInfo.getInstance().setWinEventMonitorUpdateTime(HinemosTime.currentTimeMillis()); WinEventManagerUtil.broadcastConfigured(); } else if (keySet.contains(HinemosModuleConstant.MONITOR_CUSTOM_N) || keySet.contains(HinemosModuleConstant.MONITOR_CUSTOM_S)) { // ?HinemosAgent?? SettingUpdateInfo.getInstance().setCustomMonitorUpdateTime(HinemosTime.currentTimeMillis()); CustomManagerUtil.broadcastConfigured(); } /** ? */ for (Map.Entry<RunInstructionInfo, Object> entry : prevMonitorValueMap.entrySet()) { if (sessionId.equals(entry.getKey().getSessionId())) { prevMonitorValueMap.remove(entry.getKey()); } } /** RunHistory */ for (RunInstructionInfo runInstructionInfo : runInstructionInfoList) { RunHistoryUtil.delRunHistory(runInstructionInfo); } }
From source file:backtype.storm.utils.VersionedStore.java
public void cleanup(int versionsToKeep) throws IOException { List<Long> versions = getAllVersions(); if (versionsToKeep >= 0) { versions = versions.subList(0, Math.min(versions.size(), versionsToKeep)); }//from www.j ava 2 s . c o m HashSet<Long> keepers = new HashSet<Long>(versions); for (String p : listDir(_root)) { Long v = parseVersion(p); if (v != null && !keepers.contains(v)) { deleteVersion(v); } } }
From source file:disko.flow.analyzers.socket.SocketTransmitter.java
public void process(C ctx, Ports ports) throws InterruptedException { HashSet<InputPort<?>> closedPorts = new HashSet<InputPort<?>>(); log.debug("starting socket transmitter."); while (closedPorts.size() < ports.getInputCount()) { for (InputPort<?> inputPort : ports.getInputPorts()) { if (closedPorts.contains(inputPort)) continue; Object data = inputPort.take(); if (inputPort.isEOS(data)) { closedPorts.add(inputPort); log.debug("Input port " + inputPort + " closed."); final String channelId = inputPort.getChannel().getId(); writeMessage(new Message(channelId, null)); log.debug("Sent EOS to " + channelId); continue; }//from w w w.jav a2s. c o m final Message message = new Message(inputPort.getChannel().getId(), (Serializable) data); log.debug("Sending msg " + data); writeMessage(message); } } }
From source file:com.metamx.milano.proto.MilanoTool.java
/** * Build a MilanoTool from a DescriptorProto, FileDescriptorProto, and a FileDescriptorSet representing * the dependencies./*from w w w . j a v a2 s. c o m*/ * * @param descriptorProto The Descriptor for the message. * @param fileDescriptorProto The FileDescriptorProto containing descriptorProto. * @param dependencies A possible empty FileDescriptorSet containing the dependencies for fileDescriptorProto. * * @return A MilanoTool of the message. */ public static MilanoTool with(final DescriptorProtos.DescriptorProto descriptorProto, final DescriptorProtos.FileDescriptorProto fileDescriptorProto, final DescriptorProtos.FileDescriptorSet dependencies) { HashSet<String> fileSet = new HashSet<String>(); DescriptorProtos.FileDescriptorSet.Builder storedFileSetBuilder = DescriptorProtos.FileDescriptorSet .newBuilder(); if (dependencies != null) { for (DescriptorProtos.FileDescriptorProto fileProto : dependencies.getFileList()) { log.debug(String.format("Found dependency [%s] in package [%s]", fileProto.getName(), fileProto.getPackage())); fileSet.add(fileProto.getName()); if (fileProto.getName().equals("descriptor.proto") && fileProto.getPackage().equals("google.protobuf")) { continue; } storedFileSetBuilder.addFile(fileProto); } } for (String dependency : fileDescriptorProto.getDependencyList()) { log.debug(String.format("Type requires dependency: %s", dependency)); if (!fileSet.contains(dependency) && !dependency.equals("descriptor.proto")) { throw new IllegalStateException( String.format("File requires dependency [%s] that does not exist.", dependency)); } } MilanoTypeMetadata.TypeMetadata.Builder typeMetadataBuilder = MilanoTypeMetadata.TypeMetadata.newBuilder() .setTypeName(descriptorProto.getName()).setTypePackageName(fileDescriptorProto.getPackage()) .setTypeFileDescriptor(fileDescriptorProto); if (storedFileSetBuilder.getFileCount() > 0) { typeMetadataBuilder.setTypeDependencies(storedFileSetBuilder.build()); } return new MilanoTool(typeMetadataBuilder.build()); }
From source file:com.velonuboso.made.core.rat.archetypes.RomeoJuliet.java
public double evaluate(GlobalSetup gs, ArrayList<MadeAgentInterface> agents, ArchetypeOccurrence o) { int matches = 0; // TODO//w w w. ja v a 2 s.c o m // 1.- Buscar parejas Pattern pat1 = Pattern.compile("@" + RatState.PARTNER_FOUND + " ([0-9]+)\n"); HashSet<MadeAgentInterface> partners = new HashSet<MadeAgentInterface>(); int i = 0; for (MadeAgentInterface agent : agents) { if (!partners.contains(agent)) { boolean found = false; Matcher m = pat1.matcher(agent.getStringLog()); if (m.find()) { MadeAgentInterface partner = agents.get(Integer.parseInt(m.group(1))); RatAgent parent11 = null; RatAgent parent12 = null; RatAgent parent21 = null; RatAgent parent22 = null; // 2.- Buscar los padres de las parejas Pattern pat2 = Pattern.compile("@" + RatState.DESCENDANT + " ([0-9]+) ([0-9]+)\n"); Matcher m2 = pat2.matcher(agent.getStringLog()); if (m2.find()) { parent11 = (RatAgent) agents.get(Integer.parseInt(m2.group(1))); parent12 = (RatAgent) agents.get(Integer.parseInt(m2.group(2))); } m2 = pat2.matcher(partner.getStringLog()); if (m2.find()) { parent21 = (RatAgent) agents.get(Integer.parseInt(m2.group(1))); parent22 = (RatAgent) agents.get(Integer.parseInt(m2.group(2))); } if (parent11 == null || parent12 == null || parent21 == null || parent22 == null) { // Eve and Adam } else { Pattern pat3 = Pattern.compile("@" + RatState.NUDGE_OK + " (" + parent11.getId() + "|" + parent12.getId() + "|" + parent21.getId() + "|" + parent22.getId() + ")\n"); Matcher mpat = pat3.matcher(parent11.getStringLog()); if (mpat.find()) { found = true; } else { mpat = pat3.matcher(parent12.getStringLog()); if (mpat.find()) { found = true; } else { mpat = pat3.matcher(parent21.getStringLog()); if (mpat.find()) { found = true; } else { mpat = pat3.matcher(parent22.getStringLog()); if (mpat.find()) { found = true; } } } } if (found) { if (((RatAgent) agent).getGender() == Gender.MALE) { agent.addLabel(new LabelArchetype("Romeo (" + partner.getId() + ")")); partner.addLabel(new LabelArchetype("Juliet (" + agent.getId() + ")")); } else { agent.addLabel(new LabelArchetype("Juliet (" + partner.getId() + ")")); partner.addLabel(new LabelArchetype("Romeo (" + agent.getId() + ")")); } matches += 2; } } } } } return o.getValue(agents.size(), matches); }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.FindItemInfo.java
/** * @return the duplicateIds/*from ww w . j a v a 2 s .c om*/ */ public int cleanDuplicateIds(final HashSet<Integer> usedIds) { ArrayList<Integer> ids = new ArrayList<Integer>(duplicateIds); duplicateIds.clear(); for (Integer dupId : ids) { if (usedIds == null || !usedIds.contains(dupId)) { duplicateIds.add(dupId); } } return duplicateIds.size(); }
From source file:azkaban.project.DirectoryYamlFlowLoader.java
private void addEdges(final AzkabanNode node, final AzkabanFlow azkabanFlow, final String flowName, final HashSet<String> recStack, final HashSet<String> visited) { if (!visited.contains(node.getName())) { recStack.add(node.getName());//w w w . jav a 2 s .c o m visited.add(node.getName()); final List<String> dependsOnList = node.getDependsOn(); for (final String parent : dependsOnList) { final Edge edge = new Edge(parent, node.getName()); if (!this.edgeMap.containsKey(flowName)) { this.edgeMap.put(flowName, new ArrayList<>()); } this.edgeMap.get(flowName).add(edge); if (recStack.contains(parent)) { // Cycles found, including self cycle. edge.setError("Cycles found."); this.errors.add("Cycles found at " + edge.getId()); } else { // Valid edge. Continue to process the parent node recursively. addEdges(azkabanFlow.getNode(parent), azkabanFlow, flowName, recStack, visited); } } recStack.remove(node.getName()); } }