@Test public void getNonExistingSensitivityValueByFactorContingency() { List<SensitivityValue> values = new ArrayList<>(); values.add(new SensitivityValue(factorOk, Double.NaN, Double.NaN, Double.NaN)); values.add(new SensitivityValue(factorNok, Double.NaN, Double.NaN, Double.NaN)); Map<String, List<SensitivityValue>> valuesContingency = Collections.singletonMap("Contingency", values); SensitivityAnalysisResult results = new SensitivityAnalysisResult(true, Collections.emptyMap(), "", values, valuesContingency); SensitivityFactor wrongFactor = Mockito.mock(SensitivityFactor.class); Mockito.when(wrongFactor.getFunction()).thenReturn(Mockito.mock(SensitivityFunction.class)); Mockito.when(wrongFactor.getVariable()).thenReturn(Mockito.mock(SensitivityVariable.class)); exception.expect(NoSuchElementException.class); results.getSensitivityValue(wrongFactor, "Contingency"); }
public SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable) { Optional<SensitivityValue> returnValue = sensitivityValues.stream().filter(sensitivityValue -> sensitivityValue.getFactor().getFunction().equals(function) && sensitivityValue.getFactor().getVariable().equals(variable)).findAny(); if (!returnValue.isPresent()) { throw new NoSuchElementException(String.format(VALUE_NOT_FOUND, function.getId(), variable.getId())); } return returnValue.get(); }
SensitivityAnalysisResult { public SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable) { Optional<SensitivityValue> returnValue = sensitivityValues.stream().filter(sensitivityValue -> sensitivityValue.getFactor().getFunction().equals(function) && sensitivityValue.getFactor().getVariable().equals(variable)).findAny(); if (!returnValue.isPresent()) { throw new NoSuchElementException(String.format(VALUE_NOT_FOUND, function.getId(), variable.getId())); } return returnValue.get(); } }
SensitivityAnalysisResult { public SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable) { Optional<SensitivityValue> returnValue = sensitivityValues.stream().filter(sensitivityValue -> sensitivityValue.getFactor().getFunction().equals(function) && sensitivityValue.getFactor().getVariable().equals(variable)).findAny(); if (!returnValue.isPresent()) { throw new NoSuchElementException(String.format(VALUE_NOT_FOUND, function.getId(), variable.getId())); } return returnValue.get(); } @JsonCreator  SensitivityAnalysisResult(@JsonProperty("ok") boolean ok,
                                     @JsonProperty("metrics") Map<String, String> metrics,
                                     @JsonProperty("logs") String logs,
                                     @JsonProperty("values") List<SensitivityValue> sensitivityValues,
                                     @JsonProperty("contingenciesValues") Map<String, List<SensitivityValue>> sensitivityValuesContingencies);  SensitivityAnalysisResult(boolean ok,
                                     Map<String, String> metrics,
                                     String logs,
                                     List<SensitivityValue> sensitivityValues); }
SensitivityAnalysisResult { public SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable) { Optional<SensitivityValue> returnValue = sensitivityValues.stream().filter(sensitivityValue -> sensitivityValue.getFactor().getFunction().equals(function) && sensitivityValue.getFactor().getVariable().equals(variable)).findAny(); if (!returnValue.isPresent()) { throw new NoSuchElementException(String.format(VALUE_NOT_FOUND, function.getId(), variable.getId())); } return returnValue.get(); } @JsonCreator  SensitivityAnalysisResult(@JsonProperty("ok") boolean ok,
                                     @JsonProperty("metrics") Map<String, String> metrics,
                                     @JsonProperty("logs") String logs,
                                     @JsonProperty("values") List<SensitivityValue> sensitivityValues,
                                     @JsonProperty("contingenciesValues") Map<String, List<SensitivityValue>> sensitivityValuesContingencies);  SensitivityAnalysisResult(boolean ok,
                                     Map<String, String> metrics,
                                     String logs,
                                     List<SensitivityValue> sensitivityValues); boolean isOk(); Map<String, String> getMetrics(); String getLogs(); Collection<SensitivityValue> getSensitivityValues(); Collection<SensitivityValue> getSensitivityValuesByFunction(SensitivityFunction function); Collection<SensitivityValue> getSensitivityValuesByVariable(SensitivityVariable variable); SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable); SensitivityValue getSensitivityValue(SensitivityFactor factor); boolean contingenciesArePresent(); Map<String, List<SensitivityValue>> getSensitivityValuesContingencies(); Collection<SensitivityValue> getSensitivityValuesByFunction(SensitivityFunction function, String contingencyId); Collection<SensitivityValue> getSensitivityValuesByVariable(SensitivityVariable variable, String contingencyId); SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable, String contingencyId); SensitivityValue getSensitivityValue(SensitivityFactor factor, String contingencyId); static SensitivityAnalysisResult empty(); }
SensitivityAnalysisResult { public SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable) { Optional<SensitivityValue> returnValue = sensitivityValues.stream().filter(sensitivityValue -> sensitivityValue.getFactor().getFunction().equals(function) && sensitivityValue.getFactor().getVariable().equals(variable)).findAny(); if (!returnValue.isPresent()) { throw new NoSuchElementException(String.format(VALUE_NOT_FOUND, function.getId(), variable.getId())); } return returnValue.get(); } @JsonCreator  SensitivityAnalysisResult(@JsonProperty("ok") boolean ok,
                                     @JsonProperty("metrics") Map<String, String> metrics,
                                     @JsonProperty("logs") String logs,
                                     @JsonProperty("values") List<SensitivityValue> sensitivityValues,
                                     @JsonProperty("contingenciesValues") Map<String, List<SensitivityValue>> sensitivityValuesContingencies);  SensitivityAnalysisResult(boolean ok,
                                     Map<String, String> metrics,
                                     String logs,
                                     List<SensitivityValue> sensitivityValues); boolean isOk(); Map<String, String> getMetrics(); String getLogs(); Collection<SensitivityValue> getSensitivityValues(); Collection<SensitivityValue> getSensitivityValuesByFunction(SensitivityFunction function); Collection<SensitivityValue> getSensitivityValuesByVariable(SensitivityVariable variable); SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable); SensitivityValue getSensitivityValue(SensitivityFactor factor); boolean contingenciesArePresent(); Map<String, List<SensitivityValue>> getSensitivityValuesContingencies(); Collection<SensitivityValue> getSensitivityValuesByFunction(SensitivityFunction function, String contingencyId); Collection<SensitivityValue> getSensitivityValuesByVariable(SensitivityVariable variable, String contingencyId); SensitivityValue getSensitivityValue(SensitivityFunction function, SensitivityVariable variable, String contingencyId); SensitivityValue getSensitivityValue(SensitivityFactor factor, String contingencyId); static SensitivityAnalysisResult empty();  }