Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into itools_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbagu committed Feb 2, 2017
2 parents 532b344 + bd94100 commit 5ed3843
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ public Integer getOptionalIntProperty(String name) {
return value != null ? Integer.parseInt(value) : null;
}

@Override
public Optional<Integer> getOptionalIntegerProperty(String name) {
String value = getStringProperty(name, null);
return Optional.ofNullable(value != null ? Integer.parseInt(value) : null);
}

@Override
public int getIntProperty(String name, int defaultValue) {
return Integer.parseInt(getStringProperty(name, Integer.toString(defaultValue)));
Expand Down Expand Up @@ -175,6 +181,12 @@ public Boolean getOptinalBooleanProperty(String name) {
return value != null ? Boolean.parseBoolean(value) : null;
}

@Override
public Optional<Boolean> getOptionalBooleanProperty(String name) {
String value = getStringProperty(name, null);
return Optional.ofNullable(value != null ? Boolean.parseBoolean(value) : null);
}

@Override
public Path getPathProperty(String name) {
return fs.getPath(getStringProperty(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.joda.time.DateTime;
Expand Down Expand Up @@ -37,8 +38,11 @@ public interface ModuleConfig {

int getIntProperty(String name);

@Deprecated
Integer getOptionalIntProperty(String name);

Optional<Integer> getOptionalIntegerProperty(String name);

int getIntProperty(String name, int defaultValue);

float getFloatProperty(String name);
Expand All @@ -53,8 +57,11 @@ public interface ModuleConfig {

boolean getBooleanProperty(String name, boolean defaultValue);

@Deprecated
Boolean getOptinalBooleanProperty(String name);

Optional<Boolean> getOptionalBooleanProperty(String name);

Path getPathProperty(String name);

Path getPathProperty(String name, Path defaultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Table<String, String, Float> parseMatrix(Reader reader) throws IOE
for (int i = 1; i < row.size(); i++) {
String columnHeader = columnHeaders.get(i);
String value = row.get(i);
table.put(rowHeader, columnHeader, value == null ? Float.NaN : Float.valueOf(value));
table.put(rowHeader, columnHeader, value == null ? Float.NaN : Float.parseFloat(value));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Locale;
import java.nio.charset.StandardCharsets;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand All @@ -36,7 +36,7 @@ public AsciiTableFormatter(Writer writer, String title, TableFormatterConfig con
}

public AsciiTableFormatter(String title, Column... columns) {
this(new OutputStreamWriter(System.out), title, TableFormatterConfig.load(), columns);
this(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), title, TableFormatterConfig.load(), columns);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public synchronized void load(BufferedReader reader) throws IOException {
}
SUBSET subset = Enum.valueOf(clazz, tokens[0]);
String id = tokens[1];
int num = Integer.valueOf(tokens[2]);
int num = Integer.parseInt(tokens[2]);
id2num.get(subset).put(id, num);
counter.put(subset, Math.max(counter.get(subset), num) + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ public void moduleConfigTest() throws IOException, XMLStreamException, SAXExcept
Assert.fail();
} catch (Exception e) {
}
Assert.assertTrue(modConfig.getOptionalIntProperty("i2") == null);
Assert.assertNull(modConfig.getOptionalIntProperty("i2"));
Assert.assertFalse(modConfig.getOptionalIntegerProperty("i2").isPresent());
Assert.assertTrue(modConfig.getIntProperty("i2", 4) == 4);
Assert.assertFalse(modConfig.getBooleanProperty("b"));
try {
modConfig.getBooleanProperty("b2");
Assert.fail();
} catch (Exception e) {
}
Assert.assertNull(modConfig.getOptinalBooleanProperty("b2"));
Assert.assertFalse(modConfig.getOptionalBooleanProperty("b2").isPresent());
Assert.assertTrue(modConfig.getBooleanProperty("b2", true));
Assert.assertTrue(modConfig.getDoubleProperty("d") == 2.3);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testCsv() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
TableFormatterConfig config = new TableFormatterConfig(Locale.US, ';', "inv", true, true);
CsvTableFormatterFactory factory = new CsvTableFormatterFactory();
try (TableFormatter formatter = factory.create(new OutputStreamWriter(bos), "csv test", config, COLUMNS)) {
try (TableFormatter formatter = factory.create(new OutputStreamWriter(bos, StandardCharsets.UTF_8), "csv test", config, COLUMNS)) {
write(formatter);
}
assertEquals(new String(bos.toByteArray(), StandardCharsets.UTF_8),
Expand All @@ -59,7 +59,7 @@ public void testAcsii() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
TableFormatterConfig config = new TableFormatterConfig(Locale.US, "inv");
AsciiTableFormatterFactory factory = new AsciiTableFormatterFactory();
try (TableFormatter formatter = factory.create(new OutputStreamWriter(bos), "ascii test", config, COLUMNS)) {
try (TableFormatter formatter = factory.create(new OutputStreamWriter(bos, StandardCharsets.UTF_8), "ascii test", config, COLUMNS)) {
write(formatter);
}
assertEquals(new String(bos.toByteArray(), StandardCharsets.UTF_8),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class ImportConfig {

public static final List<String> DEFAULT_POST_PROCESSORS = Arrays.asList(JavaScriptPostProcessor.NAME);
public static final List<String> DEFAULT_POST_PROCESSORS = Collections.singletonList(JavaScriptPostProcessor.NAME);

private final List<String> postProcessors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public static Object readParameter(String format, Properties parameters, Paramet
MapModuleConfig moduleConfig = new MapModuleConfig(parameters);
switch (configuredParameter.getType()) {
case BOOLEAN:
value = moduleConfig.getOptinalBooleanProperty(configuredParameter.getName());
value = moduleConfig.getOptionalBooleanProperty(configuredParameter.getName()).get();
break;
case STRING:
value = moduleConfig.getStringProperty(configuredParameter.getName(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public Terminal getTerminal(String voltageLevelId) {
Objects.requireNonNull(voltageLevelId);
boolean side1 = getTerminal1().getVoltageLevel().getId().equals(voltageLevelId);
boolean side2 = getTerminal2().getVoltageLevel().getId().equals(voltageLevelId);
if (side1) {
if (side1 && side2) {
throw new RuntimeException("Both terminals are connected to voltage level " + voltageLevelId);
} else if (side1) {
return getTerminal1();
} else if (side2) {
return getTerminal2();
} else if (side1 && side2) {
throw new RuntimeException("Both terminals are connected to voltage level " + voltageLevelId);
} else {
throw new RuntimeException("No terminal connected to voltage level " + voltageLevelId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public BusExt getBus() {

@Override
public BusExt getConnectableBus() {
ArrayList<Integer> nodes = new ArrayList<>();
nodes.add(node);
return ((NodeBreakerVoltageLevel) voltageLevel).getCalculatedBusBreakerTopology().getConnectableBus(node);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class StateManagerImplTest {

private class IdentifiableMock implements Identifiable, Stateful {
private static class IdentifiableMock implements Identifiable, Stateful {

private final String id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ public void export(Network network, Properties parameters, DataSource dataSource
BufferedOutputStream bos = new BufferedOutputStream(os)) {
Anonymizer anonymizer = NetworkXml.write(network, options, bos);
if (anonymizer != null) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(dataSource.newOutputStream("_mapping", "csv", false)))) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(dataSource.newOutputStream("_mapping", "csv", false), StandardCharsets.UTF_8))) {
anonymizer.write(writer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -168,7 +169,7 @@ public Network import_(ReadOnlyDataSource dataSource, Properties parameters) {
Anonymizer anonymizer = null;
if (dataSource.exists("_mapping", "csv")) {
anonymizer = new SimpleAnonymizer();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(dataSource.newInputStream("_mapping", "csv")))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(dataSource.newInputStream("_mapping", "csv"), StandardCharsets.UTF_8))) {
anonymizer.read(reader);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package eu.itesla_project.iidm.xml;

import com.google.common.collect.ImmutableList;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -18,7 +20,7 @@ public interface XmlConstants {

String INDENT = " ";

List<Integer> VERSION_ARRAY = Arrays.asList(1, 0);
List<Integer> VERSION_ARRAY = ImmutableList.of(1, 0);

String VERSION = VERSION_ARRAY.stream().map(Object::toString).collect(Collectors.joining("."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void writeInt(String name, int value, XMLStreamWriter writer) thro
}

public static int readIntAttribute(XMLStreamReader reader, String attributeName) {
return Integer.valueOf(reader.getAttributeValue(null, attributeName));
return Integer.parseInt(reader.getAttributeValue(null, attributeName));
}

public static boolean readBoolAttribute(XMLStreamReader reader, String attributeName) {
Expand All @@ -76,7 +76,7 @@ public static Integer readOptionalIntegerAttribute(XMLStreamReader reader, Strin

public static int readOptionalIntegerAttribute(XMLStreamReader reader, String attributeName, int defaultValue) {
String attributeValue = reader.getAttributeValue(null, attributeName);
return attributeValue != null ? Integer.valueOf(attributeValue) : defaultValue;
return attributeValue != null ? Integer.parseInt(attributeValue) : defaultValue;
}

public static float readFloatAttribute(XMLStreamReader reader, String attributeName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
public class LimitViolationFilterTest {

private FileSystem fileSystem;
private Path configDir;
private MapModuleConfig moduleConfig;
private InMemoryPlatformConfig platformConfig;

@Before
public void setUp() throws Exception {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
configDir = Files.createDirectory(fileSystem.getPath("/config"));
platformConfig = new InMemoryPlatformConfig(fileSystem);
moduleConfig = platformConfig.createModuleConfig("limit-violation-default-filter");
moduleConfig.setStringListProperty("violationTypes", Arrays.asList("CURRENT", "LOW_VOLTAGE"));
Expand Down

0 comments on commit 5ed3843

Please sign in to comment.