Java Code Examples for java.util.Set#remove()
The following examples show how to use
java.util.Set#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WhiteListTaskProvider.java From netbeans with Apache License 2.0 | 6 votes |
private static void updateErrorsInFile( @NonNull final Callback callback, @NonNull final FileObject root, @NonNull final FileObject file) { final List<Task> tasks = new ArrayList<Task>(); for (WhiteListIndex.Problem problem : WhiteListIndex.getDefault().getWhiteListViolations(root, file)) { final Map.Entry<FileObject,List<? extends Task>> task = createTask(problem); if (task != null) { tasks.addAll(task.getValue()); } } final Set<FileObject> filesWithErrors = getFilesWithAttachedErrors(root); if (tasks.isEmpty()) { filesWithErrors.remove(file); } else { filesWithErrors.add(file); } LOG.log(Level.FINE, "setting {1} for {0}", new Object[]{file, tasks}); callback.setTasks(file, tasks); }
Example 2
Source File: TestAbstractHierarchicalConfiguration.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Helper method for testing the getKeys(String) method. * * @param prefix the key to pass into getKeys() * @param expected the expected result */ private void checkKeys(final String prefix, final String[] expected) { final Set<String> values = new HashSet<>(); for (final String anExpected : expected) { values.add(anExpected.startsWith(prefix) ? anExpected : prefix + "." + anExpected); } final Iterator<String> itKeys = config.getKeys(prefix); while(itKeys.hasNext()) { final String key = itKeys.next(); if(!values.contains(key)) { fail("Found unexpected key: " + key); } else { values.remove(key); } } assertTrue("Remaining keys " + values, values.isEmpty()); }
Example 3
Source File: CacheOnlineUserManager.java From boubei-tss with Apache License 2.0 | 6 votes |
public String logout(String appCode, String sessionId) { // 删除当前sessionId在当前应用中登陆后产生的在线用户信息 OnlineUser userInfo = (OnlineUser) sessionIdMap.remove(sessionId); if (userInfo == null) return null; String token = userInfo.getToken(); Set<OnlineUser> userInfos = tokenMap.get(token); userInfos.remove(userInfo); //删除令牌在当前应用下的 在线用户信息,不包含其它的应用。 // 判断Token是否已经退出了所有应用,是的话移除此Token if (userInfos.size() == 0) { tokenMap.remove(token); usersMap.remove(userInfo.getUserId()); } userInfo = null; userInfos = null; return token; }
Example 4
Source File: ConcurrentHashMapWrapper.java From TorrentEngine with GNU General Public License v3.0 | 5 votes |
/** * NOT MODIFIABLE * @return */ public Set<S> keySet() { Set<S> result = map.keySet(); if ( result.contains( S_NULL )){ result.remove( S_NULL ); result.add( null ); } return( Collections.unmodifiableSet( result )); }
Example 5
Source File: RecordSetSuite.java From herddb with Apache License 2.0 | 5 votes |
@Test public void testLimitsSwap() throws Exception { RecordSetFactory factory = buildRecordSetFactory(1); Column[] columns = new Column[2]; columns[0] = Column.column("s1", ColumnTypes.STRING); columns[1] = Column.column("n1", ColumnTypes.LONG); String[] fieldNames = Column.buildFieldNamesList(columns); try (MaterializedRecordSet rs = factory.createRecordSet(fieldNames, columns)) { Set<String> expected_s1 = new HashSet<>(); Set<Integer> expected_n1 = new HashSet<>(); for (int i = 0; i < 100; i++) { Map<String, Object> record = new HashMap<>(); String s1 = "test_" + i; record.put("s1", s1); record.put("n1", i); if (i >= 10 && i < 30) { expected_s1.add(s1); expected_n1.add(i); } rs.add(new Tuple(record, fieldNames)); } rs.writeFinished(); rs.applyLimits(new ScanLimitsImpl(20, 10), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT()); for (DataAccessor t : rs) { expected_s1.remove(t.get("s1").toString()); expected_n1.remove(t.get("n1")); } assertTrue(expected_n1.isEmpty()); assertTrue(expected_s1.isEmpty()); } }
Example 6
Source File: XmlBeanDefinitionReader.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Load bean definitions from the specified XML file. * @param encodedResource the resource descriptor for the XML file, * allowing to specify an encoding to use for parsing the file * @return the number of bean definitions found * @throws BeanDefinitionStoreException in case of loading or parsing errors */ public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException { Assert.notNull(encodedResource, "EncodedResource must not be null"); if (logger.isInfoEnabled()) { logger.info("Loading XML bean definitions from " + encodedResource.getResource()); } Set<EncodedResource> currentResources = this.resourcesCurrentlyBeingLoaded.get(); if (currentResources == null) { currentResources = new HashSet<EncodedResource>(4); this.resourcesCurrentlyBeingLoaded.set(currentResources); } if (!currentResources.add(encodedResource)) { throw new BeanDefinitionStoreException( "Detected cyclic loading of " + encodedResource + " - check your import definitions!"); } try { InputStream inputStream = encodedResource.getResource().getInputStream(); try { InputSource inputSource = new InputSource(inputStream); if (encodedResource.getEncoding() != null) { inputSource.setEncoding(encodedResource.getEncoding()); } return doLoadBeanDefinitions(inputSource, encodedResource.getResource()); } finally { inputStream.close(); } } catch (IOException ex) { throw new BeanDefinitionStoreException( "IOException parsing XML document from " + encodedResource.getResource(), ex); } finally { currentResources.remove(encodedResource); if (currentResources.isEmpty()) { this.resourcesCurrentlyBeingLoaded.remove(); } } }
Example 7
Source File: CommonAnnotationHelperTest.java From netbeans with Apache License 2.0 | 5 votes |
private void assertResourceEnvRefNames(final Set<String> resourceNames, final ResourceEnvRef[] resourceEnvRefs) { assertEquals(resourceNames.size(), resourceEnvRefs.length); Set<String> resourceNamesCopy = new HashSet<String>(resourceNames); for (ResourceEnvRef resourceEnvRef : resourceEnvRefs) { assertTrue(resourceNamesCopy.contains(resourceEnvRef.getResourceEnvRefName())); resourceNamesCopy.remove(resourceEnvRef.getResourceEnvRefName()); } }
Example 8
Source File: ServerNotifForwarder.java From hottub with GNU General Public License v2.0 | 5 votes |
public void removeNotificationListener(ObjectName name, Integer listenerID) throws InstanceNotFoundException, ListenerNotFoundException, IOException { if (logger.traceOn()) { logger.trace("removeNotificationListener", "Remove the listener " + listenerID + " from " + name); } checkState(); if (name != null && !name.isPattern()) { if (!mbeanServer.isRegistered(name)) { throw new InstanceNotFoundException("The MBean " + name + " is not registered."); } } synchronized (listenerMap) { // Tread carefully because if set.size() == 1 it may be a // Collections.singleton, which is unmodifiable. Set<IdAndFilter> set = listenerMap.get(name); IdAndFilter idaf = new IdAndFilter(listenerID, null); if (set == null || !set.contains(idaf)) throw new ListenerNotFoundException("Listener not found"); if (set.size() == 1) listenerMap.remove(name); else set.remove(idaf); } }
Example 9
Source File: MessageHeadersBuilder.java From ditto with Eclipse Public License 2.0 | 5 votes |
private static Set<MessageHeaderDefinition> determineMessageHeaderDefinitions() { final Set<MessageHeaderDefinition> result = EnumSet.allOf(MessageHeaderDefinition.class); // remove deprecated timeout entry as this is now defined in DittoHeaderDefinitions result.remove(MessageHeaderDefinition.TIMEOUT); return result; }
Example 10
Source File: RemoveModifier.java From netbeans with Apache License 2.0 | 5 votes |
@Override public ChangeInfo implement() { CancellableTask<WorkingCopy> task = new CancellableTask<WorkingCopy>() { @Override public void cancel() { } @Override public void run(WorkingCopy workingCopy) throws Exception { workingCopy.toPhase(JavaSource.Phase.RESOLVED); TypeElement clazz = classHandle.resolve(workingCopy); if (clazz != null) { ClassTree clazzTree = workingCopy.getTrees().getTree(clazz); TreeMaker make = workingCopy.getTreeMaker(); Set<Modifier> flags = new HashSet<>(clazzTree.getModifiers().getFlags()); flags.remove(modifier); ModifiersTree newModifiers = make.Modifiers(flags, clazzTree.getModifiers().getAnnotations()); workingCopy.rewrite(clazzTree.getModifiers(), newModifiers); } } }; JavaSource javaSource = JavaSource.forFileObject(fileObject); try { javaSource.runModificationTask(task).commit(); } catch (IOException e) { LOG.log(Level.SEVERE, e.getMessage(), e); } return null; }
Example 11
Source File: FileStatusCache.java From netbeans with Apache License 2.0 | 5 votes |
private void updateIndex(File file, FileInformation fi, boolean addToIndex) { File parent = file.getParentFile(); if (parent != null) { Set<File> conflicted = new HashSet<>(Arrays.asList(conflictedFiles.get(parent))); Set<File> modified = new HashSet<>(Arrays.asList(modifiedFiles.get(parent))); Set<File> ignored = new HashSet<>(Arrays.asList(ignoredFiles.get(parent))); boolean modifiedChange = modified.remove(file); boolean conflictedChange = conflicted.remove(file); boolean ignoredChange = USE_IGNORE_INDEX && ignored.remove(file); if (addToIndex) { if (fi.containsStatus(Status.NOTVERSIONED_EXCLUDED)) { ignoredChange |= USE_IGNORE_INDEX && ignored.add(file); } else { modifiedChange |= modified.add(file); if (fi.containsStatus(Status.IN_CONFLICT)) { conflictedChange |= conflicted.add(file); } } } if (modifiedChange) { modifiedFiles.add(parent, modified); } if (conflictedChange) { conflictedFiles.add(parent, conflicted); } if (ignoredChange) { ignoredFiles.add(parent, ignored); } } }
Example 12
Source File: TestFileInputFormatPathFilter.java From big-c with Apache License 2.0 | 5 votes |
private void _testInputFiles(boolean withFilter, boolean withGlob) throws Exception { Set<Path> createdFiles = createFiles(); JobConf conf = new JobConf(); Path inputDir = (withGlob) ? new Path(workDir, "a*") : workDir; FileInputFormat.setInputPaths(conf, inputDir); conf.setInputFormat(DummyFileInputFormat.class); if (withFilter) { FileInputFormat.setInputPathFilter(conf, TestPathFilter.class); } DummyFileInputFormat inputFormat = (DummyFileInputFormat) conf.getInputFormat(); Set<Path> computedFiles = new HashSet<Path>(); for (FileStatus file : inputFormat.listStatus(conf)) { computedFiles.add(file.getPath()); } createdFiles.remove(localFs.makeQualified(new Path(workDir, "_hello"))); createdFiles.remove(localFs.makeQualified(new Path(workDir, ".hello"))); if (withFilter) { createdFiles.remove(localFs.makeQualified(new Path(workDir, "aa"))); createdFiles.remove(localFs.makeQualified(new Path(workDir, "bb"))); } if (withGlob) { createdFiles.remove(localFs.makeQualified(new Path(workDir, "b"))); createdFiles.remove(localFs.makeQualified(new Path(workDir, "bb"))); } assertEquals(createdFiles, computedFiles); }
Example 13
Source File: FlagDbFile.java From vespa with Apache License 2.0 | 5 votes |
public boolean sync(Map<FlagId, FlagData> flagData) { boolean modified = false; Map<FlagId, FlagData> currentFlagData = read(); Set<FlagId> flagIdsToBeRemoved = new HashSet<>(currentFlagData.keySet()); List<FlagData> flagDataList = new ArrayList<>(flagData.values()); for (FlagData data : flagDataList) { flagIdsToBeRemoved.remove(data.id()); FlagData existingFlagData = currentFlagData.get(data.id()); if (existingFlagData == null) { logger.log(Level.INFO, "New flag " + data.id() + ": " + data.serializeToJson()); modified = true; // Could also consider testing with FlagData::equals, but that would be too fragile? } else if (!Objects.equals(data.serializeToJson(), existingFlagData.serializeToJson())){ logger.log(Level.INFO, "Updating flag " + data.id() + " from " + existingFlagData.serializeToJson() + " to " + data.serializeToJson()); modified = true; } } if (!flagIdsToBeRemoved.isEmpty()) { String flagIdsString = flagIdsToBeRemoved.stream().map(FlagId::toString).collect(Collectors.joining(", ")); logger.log(Level.INFO, "Removing flags " + flagIdsString); modified = true; } if (!modified) return false; writeFile(FlagData.serializeListToUtf8Json(flagDataList)); return modified; }
Example 14
Source File: DataSetParentUidsHelper.java From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License | 4 votes |
static Set<String> getAssignedOptionSetUids(List<DataElement> dataElements) { Set<String> dataElementUids = new HashSet<>(); if (dataElements != null) { for (DataElement dataElement : dataElements) { String optionSetUid = dataElement.optionSetUid(); dataElementUids.add(optionSetUid); } dataElementUids.remove(null); } return dataElementUids; }
Example 15
Source File: InstrumentationRepository.java From android-test with Apache License 2.0 | 4 votes |
private void findInstrumentations() { if (testRunner != null) { return; } List<Instrumentation> availableInstrumentations = instrumentationsProvider.get(); Set<String> ignoredPackages = new HashSet<>(ignoreTestPackages); ignoredPackages.addAll(IGNORE_INSTRUMENTATION_PACKAGES); // Don't ignore the bootstrap package when looking for the test runner. // (We'd only want to ignore it when looking for tests in TestInfoRepository.) if (!Strings.isNullOrEmpty(bootstrapInstrumentationPackage)) { ignoredPackages.remove(bootstrapInstrumentationPackage); } // Filter the list to only contain supported instrumentations. List<Instrumentation> filteredInstrumentations = Lists.newArrayList(); for (Instrumentation instrumentation : availableInstrumentations) { if (ignoredPackages.contains(instrumentation.getAndroidPackage())) { logger.info( String.format( "Ignoring instrumentation class: %s/%s", instrumentation.getAndroidPackage(), instrumentation.getInstrumentationClass())); } else if (AdbController.SUPPORTED_INSTRUMENTATION_NAMES.contains( instrumentation.getFullInstrumentationClass()) || // TODO(b/150524968): remove support for custom runner classes AdbController.SUPPORTED_INSTRUMENTATION_NAMES.contains( instrumentation.getInstrumentationClass())) { filteredInstrumentations.add(instrumentation); // Assume the first supported non-bootstrap instrumentation found also contains the tests. if (Strings.isNullOrEmpty(defaultTestPackage) && !instrumentation.getAndroidPackage().equals(bootstrapInstrumentationPackage)) { defaultTestPackage = instrumentation.getAndroidPackage(); logger.info("Found test package: " + defaultTestPackage); } } } if (!Strings.isNullOrEmpty(bootstrapInstrumentationPackage)) { testRunner = getBootstrapInstrumentation(availableInstrumentations, filteredInstrumentations); } else { testRunner = getFirstInstrumentation(filteredInstrumentations); } }
Example 16
Source File: MavenWhiteListQueryImpl.java From netbeans with Apache License 2.0 | 4 votes |
private Set<String> getAllPackages(FileObject root) { Set<String> toRet = new HashSet<String>(); processFolder(root, root, toRet); toRet.remove(""); return toRet; }
Example 17
Source File: DefaultSingletonBeanRegistry.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Destroy the given bean. Must destroy beans that depend on the given * bean before the bean itself. Should not throw any exceptions. * @param beanName the name of the bean * @param bean the bean instance to destroy */ protected void destroyBean(String beanName, DisposableBean bean) { // Trigger destruction of dependent beans first... Set<String> dependencies = this.dependentBeanMap.remove(beanName); if (dependencies != null) { if (logger.isDebugEnabled()) { logger.debug("Retrieved dependent beans for bean '" + beanName + "': " + dependencies); } for (String dependentBeanName : dependencies) { destroySingleton(dependentBeanName); } } // Actually destroy the bean now... if (bean != null) { try { bean.destroy(); } catch (Throwable ex) { logger.error("Destroy method on bean with name '" + beanName + "' threw an exception", ex); } } // Trigger destruction of contained beans... Set<String> containedBeans = this.containedBeanMap.remove(beanName); if (containedBeans != null) { for (String containedBeanName : containedBeans) { destroySingleton(containedBeanName); } } // Remove destroyed bean from other beans' dependencies. synchronized (this.dependentBeanMap) { for (Iterator<Map.Entry<String, Set<String>>> it = this.dependentBeanMap.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Set<String>> entry = it.next(); Set<String> dependenciesToClean = entry.getValue(); dependenciesToClean.remove(beanName); if (dependenciesToClean.isEmpty()) { it.remove(); } } } // Remove destroyed bean's prepared dependency information. this.dependenciesForBeanMap.remove(beanName); }
Example 18
Source File: Strings.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Override public String resolve(final String variable, final Resolver resolver) { boolean clearStack = false; Set<String> currentStack = _stack.get(); if(currentStack == null) { currentStack = new HashSet<>(); _stack.set(currentStack); clearStack = true; } try { if(currentStack.contains(variable)) { throw new IllegalArgumentException("The value of attribute " + variable + " is defined recursively"); } if (variable.startsWith(_prefix)) { currentStack.add(variable); final Stack<String> stack = new Stack<>(); stack.add(variable); String expanded = Strings.expand("${" + variable.substring(_prefix.length()) + "}", resolver, stack, false); currentStack.remove(variable); if(expanded != null) { for(Map.Entry<String,String> entry : _substitutions.entrySet()) { expanded = expanded.replace(entry.getKey(), entry.getValue()); } } return expanded; } else { return null; } } finally { if(clearStack) { _stack.remove(); } } }
Example 19
Source File: RetainedStateTestEnvironment.java From Akatsuki with Apache License 2.0 | 4 votes |
public void executeTestCaseWithFields(Set<? extends TestField> fieldList, Predicate<String> methodNamePredicate, FieldFilter accessorTypeFilter, Accessor accessor, Function<TestField, Integer> times) { Set<TestField> allFields = new HashSet<>(fieldList); for (Method method : Bundle.class.getMethods()) { // check correct signature and name predicate if (!checkMethodIsAccessor(method, accessor) || !methodNamePredicate.test(method.getName())) { continue; } // find methods who's accessor type matches the given fields List<TestField> matchingField = allFields.stream() .filter(f -> filterTypes(method, accessor, accessorTypeFilter, f)) .collect(Collectors.toList()); // no signature match if (matchingField.isEmpty()) { continue; } // more than one match, we should have exactly one match if (matchingField.size() > 1) { throw new AssertionError(method.toString() + " matches multiple field " + fieldList + ", this is ambiguous and should not happen." + environment.printReport()); } final TestField field = matchingField.get(0); try { if (accessor == Accessor.PUT) { method.invoke(verify(mockedBundle, times(times.apply(field))), eq(field.name), any(field.clazz)); } else { method.invoke(verify(mockedBundle, times(times.apply(field))), eq(field.name)); } allFields.remove(field); } catch (Exception e) { throw new AssertionError("Invocation of method " + method.getName() + " on mocked object failed." + environment.printReport(), e); } } if (!allFields.isEmpty()) throw new RuntimeException("While testing for accessor:" + accessor + " some fields are left untested because a suitable accessor cannot be found: " + allFields + environment.printReport()); }
Example 20
Source File: TemporaryFiles.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
static void testTempDirectory(String prefix, Path dir) throws IOException { Path subdir = (dir == null) ? Files.createTempDirectory(prefix) : Files.createTempDirectory(dir, prefix); try { // check file name String name = subdir.getFileName().toString(); if (prefix != null && !name.startsWith(prefix)) throw new RuntimeException("Should start with " + prefix); // check directory is in expected directory checkInDirectory(subdir, dir); // check directory is empty DirectoryStream<Path> stream = Files.newDirectoryStream(subdir); try { if (stream.iterator().hasNext()) throw new RuntimeException("Tempory directory not empty"); } finally { stream.close(); } // check that we can create file in directory Path file = Files.createFile(subdir.resolve("foo")); try { Files.newByteChannel(file, READ,WRITE).close(); } finally { Files.delete(file); } // check file permissions are 0700 or more secure if (Files.getFileStore(subdir).supportsFileAttributeView("posix")) { Set<PosixFilePermission> perms = Files.getPosixFilePermissions(subdir); perms.remove(PosixFilePermission.OWNER_READ); perms.remove(PosixFilePermission.OWNER_WRITE); perms.remove(PosixFilePermission.OWNER_EXECUTE); if (!perms.isEmpty()) throw new RuntimeException("Temporary directory is not secure"); } } finally { Files.delete(subdir); } }