Example usage for org.apache.commons.collections4 MapUtils isNotEmpty

List of usage examples for org.apache.commons.collections4 MapUtils isNotEmpty

Introduction

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

Prototype

public static boolean isNotEmpty(final Map<?, ?> map) 

Source Link

Document

Null-safe check if the specified map is not empty.

Usage

From source file:io.cloudslang.lang.tools.build.tester.parallel.MultiTriggerTestCaseEventListener.java

@Override
public synchronized void onEvent(ScoreEvent scoreEvent) throws InterruptedException {
    @SuppressWarnings("unchecked")
    Map<String, Serializable> data = (Map<String, Serializable>) scoreEvent.getData();
    LanguageEventData eventData;//w  ww.j  a v  a2 s. com
    Long executionId = (data instanceof LanguageEventData) ? (((LanguageEventData) data).getExecutionId())
            : (Long) ((Map) data.get(SYSTEM_CONTEXT)).get(EXECUTION_ID_CONTEXT);

    switch (scoreEvent.getEventType()) {
    case SCORE_FINISHED_EVENT:
        break;
    case SCORE_ERROR_EVENT:
    case SCORE_FAILURE_EVENT:
        String errorMessage = data.get(SCORE_ERROR_LOG_MSG) + " , " + data.get(SCORE_ERROR_MSG);
        errorMessageMap.put(executionId, errorMessage);
        flowFinishedMap.put(executionId, true);
        break;

    case EVENT_EXECUTION_FINISHED:
        eventData = (LanguageEventData) data;
        resultMap.put(executionId, eventData.getResult());
        flowFinishedMap.put(executionId, true);
        break;

    case EVENT_OUTPUT_END:
        eventData = (LanguageEventData) data;
        Map<String, Serializable> extractOutputs = TriggerTestCaseEventListener.extractOutputs(eventData);
        if (MapUtils.isNotEmpty(extractOutputs)) {
            outputsMap.put(executionId, extractOutputs);
        }
        break;
    default:
        break;
    }
}

From source file:io.github.swagger2markup.internal.component.PropertiesTableComponent.java

public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    //TODO: This method is too complex, split it up in smaller methods to increase readability
    StringColumn.Builder nameColumnBuilder = StringColumn
            .builder(ColumnIds.StringColumnId.of(labels.getLabel(NAME_COLUMN)))
            .putMetaData(TableComponent.WIDTH_RATIO, "3");

    StringColumn.Builder descriptionColumnBuilder = StringColumn
            .builder(ColumnIds.StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
            .putMetaData(TableComponent.WIDTH_RATIO, "11").putMetaData(TableComponent.HEADER_COLUMN, "true");

    StringColumn.Builder schemaColumnBuilder = StringColumn
            .builder(ColumnIds.StringColumnId.of(labels.getLabel(SCHEMA_COLUMN)))
            .putMetaData(TableComponent.WIDTH_RATIO, "4").putMetaData(TableComponent.HEADER_COLUMN, "true");

    Map<String, Property> properties = params.properties;
    if (MapUtils.isNotEmpty(properties)) {
        Map<String, Property> sortedProperties = toSortedMap(properties, config.getPropertyOrdering());
        sortedProperties.forEach((String propertyName, Property property) -> {
            PropertyAdapter propertyAdapter = new PropertyAdapter(property);
            Type propertyType = propertyAdapter.getType(definitionDocumentResolver);

            if (config.isInlineSchemaEnabled()) {
                propertyType = createInlineType(propertyType, propertyName,
                        params.parameterName + " " + propertyName, params.inlineDefinitions);
            }/*from  ww w . ja  v a 2  s .c  o m*/

            Optional<Object> optionalExample = propertyAdapter.getExample(config.isGeneratedExamplesEnabled(),
                    markupDocBuilder);
            Optional<Object> optionalDefaultValue = propertyAdapter.getDefaultValue();
            Optional<Integer> optionalMaxLength = propertyAdapter.getMaxlength();
            Optional<Integer> optionalMinLength = propertyAdapter.getMinlength();
            Optional<String> optionalPattern = propertyAdapter.getPattern();
            Optional<Number> optionalMinValue = propertyAdapter.getMin();
            boolean exclusiveMin = propertyAdapter.getExclusiveMin();
            Optional<Number> optionalMaxValue = propertyAdapter.getMax();
            boolean exclusiveMax = propertyAdapter.getExclusiveMax();

            MarkupDocBuilder propertyNameContent = copyMarkupDocBuilder(markupDocBuilder);
            propertyNameContent.boldTextLine(propertyName, true);
            if (property.getRequired())
                propertyNameContent.italicText(labels.getLabel(FLAGS_REQUIRED).toLowerCase());
            else
                propertyNameContent.italicText(labels.getLabel(FLAGS_OPTIONAL).toLowerCase());
            if (propertyAdapter.getReadOnly()) {
                propertyNameContent.newLine(true);
                propertyNameContent.italicText(labels.getLabel(FLAGS_READ_ONLY).toLowerCase());
            }

            MarkupDocBuilder descriptionContent = copyMarkupDocBuilder(markupDocBuilder);
            String description = markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder,
                    property.getDescription());
            if (isNotBlank(description))
                descriptionContent.text(description);

            if (optionalDefaultValue.isPresent()) {
                if (isNotBlank(descriptionContent.toString())) {
                    descriptionContent.newLine(true);
                }
                descriptionContent.boldText(labels.getLabel(DEFAULT_COLUMN)).text(COLON)
                        .literalText(Json.pretty(optionalDefaultValue.get()));
            }

            if (optionalMinLength.isPresent() && optionalMaxLength.isPresent()) {
                // combination of minlength/maxlength
                Integer minLength = optionalMinLength.get();
                Integer maxLength = optionalMaxLength.get();

                if (isNotBlank(descriptionContent.toString())) {
                    descriptionContent.newLine(true);
                }

                String lengthRange = minLength + " - " + maxLength;
                if (minLength.equals(maxLength)) {
                    lengthRange = minLength.toString();
                }

                descriptionContent.boldText(labels.getLabel(LENGTH_COLUMN)).text(COLON)
                        .literalText(lengthRange);

            } else {
                if (optionalMinLength.isPresent()) {
                    if (isNotBlank(descriptionContent.toString())) {
                        descriptionContent.newLine(true);
                    }
                    descriptionContent.boldText(labels.getLabel(MINLENGTH_COLUMN)).text(COLON)
                            .literalText(optionalMinLength.get().toString());
                }

                if (optionalMaxLength.isPresent()) {
                    if (isNotBlank(descriptionContent.toString())) {
                        descriptionContent.newLine(true);
                    }
                    descriptionContent.boldText(labels.getLabel(MAXLENGTH_COLUMN)).text(COLON)
                            .literalText(optionalMaxLength.get().toString());
                }
            }

            if (optionalPattern.isPresent()) {
                if (isNotBlank(descriptionContent.toString())) {
                    descriptionContent.newLine(true);
                }
                descriptionContent.boldText(labels.getLabel(PATTERN_COLUMN)).text(COLON)
                        .literalText(Json.pretty(optionalPattern.get()));
            }

            if (optionalMinValue.isPresent()) {
                if (isNotBlank(descriptionContent.toString())) {
                    descriptionContent.newLine(true);
                }
                String minValueColumn = exclusiveMin ? labels.getLabel(MINVALUE_EXCLUSIVE_COLUMN)
                        : labels.getLabel(MINVALUE_COLUMN);
                descriptionContent.boldText(minValueColumn).text(COLON)
                        .literalText(optionalMinValue.get().toString());
            }

            if (optionalMaxValue.isPresent()) {
                if (isNotBlank(descriptionContent.toString())) {
                    descriptionContent.newLine(true);
                }
                String maxValueColumn = exclusiveMax ? labels.getLabel(MAXVALUE_EXCLUSIVE_COLUMN)
                        : labels.getLabel(MAXVALUE_COLUMN);
                descriptionContent.boldText(maxValueColumn).text(COLON)
                        .literalText(optionalMaxValue.get().toString());
            }

            if (optionalExample.isPresent()) {
                if (isNotBlank(description) || optionalDefaultValue.isPresent()) {
                    descriptionContent.newLine(true);
                }
                descriptionContent.boldText(labels.getLabel(EXAMPLE_COLUMN)).text(COLON)
                        .literalText(Json.pretty(optionalExample.get()));
            }

            nameColumnBuilder.add(propertyNameContent.toString());
            descriptionColumnBuilder.add(descriptionContent.toString());
            schemaColumnBuilder.add(propertyType.displaySchema(markupDocBuilder));
        });
    }

    return tableComponent.apply(markupDocBuilder, TableComponent.parameters(nameColumnBuilder.build(),
            descriptionColumnBuilder.build(), schemaColumnBuilder.build()));
}

From source file:com.evolveum.midpoint.model.common.expression.functions.CustomFunctions.java

public <V extends PrismValue, D extends ItemDefinition> Object execute(String functionName,
        Map<String, Object> params) throws ExpressionEvaluationException {
    Validate.notNull(functionName, "Function name must be specified");

    List<ExpressionType> functions = library.getFunction().stream()
            .filter(expression -> functionName.equals(expression.getName())).collect(Collectors.toList());

    LOGGER.trace("functions {}", functions);
    ExpressionType expressionType = functions.iterator().next();

    LOGGER.trace("function to execute {}", expressionType);

    try {// w w  w .  j av a2  s .  co m
        ExpressionVariables variables = new ExpressionVariables();
        if (MapUtils.isNotEmpty(params)) {
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                variables.addVariableDefinition(new QName(entry.getKey()), convertInput(entry, expressionType));
            }
            ;
        }

        QName returnType = expressionType.getReturnType();
        if (returnType == null) {
            returnType = DOMUtil.XSD_STRING;
        }

        D outputDefinition = (D) prismContext.getSchemaRegistry().findItemDefinitionByType(returnType);
        if (outputDefinition == null) {
            outputDefinition = (D) new PrismPropertyDefinitionImpl(SchemaConstantsGenerated.C_VALUE, returnType,
                    prismContext);
        }
        if (expressionType.getReturnMultiplicity() != null
                && expressionType.getReturnMultiplicity() == ExpressionReturnMultiplicityType.MULTI) {
            outputDefinition.setMaxOccurs(-1);
        } else {
            outputDefinition.setMaxOccurs(1);
        }
        String shortDesc = "custom function execute";
        Expression<V, D> expression = expressionFactory.makeExpression(expressionType, outputDefinition,
                shortDesc, task, result);

        ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, shortDesc, task,
                result);
        PrismValueDeltaSetTriple<V> outputTriple = expression.evaluate(context);

        LOGGER.trace("Result of the expression evaluation: {}", outputTriple);

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

        Collection<V> nonNegativeValues = outputTriple.getNonNegativeValues();

        if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
            return null;
        }

        if (outputDefinition.isMultiValue()) {
            return PrismValue.getRealValuesOfCollection(nonNegativeValues);
        }

        if (nonNegativeValues.size() > 1) {
            throw new ExpressionEvaluationException("Expression returned more than one value ("
                    + nonNegativeValues.size() + ") in " + shortDesc);
        }

        return nonNegativeValues.iterator().next().getRealValue();

    } catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException
            | ConfigurationException | SecurityViolationException e) {
        throw new ExpressionEvaluationException(e.getMessage(), e);
    }

}

From source file:io.cloudslang.lang.compiler.modeller.model.Metadata.java

private void appendMapField(StringBuilder stringBuilder, String fieldName, Map<String, String> fieldMap)
        throws IOException {
    if (MapUtils.isNotEmpty(fieldMap)) {
        stringBuilder.append(fieldName).append(": ");
        appendMap(stringBuilder, fieldMap);
    }/*from   w w  w.  j  av  a  2  s  .c om*/
}

From source file:io.github.swagger2markup.internal.document.PathsDocument.java

/**
 * Builds the paths MarkupDocument./* w ww  .java 2 s .  c o m*/
 *
 * @return the paths MarkupDocument
 */
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, PathsDocument.Parameters params) {
    Map<String, Path> paths = params.paths;
    if (MapUtils.isNotEmpty(paths)) {
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder));
        buildPathsTitle(markupDocBuilder);
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder));
        buildsPathsSection(markupDocBuilder, paths);
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder));
        applyPathsDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder));
    }
    return markupDocBuilder;
}

From source file:io.github.swagger2markup.internal.document.builder.DefinitionsDocumentBuilder.java

/**
 * Builds the definitions MarkupDocument.
 *
 * @return the definitions MarkupDocument
 *///from  w ww  .ja v a2s.c om
@Override
public MarkupDocument build() {
    if (MapUtils.isNotEmpty(globalContext.getSwagger().getDefinitions())) {
        applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, this.markupDocBuilder));
        buildDefinitionsTitle(DEFINITIONS);
        applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, this.markupDocBuilder));
        buildDefinitionsSection();
        applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_END, this.markupDocBuilder));
        applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_AFTER, this.markupDocBuilder));
    }
    return new MarkupDocument(markupDocBuilder);
}

From source file:com.dangdang.ddframe.rdb.sharding.config.common.api.ShardingRuleBuilder.java

private DataSourceRule buildDataSourceRule() {
    Preconditions.checkArgument(//w  ww. j a  v a 2  s. co  m
            !shardingRuleConfig.getDataSource().isEmpty() || MapUtils.isNotEmpty(externalDataSourceMap),
            "Sharding JDBC: No data source config");
    return shardingRuleConfig.getDataSource().isEmpty()
            ? new DataSourceRule(externalDataSourceMap, shardingRuleConfig.getDefaultDataSourceName())
            : new DataSourceRule(shardingRuleConfig.getDataSource(),
                    shardingRuleConfig.getDefaultDataSourceName());
}

From source file:com.ebay.myriad.Main.java

private void initProfiles(final MyriadConfiguration cfg, final Environment env, Injector injector) {
    LOGGER.info("Initializing Profiles");
    NMProfileManager profileManager = injector.getInstance(NMProfileManager.class);
    Map<String, Map<String, String>> profiles = cfg.getProfiles();
    if (MapUtils.isNotEmpty(profiles)) {
        Iterator<String> profileKeys = profiles.keySet().iterator();
        while (profileKeys.hasNext()) {
            String profileKey = profileKeys.next();
            Map<String, String> profileResourceMap = profiles.get(profileKey);
            if (MapUtils.isNotEmpty(profiles) && profileResourceMap.containsKey("cpu")
                    && profileResourceMap.containsKey("mem")) {
                double cpu = Double.parseDouble(profileResourceMap.get("cpu"));
                double mem = Double.parseDouble(profileResourceMap.get("mem"));

                profileManager.add(new NMProfile(profileKey, cpu, mem));
            } else {
                LOGGER.error("Invalid definition for profile: " + profileKey);
            }/*w  w w. ja  va 2s.co m*/
        }
    }
}

From source file:com.tongbanjie.tarzan.rpc.protocol.RpcCommand.java

public CustomHeader decodeCustomHeader(Class<? extends CustomHeader> classHeader) throws RpcCommandException {
    CustomHeader objectHeader;/*  w  ww .  j  a  va  2s. c o  m*/
    try {
        objectHeader = classHeader.newInstance();
    } catch (InstantiationException e) {
        return null;
    } catch (IllegalAccessException e) {
        return null;
    }
    if (MapUtils.isNotEmpty(this.customFields)) {
        Field[] fields = getClazzFields(classHeader);
        for (Field field : fields) {
            String fieldName = field.getName();
            Class clazz = field.getType();
            if (Modifier.isStatic(field.getModifiers()) || fieldName.startsWith("this")) {
                continue;
            }
            String value = this.customFields.get(fieldName);
            if (value == null) {
                continue;
            }
            field.setAccessible(true);
            Object valueParsed;
            if (clazz.isEnum()) {
                valueParsed = Enum.valueOf(clazz, value);
            } else {
                String type = getCanonicalName(clazz);
                try {
                    valueParsed = ClassUtils.parseSimpleValue(type, value);
                } catch (ParseException e) {
                    throw new RpcCommandException("Encode the header failed, the custom field <" + fieldName
                            + "> type <" + getCanonicalName(clazz) + "> parse error:" + e.getMessage());
                }
            }
            if (valueParsed == null) {
                throw new RpcCommandException("Encode the header failed, the custom field <" + fieldName
                        + "> type <" + getCanonicalName(clazz) + "> is not supported.");
            }
            try {
                field.set(objectHeader, valueParsed);
            } catch (IllegalAccessException e) {
                throw new RpcCommandException(
                        "Encode the header failed, set the value of field < " + fieldName + "> error.", e);
            }
        }

        objectHeader.checkFields();
    }

    return objectHeader;
}

From source file:com.haulmont.cuba.web.gui.components.WebAbstractTextField.java

@Override
public void setDatasource(Datasource datasource, String property) {
    super.setDatasource(datasource, property);

    if (metaProperty != null) {
        Map<String, Object> annotations = metaProperty.getAnnotations();

        if (this instanceof CaseConversionSupported
                && ((CaseConversionSupported) this).getCaseConversion() == CaseConversion.NONE) {
            String caseConversionAnnotation = com.haulmont.cuba.core.entity.annotation.CaseConversion.class
                    .getName();/*w ww  .  java 2  s.  com*/
            //noinspection unchecked
            Map<String, Object> caseConversion = (Map<String, Object>) annotations
                    .get(caseConversionAnnotation);
            if (MapUtils.isNotEmpty(caseConversion)) {
                ConversionType conversionType = (ConversionType) caseConversion.get("type");
                CaseConversion conversion = CaseConversion.valueOf(conversionType.name());

                ((CaseConversionSupported) this).setCaseConversion(conversion);
            }
        }

        if (this instanceof TextInputField.MaxLengthLimited) {
            MaxLengthLimited maxLengthLimited = (MaxLengthLimited) this;

            Integer maxLength = (Integer) annotations.get("length");
            if (maxLength != null) {
                maxLengthLimited.setMaxLength(maxLength);
            }

            Integer sizeMax = (Integer) annotations.get(Size.class.getName() + "_max");
            if (sizeMax != null) {
                maxLengthLimited.setMaxLength(sizeMax);
            }

            Integer lengthMax = (Integer) annotations.get(Length.class.getName() + "_max");
            if (lengthMax != null) {
                maxLengthLimited.setMaxLength(lengthMax);
            }
        }
    }
}