List of usage examples for org.apache.commons.collections4 MapUtils isNotEmpty
public static boolean isNotEmpty(final Map<?, ?> map)
From source file:fr.landel.utils.assertor.utils.AssertorMap.java
private static <M extends Map<K, V>, K, V> StepAssertor<M> containsValues(final StepAssertor<M> step, final Iterable<V> values, final CharSequence key, final boolean all, final MessageAssertor message) { final Predicate<M> preChecker = (map) -> MapUtils.isNotEmpty(map) && !IterableUtils.isEmpty(values); final BiPredicate<M, Boolean> checker = (map, not) -> AssertorMap.contains(map, values, map::containsValue, all, not, step.getAnalysisMode()); return new StepAssertor<>(step, preChecker, checker, true, message, key, false, new ParameterAssertor<>(values, EnumType.ITERABLE)); }
From source file:fr.landel.utils.assertor.utils.AssertorMap.java
private static <M extends Map<K, V>, K, V> StepAssertor<M> contains(final StepAssertor<M> step, final Map<K, V> map, final CharSequence key, final boolean all, final MessageAssertor message) { final Predicate<M> preChecker = (map1) -> MapUtils.isNotEmpty(map1) && MapUtils.isNotEmpty(map); final BiPredicate<M, Boolean> checker = (map1, not) -> AssertorMap.contains(map1, map, all, not, step.getAnalysisMode());// ww w.j a v a2s . c om return new StepAssertor<>(step, preChecker, checker, true, message, key, false, new ParameterAssertor<>(map, EnumType.MAP)); }
From source file:io.cloudslang.lang.compiler.modeller.ExecutableBuilder.java
private WorkflowModellingResult compileWorkFlow(List<Map<String, Map<String, Object>>> workFlowRawData, Map<String, String> imports, Workflow onFailureWorkFlow, boolean onFailureSection, String namespace, SensitivityLevel sensitivityLevel) { List<RuntimeException> errors = new ArrayList<>(); Deque<Step> steps = new LinkedList<>(); Set<String> stepNames = new HashSet<>(); Deque<Step> onFailureSteps = !(onFailureSection || onFailureWorkFlow == null) ? onFailureWorkFlow.getSteps() : new LinkedList<Step>(); List<String> onFailureStepNames = getStepNames(onFailureSteps); boolean onFailureStepFound = onFailureStepNames.size() > 0; String defaultFailure = onFailureStepFound ? onFailureStepNames.get(0) : ScoreLangConstants.FAILURE_RESULT; PeekingIterator<Map<String, Map<String, Object>>> iterator = new PeekingIterator<>( workFlowRawData.iterator()); while (iterator.hasNext()) { Map<String, Map<String, Object>> stepRawData = iterator.next(); String stepName = getStepName(stepRawData); validateStepName(stepName, errors); if (stepNames.contains(stepName) || onFailureStepNames.contains(stepName)) { errors.add(new RuntimeException("Step name: \'" + stepName + "\' appears more than once in the workflow. " + UNIQUE_STEP_NAME_MESSAGE_SUFFIX)); }/*from w w w . j a v a 2 s . c o m*/ stepNames.add(stepName); Map<String, Object> stepRawDataValue; String message = "Step: " + stepName + " syntax is illegal.\nBelow step name, there should " + "be a map of values in the format:\ndo:\n\top_name:"; try { stepRawDataValue = stepRawData.values().iterator().next(); if (MapUtils.isNotEmpty(stepRawDataValue)) { boolean loopKeyFound = stepRawDataValue.containsKey(LOOP_KEY); boolean parallelLoopKeyFound = stepRawDataValue.containsKey(PARALLEL_LOOP_KEY); if (loopKeyFound) { if (parallelLoopKeyFound) { errors.add(new RuntimeException( "Step: " + stepName + " syntax is illegal.\nBelow step name, " + "there can be either \'loop\' or \'aync_loop\' key.")); } message = "Step: " + stepName + " syntax is illegal.\nBelow the 'loop' keyword, there " + "should be a map of values in the format:\nfor:\ndo:\n\top_name:"; @SuppressWarnings("unchecked") Map<String, Object> loopRawData = (Map<String, Object>) stepRawDataValue.remove(LOOP_KEY); stepRawDataValue.putAll(loopRawData); } if (parallelLoopKeyFound) { message = "Step: " + stepName + " syntax is illegal.\nBelow the 'parallel_loop' keyword, there " + "should be a map of values in the format:\nfor:\ndo:\n\top_name:"; @SuppressWarnings("unchecked") Map<String, Object> parallelLoopRawData = (Map<String, Object>) stepRawDataValue .remove(PARALLEL_LOOP_KEY); errors.addAll(preCompileValidator.checkKeyWords(stepName, SlangTextualKeys.PARALLEL_LOOP_KEY, parallelLoopRawData, Collections.emptyList(), parallelLoopValidKeywords, null)); parallelLoopRawData.put(PARALLEL_LOOP_KEY, parallelLoopRawData.remove(FOR_KEY)); stepRawDataValue.putAll(parallelLoopRawData); } } } catch (ClassCastException ex) { stepRawDataValue = new HashMap<>(); errors.add(new RuntimeException(message)); } String defaultSuccess; Map<String, Map<String, Object>> nextStepData = iterator.peek(); if (nextStepData != null) { defaultSuccess = nextStepData.keySet().iterator().next(); } else { defaultSuccess = onFailureSection ? ScoreLangConstants.FAILURE_RESULT : SUCCESS_RESULT; } String onFailureStepName = onFailureStepFound ? onFailureStepNames.get(0) : null; StepModellingResult stepModellingResult = compileStep(stepName, stepRawDataValue, defaultSuccess, imports, defaultFailure, namespace, onFailureStepName, onFailureSection, sensitivityLevel); errors.addAll(stepModellingResult.getErrors()); steps.add(stepModellingResult.getStep()); } if (onFailureStepFound) { steps.addAll(onFailureSteps); } return new WorkflowModellingResult(new Workflow(steps), errors); }
From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesPanel.java
private void updateAddButton() { dependencyAddButton.setEnabled(MapUtils.isNotEmpty(getAllowedChannels(true))); dependentAddButton.setEnabled(MapUtils.isNotEmpty(getAllowedChannels(false))); }
From source file:fr.landel.utils.assertor.utils.AssertorMap.java
/** * Prepare the next step to validate if the {@link Map} contains the entries * in a specified order. To work correctly, the map must be sorted or * linked.// www. j av a 2 s . co m * * <p> * precondition: {@link Map} and {@link Iterable} cannot be {@code null} or * empty * </p> * * @param step * the current step * @param keys * the keys to find * @param message * the message if invalid * @param <M> * the {@link Map} type * @param <K> * the {@link Map} key elements type * @param <V> * the {@link Map} value elements type * @return the next step */ public static <M extends Map<K, V>, K, V> StepAssertor<M> containsKeysInOrder(final StepAssertor<M> step, final Iterable<K> keys, final MessageAssertor message) { final Predicate<M> preChecker = map1 -> MapUtils.isNotEmpty(map1) && !IterableUtils.isEmpty(keys); final BiPredicate<M, Boolean> checker = (map1, not) -> AssertorMap.hasInOrder(map1, keys, not, step.getAnalysisMode(), MapUtils2::areKeysEqual, CastUtils.cast(Object.class)); return new StepAssertor<>(step, preChecker, checker, true, message, MSG.MAP.CONTAINS_KEYS_IN_ORDER, false, new ParameterAssertor<>(keys, EnumType.ITERABLE)); }
From source file:fr.landel.utils.assertor.utils.AssertorMap.java
/** * Prepare the next step to validate if the {@link Map} contains the entries * in a specified order. To work correctly, the map must be sorted or * linked./* w w w . j av a2s . c o m*/ * * <p> * precondition: {@link Map} and {@link Iterable} cannot be {@code null} or * empty * </p> * * @param step * the current step * @param values * the values to find * @param message * the message if invalid * @param <M> * the {@link Map} type * @param <K> * the {@link Map} key elements type * @param <V> * the {@link Map} value elements type * @return the next step */ public static <M extends Map<K, V>, K, V> StepAssertor<M> containsValuesInOrder(final StepAssertor<M> step, final Iterable<V> values, final MessageAssertor message) { final Predicate<M> preChecker = map1 -> MapUtils.isNotEmpty(map1) && !IterableUtils.isEmpty(values); final BiPredicate<M, Boolean> checker = (map1, not) -> AssertorMap.hasInOrder(map1, values, not, step.getAnalysisMode(), MapUtils2::areValuesEqual, CastUtils.cast(Object.class)); return new StepAssertor<>(step, preChecker, checker, true, message, MSG.MAP.CONTAINS_VALUES_IN_ORDER, false, new ParameterAssertor<>(values, EnumType.ITERABLE)); }
From source file:io.cloudslang.lang.compiler.modeller.ExecutableBuilder.java
private StepModellingResult compileStep(String stepName, Map<String, Object> stepRawData, String defaultSuccess, Map<String, String> imports, String defaultFailure, String namespace, String onFailureStepName, boolean onFailureSection, SensitivityLevel sensitivityLevel) { List<RuntimeException> errors = new ArrayList<>(); if (MapUtils.isEmpty(stepRawData)) { stepRawData = new HashMap<>(); errors.add(new RuntimeException("Step: " + stepName + " has no data")); }/*from ww w . ja v a 2 s. c o m*/ final boolean isExternal = stepRawData.containsKey(DO_EXTERNAL_KEY); final List<Transformer> localPreStepTransformers = isExternal ? externalPreStepTransformers : preStepTransformers; final List<Transformer> localPostStepTransformers = isExternal ? externalPostStepTransformers : postStepTransformers; Map<String, Serializable> preStepData = new HashMap<>(); Map<String, Serializable> postStepData = new HashMap<>(); errors.addAll(preCompileValidator.checkKeyWords(stepName, "", stepRawData, ListUtils.union(localPreStepTransformers, localPostStepTransformers), stepAdditionalKeyWords, null)); String errorMessagePrefix = "For step '" + stepName + "' syntax is illegal.\n"; preStepData.putAll(transformersHandler.runTransformers(stepRawData, localPreStepTransformers, errors, errorMessagePrefix, sensitivityLevel)); postStepData.putAll(transformersHandler.runTransformers(stepRawData, localPostStepTransformers, errors, errorMessagePrefix, sensitivityLevel)); replaceOnFailureReference(postStepData, onFailureStepName); String workerGroup = (String) stepRawData.get(SlangTextualKeys.WORKER_GROUP); String refId = ""; final List<Argument> arguments = getArgumentsFromDoStep(preStepData); final Map<String, Object> doRawData = getRawDataFromDoStep(stepRawData); if (MapUtils.isNotEmpty(doRawData)) { try { String refString = doRawData.keySet().iterator().next(); refId = resolveReferenceId(refString, imports, namespace, preStepData); } catch (RuntimeException rex) { errors.add(rex); } } List<Map<String, String>> navigationStrings = getNavigationStrings(postStepData, defaultSuccess, defaultFailure, errors); Step step = createStep(stepName, onFailureSection, preStepData, postStepData, arguments, workerGroup, refId, navigationStrings); return new StepModellingResult(step, errors); }
From source file:io.cloudslang.lang.tools.build.tester.SlangTestRunner.java
private void handleTestCaseFailuresFromOutputs(SlangTestCase testCase, String testCaseReference, Map<String, Serializable> outputs, Map<String, Serializable> executionOutputs) { String message;/* w ww . ja v a 2 s.co m*/ if (MapUtils.isNotEmpty(outputs)) { for (Map.Entry<String, Serializable> output : outputs.entrySet()) { String outputName = output.getKey(); Serializable outputValue = output.getValue(); Serializable executionOutputValue = executionOutputs.get(outputName); if (!executionOutputs.containsKey(outputName) || !outputsAreEqual(outputValue, executionOutputValue)) { message = TEST_CASE_FAILED + testCaseReference + " - " + testCase.getDescription() + "\n\tFor output: " + outputName + "\n\tExpected value: " + outputValue + "\n\tActual value: " + executionOutputValue; loggingService.logEvent(Level.ERROR, message); throw new RuntimeException(message); } } } }
From source file:fr.landel.utils.assertor.utils.AssertorMap.java
/** * Prepare the next step to validate if the {@link Map} contains the entries * in a specified order. To work correctly, the map must be sorted or * linked.//w w w . ja v a 2 s . c o m * * <p> * precondition: {@link Map} cannot be {@code null} or empty * </p> * * @param step * the current step * @param map * the map entries to find * @param message * the message if invalid * @param <M> * the {@link Map} type * @param <K> * the {@link Map} key elements type * @param <V> * the {@link Map} value elements type * @return the next step */ public static <M extends Map<K, V>, K, V> StepAssertor<M> containsInOrder(final StepAssertor<M> step, final Map<K, V> map, final MessageAssertor message) { final Predicate<M> preChecker = map1 -> MapUtils.isNotEmpty(map1) && MapUtils.isNotEmpty(map); final BiPredicate<M, Boolean> checker = (map1, not) -> AssertorMap.hasInOrder(map1, IterableUtils.toList(map.entrySet()), not, step.getAnalysisMode(), MapUtils2::areEntriesEqual, CastUtils.cast(Entry.class)); return new StepAssertor<>(step, preChecker, checker, true, message, MSG.MAP.CONTAINS_MAP_IN_ORDER, false, new ParameterAssertor<>(map, EnumType.MAP)); }
From source file:com.epam.catgenome.manager.gene.GffManager.java
private void setProteinSequences(final Map<Gene, List<ProteinSequenceEntry>> aminoAcids, Gene item, GeneLowLevel geneLowLevel) {// w w w . j av a 2 s. c o m if (MapUtils.isNotEmpty(aminoAcids) && GeneUtils.isTranscript(item)) { final List<ProteinSequenceEntry> psEntryList = aminoAcids.get(item); if (CollectionUtils.isNotEmpty(psEntryList)) { List<ProteinSequence> psList = psEntryList.stream().map(ProteinSequence::new) .collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(psList)) { geneLowLevel.setPsList(psList); } } } }