public List<FactMappingValue> getFactMappingValuesByFactIdentifier(FactIdentifier factIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier)).collect(toList()); }
public Collection<String> getFactNames() { return factMappingValues.stream().map(e -> e.getFactIdentifier().getName()).collect(toSet()); }
public List<FactMappingValue> getFactMappingValuesByFactIdentifier(FactIdentifier factIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier)).collect(toList()); }
public Collection<String> getFactNames() { return factMappingValues.stream().map(e -> e.getFactIdentifier().getName()).collect(toSet()); }
public void sort() { factMappingValues.sort((a, b) -> { Integer aIndex = simulationDescriptor.getIndexByIdentifier(a.getFactIdentifier(), a.getExpressionIdentifier()); Integer bIndex = simulationDescriptor.getIndexByIdentifier(b.getFactIdentifier(), b.getExpressionIdentifier()); return aIndex.compareTo(bIndex); }); }
public void sort() { factMappingValues.sort((a, b) -> { Integer aIndex = simulationDescriptor.getIndexByIdentifier(a.getFactIdentifier(), a.getExpressionIdentifier()); Integer bIndex = simulationDescriptor.getIndexByIdentifier(b.getFactIdentifier(), b.getExpressionIdentifier()); return aIndex.compareTo(bIndex); }); }
public Optional<FactMappingValue> getFactMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier) && e.getExpressionIdentifier().equals(expressionIdentifier)).findFirst(); }
public Optional<FactMappingValue> getFactMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier) && e.getExpressionIdentifier().equals(expressionIdentifier)).findFirst(); }
public Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifierAndFilter(List<FactMappingValue> factMappingValues, FactMappingType type) { Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = new HashMap<>(); for (FactMappingValue factMappingValue : factMappingValues) { FactIdentifier factIdentifier = factMappingValue.getFactIdentifier(); // null means skip if (factMappingValue.getRawValue() == null) { continue; } ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier(); if (expressionIdentifier == null) { throw new IllegalArgumentException("ExpressionIdentifier malformed"); } if (!Objects.equals(expressionIdentifier.getType(), type)) { continue; } groupByFactIdentifier.computeIfAbsent(factIdentifier, key -> new ArrayList<>()) .add(factMappingValue); } return groupByFactIdentifier; }
public String getDescription() { return factMappingValues.stream() .filter(e -> e.getExpressionIdentifier().equals(ExpressionIdentifier.DESCRIPTION) && e.getFactIdentifier().equals(FactIdentifier.DESCRIPTION) && e.getRawValue() != null) .map(e -> (String) e.getRawValue()) .findFirst().orElse(""); }
public String getDescription() { return factMappingValues.stream() .filter(e -> e.getExpressionIdentifier().equals(ExpressionIdentifier.DESCRIPTION) && e.getFactIdentifier().equals(FactIdentifier.DESCRIPTION) && e.getRawValue() != null) .map(e -> (String) e.getRawValue()) .findFirst().orElse(""); }
protected Function<Object, ResultWrapper> createExtractorFunction(ExpressionEvaluator expressionEvaluator, FactMappingValue expectedResult, SimulationDescriptor simulationDescriptor) { return objectToCheck -> { ExpressionIdentifier expressionIdentifier = expectedResult.getExpressionIdentifier(); FactMapping factMapping = simulationDescriptor.getFactMapping(expectedResult.getFactIdentifier(), expressionIdentifier) .orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen")); List<String> pathToValue = factMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(toList()); ScenarioBeanWrapper<?> scenarioBeanWrapper = ScenarioBeanUtil.navigateToObject(objectToCheck, pathToValue, false); Object resultValue = scenarioBeanWrapper.getBean(); try { return expressionEvaluator.evaluate(expectedResult.getRawValue(), resultValue, scenarioBeanWrapper.getBeanClass()) ? createResult(resultValue) : createErrorResult(); } catch (Exception e) { expectedResult.setError(true); throw new ScenarioException(e.getMessage(), e); } }; }
/** * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code> * @param row */ public void insertRowGridOnly(final int rowIndex, final GridRow row, final Scenario scenario) { checkSimulation(); super.insertRow(rowIndex, row); scenario.getUnmodifiableFactMappingValues().forEach(value -> { FactIdentifier factIdentifier = value.getFactIdentifier(); ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier(); if (value.getRawValue() == null || value.getRawValue() instanceof String) { // Let' put a placeholder String stringValue = (String) value.getRawValue(); int columnIndex = simulation.getSimulationDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier); String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder(); setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder))); } else { throw new UnsupportedOperationException("Only string is supported at the moment"); } }); updateIndexColumn(); }