WCAUtils { public static void writeContingencies(Collection<Contingency> contingencies, DataSource dataSource, StringToIntMapper<AmplSubset> mapper) { Objects.requireNonNull(contingencies); Objects.requireNonNull(dataSource); Objects.requireNonNull(mapper); try (Writer writer = new OutputStreamWriter(dataSource.newOutputStream(WCAConstants.FAULTS_FILE_SUFFIX, WCAConstants.TXT_EXT, false), StandardCharsets.UTF_8); TableFormatter formatter = new AmplDatTableFormatter( writer, "Contingencies", AmplConstants.INVALID_FLOAT_VALUE, true, AmplConstants.LOCALE, new Column("num"), new Column("id"))) { for (Contingency contingency : contingencies) { int contingencyNum = mapper.getInt(AmplSubset.FAULT, contingency.getId()); formatter.writeCell(contingencyNum) .writeCell(contingency.getId()); } } catch (IOException e) { throw new RuntimeException(e); } } private  WCAUtils(); static void exportState(Network network, Path folder, int faultNum, int actionNum); static WCADomainsResult readDomainsResult(String domainsPrefix, Path workingDir, String uncertaintiesFile); static WCAClustersResult readClustersResult(String clustersPrefix, Path workingDir, String flowsFile, String uncertaintiesFile); static void writeContingencies(Collection<Contingency> contingencies, DataSource dataSource, StringToIntMapper<AmplSubset> mapper); static void writeActions(Collection<String> actionIds, DataSource dataSource, StringToIntMapper<AmplSubset> mapper,
                                     String title, AmplSubset amplSubset); static void applyInjections(Network network, String stateId, Map<String, Float> injections); static boolean containsViolation(List<LimitViolation> violations, LimitViolation violation);  }
@Test public void testWriteContingencies() { ContingencyElement contingencyElement = new BranchContingency("line"); Contingency contingency = new Contingency("contigency_1", contingencyElement); MemDataSource dataSource = new MemDataSource(); StringToIntMapper<AmplSubset> mapper = new StringToIntMapper<>(AmplSubset.class); mapper.newInt(AmplSubset.FAULT, contingency.getId()); WCAUtils.writeContingencies(Collections.singleton(contingency), dataSource, mapper); assertEqualsToRef(dataSource, WCAConstants.FAULTS_FILE_SUFFIX, "Contingencies", "contigency_1"); }