Example usage for org.apache.commons.collections4 IterableUtils find

List of usage examples for org.apache.commons.collections4 IterableUtils find

Introduction

In this page you can find the example usage for org.apache.commons.collections4 IterableUtils find.

Prototype

public static <E> E find(final Iterable<E> iterable, final Predicate<? super E> predicate) 

Source Link

Document

Finds the first element in the given iterable which matches the given predicate.

Usage

From source file:com.thoughtworks.go.server.service.PipelineTriggerServiceIntegrationTest.java

@Test
public void shouldScheduleAPipelineWithTheProvidedEncryptedEnvironmentVariable() throws CryptoException {
    pipelineConfig.addEnvironmentVariable(
            new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
    pipelineConfigService.updatePipelineConfig(admin, pipelineConfig,
            entityHashingService.md5ForEntity(pipelineConfig), 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, result);

    assertThat(result.isSuccess(), is(true));
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));

    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineNameCaseInsensitive);
    assertNotNull(buildCause);/*from   w  ww. j ava  2 s .  c  o  m*/
    EnvironmentVariable secureVariable = IterableUtils.find(buildCause.getVariables(),
            variable -> variable.getName().equals("SECURE_VAR1"));
    assertThat(secureVariable.getValue(), is("overridden_value"));
    assertThat(secureVariable.isSecure(), is(true));
}

From source file:it.infn.ct.futuregateway.apiserver.resources.Task.java

/**
 * Retrieves the associated infrastructure Id.
 * This is the infrastructure selected to execute the task among
 * the many the application can run on.//  w ww.  java2 s.co  m
 *
 * @return The infrastructure
 */
@Transient
public Infrastructure getAssociatedInfrastructure() {
    if (applicationDetail == null) {
        return null;
    }
    return IterableUtils.find(applicationDetail.getInfrastructures(), new Predicate<Infrastructure>() {
        @Override
        public boolean evaluate(final Infrastructure t) {
            return t.getId().equals(getAssociatedInfrastructureId());
        }
    });
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.DataGridLoader.java

protected void addDynamicAttributes(DataGrid component, Datasource ds, List<Column> availableColumns) {
    if (metadataTools.isPersistent(ds.getMetaClass())) {
        Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools
                .getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId());
        if (CollectionUtils.isNotEmpty(attributesToShow)) {
            ds.setLoadDynamicAttributes(true);
            for (CategoryAttribute attribute : attributesToShow) {
                final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils
                        .getMetaPropertyPath(ds.getMetaClass(), attribute);

                Object columnWithSameId = IterableUtils.find(availableColumns, column -> {
                    MetaPropertyPath propertyPath = column.getPropertyPath();
                    return propertyPath != null && propertyPath.equals(metaPropertyPath);
                });//  w  ww  . j  av a 2 s .  co m

                if (columnWithSameId != null) {
                    continue;
                }

                final Column column = component.addColumn(metaPropertyPath.getMetaProperty().getName(),
                        metaPropertyPath);

                column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames())
                        ? attribute.getLocaleName()
                        : StringUtils.capitalize(attribute.getName()));
            }
        }

        dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
    }
}

From source file:it.infn.ct.futuregateway.apiserver.resources.Task.java

/**
 * Update the status of input files./* w w w  .  j  a va 2 s . com*/
 * Change the status value for the input file specified. If the name is not
 * associated with any input file nothing happen.
 * <p>
 * There is not check on the file existence and real status which
 * is delegated to the caller object.
 *
 * @param name File name
 * @param aStatus New status
 */
public final void updateInputFileStatus(final String name, final TaskFile.FILESTATUS aStatus) {

    TaskFileInput tfi = IterableUtils.find(inputFiles, new Predicate<TaskFileInput>() {
        @Override
        public boolean evaluate(final TaskFileInput t) {
            return t.getName().equals(name);
        }
    });
    if (tfi != null) {
        tfi.setStatus(aStatus);
        lastChange = new Date();
        setChanged();
        notifyObservers();
    }
}

From source file:com.feilong.core.util.CollectionsUtil.java

/**
 * ?<code>predicate</code> .
 * //from   w  w w .j av  a  2 s.co  m
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * List{@code <User>} list = toList(//
 *                 new User("", 23),
 *                 new User("", 24),
 *                 new User("", 25),
 *                 new User("", 30));
 * Predicate{@code <User>} predicate = PredicateUtils
 *                 .andPredicate(BeanPredicateUtil.equalPredicate("name", ""), BeanPredicateUtil.equalPredicate("age", 30));
 * User user = CollectionsUtil.find(list, predicate);
 * LOGGER.debug(JsonUtil.format(user));
 * 
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 * {
"age": 30,
"name": ""
 * }
 * </pre>
 * 
 * </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);
}

From source file:org.apache.syncope.client.console.panels.ResourceMappingPanel.java

private List<String> getSchemaNames(final Long connectorId, final Set<ConnConfProperty> conf) {
    final ConnInstanceTO connInstanceTO = new ConnInstanceTO();
    connInstanceTO.setKey(connectorId);/*from w w  w  .j  a va 2  s. c om*/
    connInstanceTO.getConf().addAll(conf);

    // SYNCOPE-156: use provided info to give schema names (and type!) by ObjectClass
    ConnIdObjectClassTO clazz = IterableUtils.find(connRestClient.buildObjectClassInfo(connInstanceTO, true),
            new Predicate<ConnIdObjectClassTO>() {

                @Override
                public boolean evaluate(final ConnIdObjectClassTO object) {
                    return object.getType()
                            .equalsIgnoreCase(ResourceMappingPanel.this.provisionTO.getObjectClass());
                }
            });

    return clazz == null ? new ArrayList<String>()
            : IterableUtils
                    .toList(IterableUtils.filteredIterable(clazz.getAttributes(), new Predicate<String>() {

                        @Override
                        public boolean evaluate(final String object) {
                            return !("__NAME__".equals(object) || "__ENABLE__".equals(object)
                                    || "__PASSWORD__".equals(object));
                        }
                    }));
}

From source file:org.apache.syncope.client.console.panels.VirSchemaDetails.java

private List<String> getExtAttrNames() {
    ConnInstanceTO connInstanceTO = new ConnInstanceTO();
    connInstanceTO.setKey(selectedResource.getConnector());
    connInstanceTO.getConf().addAll(selectedResource.getConfOverride());

    ConnIdObjectClassTO connIdObjectClass = IterableUtils.find(
            connRestClient.buildObjectClassInfo(connInstanceTO, false), new Predicate<ConnIdObjectClassTO>() {

                @Override/*from  w  ww  . ja  v a2s .c om*/
                public boolean evaluate(final ConnIdObjectClassTO object) {
                    return object.getType().equals(anyTypes.get(anyType.getModelObject()));
                }
            });

    return connIdObjectClass == null ? Collections.<String>emptyList() : connIdObjectClass.getAttributes();
}

From source file:org.apache.syncope.client.console.wicket.markup.html.form.SelectChoiceRenderer.java

@Override
public T getObject(final String id, final IModel<? extends List<? extends T>> choices) {
    return IterableUtils.find(choices.getObject(), new Predicate<T>() {

        @Override/*from ww  w. j a  v  a2  s  .c  o m*/
        public boolean evaluate(final T object) {
            return id != null && id.equals(getIdValue(object, 0));
        }
    });
}

From source file:org.apache.syncope.client.console.widgets.reconciliation.ReconciliationReportParser.java

public static ReconciliationReport parse(final Date run, final InputStream in) throws XMLStreamException {
    XMLStreamReader streamReader = INPUT_FACTORY.createXMLStreamReader(in);
    streamReader.nextTag(); // root
    streamReader.nextTag(); // report
    streamReader.nextTag(); // reportlet

    ReconciliationReport report = new ReconciliationReport(run);

    List<Missing> missing = new ArrayList<>();
    List<Misaligned> misaligned = new ArrayList<>();
    Set<String> onSyncope = null;
    Set<String> onResource = null;

    Any user = null;/*  ww  w  . j a  v  a  2 s.  co  m*/
    Any group = null;
    Any anyObject = null;
    String lastAnyType = null;
    while (streamReader.hasNext()) {
        if (streamReader.isStartElement()) {
            switch (streamReader.getLocalName()) {
            case "users":
                Anys users = new Anys();
                users.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total")));
                report.setUsers(users);
                break;

            case "user":
                user = new Any();
                user.setType(AnyTypeKind.USER.name());
                user.setKey(streamReader.getAttributeValue("", "key"));
                user.setName(streamReader.getAttributeValue("", "username"));
                report.getUsers().getAnys().add(user);
                break;

            case "groups":
                Anys groups = new Anys();
                groups.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total")));
                report.setGroups(groups);
                break;

            case "group":
                group = new Any();
                group.setType(AnyTypeKind.GROUP.name());
                group.setKey(streamReader.getAttributeValue("", "key"));
                group.setName(streamReader.getAttributeValue("", "groupName"));
                report.getGroups().getAnys().add(group);
                break;

            case "anyObjects":
                lastAnyType = streamReader.getAttributeValue("", "type");
                Anys anyObjects = new Anys();
                anyObjects.setAnyType(lastAnyType);
                anyObjects.setTotal(Integer.valueOf(streamReader.getAttributeValue("", "total")));
                report.getAnyObjects().add(anyObjects);
                break;

            case "anyObject":
                anyObject = new Any();
                anyObject.setType(lastAnyType);
                anyObject.setKey(streamReader.getAttributeValue("", "key"));
                final String anyType = lastAnyType;
                IterableUtils.find(report.getAnyObjects(), new Predicate<Anys>() {

                    @Override
                    public boolean evaluate(final Anys anys) {
                        return anyType.equals(anys.getAnyType());
                    }
                }).getAnys().add(anyObject);
                break;

            case "missing":
                missing.add(new Missing(streamReader.getAttributeValue("", "resource"),
                        streamReader.getAttributeValue("", "connObjectKeyValue")));
                break;

            case "misaligned":
                misaligned.add(new Misaligned(streamReader.getAttributeValue("", "resource"),
                        streamReader.getAttributeValue("", "connObjectKeyValue"),
                        streamReader.getAttributeValue("", "name")));
                break;

            case "onSyncope":
                onSyncope = new HashSet<>();
                break;

            case "onResource":
                onResource = new HashSet<>();
                break;

            case "value":
                Set<String> set = onSyncope == null ? onResource : onSyncope;
                set.add(streamReader.getElementText());
                break;

            default:
            }
        } else if (streamReader.isEndElement()) {
            switch (streamReader.getLocalName()) {
            case "user":
                user.getMissing().addAll(missing);
                user.getMisaligned().addAll(misaligned);
                missing.clear();
                misaligned.clear();
                break;

            case "group":
                group.getMissing().addAll(missing);
                group.getMisaligned().addAll(misaligned);
                missing.clear();
                misaligned.clear();
                break;

            case "anyObject":
                anyObject.getMissing().addAll(missing);
                anyObject.getMisaligned().addAll(misaligned);
                missing.clear();
                misaligned.clear();
                break;

            case "onSyncope":
                misaligned.get(misaligned.size() - 1).getOnSyncope().addAll(onSyncope);
                onSyncope = null;
                break;

            case "onResource":
                misaligned.get(misaligned.size() - 1).getOnResource().addAll(onResource);
                onResource = null;
                break;

            default:
            }

        }

        streamReader.next();
    }

    return report;
}

From source file:org.apache.syncope.common.lib.patch.GroupPatch.java

@JsonIgnore
public TypeExtensionTO getTypeExtension(final String anyType) {
    return IterableUtils.find(typeExtensions, new Predicate<TypeExtensionTO>() {

        @Override/*  w ww. j a va 2 s. co  m*/
        public boolean evaluate(final TypeExtensionTO typeExtension) {
            return anyType != null && anyType.equals(typeExtension.getAnyType());
        }
    });
}