Skip to content

Commit

Permalink
Pretty code
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Courtier <[email protected]>
  • Loading branch information
rcourtier committed Feb 18, 2025
1 parent 8227667 commit 1e8fdfd
Showing 1 changed file with 39 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
public final class CgmesNamespace {

private static final Logger LOG = LoggerFactory.getLogger(CgmesNamespace.class);

private CgmesNamespace() {
}

private static final Logger LOG = LoggerFactory.getLogger(CgmesNamespace.class);

// cim14 is the CIM version corresponding to ENTSO-E Profile 1
// It is used in this project to explore how to support future CGMES versions
// We have sample models in cim14 and we use a different set of queries to obtain data
Expand Down Expand Up @@ -66,13 +66,8 @@ private CgmesNamespace() {

public static final List<Cim> CIM_LIST = List.of(CIM_14, CIM_16, CIM_100);

public static boolean isValid(String ns) {
// Until CIM16 the CIM namespace contained the string "CIM-schema-cim<versionNumber>#"
// Since CIM100 the namespace seems to follow the pattern "/CIM<versionNumber>#"
return VALID_CIM_NAMESPACES.contains(ns) || CIM_100_PLUS_NAMESPACE_PATTERN.matcher(ns).matches();
}

public interface Cim {

int getVersion();

String getNamespace();
Expand All @@ -91,9 +86,15 @@ public interface Cim {
}

private abstract static class AbstractCim implements Cim {

private final int version;
private final String namespace;

private AbstractCim(int version, String namespace) {
this.version = version;
this.namespace = namespace;
}

@Override
public int getVersion() {
return version;
Expand All @@ -103,15 +104,14 @@ public int getVersion() {
public String getNamespace() {
return namespace;
}

private AbstractCim(int version, String namespace) {
this.version = version;
this.namespace = namespace;
}
}

private static final class Cim14 extends AbstractCim {

private Cim14() {
super(14, CIM_14_NAMESPACE);
}

@Override
public boolean hasProfiles() {
return false;
Expand Down Expand Up @@ -141,10 +141,6 @@ public String getEuPrefix() {
public String getEuNamespace() {
throw new PowsyblException("Undefined EU namespace for version 14");
}

private Cim14() {
super(14, CIM_14_NAMESPACE);
}
}

private abstract static class AbstractCim16AndAbove extends AbstractCim {
Expand All @@ -153,6 +149,13 @@ private abstract static class AbstractCim16AndAbove extends AbstractCim {
private final String euNamespace;
private final BiMap<String, String> profiles = HashBiMap.create();

private AbstractCim16AndAbove(int version, String namespace, String euPrefix, String euNamespace, Map<String, String> profiles) {
super(version, namespace);
this.euPrefix = euPrefix;
this.euNamespace = euNamespace;
this.profiles.putAll(profiles);
}

@Override
public String getEuPrefix() {
return euPrefix;
Expand Down Expand Up @@ -182,36 +185,41 @@ public String getProfileUri(String profile) {
public String getProfile(String profileUri) {
return profiles.inverse().get(profileUri);
}

private AbstractCim16AndAbove(int version, String namespace, String euPrefix, String euNamespace, Map<String, String> profiles) {
super(version, namespace);
this.euPrefix = euPrefix;
this.euNamespace = euNamespace;
this.profiles.putAll(profiles);
}
}

private static final class Cim16 extends AbstractCim16AndAbove {

private Cim16() {
super(16, CIM_16_NAMESPACE, "entsoe", ENTSOE_NAMESPACE,
Map.of("EQ", CIM_16_EQ_PROFILE, "EQ_OP",
CIM_16_EQ_OPERATION_PROFILE, "SSH", CIM_16_SSH_PROFILE, "SV",
CIM_16_SV_PROFILE, "TP", CIM_16_TP_PROFILE,
"EQ_BD", CIM_16_EQ_BD_PROFILE, "TP_BD", CIM_16_TP_BD_PROFILE));
Map.of("EQ", CIM_16_EQ_PROFILE,
"EQ_OP", CIM_16_EQ_OPERATION_PROFILE,
"SSH", CIM_16_SSH_PROFILE,
"SV", CIM_16_SV_PROFILE,
"TP", CIM_16_TP_PROFILE,
"EQ_BD", CIM_16_EQ_BD_PROFILE,
"TP_BD", CIM_16_TP_BD_PROFILE));
}
}

private static final class Cim100 extends AbstractCim16AndAbove {

private Cim100() {
super(100, CIM_100_NAMESPACE, "eu", EU_NAMESPACE,
Map.of("EQ", CIM_100_EQ_PROFILE, "EQ_OP", CIM_100_EQ_OPERATION_PROFILE,
"SSH", CIM_100_SSH_PROFILE, "SV", CIM_100_SV_PROFILE, "TP", CIM_100_TP_PROFILE,
"EQ_BD", CIM_100_EQ_BD_PROFILE));
Map.of("EQ", CIM_100_EQ_PROFILE,
"EQ_OP", CIM_100_EQ_OPERATION_PROFILE,
"SSH", CIM_100_SSH_PROFILE,
"SV", CIM_100_SV_PROFILE,
"TP", CIM_100_TP_PROFILE,
"EQ_BD", CIM_100_EQ_BD_PROFILE));
}
}

public static boolean isValid(String ns) {
// Until CIM16 the CIM namespace contained the string "CIM-schema-cim<versionNumber>#"
// Since CIM100 the namespace seems to follow the pattern "/CIM<versionNumber>#"
return VALID_CIM_NAMESPACES.contains(ns) || CIM_100_PLUS_NAMESPACE_PATTERN.matcher(ns).matches();
}

public static Cim getCim(int cimVersion) {
switch (cimVersion) {
case 14:
Expand Down

0 comments on commit 1e8fdfd

Please sign in to comment.