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.AbstractOutputsTransformer.java

public TransformModellingResult<List<Output>> transform(List<Object> rawData) {
    List<Output> transformedData = new ArrayList<>();
    List<RuntimeException> errors = new ArrayList<>();

    if (CollectionUtils.isEmpty(rawData)) {
        return new BasicTransformModellingResult<>(transformedData, errors);
    }//from  w  w  w.  ja v a2s. co m

    for (Object rawOutput : rawData) {
        try {
            if (rawOutput instanceof Map) {

                @SuppressWarnings("unchecked")
                Map.Entry<String, ?> entry = ((Map<String, ?>) rawOutput).entrySet().iterator().next();
                Serializable entryValue = (Serializable) entry.getValue();
                if (entryValue == null) {
                    throw new RuntimeException(
                            "Could not transform Output : " + rawOutput + " since it has a null value.\n\n"
                                    + "Make sure a value is specified or that indentation is properly done.");
                }
                if (entryValue instanceof Map) {
                    // - some_output:
                    //     property1: value1
                    //     property2: value2
                    // this is the verbose way of defining outputs with all of the properties available
                    handleOutputProperties(transformedData, entry, errors);
                } else {
                    // - some_output: some_expression
                    addOutput(transformedData, createOutput(entry.getKey(), entryValue, false), errors);
                }
            } else {
                //- some_output
                //this is our default behavior that if the user specifies only a key,
                // the key is also the ref we look for
                addOutput(transformedData, createRefOutput((String) rawOutput, false), errors);
            }
        } catch (RuntimeException rex) {
            errors.add(rex);
        }
    }
    return new BasicTransformModellingResult<>(transformedData, errors);
}

From source file:co.rsk.validators.BlockTxsValidationRule.java

@Override
public boolean isValid(Block block, Block parent) {
    if (block == null || parent == null) {
        return false;
    }/* w  w w . j av  a 2 s .c o  m*/

    List<Transaction> txs = block.getTransactionsList();
    if (CollectionUtils.isEmpty(txs))
        return true;

    Repository parentRepo = repository.getSnapshotTo(parent.getStateRoot());

    Map<ByteArrayWrapper, BigInteger> curNonce = new HashMap<>();

    for (Transaction tx : txs) {
        byte[] txSender = tx.getSender();
        ByteArrayWrapper key = new ByteArrayWrapper(txSender);
        BigInteger expectedNonce = curNonce.get(key);
        if (expectedNonce == null) {
            expectedNonce = parentRepo.getNonce(txSender);
        }
        curNonce.put(key, expectedNonce.add(ONE));
        BigInteger txNonce = new BigInteger(1, tx.getNonce());

        if (!expectedNonce.equals(txNonce)) {
            logger.error("Invalid transaction: Tx nonce {} != expected nonce {} (parent nonce: {}): {}",
                    txNonce, expectedNonce, parentRepo.getNonce(txSender), tx);

            panicProcessor.panic("invalidtransaction",
                    String.format(
                            "Invalid transaction: Tx nonce %s != expected nonce %s (parent nonce: %s): %s",
                            txNonce.toString(), expectedNonce.toString(),
                            parentRepo.getNonce(txSender).toString(), Hex.toHexString(tx.getHash())));

            return false;
        }
    }

    return true;
}

From source file:io.kodokojo.bdd.MarathonBrickUrlFactory.java

@Override
public String forgeUrl(String entity, String projectName, String stackName, String brickType,
        String brickName) {//from   w  w w.j  a v  a 2  s.  co  m
    Set<Service> services = marathonServiceLocator.getService(brickType, projectName);
    if (CollectionUtils.isEmpty(services)) {
        return fallBack.forgeUrl(entity, projectName, stackName, brickName, brickName);
    } else {
        Service service = services.iterator().next();
        return service.getHost() + ":" + service.getPort();
    }
}

From source file:com.thoughtworks.go.config.SecretParams.java

public static SecretParams union(SecretParams... params) {
    final SecretParams newMergedList = new SecretParams();
    for (SecretParams param : params) {
        if (!CollectionUtils.isEmpty(param)) {
            newMergedList.addAll(param);
        }// w  ww .jav a2  s  .c  o m
    }
    return newMergedList;
}

From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetFileName.java

/**
 * Resolves file name from provided file path. File path can be provided as {@link String}, {@link Node} or
 * {@link NodeList} (first node item containing file path).
 *
 * @param args//from  w ww  .  j a v a2 s  . co  m
 *            arguments list containing file path as first item
 * @return file name resolved from provided path
 *
 * @see Node
 * @see NodeList
 */
@Override
@SuppressWarnings("rawtypes")
public Object evaluate(List args) {
    Object param = CollectionUtils.isEmpty(args) ? null : args.get(0);

    if (param == null) {
        return param;
    }

    String filePath = null;
    if (param instanceof String) {
        filePath = (String) param;
    } else if (param instanceof Node) {
        filePath = ((Node) param).getTextContent();
    } else if (param instanceof NodeList) {
        NodeList nodes = (NodeList) param;

        if (nodes.getLength() > 0) {
            Node node = nodes.item(0);
            filePath = node.getTextContent();
        }
    }

    if (StringUtils.isEmpty(filePath)) {
        return filePath;
    }

    return filePath.substring(filePath.lastIndexOf(UNIX_PATH_SEPARATOR) + 1)
            .substring(filePath.lastIndexOf(WIN_PATH_SEPARATOR) + 1);
}

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

@Override
public List<DashboardStatus> getChannelStatusList(Set<String> channelIds, boolean includeUndeployed) {
    if (CollectionUtils.isEmpty(channelIds)) {
        return redactChannelStatuses(engineController.getChannelStatusList(null, includeUndeployed));
    } else {/*  w w w  .jav  a 2 s  .c om*/
        return engineController.getChannelStatusList(redactChannelIds(channelIds), includeUndeployed);
    }
}

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

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

    // If there are no results specified, add the default SUCCESS & FAILURE results
    if (CollectionUtils.isEmpty(rawData)) {
        return postProcessResults(transformedData, errors);
    }/*from w w  w  .ja  va 2s . c  o m*/
    for (Object rawResult : rawData) {
        try {
            if (rawResult instanceof String) {
                //- some_result
                addResult(transformedData, createNoExpressionResult((String) rawResult), errors);
            } else if (rawResult instanceof Map) {
                // - some_result: some_expression
                // the value of the result is an expression we need to evaluate at runtime
                @SuppressWarnings("unchecked")
                Map.Entry<String, Serializable> entry = (Map.Entry<String, Serializable>) (((Map) rawResult)
                        .entrySet()).iterator().next();
                addResult(transformedData, createExpressionResult(entry.getKey(), entry.getValue()), errors);
            }
        } catch (RuntimeException rex) {
            errors.add(rex);
        }
    }
    return postProcessResults(transformedData, errors);
}

From source file:com.sap.csc.poc.ems.persistence.initial.entitlement.EntitlementItemAttributeDataInitializer.java

@Override
public Collection<EntitlementItemAttribute> create() {
    ArrayList<EntitlementItemAttribute> attributes = new ArrayList<>();
    // Software License
    EntitlementType sl = entitlementTypeDataInitializer.getByName("SL");
    // Software License - Item Attributes
    Field[] itemFields = FieldUtils.getAllFields(SoftwareLicenseEntitlementItem.class);
    sl.setItemAttributes(new ArrayList<>(itemFields.length));
    for (Field itemField : itemFields) {
        if (!Modifier.isStatic(itemField.getModifiers()) &&
        // Exclusion from JPA annotations
                CollectionUtils.isEmpty(CollectionUtils.intersection(
                        // Annotations
                        Arrays.asList(itemField.getAnnotations()).stream()
                                .map(annotation -> annotation.annotationType()).collect(Collectors.toList()),
                        // Exclusions
                        EXCLUSION_PROPERTY_ATTRIBUTES)))
            sl.getItemAttributes()/* www  . j  a  va  2  s  .c om*/
                    .add(generateEntitlementAttributes(itemField, new EntitlementItemAttribute()));
    }
    for (EntitlementItemAttribute itemAttribute : sl.getItemAttributes()) {
        itemAttribute.setEntitlementType(sl);
        attributes.add(itemAttribute);
    }

    return attributes;
}

From source file:com.boozallen.cognition.ingest.storm.bolt.enrich.GeoJsonPointReverseArrayBolt.java

String reverseJsonArray(String src) {
    Gson gson = new Gson();
    List list = gson.fromJson(src, List.class);

    if (CollectionUtils.isEmpty(list)) {
        return StringUtils.EMPTY;
    } else {/*from   w w  w  . j ava2 s .c  o m*/
        Collections.reverse(list);
        return gson.toJson(list);
    }
}

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

@Override
public void deployChannels(Set<String> channelIds, boolean returnErrors) {
    if (CollectionUtils.isEmpty(channelIds)) {
        channelIds = channelController.getChannelIds();
    }/*from  ww w .j  a  va 2 s  .  com*/
    ErrorTaskHandler handler = new ErrorTaskHandler();
    engineController.deployChannels(redactChannelIds(channelIds), context, handler);
    if (returnErrors && handler.isErrored()) {
        throw new MirthApiException(handler.getError());
    }
}