public Optional<FactMappingValue> getFactMappingValueByIndex(int index) { FactMapping factMappingByIndex; try { factMappingByIndex = simulationDescriptor.getFactMappingByIndex(index); } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException( new StringBuilder().append("Impossible to retrieve FactMapping at index ").append(index).toString(), e); } return getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier()); }
public Optional<FactMappingValue> getFactMappingValueByIndex(int index) { FactMapping factMappingByIndex; try { factMappingByIndex = simulationDescriptor.getFactMappingByIndex(index); } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException( new StringBuilder().append("Impossible to retrieve FactMapping at index ").append(index).toString(), e); } return getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier()); }
private void cleanScenarios(FactMapping toRemove) { scenarios.forEach(e -> e.removeFactMappingValueByIdentifiers(toRemove.getFactIdentifier(), toRemove.getExpressionIdentifier())); } }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
private void cleanScenarios(FactMapping toRemove) { scenarios.forEach(e -> e.removeFactMappingValueByIdentifiers(toRemove.getFactIdentifier(), toRemove.getExpressionIdentifier())); } }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
public List<FactMapping> getFactMappingsByFactName(String factName) { return internalFilter(e -> e.getFactIdentifier().getName().equalsIgnoreCase(factName)); }
public List<FactMapping> getFactMappingsByFactName(String factName) { return internalFilter(e -> e.getFactIdentifier().getName().equalsIgnoreCase(factName)); }
protected boolean isUnique(String value, int rowIndex, int columnIndex) { Range instanceLimits = getInstanceLimits(columnIndex); SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier(); return IntStream.range(0, getColumnCount()) .filter(index -> index < instanceLimits.getMinRowIndex() || index > instanceLimits.getMaxRowIndex()) .filter(index -> !Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())) .mapToObj(index -> getColumns().get(index)) .filter(elem -> elem.getHeaderMetaData().size() > rowIndex) .map(elem -> (ScenarioHeaderMetaData) elem.getHeaderMetaData().get(rowIndex)) .noneMatch(elem -> Objects.equals(elem.getTitle(), value)); }
public Optional<FactMapping> getFactMapping(FactIdentifier factIdentifier, ExpressionIdentifier ei) { List<FactMapping> factMappings = internalFilter(e -> e.getExpressionIdentifier().equals(ei) && e.getFactIdentifier().equals(factIdentifier)); return factMappings.stream().findFirst(); }
public Optional<FactMapping> getFactMapping(FactIdentifier factIdentifier, ExpressionIdentifier ei) { List<FactMapping> factMappings = internalFilter(e -> e.getExpressionIdentifier().equals(ei) && e.getFactIdentifier().equals(factIdentifier)); return factMappings.stream().findFirst(); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FactMapping that = (FactMapping) o; return getExpressionElements().equals(that.getExpressionElements()) && Objects.equals(getExpressionIdentifier(), that.getExpressionIdentifier()) && Objects.equals(getFactIdentifier(), that.getFactIdentifier()) && Objects.equals(getClassName(), that.getClassName()) && Objects.equals(getFactAlias(), that.getFactAlias()) && Objects.equals(getExpressionAlias(), that.getExpressionAlias()); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FactMapping that = (FactMapping) o; return getExpressionElements().equals(that.getExpressionElements()) && Objects.equals(getExpressionIdentifier(), that.getExpressionIdentifier()) && Objects.equals(getFactIdentifier(), that.getFactIdentifier()) && Objects.equals(getClassName(), that.getClassName()) && Objects.equals(getFactAlias(), that.getFactAlias()) && Objects.equals(getExpressionAlias(), that.getExpressionAlias()); }
@Override public int hashCode() { return Objects.hash(getExpressionElements(), getExpressionIdentifier(), getFactIdentifier(), getClassName(), getFactAlias(), getExpressionAlias()); } }
@Override public int hashCode() { return Objects.hash(getExpressionElements(), getExpressionIdentifier(), getFactIdentifier(), getClassName(), getFactAlias(), getExpressionAlias()); } }
@Test public void getIndexByIdentifierTest() { List<FactMapping> originalFactMappings = IntStream.range(0, 2).boxed() .map(i -> simulationDescriptor .addFactMapping(FactIdentifier.create("test " + i, String.class.getCanonicalName()), this.expressionIdentifier) ).collect(Collectors.toList()); int indexToCheck = 0; int indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); indexToCheck = 1; indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); }
@Test public void getIndexByIdentifierTest() { List<FactMapping> originalFactMappings = IntStream.range(0, 2).boxed() .map(i -> simulationDescriptor .addFactMapping(FactIdentifier.create("test " + i, String.class.getCanonicalName()), this.expressionIdentifier) ).collect(Collectors.toList()); int indexToCheck = 0; int indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); indexToCheck = 1; indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); }
@Override public Function<String, String> from1_2to1_3() { return rawXml -> { ScenarioSimulationXMLPersistence xmlPersistence = ScenarioSimulationXMLPersistence.getInstance(); ScenarioSimulationModel model = xmlPersistence.unmarshal(rawXml, false); for (FactMapping factMapping : model.getSimulation().getSimulationDescriptor().getUnmodifiableFactMappings()) { factMapping.getExpressionElements().add(0, new ExpressionElement(factMapping.getFactIdentifier().getName())); } return xmlPersistence.marshal(model).replaceAll("<ScenarioSimulationModel version=\"1.2\">", "<ScenarioSimulationModel version=\"1.3\">"); }; } }
@Override public Range deleteCell(int rowIndex, int columnIndex) { FactMapping factMapping = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); simulation.getScenarioByIndex(rowIndex) .removeFactMappingValueByIdentifiers(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier()); return super.deleteCell(rowIndex, columnIndex); }
protected void commonAddRow(int rowIndex) { Scenario scenario = simulation.addScenario(rowIndex); final SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); IntStream.range(1, getColumnCount()).forEach(columnIndex -> { final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); scenario.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), null); String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).isPropertyAssigned() ? ScenarioSimulationEditorConstants.INSTANCE.insertValue() : ScenarioSimulationEditorConstants.INSTANCE.defineValidType(); setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder))); }); updateIndexColumn(); }