Skip to content

Commit

Permalink
fixes cut naming strategy (making it dico-values aware)
Browse files Browse the repository at this point in the history
  • Loading branch information
CBiasuzzi committed Dec 14, 2017
1 parent 30fec2a commit 856c992
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import com.google.common.base.Strings;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -17,6 +19,18 @@
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class CutEurostagNamingStrategy implements EurostagNamingStrategy {

private Set<String> forbiddenEsgIds;

public CutEurostagNamingStrategy() {
forbiddenEsgIds = Collections.emptySet();
}

public CutEurostagNamingStrategy(final Set<String> forbiddenEsgIds) {
Objects.requireNonNull(forbiddenEsgIds);
this.forbiddenEsgIds = forbiddenEsgIds;
}

@Override
public void fillDictionary(EurostagDictionary dictionary, NameType nameType, Set<String> iidmIds) {
EurostagEchExportConfig config = dictionary.getConfig();
Expand All @@ -40,7 +54,7 @@ private String getEsgId(EurostagDictionary dictionary, NameType nameType, String
esgId = esgId.replaceAll(regex, repl);
}
int counter = 0;
while (dictionary.esgIdExists(esgId)) {
while (dictionary.esgIdExists(esgId) || forbiddenEsgIds.contains(esgId)) {
String counterStr = Integer.toString(counter++);
if (counterStr.length() > nameType.getLength()) {
throw new RuntimeException("Renaming fatal error " + iidmId + " -> " + esgId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DicoEurostagNamingStrategy implements EurostagNamingStrategy {

private BiMap<String, String> dicoMap = HashBiMap.create();

private final CutEurostagNamingStrategy defaultStrategy = new CutEurostagNamingStrategy();
private final CutEurostagNamingStrategy defaultStrategy;

class DicoCsvReader {

Expand Down Expand Up @@ -91,6 +91,7 @@ public DicoEurostagNamingStrategy(Path dicoFile) {
}
dicoMap.put(iidmId, esgId);
}
defaultStrategy = new CutEurostagNamingStrategy(new HashSet(dicoMap.values()));
}
}

Expand Down

0 comments on commit 856c992

Please sign in to comment.