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:com.sap.csc.poc.ems.persistence.initial.entitlement.EntitlementHeaderAttributeDataInitializer.java

@Override
public Collection<EntitlementHeaderAttribute> create() {
    ArrayList<EntitlementHeaderAttribute> attributes = new ArrayList<>();
    // Software License
    EntitlementType sl = entitlementTypeDataInitializer.getByName("SL");
    // Software License - Header Attributes
    Field[] headerFields = FieldUtils.getAllFields(SoftwareLicenseEntitlementHeader.class);
    sl.setHeaderAttributes(new ArrayList<>(headerFields.length));
    for (Field headerField : headerFields) {
        if (!Modifier.isStatic(headerField.getModifiers()) &&
        // Exclusion from JPA annotations
                CollectionUtils.isEmpty(CollectionUtils.intersection(
                        // Annotations
                        Arrays.asList(headerField.getAnnotations()).stream()
                                .map(annotation -> annotation.annotationType()).collect(Collectors.toList()),
                        // Exclusions
                        EXCLUSION_PROPERTY_ATTRIBUTES)))
            sl.getHeaderAttributes()// www .  j a  va  2 s .  c o m
                    .add(generateEntitlementAttributes(headerField, new EntitlementHeaderAttribute()));
    }
    for (EntitlementHeaderAttribute headerAttribute : sl.getHeaderAttributes()) {
        headerAttribute.setEntitlementType(sl);
        attributes.add(headerAttribute);
    }

    return attributes;
}

From source file:com.kumarvv.setl.core.Transformer.java

/**
 * - identifies transform columns and process them one by one
 * - interpolates sql variables with values
 * - check cache for sql results, if not available runs sql and caches
 *
 * @param row//from  w  w  w  .j  a  v  a2  s.c  o m
 * @return
 */
public Map<String, Object> transform(final Map<String, Object> row) {
    if (def == null || def.getTransform() == null) {
        return new HashMap<>();
    }

    final List<Column> columns = def.getTransform().getColumns();
    if (CollectionUtils.isEmpty(columns)) {
        Logger.trace("no columns in transform config");
        return new HashMap<>();
    }

    columns.stream().forEach(col -> transformSql(row, col));
    return row;
}

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

@Override
public CodeTemplateLibrary getCodeTemplateLibrary(String libraryId, boolean includeCodeTemplates) {
    try {//ww w .ja  va  2 s. c o  m
        List<CodeTemplateLibrary> libraries = codeTemplateController
                .getLibraries(Collections.singleton(libraryId), includeCodeTemplates);
        if (CollectionUtils.isEmpty(libraries)) {
            throw new MirthApiException(Status.NOT_FOUND);
        }
        return libraries.iterator().next();
    } catch (ControllerException e) {
        throw new MirthApiException(e);
    }
}

From source file:com.braffdev.server.core.module.acceptor.AcceptorModuleInitializor.java

/**
 * @param config//from  www .ja  va 2 s. c  om
 * @return
 */
private List<Acceptor> getAcceptors(ServerConfig config) {
    if (CollectionUtils.isEmpty(config.getAcceptors())) {
        return null;
    }

    List<Acceptor> acceptors = new ArrayList<Acceptor>();
    for (AcceptorConfig accConfig : config.getAcceptors()) {
        try {
            acceptors.add(new Acceptor(accConfig));
        } catch (IOException e) {
            LOGGER.critical("Cannot initialize acceptor", e);
        }
    }

    return acceptors;
}

From source file:com.epam.catgenome.controller.vo.converter.ProjectConverter.java

/**
 * Converts a {@code List} of {@code Project} entities into {@code List} of {@code ProjectVO}
 * @param projects a {@code List} of {@code Project} entities
 * @return {@code List} of {@code ProjectVO}
 *//*from   ww w . ja  v  a2s . com*/
public static List<ProjectVO> convertTo(List<Project> projects) {
    if (CollectionUtils.isEmpty(projects)) {
        return Collections.emptyList();
    }

    return projects.stream().map(ProjectConverter::convertTo).collect(Collectors.toList());
}

From source file:eu.europa.ec.fisheries.uvms.reporting.service.bean.impl.AlarmServiceBean.java

public ObjectNode getAlarmsForMovements(AlarmMovementList alarmMovementList, String userName)
        throws ReportingServiceException {
    List<String> movementIds = getMovementIds(alarmMovementList.getAlarmMovementList());
    List<TicketAndRuleType> ticketAndRules = getTicketAndRules(movementIds);
    if (ticketAndRules == null || CollectionUtils.isEmpty(ticketAndRules)) {
        return null;
    }//w w  w  .  j av a2s  .  c  om
    return createGeoJsonWithAlarmProperties(ticketAndRules, alarmMovementList.getAlarmMovementList(), userName);
}

From source file:net.ontopia.topicmaps.rest.v1.association.AssociationController.java

public AssociationIF add(TopicMapIF tm, TopicIF type, Association association) {

    if (CollectionUtils.isEmpty(association.getRoles())) {
        throw OntopiaRestErrors.MANDATORY_FIELD_IS_NULL.build("roles");
    }//w ww  .  j  a  v  a2 s  .c o m

    TopicMapBuilderIF builder = tm.getBuilder();

    AssociationIF result = builder.makeAssociation(type);

    for (AssociationRole role : association.getRoles()) {
        roles.add(tm, result, role);
    }

    // ScopedIF
    scoped.setScope(result, association.getScope());
    // ReifiableIF
    reifiable.setReifier(result, association.getReifier());
    // TMObjectIF
    tmobject.setItemIdentifiers(result, association);

    return result;
}

From source file:net.ontopia.topicmaps.rest.v1.topic.TopicController.java

public TopicIF resolve(TopicMapIF tm, Topic topic) {
    TMObjectIF resolved = tmobject.resolve(tm, topic.getObjectId(), topic.getItemIdentifiers());
    if (resolved != null) {
        if (resolved instanceof TopicIF) {
            return (TopicIF) resolved;
        } else {/*from ww  w.  j  av  a2 s.co m*/
            throw OntopiaRestErrors.MANDATORY_OBJECT_IS_WRONG_TYPE.build("TopicIF", resolved);
        }
    }

    // SI
    if (!CollectionUtils.isEmpty(topic.getSubjectIdentifiers())) {
        for (URILocator si : topic.getSubjectIdentifiers()) {
            TopicIF t = tm.getTopicBySubjectIdentifier(si);
            if (t != null) {
                return t;
            }
        }
    }

    // SL
    if (!CollectionUtils.isEmpty(topic.getSubjectLocators())) {
        for (URILocator sl : topic.getSubjectLocators()) {
            TopicIF t = tm.getTopicBySubjectLocator(sl);
            if (t != null) {
                return t;
            }
        }
    }

    throw OntopiaRestErrors.MANDATORY_OBJECT_IS_NULL.build("TopicIF");
}

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

/**
 * Resolves the result name of an executable based on the list of all the possible results, the run context
 * and in the case of a flow, also the already preset result name
 * <p>//from  ww  w  . j  a  v  a 2 s . co  m
 * Throws a runtime exception in the following cases:
 * 1. No possible results were given
 * 2. In the case of a flow, the preset result name is not present in the possible results list
 * 3. One or more of the results contains an illegal expression - not evaluated to true\false value
 * 4. No result was resolved - none of the results expression returned true
 *
 * @param inputs          the executable's inputs
 * @param context         the run context
 * @param possibleResults list of all the possible Result objects of the executable
 * @param presetResult    a given result name. Will be not null only in the case of resolving a result of a flow
 * @return the resolved result name
 */
public String resolveResult(Map<String, Value> inputs, Map<String, Value> context,
        Set<SystemProperty> systemProperties, List<Result> possibleResults, String presetResult) {

    // We must have possible results
    if (CollectionUtils.isEmpty(possibleResults)) {
        throw new RuntimeException("No results were found");
    }

    // In case of calculating the result of a flow, we already have a preset result from the last step of the flow,
    // we look for it in the possible results of the flow.
    // If the flow has it as a possible result, we return it as the resolved result.
    // If not, we throw an exception
    if (presetResult != null) {
        for (Result possibleResult : possibleResults) {
            if (presetResult.equals(possibleResult.getName())) {
                return presetResult;
            }
        }
        throw new RuntimeException("Result: " + presetResult
                + " that was calculated in the last step is not a possible result of the flow.");
    }

    // In the case of operation, we resolve the result by searching for the first result with a true expression
    // An empty expression passes as true
    for (Result result : possibleResults) {
        String resultName = result.getName();

        if (ResultUtils.isDefaultResult(result)) {
            return resultName;
        }

        Serializable rawValue = result.getValue().get();
        if (rawValue instanceof String) {
            String expression = ExpressionUtils.extractExpression(rawValue);
            if (expression == null) {
                throw new RuntimeException(
                        "Error resolving the result. The expression: '" + rawValue + "' is not valid."
                                + " Accepted format is: " + ScoreLangConstants.EXPRESSION_START_DELIMITER
                                + " expression " + ScoreLangConstants.EXPRESSION_END_DELIMITER);
            }

            Map<String, Value> scriptContext = MapUtils.mergeMaps(inputs, context);

            try {
                Value expressionResult = scriptEvaluator.evalExpr(expression, scriptContext, systemProperties,
                        result.getFunctionDependencies());
                Boolean evaluatedResult;
                if (expressionResult.get() instanceof Integer) {
                    evaluatedResult = (Integer) expressionResult.get() != 0;
                } else {
                    evaluatedResult = (Boolean) expressionResult.get();
                }
                if (evaluatedResult == null) {
                    throw new RuntimeException("Expression of the operation result: " + expression
                            + " cannot be evaluated correctly to true or false value");
                }
                if (evaluatedResult) {
                    return resultName;
                }
            } catch (ClassCastException ex) {
                throw new RuntimeException("Error resolving the result. The expression " + expression
                        + " does not return boolean value", ex);
            } catch (Throwable t) {
                throw new RuntimeException(
                        "Error evaluating result: '" + resultName + "',\n\tError is: " + t.getMessage(), t);
            }
        } else {
            throw new RuntimeException("Error resolving the result. Value: '" + rawValue + "' is not valid.");
        }
    }
    throw new RuntimeException("No possible result was resolved");
}

From source file:me.adaptive.services.notification.NotificationSender.java

@PostConstruct
void init() {//from w  ww  . ja v  a2 s .  c  o m
    LOGGER.info("Initializing");
    if (!CollectionUtils.isEmpty(services)) {
        executorService = Executors.newFixedThreadPool(services.size(),
                new CustomizableThreadFactory("NOTIFICATION-"));
        for (NotificationService service : services) {
            if (!notificationServices.containsKey(service.getChannel())) {
                notificationServices.put(service.getChannel(), new HashSet<>());
            }
            notificationServices.get(service.getChannel()).add(service);
        }
    }
    LOGGER.info("NotificationSender initialized with {} NotificationServices with the Channels {}",
            services.size(),
            Arrays.toString(notificationServices.keySet().stream().map(Enum::toString).toArray()));
}