Example usage for org.apache.commons.collections4 CollectionUtils isEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty

Introduction

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

Prototype

public static boolean isEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is empty.

Usage

From source file:io.cloudslang.lang.compiler.modeller.transformers.NavigateTransformer.java

@Override
public TransformModellingResult<List<Map<String, String>>> transform(List<Object> rawData,
        SensitivityLevel sensitivityLevel) {
    List<Map<String, String>> transformedData = new ArrayList<>();
    List<RuntimeException> errors = new ArrayList<>();

    if (CollectionUtils.isEmpty(rawData)) {
        return new BasicTransformModellingResult<>(transformedData, errors);
    }//from w  w w. j av  a2s . c  om

    for (Object elementAsObject : rawData) {
        try {
            if (elementAsObject instanceof Map) {
                Map elementAsMap = (Map) elementAsObject;
                if (elementAsMap.size() != 1) {
                    throw new RuntimeException("Each list item in the navigate "
                            + "section should contain exactly one key:value pair.");
                }
                // - SUCCESS: some_step
                Map.Entry navigationEntry = (Map.Entry) elementAsMap.entrySet().iterator().next();
                Object navigationKey = navigationEntry.getKey();
                Object navigationValue = navigationEntry.getValue();
                if (!(navigationKey instanceof String)) {
                    throw new RuntimeException("Each key in the navigate section should be a string.");
                }
                if (!(navigationValue instanceof String)) {
                    throw new RuntimeException("Each value in the navigate section should be a string.");
                }
                @SuppressWarnings("unchecked")
                Map<String, String> elementAsStringMap = elementAsMap;
                transformedData.add(elementAsStringMap);
            } else {
                throw new RuntimeException("Navigation rule should be a Map. Actual type is "
                        + elementAsObject.getClass().getName() + ": " + elementAsObject);
            }
        } catch (RuntimeException rex) {
            errors.add(rex);
        }
    }

    try {
        List<Map<String, String>> navigationStrings = (List<Map<String, String>>) (List) rawData;
        if (!navigationStrings.isEmpty() && errors.isEmpty()) {
            executableValidator.validateNavigationStrings(navigationStrings);
        }
    } catch (RuntimeException e) {
        errors.add(e);
    }
    return new BasicTransformModellingResult<>(transformedData, errors);
}

From source file:com.ebay.myriad.scheduler.TaskTerminator.java

@Override
public void run() {
    Set<String> killableTasks = schedulerState.getKillableTasks();

    if (CollectionUtils.isEmpty(killableTasks)) {
        return;/* w w w . jav a 2s.co  m*/
    }

    Status driverStatus = driverManager.getDriverStatus();
    if (Status.DRIVER_RUNNING != driverStatus) {
        LOGGER.warn("Cannot kill tasks, as driver is not running. Status: {}", driverStatus);
        return;
    }

    Iterator<String> iterator = killableTasks.iterator();

    while (iterator.hasNext()) {
        String taskIdToKill = iterator.next();
        NodeTask task = this.schedulerState.getTask(taskIdToKill);
        TaskID mesosTaskId = task.getMesosTaskId();
        Status status = this.driverManager.kill(mesosTaskId);
        this.schedulerState.removeTask(taskIdToKill);
        Preconditions.checkState(status == Status.DRIVER_RUNNING);
    }
}

From source file:com.mirth.connect.server.api.servlets.CodeTemplateServlet.java

@Override
public List<CodeTemplateLibrary> getCodeTemplateLibraries(Set<String> libraryIds,
        boolean includeCodeTemplates) {
    try {/*from w w  w  .j a v a  2  s  .  c o m*/
        if (CollectionUtils.isEmpty(libraryIds)) {
            libraryIds = null;
        }
        return codeTemplateController.getLibraries(libraryIds, includeCodeTemplates);
    } catch (ControllerException e) {
        throw new MirthApiException(e);
    }
}

From source file:com.mpush.cache.redis.manager.ZKRedisClusterManager.java

/**
 * zk ??//from  ww  w. j  a va2s.c o  m
 */
@Override
public void init() {
    Logs.Console.info("begin init redis cluster");
    if (!ZKClient.I.isRunning())
        throw new RedisException("init redis cluster ex, ZK client not running.");

    if (CollectionUtils.isNotEmpty(CC.mp.redis.nodes)) {
        register(CC.mp.redis.nodes);
    }

    watcher.watch();
    Collection<ZKRedisNode> nodes = watcher.getCache().values();
    if (CollectionUtils.isEmpty(nodes)) {
        Logs.REDIS.error("init redis client error, redis server is none.");
        throw new RedisException("init redis client error, redis server is none.");
    }

    if (nodes.isEmpty())
        throw new RedisException("init redis sever fail groupList is null");
    Logs.Console.info("init redis cluster success...");
}

From source file:com.jkoolcloud.tnt4j.streams.scenario.WsScenario.java

/**
 * Checks if scenario has no steps defined.
 *
 * @return flag indicating scenario has no steps defined
 *//*from  ww  w.j  a va  2  s.co m*/
public boolean isEmpty() {
    return CollectionUtils.isEmpty(stepsList);
}

From source file:cop.maven.plugins.RamlMojo.java

@Override
public Set<File> getSourceDirectories() {
    if (CollectionUtils.isEmpty(sourceDirectories))
        return Collections.singleton(new File(project.getBuild().getSourceDirectory()));

    Set<File> dirs = new HashSet<>();

    for (File file : sourceDirectories)
        if (file != null && file.isDirectory())
            dirs.add(file);//from  w  w  w  .j  a  v a2s  .c o m

    return dirs;
}

From source file:com.evolveum.midpoint.web.component.prism.ShadowAssociationWrapper.java

@Override
public PrismContainer<ShadowAssociationType> createContainerAddDelta() throws SchemaException {
    if (CollectionUtils.isEmpty(getValues())) {
        return null;
    }/*from w  ww.  j ava2  s .  co  m*/

    PrismContainer<ShadowAssociationType> shadowAssociation = getItemDefinition().instantiate();

    //we know that there is always only one value
    ContainerValueWrapper<ShadowAssociationType> containerValueWrappers = getValues().iterator().next();
    for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {

        if (!(itemWrapper instanceof ReferenceWrapper)) {
            LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
            continue;
        }

        ReferenceWrapper refWrapper = (ReferenceWrapper) itemWrapper;
        if (!refWrapper.hasChanged()) {
            return null;
        }

        PrismReference updatedRef = refWrapper.getUpdatedItem(getItem().getPrismContext());

        for (PrismReferenceValue updatedRefValue : updatedRef.getValues()) {
            ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
            shadowAssociationType.setName(refWrapper.getName());
            shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue));
            shadowAssociation.add(shadowAssociationType.asPrismContainerValue());
        }

    }

    if (shadowAssociation.isEmpty() || shadowAssociation.getValues().isEmpty()) {
        return null;
    }
    return shadowAssociation;
}

From source file:com.mirth.connect.server.api.servlets.EventServlet.java

@Override
public ServerEvent getEvent(Integer eventId) {
    try {//from  www.  j a v  a  2  s  .co m
        EventFilter filter = new EventFilter();
        filter.setId(eventId);
        List<ServerEvent> events = eventController.getEvents(filter, 0, 1);
        if (CollectionUtils.isEmpty(events)) {
            throw new MirthApiException(Status.NOT_FOUND);
        }
        return events.iterator().next();
    } catch (ControllerException e) {
        throw new MirthApiException(e);
    }
}

From source file:com.haulmont.cuba.core.app.ConstraintLocalizationServiceBean.java

@Nullable
@Override//from w  ww.  j  a  va2s.  co  m
public LocalizedConstraintMessage findLocalizedConstraintMessage(String entityName,
        ConstraintOperationType operationType) {
    Preconditions.checkNotNullArgument(entityName);
    Preconditions.checkNotNullArgument(operationType);

    LoadContext<LocalizedConstraintMessage> loadContext = new LoadContext<>(LocalizedConstraintMessage.class);
    loadContext
            .setQueryString("select e from sec$LocalizedConstraintMessage e "
                    + "where e.entityName = :name and e.operationType = :type")
            .setParameter("name", entityName).setParameter("type", operationType);

    List<LocalizedConstraintMessage> localizations = dataManager.loadList(loadContext);

    if (CollectionUtils.isEmpty(localizations)) {
        return null;
    } else if (localizations.size() == 1) {
        return localizations.get(0);
    } else {
        throw new IllegalStateException(
                "Several entities with the same 'entity name/operation type' combination");
    }
}

From source file:io.cloudslang.lang.runtime.bindings.AsyncLoopBinding.java

public List<Serializable> bindAsyncLoopList(AsyncLoopStatement asyncLoopStatement, Context flowContext,
        String nodeName) {//www  .j  a  va 2s .  com
    Validate.notNull(asyncLoopStatement, "async loop statement cannot be null");
    Validate.notNull(flowContext, "flow context cannot be null");
    Validate.notNull(nodeName, "node name cannot be null");

    List<Serializable> evalResult;
    try {
        evalResult = (List<Serializable>) scriptEvaluator.evalExpr(asyncLoopStatement.getExpression(),
                flowContext.getImmutableViewOfVariables());
    } catch (Throwable t) {
        throw new RuntimeException(generateAsyncLoopExpressionMessage(nodeName, t.getMessage()), t);
    }
    if (CollectionUtils.isEmpty(evalResult)) {
        throw new RuntimeException(generateAsyncLoopExpressionMessage(nodeName, "expression is empty"));
    }
    return evalResult;
}