/** * Finds the first element in the given collection which matches the given predicate. * <p> * If the input collection or predicate is null, or no element of the collection * matches the predicate, null is returned. * * @param <T> the type of object the {@link Iterable} contains * @param collection the collection to search, may be null * @param predicate the predicate to use, may be null * @return the first element of the collection which matches the predicate or null if none could be found * @deprecated since 4.1, use {@link IterableUtils#find(Iterable, Predicate)} instead */ @Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) { return predicate != null ? IterableUtils.find(collection, predicate) : null; }
@Override public void removePluginJarChangeListener(final PluginJarChangeListener listener) { WeakReference<PluginJarChangeListener> referenceOfListenerToBeRemoved = IterableUtils.find(pluginJarChangeListener, listenerWeakReference -> { PluginJarChangeListener registeredListener = listenerWeakReference.get(); return registeredListener != null && registeredListener == listener; }); pluginJarChangeListener.remove(referenceOfListenerToBeRemoved); removeClearedWeakReferences(); }
public CommandSnippet findByRelativePath(final String snippetRelativePath) { return find(snippets, commandSnippet -> commandSnippet.getRelativePath().equals(snippetRelativePath)); }
public GoPluginDescriptor getPluginByIdOrFileName(String pluginID, final String fileName) { if (pluginID != null) { GoPluginDescriptor descriptor = idToDescriptorMap.get(pluginID); if (descriptor != null) { return descriptor; } } return IterableUtils.find(idToDescriptorMap.values(), object -> object.fileName().equals(fileName)); }
private void validateIfRevisionMatchesTheCurrentConfig(ReportingFanInGraphContext context, Pair<StageIdentifier, List<ReportingFaninScmMaterial>> stageIdentifierScmPair) { if (stageIdentifierScmPair == null) { return; } final Set<MaterialConfig> currentScmMaterials = context.pipelineScmDepMap.get(materialConfig); final List<ReportingFaninScmMaterial> scmMaterials = stageIdentifierScmPair.last(); printCurrentAndOldSCMs(context, currentScmMaterials, scmMaterials, stageIdentifierScmPair); final List<ReportingFaninScmMaterial> setOfRevisions = new ArrayList<>(); for (final ReportingFaninScmMaterial scmMaterial : scmMaterials) { ReportingFaninScmMaterial mat = IterableUtils.find(setOfRevisions, mat1 -> { if (mat1 == null) { return false; } return scmMaterial.fingerprint.equals(mat1.fingerprint) && scmMaterial.revision.equals(mat1.revision); }); if (mat == null) { setOfRevisions.add(scmMaterial); } } context.out.println("SCM Revisions of Latest Revision of Material:"); context.out.println(setOfRevisions); }
/** * Detects the presence of the {@link EntityMarkerClassTransformer} and throws an exception if this is misconfigured. If there * are no class transformes within {@link #mergedClassTransformers} then this does nothing */ protected void exceptionIfEntityMarkerNotFound() { if (CollectionUtils.isNotEmpty(mergedClassTransformers)) { boolean foundEntityMarkerTransformer = IterableUtils.find(mergedClassTransformers, new Predicate<BroadleafClassTransformer>(){ @Override public boolean evaluate(BroadleafClassTransformer object) { return EntityMarkerClassTransformer.class.isAssignableFrom(object.getClass()); } }) != null; if (!foundEntityMarkerTransformer) { BeanDefinition transformersBeanDef = ((BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory()).getBeanDefinition("blMergedClassTransformers"); String msg = "The EntityMarkerClassTransformer was not detected as registered in the the list of blMergedClassTransformers. This is" + " usually caused the blMergedClassTransformers being overridden in a different configuration. Without this transformer Broadleaf" + " is unable to validate whether or not class transformation happened as expected. This bean was registered as " + transformersBeanDef + " but it should have been detected as registerd in bl-common-applicationContext.xml. Change the definition in " + transformersBeanDef.getResourceDescription() + " to instead utilize the EarlyStageMergeBeanPostProcessor in XML or an @Merge(targetRef=\"blMergedClassTransformers\" early = true) in a Java configuration class"; throw new IllegalStateException(msg); } } }
@NonNull private static Locale find(List<Locale> locales, Predicate<Locale> predicate) { Locale result = IterableUtils.find(locales, predicate); return result == null ? SyncAvoid.DEFAULT : result; }
WiFiDetail find(@NonNull Series series) { return IterableUtils.find(cache.keySet(), new FindPredicate(series)); }
void addColor(long primaryColor) { GraphColor graphColor = IterableUtils.find(getAvailableGraphColors(), new ColorPredicate(primaryColor)); if (graphColor == null || currentGraphColors.contains(graphColor)) { return; } currentGraphColors.push(graphColor); }
public Validator getValidatorByName(final String name) { return (Validator) IterableUtils.find(this.validators, (Predicate) object -> StringUtils.equals(((Validator) object).getName(), name)); }
@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; }
public static synchronized ProductType getProduct(int vendorId, final int productId, String... searchPaths) { LOGGER.info("Load the product with vendorId: {} and productId: {}", vendorId, productId); List<ProductType> products = new BidibProductsFactory().loadProducts(vendorId, searchPaths); if (CollectionUtils.isNotEmpty(products)) { ProductType product = IterableUtils.find(products, new Predicate<ProductType>() { @Override public boolean evaluate(ProductType product) { return product.getProductTypeId() == productId; } }); return product; } return null; }
@NonNull public WiFiDetail getConnection() { WiFiDetail wiFiDetail = IterableUtils.find(wiFiDetails, new ConnectionPredicate()); return wiFiDetail == null ? WiFiDetail.EMPTY : copyWiFiDetail(wiFiDetail); }
@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); }
public void assignPermissionVariant(final String attribute, AttributePermissionVariant permissionVariant) { AttributeTarget attrTarget = IterableUtils.find(getPermissions(), object -> object != null && attribute.equals(object.getId())); if (attrTarget != null) { attrTarget.setPermissionVariant(permissionVariant); } }
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()); }); }
@NonNull public static Security findOne(String capabilities) { Security result = IterableUtils.find(EnumUtils.values(Security.class), new SecurityPredicate(findAll(capabilities))); return result == null ? Security.NONE : result; }
public AttributePermissionVariant getPermissionVariant(final String attribute) { AttributeTarget attrTarget = IterableUtils.find(getPermissions(), object -> object != null && attribute.equals(object.getId())); if (attrTarget != null) return attrTarget.getPermissionVariant(); else return null; }
@NonNull WiFiChannel getWiFiChannelByChannel(int channel) { Pair<WiFiChannel, WiFiChannel> found = IterableUtils.find(wiFiChannelPairs, new ChannelPredicate(channel)); return found == null ? WiFiChannel.UNKNOWN : new WiFiChannel(channel, found.first.getFrequency() + ((channel - found.first.getChannel()) * FREQUENCY_SPREAD)); }
public boolean isActive() { return IterableUtils.find(getFilterAdapters(isAccessPoints()), new ActivePredicate()) != null; }