List of usage examples for org.apache.commons.collections4 IterableUtils forEach
public static <E> void forEach(final Iterable<E> iterable, final Closure<? super E> closure)
From source file:com.vrem.wifianalyzer.wifi.timegraph.DataManagerTest.java
@Test public void testAdjustDataAppendsData() throws Exception { // setup/*from w w w . j a v a2s . c om*/ Set<WiFiDetail> wiFiDetails = new TreeSet<>(); List<WiFiDetail> difference = makeWiFiDetails(); int xValue = fixture.getXValue(); final Integer scanCount = fixture.getScanCount(); final DataPoint dataPoint = new DataPoint(xValue, DataManager.MIN_Y + DataManager.MIN_Y_OFFSET); when(graphViewWrapper.differenceSeries(wiFiDetails)).thenReturn(difference); // execute fixture.adjustData(graphViewWrapper, wiFiDetails); // validate IterableUtils.forEach(difference, new Closure<WiFiDetail>() { @Override public void execute(WiFiDetail wiFiDetail) { verify(graphViewWrapper).appendToSeries(argThat(equalTo(wiFiDetail)), argThat(new DataPointEquals(dataPoint)), argThat(equalTo(scanCount)), argThat(equalTo(wiFiDetail.getWiFiAdditional().getWiFiConnection().isConnected()))); verify(timeGraphCache).add(wiFiDetail); } }); verify(timeGraphCache).clear(); }
From source file:com.thoughtworks.go.plugin.infra.FelixGoPluginOSGiFramework.java
private Bundle getBundle(GoPluginDescriptor pluginDescriptor, File bundleLocation) { Bundle bundle = null;//from www. j a v a2s . c om try { bundle = framework.getBundleContext().installBundle("reference:" + bundleLocation.toURI()); pluginDescriptor.setBundle(bundle); bundle.start(); if (pluginDescriptor.isInvalid()) { handlePluginInvalidation(pluginDescriptor, bundleLocation, bundle); return bundle; } registry.registerExtensions(pluginDescriptor, getExtensionsInfoFromThePlugin(pluginDescriptor.id())); if (pluginExtensionsAndVersionValidator != null) { final PluginExtensionsAndVersionValidator.ValidationResult result = pluginExtensionsAndVersionValidator .validate(pluginDescriptor); if (result.hasError()) { pluginDescriptor.markAsInvalid(singletonList(result.toErrorMessage()), null); LOGGER.error(format("Skipped notifying all %s because of error: %s", PluginChangeListener.class.getSimpleName(), result.toErrorMessage())); return bundle; } } if (pluginDescriptor.isInvalid()) { return bundle; } IterableUtils.forEach(pluginChangeListeners, notifyPluginLoadedEvent(pluginDescriptor)); return bundle; } catch (Exception e) { pluginDescriptor.markAsInvalid(asList(e.getMessage()), e); LOGGER.error("Failed to load plugin: {}", bundleLocation, e); handlePluginInvalidation(pluginDescriptor, bundleLocation, bundle); throw new RuntimeException("Failed to load plugin: " + bundleLocation, e); } }
From source file:com.thoughtworks.go.server.service.BuildAssignmentService.java
protected EntityConfigChangedListener<PipelineConfig> pipelineConfigChangedListener() { return new EntityConfigChangedListener<PipelineConfig>() { @Override/*w ww . j a va 2 s . c om*/ public void onEntityConfigChange(PipelineConfig pipelineConfig) { LOGGER.info("[Configuration Changed] Removing deleted jobs for pipeline {}.", pipelineConfig.name()); synchronized (BuildAssignmentService.this) { List<JobPlan> jobsToRemove; if (goConfigService.hasPipelineNamed(pipelineConfig.name())) { jobsToRemove = getMismatchingJobPlansFromUpdatedPipeline(pipelineConfig, jobPlans); } else { jobsToRemove = getAllJobPlansFromDeletedPipeline(pipelineConfig, jobPlans); } IterableUtils.forEach(jobsToRemove, o -> removeJob(o)); } } }; }
From source file:com.vrem.wifianalyzer.wifi.channelgraph.ChannelGraphNavigationTest.java
@Test public void testUpdateWithGHZ5AndUS() throws Exception { // setup//from ww w. ja v a2s . c o m final int colorSelected = ContextCompat.getColor(mainActivity, R.color.connected); final int colorNotSelected = ContextCompat.getColor(mainActivity, R.color.connected_background); final Pair<WiFiChannel, WiFiChannel> selectedKey = WiFiBand.GHZ5.getWiFiChannels().getWiFiChannelPairs() .get(0); when(configuration.getWiFiChannelPair()).thenReturn(selectedKey); when(settings.getCountryCode()).thenReturn(Locale.US.getCountry()); when(settings.getWiFiBand()).thenReturn(WiFiBand.GHZ5); when(settings.getSortBy()).thenReturn(SortBy.CHANNEL); // execute fixture.update(WiFiData.EMPTY); // validate verify(layout).setVisibility(View.VISIBLE); IterableUtils.forEach(views.keySet(), new Closure<Pair<WiFiChannel, WiFiChannel>>() { @Override public void execute(Pair<WiFiChannel, WiFiChannel> key) { Button button = (Button) views.get(key); verify(button).setVisibility(View.VISIBLE); verify(button).setBackgroundColor(selectedKey.equals(key) ? colorSelected : colorNotSelected); verify(button).setSelected(selectedKey.equals(key)); } }); IterableUtils.forEach(ChannelGraphNavigation.ids.values(), new Closure<Integer>() { @Override public void execute(Integer id) { verify(layout, times(2)).findViewById(id); } }); verify(settings).getCountryCode(); verify(settings, times(2)).getWiFiBand(); verify(settings).getSortBy(); verify(configuration).getWiFiChannelPair(); }
From source file:com.vrem.wifianalyzer.wifi.graphutils.SeriesCacheTest.java
@Test public void testRemoveNonExistingOne() throws Exception { // setup/*from w w w . j ava2s. com*/ List<WiFiDetail> expected = withData(); List<WiFiDetail> toRemove = Collections.singletonList(makeWiFiDetail("SSID-999")); // execute List<BaseSeries<DataPoint>> actual = fixture.remove(toRemove); // validate assertTrue(actual.isEmpty()); IterableUtils.forEach(expected, new Closure<WiFiDetail>() { @Override public void execute(WiFiDetail wiFiDetail) { assertTrue(fixture.contains(wiFiDetail)); } }); }
From source file:com.vrem.util.EnumUtilsTest.java
private void validate(Collection<TestObject> expected, final Collection<TestObject> actual) { assertEquals(expected.size(), actual.size()); IterableUtils.forEach(expected, new Closure<TestObject>() { @Override/*from ww w. j a v a 2 s . c o m*/ public void execute(TestObject input) { assertTrue(actual.contains(input)); } }); }
From source file:com.vrem.wifianalyzer.wifi.channelgraph.ChannelGraphNavigationTest.java
@Test public void testUpdateGHZ5WithJapan() throws Exception { // setup/*www .j a v a2 s. co m*/ when(settings.getCountryCode()).thenReturn(Locale.JAPAN.getCountry()); when(settings.getWiFiBand()).thenReturn(WiFiBand.GHZ5); when(settings.getSortBy()).thenReturn(SortBy.CHANNEL); // execute fixture.update(WiFiData.EMPTY); // validate verify(layout).setVisibility(View.VISIBLE); IterableUtils.forEach(views.keySet(), new Closure<Pair<WiFiChannel, WiFiChannel>>() { @Override public void execute(Pair<WiFiChannel, WiFiChannel> key) { verify(views.get(key)).setVisibility(WiFiChannelsGHZ5.SET3.equals(key) ? View.GONE : View.VISIBLE); } }); verify(settings).getCountryCode(); verify(settings, times(2)).getWiFiBand(); verify(settings).getSortBy(); }
From source file:org.apache.syncope.core.logic.report.ReconciliationReportlet.java
private void doExtract(final ContentHandler handler, final List<? extends Any<?>> anys) throws SAXException, ReportException { final Set<Missing> missing = new HashSet<>(); final Set<Misaligned> misaligned = new HashSet<>(); for (Any<?> any : anys) { missing.clear();/* ww w . j av a 2 s. com*/ misaligned.clear(); AnyUtils anyUtils = anyUtilsFactory.getInstance(any); for (final ExternalResource resource : anyUtils.getAllResources(any)) { Provision provision = resource.getProvision(any.getType()); MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); final String connObjectKeyValue = connObjectKeyItem == null ? StringUtils.EMPTY : mappingManager.getConnObjectKeyValue(any, provision); if (provision != null && connObjectKeyItem != null && StringUtils.isNotBlank(connObjectKeyValue)) { // 1. read from the underlying connector Connector connector = connFactory.getConnector(resource); ConnectorObject connectorObject = connector.getObject(provision.getObjectClass(), new Uid(connObjectKeyValue), MappingUtils.buildOperationOptions(provision.getMapping().getItems().iterator())); if (connectorObject == null) { // 2. not found on resource? LOG.error("Object {} with class {} not found on resource {}", connObjectKeyValue, provision.getObjectClass(), resource); missing.add(new Missing(resource.getKey(), connObjectKeyValue)); } else { // 3. found but misaligned? Pair<String, Set<Attribute>> preparedAttrs = mappingManager.prepareAttrs(any, null, false, null, provision); preparedAttrs.getRight().add(AttributeBuilder.build(Uid.NAME, preparedAttrs.getLeft())); preparedAttrs.getRight().add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), preparedAttrs.getLeft())); final Map<String, Set<Object>> syncopeAttrs = new HashMap<>(); for (Attribute attr : preparedAttrs.getRight()) { syncopeAttrs.put(attr.getName(), attr.getValue() == null ? null : new HashSet<>(attr.getValue())); } final Map<String, Set<Object>> resourceAttrs = new HashMap<>(); for (Attribute attr : connectorObject.getAttributes()) { if (!OperationalAttributes.PASSWORD_NAME.equals(attr.getName()) && !OperationalAttributes.ENABLE_NAME.equals(attr.getName())) { resourceAttrs.put(attr.getName(), attr.getValue() == null ? null : new HashSet<>(attr.getValue())); } } IterableUtils.forEach( CollectionUtils.subtract(syncopeAttrs.keySet(), resourceAttrs.keySet()), new Closure<String>() { @Override public void execute(final String name) { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, name, syncopeAttrs.get(name), Collections.emptySet())); } }); for (Map.Entry<String, Set<Object>> entry : resourceAttrs.entrySet()) { if (syncopeAttrs.containsKey(entry.getKey())) { if (!Objects.equals(syncopeAttrs.get(entry.getKey()), entry.getValue())) { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), syncopeAttrs.get(entry.getKey()), entry.getValue())); } } else { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), Collections.emptySet(), entry.getValue())); } } } } } if (!missing.isEmpty() || !misaligned.isEmpty()) { doExtract(handler, any, missing, misaligned); } } }
From source file:org.apache.syncope.core.misc.security.AuthDataAccessor.java
@Transactional public Set<SyncopeGrantedAuthority> load(final String username) { final Set<SyncopeGrantedAuthority> authorities = new HashSet<>(); if (anonymousUser.equals(username)) { authorities.add(new SyncopeGrantedAuthority(StandardEntitlement.ANONYMOUS)); } else if (adminUser.equals(username)) { CollectionUtils.collect(EntitlementsHolder.getInstance().getValues(), new Transformer<String, SyncopeGrantedAuthority>() { @Override/*from w w w . j av a2 s. co m*/ public SyncopeGrantedAuthority transform(final String entitlement) { return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM); } }, authorities); } else { User user = userDAO.find(username); if (user == null) { throw new UsernameNotFoundException("Could not find any user with id " + username); } if (user.isMustChangePassword()) { authorities.add(new SyncopeGrantedAuthority(StandardEntitlement.MUST_CHANGE_PASSWORD)); } else { final Map<String, Set<String>> entForRealms = new HashMap<>(); // Give entitlements as assigned by roles (with realms, where applicable) - assigned either // statically and dynamically for (final Role role : userDAO.findAllRoles(user)) { IterableUtils.forEach(role.getEntitlements(), new Closure<String>() { @Override public void execute(final String entitlement) { Set<String> realms = entForRealms.get(entitlement); if (realms == null) { realms = new HashSet<>(); entForRealms.put(entitlement, realms); } CollectionUtils.collect(role.getRealms(), new Transformer<Realm, String>() { @Override public String transform(final Realm realm) { return realm.getFullPath(); } }, realms); } }); } // Give group entitlements for owned groups for (Group group : groupDAO.findOwnedByUser(user.getKey())) { for (String entitlement : Arrays.asList(StandardEntitlement.GROUP_READ, StandardEntitlement.GROUP_UPDATE, StandardEntitlement.GROUP_DELETE)) { Set<String> realms = entForRealms.get(entitlement); if (realms == null) { realms = new HashSet<>(); entForRealms.put(entitlement, realms); } realms.add(RealmUtils.getGroupOwnerRealm(group.getRealm().getFullPath(), group.getKey())); } } // Finally normalize realms for each given entitlement and generate authorities for (Map.Entry<String, Set<String>> entry : entForRealms.entrySet()) { SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entry.getKey()); authority.addRealms(RealmUtils.normalize(entry.getValue())); authorities.add(authority); } } } return authorities; }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAConnInstanceDAO.java
@Override public void delete(final String key) { ConnInstance connInstance = find(key); if (connInstance == null) { return;/*w w w. ja v a 2 s. com*/ } IterableUtils.forEach(new CopyOnWriteArrayList<>(connInstance.getResources()), new Closure<ExternalResource>() { @Override public void execute(final ExternalResource input) { resourceDAO.delete(input.getKey()); } }); entityManager().remove(connInstance); connRegistry.unregisterConnector(key.toString()); }