Java Code Examples for org.apache.commons.collections4.IterableUtils#find()
The following examples show how to use
org.apache.commons.collections4.IterableUtils#find() .
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: JmxConnectionHelper.java From cuba with Apache License 2.0 | 6 votes |
protected static ObjectName getObjectName(final MBeanServerConnection connection, final String remoteContext, final Class objectClass) throws IOException { Set<ObjectName> names = connection.queryNames(null, null); return IterableUtils.find(names, o -> { if (!Objects.equals(remoteContext, o.getDomain())) { return false; } MBeanInfo info; try { info = connection.getMBeanInfo(o); } catch (Exception e) { throw new JmxControlException(e); } return Objects.equals(objectClass.getName(), info.getClassName()); }); }
Example 2
Source File: DefaultProxyConnectorAdmin.java From archiva with Apache License 2.0 | 6 votes |
private ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId, Configuration configuration ) { if ( StringUtils.isBlank( sourceId ) ) { return null; } if ( StringUtils.isBlank( targetId ) ) { return null; } ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId ); return IterableUtils.find( configuration.getProxyConnectors(), selectedProxy ); }
Example 3
Source File: PipelineTriggerServiceIntegrationTest.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldScheduleAPipelineWithTheProvidedEncryptedEnvironmentVariable() throws CryptoException { pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true)); String digest = entityHashingService.hashForEntity(pipelineConfigService.getPipelineConfig(pipelineConfig.name().toString()), group); pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, group, digest, new HttpLocalizedOperationResult()); CaseInsensitiveString pipelineNameCaseInsensitive = new CaseInsensitiveString(this.pipelineName); assertThat(triggerMonitor.isAlreadyTriggered(pipelineNameCaseInsensitive), is(false)); PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions(); String overriddenEncryptedValue = new GoCipher().encrypt("overridden_value"); pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", overriddenEncryptedValue)); pipelineTriggerService.schedule(this.pipelineName, pipelineScheduleOptions, admin, this.result); assertThat(this.result.isSuccess(), is(true)); materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1)); BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineNameCaseInsensitive); assertNotNull(buildCause); EnvironmentVariable secureVariable = IterableUtils.find(buildCause.getVariables(), variable -> variable.getName().equals("SECURE_VAR1")); assertThat(secureVariable.getValue(), is("overridden_value")); assertThat(secureVariable.isSecure(), is(true)); }
Example 4
Source File: WiFiChannelsGHZ5.java From WiFiAnalyzer with GNU General Public License v3.0 | 5 votes |
@Override @NonNull public Pair<WiFiChannel, WiFiChannel> getWiFiChannelPairFirst(String countryCode) { Pair<WiFiChannel, WiFiChannel> found = null; if (StringUtils.isNotBlank(countryCode)) { found = IterableUtils.find(getWiFiChannelPairs(), new WiFiChannelPredicate(countryCode)); } return found == null ? SET1 : found; }
Example 5
Source File: DefaultPluginRegistry.java From gocd with Apache License 2.0 | 5 votes |
public GoPluginDescriptor getPluginByIdOrFileName(String pluginID, final String fileName) { if (pluginID != null) { GoPluginDescriptor descriptor = idToDescriptorMap.get(pluginID.toLowerCase()); if (descriptor != null) { return descriptor; } } return IterableUtils.find(idToDescriptorMap.values(), object -> object.fileName().equals(fileName)); }
Example 6
Source File: DefaultPluginJarLocationMonitor.java From gocd with Apache License 2.0 | 5 votes |
@Override public void removePluginJarChangeListener(final PluginJarChangeListener listener) { WeakReference<PluginJarChangeListener> referenceOfListenerToBeRemoved = IterableUtils.find(pluginJarChangeListeners, listenerWeakReference -> { PluginJarChangeListener registeredListener = listenerWeakReference.get(); return registeredListener != null && registeredListener == listener; }); pluginJarChangeListeners.remove(referenceOfListenerToBeRemoved); removeClearedWeakReferences(); }
Example 7
Source File: Security.java From WiFiAnalyzer with GNU General Public License v3.0 | 5 votes |
@Override public Security transform(String input) { try { return Security.valueOf(input); } catch (Exception e) { return IterableUtils.find(EnumUtils.values(Security.class), new SecurityAdditionalPredicate(input)); } }
Example 8
Source File: FindACustomerInGivenList.java From tutorials with MIT License | 5 votes |
public Customer findUsingApacheCommon(String name, List<Customer> customers) { return IterableUtils.find(customers, new org.apache.commons.collections4.Predicate<Customer>() { public boolean evaluate(Customer customer) { return customer.getName().equals(name); } }); }
Example 9
Source File: WiFiChannels.java From WiFiAnalyzer with GNU General Public License v3.0 | 5 votes |
@NonNull public WiFiChannel getWiFiChannelByFrequency(int frequency) { Pair<WiFiChannel, WiFiChannel> found = null; if (isInRange(frequency)) { found = IterableUtils.find(wiFiChannelPairs, new FrequencyPredicate(frequency)); } return found == null ? WiFiChannel.UNKNOWN : getWiFiChannel(frequency, found); }
Example 10
Source File: DefaultPluginRegistry.java From gocd with Apache License 2.0 | 5 votes |
@Override public String pluginIDFor(String bundleSymbolicName, String extensionClassCannonicalName) { final GoPluginBundleDescriptor bundleDescriptor = getBundleDescriptor(bundleSymbolicName); final GoPluginDescriptor firstPluginDescriptor = bundleDescriptor.descriptors().get(0); if (firstPluginDescriptor.extensionClasses().isEmpty()) { return firstPluginDescriptor.id(); } final GoPluginDescriptor descriptorWithExtension = IterableUtils.find(bundleDescriptor.descriptors(), pluginDescriptor -> pluginDescriptor.extensionClasses().contains(extensionClassCannonicalName)); return descriptorWithExtension == null ? null : descriptorWithExtension.id(); }
Example 11
Source File: GraphColors.java From WiFiAnalyzer with GNU General Public License v3.0 | 5 votes |
void addColor(long primaryColor) { GraphColor graphColor = IterableUtils.find(getAvailableGraphColors(), new ColorPredicate(primaryColor)); if (graphColor == null || currentGraphColors.contains(graphColor)) { return; } currentGraphColors.push(graphColor); }
Example 12
Source File: AbstractDataGridLoader.java From cuba with Apache License 2.0 | 5 votes |
protected void addDynamicAttributes(DataGrid component, MetaClass metaClass, @Nullable Datasource ds, @Nullable CollectionLoader collectionLoader, List<Column> availableColumns) { if (getMetadataTools().isPersistent(metaClass)) { String windowId = getWindowId(context); // May be no windowId, if a loader is used from a CompositeComponent if (windowId == null) { return; } Set<CategoryAttribute> attributesToShow = getDynamicAttributesGuiTools().getAttributesToShowOnTheScreen(metaClass, windowId, component.getId()); if (CollectionUtils.isNotEmpty(attributesToShow)) { if (collectionLoader != null) { collectionLoader.setLoadDynamicAttributes(true); } else if (ds != null) { ds.setLoadDynamicAttributes(true); } for (CategoryAttribute attribute : attributesToShow) { final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, attribute); Object columnWithSameId = IterableUtils.find(availableColumns, column -> { MetaPropertyPath propertyPath = column.getPropertyPath(); return propertyPath != null && propertyPath.equals(metaPropertyPath); }); if (columnWithSameId != null) { continue; } addDynamicAttributeColumn(component, attribute, metaPropertyPath); } } if (ds != null) { getDynamicAttributesGuiTools().listenDynamicAttributesChanges(ds); } } }
Example 13
Source File: AbstractTableLoader.java From cuba with Apache License 2.0 | 5 votes |
protected void addDynamicAttributes(Table component, MetaClass metaClass, @Nullable Datasource ds, @Nullable CollectionLoader collectionLoader, List<Table.Column> availableColumns) { if (getMetadataTools().isPersistent(metaClass)) { String windowId = getWindowId(context); // May be no windowId, if a loader is used from a CompositeComponent if (windowId == null) { return; } List<CategoryAttribute> attributesToShow = getDynamicAttributesGuiTools().getSortedAttributesToShowOnTheScreen(metaClass, windowId, component.getId()); if (CollectionUtils.isNotEmpty(attributesToShow)) { if (collectionLoader != null) { collectionLoader.setLoadDynamicAttributes(true); } else if (ds != null) { ds.setLoadDynamicAttributes(true); } for (CategoryAttribute attribute : attributesToShow) { MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, attribute); Object columnWithSameId = IterableUtils.find(availableColumns, o -> o.getId().equals(metaPropertyPath)); if (columnWithSameId != null) { continue; } addDynamicAttributeColumn(component, attribute, metaPropertyPath); } } if (ds != null) { getDynamicAttributesGuiTools().listenDynamicAttributesChanges(ds); } } }
Example 14
Source File: DefaultPluginRegistry.java From gocd with Apache License 2.0 | 5 votes |
@Override public GoPluginBundleDescriptor getBundleDescriptor(String bundleSymbolicName) { final GoPluginDescriptor descriptor = IterableUtils.find(idToDescriptorMap.values(), pluginDescriptor -> pluginDescriptor.bundleDescriptor().bundleSymbolicName().equals(bundleSymbolicName)); if (descriptor == null) { return null; } return descriptor.bundleDescriptor(); }
Example 15
Source File: SeriesCache.java From WiFiAnalyzer with GNU General Public License v3.0 | 4 votes |
WiFiDetail find(@NonNull Series series) { return IterableUtils.find(cache.keySet(), new FindPredicate(series)); }
Example 16
Source File: WiFiData.java From WiFiAnalyzer with GNU General Public License v3.0 | 4 votes |
@NonNull public WiFiDetail getConnection() { WiFiDetail wiFiDetail = IterableUtils.find(wiFiDetails, new ConnectionPredicate()); return wiFiDetail == null ? WiFiDetail.EMPTY : copyWiFiDetail(wiFiDetail); }
Example 17
Source File: FilterAdapter.java From WiFiAnalyzer with GNU General Public License v3.0 | 4 votes |
public boolean isActive() { return IterableUtils.find(getFilterAdapters(isAccessPoints()), new ActivePredicate()) != null; }
Example 18
Source File: PipelineTriggerServiceIntegrationTest.java From gocd with Apache License 2.0 | 4 votes |
@Test public void shouldScheduleAPipelineWithTheProvidedEnvironmentVariables() throws IOException { pipelineConfig.addEnvironmentVariable("ENV_VAR1", "VAL1"); pipelineConfig.addEnvironmentVariable("ENV_VAR2", "VAL2"); pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true)); pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR2", "SECURE_VAL2", true)); String digest = entityHashingService.hashForEntity(pipelineConfigService.getPipelineConfig(pipelineConfig.name().toString()), group); pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, group, digest, new HttpLocalizedOperationResult()); Integer pipelineCounterBefore = pipelineSqlMapDao.getCounterForPipeline(pipelineName); CaseInsensitiveString pipelineNameCaseInsensitive = new CaseInsensitiveString(this.pipelineName); assertThat(triggerMonitor.isAlreadyTriggered(pipelineNameCaseInsensitive), is(false)); PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions(); pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false)); pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true)); pipelineTriggerService.schedule(this.pipelineName, pipelineScheduleOptions, admin, result); assertThat(result.isSuccess(), is(true)); assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", this.pipelineName))); assertThat(result.httpCode(), is(202)); assertThat(triggerMonitor.isAlreadyTriggered(pipelineNameCaseInsensitive), is(true)); materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1)); BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineNameCaseInsensitive); assertNotNull(buildCause); assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername()))); assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s3")); assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1")); assertThat(buildCause.getVariables().size(), is(2)); EnvironmentVariable plainTextVariable = IterableUtils.find(buildCause.getVariables(), variable -> variable.getName().equals("ENV_VAR1")); EnvironmentVariable secureVariable = IterableUtils.find(buildCause.getVariables(), variable -> variable.getName().equals("SECURE_VAR1")); assertThat(plainTextVariable.getValue(), is("overridden_value")); assertThat(secureVariable.getValue(), is("overridden_secure_value")); assertThat(secureVariable.isSecure(), is(true)); scheduleService.autoSchedulePipelinesFromRequestBuffer(); Integer pipelineCounterAfter = pipelineSqlMapDao.getCounterForPipeline(this.pipelineName); assertThat(pipelineCounterAfter, is(pipelineCounterBefore + 1)); BuildCause buildCauseOfLatestRun = pipelineSqlMapDao.findBuildCauseOfPipelineByNameAndCounter(this.pipelineName, pipelineCounterAfter); assertThat(buildCauseOfLatestRun, is(buildCause)); }
Example 19
Source File: Record.java From dbsync with Apache License 2.0 | 3 votes |
public Value findField(final String fieldName){ Value value; value = IterableUtils.find(this, object -> object.getMetadata().getName().equals(fieldName)); return value; }
Example 20
Source File: CollectionsUtil.java From feilong-core with Apache License 2.0 | 2 votes |
/** * 迭代查找匹配<code>predicate</code> 的第一个元素并返回. * * <h3>示例:</h3> * * <blockquote> * * <p> * <b>场景:</b> 从list中查找name是 关羽,并且 age等于30的User对象 * </p> * * <pre class="code"> * List{@code <User>} list = toList(// * new User("张飞", 23), * new User("关羽", 24), * new User("刘备", 25), * new User("关羽", 30)); * * Map{@code <String, Object>} map = new HashMap{@code <>}(); * map.put("name", "关羽"); * map.put("age", 30); * * Predicate{@code <User>} predicate = BeanPredicateUtil.equalPredicate(map); * * User user = CollectionsUtil.find(list, predicate); * LOGGER.debug(JsonUtil.format(user)); * </pre> * * <b>返回:</b> * * <pre class="code"> * { * "age": 30, * "name": "关羽" * } * </pre> * * </blockquote> * * <h3>说明:</h3> * <blockquote> * <ol> * <li>返回第一个匹配对象</li> * </ol> * </blockquote> * * @param <O> * the generic type * @param iterable * the iterable to search, may be null * @param predicate * the predicate to use, may not be null * @return 如果 <code>predicate</code> 是 null,将抛出{@link NullPointerException} <br> * 如果 <code>iterable</code>是null, 返回null<br> * 如果 <code>iterable</code>中没有相关元素匹配 <code>predicate</code>,返回null * @see IterableUtils#find(Iterable, Predicate) * @since 1.5.5 */ public static <O> O find(Iterable<O> iterable,Predicate<O> predicate){ return IterableUtils.find(iterable, predicate); }