WCAUtils { public static void writeActions(Collection<String> actionIds, DataSource dataSource, StringToIntMapper<AmplSubset> mapper, String title, AmplSubset amplSubset) { Objects.requireNonNull(actionIds); Objects.requireNonNull(dataSource); Objects.requireNonNull(mapper); Objects.requireNonNull(title); Objects.requireNonNull(amplSubset); try (Writer writer = new OutputStreamWriter(dataSource.newOutputStream(WCAConstants.ACTIONS_FILE_SUFFIX, WCAConstants.TXT_EXT, false), StandardCharsets.UTF_8); TableFormatter formatter = new AmplDatTableFormatter( writer, title, AmplConstants.INVALID_FLOAT_VALUE, true, AmplConstants.LOCALE, new Column("num"), new Column("id"))) { for (String actionId : actionIds) { int actionNum = mapper.getInt(amplSubset, actionId); formatter.writeCell(actionNum) .writeCell(actionId); } } 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 testWriteActions() { MemDataSource dataSource = new MemDataSource(); StringToIntMapper<AmplSubset> mapper = new StringToIntMapper<>(AmplSubset.class); mapper.newInt(AmplSubset.CURATIVE_ACTION, "action_1"); WCAUtils.writeActions(Collections.singleton("action_1"), dataSource, mapper, "Curative actions", AmplSubset.CURATIVE_ACTION); assertEqualsToRef(dataSource, WCAConstants.ACTIONS_FILE_SUFFIX, "Curative actions", "action_1"); mapper.newInt(AmplSubset.PREVENTIVE_ACTION, "action_1"); WCAUtils.writeActions(Collections.singleton("action_1"), dataSource, mapper, "Preventive actions", AmplSubset.PREVENTIVE_ACTION); assertEqualsToRef(dataSource, WCAConstants.ACTIONS_FILE_SUFFIX, "Preventive actions", "action_1"); }