public Scenario cloneScenario(int sourceIndex, int targetIndex) { if (sourceIndex < 0 || sourceIndex >= scenarios.size()) { throw new IllegalArgumentException(new StringBuilder().append("SourceIndex out of range ").append(sourceIndex).toString()); } if (targetIndex < 0 || targetIndex > scenarios.size()) { throw new IllegalArgumentException(new StringBuilder().append("TargetIndex out of range ").append(targetIndex).toString()); } Scenario scenarioByIndex = getScenarioByIndex(sourceIndex); Scenario clonedScenario = scenarioByIndex.cloneScenario(); scenarios.add(targetIndex, clonedScenario); return clonedScenario; }
public Scenario cloneScenario(int sourceIndex, int targetIndex) { if (sourceIndex < 0 || sourceIndex >= scenarios.size()) { throw new IllegalArgumentException(new StringBuilder().append("SourceIndex out of range ").append(sourceIndex).toString()); } if (targetIndex < 0 || targetIndex > scenarios.size()) { throw new IllegalArgumentException(new StringBuilder().append("TargetIndex out of range ").append(targetIndex).toString()); } Scenario scenarioByIndex = getScenarioByIndex(sourceIndex); Scenario clonedScenario = scenarioByIndex.cloneScenario(); scenarios.add(targetIndex, clonedScenario); return clonedScenario; }
public void resetErrors(int rowIndex) { Scenario scenarioByIndex = simulation.getScenarioByIndex(rowIndex); scenarioByIndex.resetErrors(); refreshErrors(); }
protected void refreshErrorsRow(int rowIndex) { SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); Scenario scenarioByIndex = simulation.getScenarioByIndex(rowIndex); IntStream.range(0, getColumnCount()).forEach(columnIndex -> { ScenarioGridCell cell = (ScenarioGridCell) getCell(rowIndex, columnIndex); if (cell == null) { return; } final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); Optional<FactMappingValue> factMappingValue = scenarioByIndex.getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier()); if (factMappingValue.isPresent()) { cell.setErrorMode(factMappingValue.get().isError()); } else { cell.setErrorMode(false); } }); }
@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); }
@Test public void cloneScenarioTest() { Scenario clonedScenario = simulation.cloneScenario(0, 1); assertEquals(originalScenario.getDescription(), clonedScenario.getDescription()); assertEquals(originalScenario.getUnmodifiableFactMappingValues().size(), clonedScenario.getUnmodifiableFactMappingValues().size()); assertEquals(originalScenario, simulation.getScenarioByIndex(0)); assertEquals(clonedScenario, simulation.getScenarioByIndex(1)); assertNotEquals(originalScenario, clonedScenario); assertNotEquals(originalScenario.getUnmodifiableFactMappingValues().get(0), clonedScenario.getUnmodifiableFactMappingValues().get(0)); }
@Test public void cloneScenarioTest() { Scenario clonedScenario = simulation.cloneScenario(0, 1); assertEquals(originalScenario.getDescription(), clonedScenario.getDescription()); assertEquals(originalScenario.getUnmodifiableFactMappingValues().size(), clonedScenario.getUnmodifiableFactMappingValues().size()); assertEquals(originalScenario, simulation.getScenarioByIndex(0)); assertEquals(clonedScenario, simulation.getScenarioByIndex(1)); assertNotEquals(originalScenario, clonedScenario); assertNotEquals(originalScenario.getUnmodifiableFactMappingValues().get(0), clonedScenario.getUnmodifiableFactMappingValues().get(0)); }
when(simulationMock.getScenarioByIndex(rowIndex)).thenReturn(scenarioMock); when(simulationMock.cloneScenario(rowIndex, rowIndex + 1)).thenReturn(scenarioMock); gridRows.add(gridRowMock); }); when(simulationMock.addScenario(ROW_COUNT)).thenReturn(scenarioMock); when(simulationMock.getScenarioByIndex(ROW_COUNT)).thenReturn(scenarioMock); when(simulationMock.cloneScenario(ROW_COUNT, ROW_COUNT + 1)).thenReturn(scenarioMock);
/** * This method <i>set</i> a cell value to the grid <b>and</b> to the underlying model * @param rowIndex * @param columnIndex * @param cellSupplier */ @Override public Range setCell(int rowIndex, int columnIndex, Supplier<GridCell<?>> cellSupplier) { checkSimulation(); Range toReturn = super.setCell(rowIndex, columnIndex, cellSupplier); try { Optional<?> optionalValue = getCellValue(getCell(rowIndex, columnIndex)); Object rawValue = optionalValue.orElse(null); String cellValue = (rawValue instanceof String) ? (String) rawValue : null; Scenario scenarioByIndex = simulation.getScenarioByIndex(rowIndex); FactMapping factMappingByIndex = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); FactIdentifier factIdentifier = factMappingByIndex.getFactIdentifier(); ExpressionIdentifier expressionIdentifier = factMappingByIndex.getExpressionIdentifier(); scenarioByIndex.addOrUpdateMappingValue(factIdentifier, expressionIdentifier, cellValue); } catch (Throwable t) { toReturn = super.deleteCell(rowIndex, columnIndex); eventBus.fireEvent(new ScenarioGridReloadEvent()); } return toReturn; }
ScenarioSimulationModel scenarioSimulationModel = new ScenarioSimulationModel(); scenarioSimulationModel.setSimulation(new RULESimulationCreationStrategy().createSimulation(this.path, "default")); Scenario scenario = scenarioSimulationModel.getSimulation().getScenarioByIndex(0); scenario.setDescription("Test Scenario"); String errorMessage = "Test Error";