5656import java .time .ZonedDateTime ;
5757import java .time .format .DateTimeFormatter ;
5858import java .util .*;
59+ import java .util .concurrent .ConcurrentHashMap ;
60+ import java .util .concurrent .ConcurrentMap ;
5961import java .util .concurrent .ExecutorService ;
6062import java .util .concurrent .ForkJoinPool ;
6163import java .util .function .Supplier ;
@@ -89,7 +91,7 @@ public final class NetworkSerDe {
8991 static final byte [] BIIDM_MAGIC_NUMBER = {0x42 , 0x69 , 0x6e , 0x61 , 0x72 , 0x79 , 0x20 , 0x49 , 0x49 , 0x44 , 0x4d };
9092
9193 private static final Supplier <Schema > DEFAULT_SCHEMA_SUPPLIER = Suppliers .memoize (() -> NetworkSerDe .createSchema (DefaultExtensionsSupplier .getInstance ()));
92- private static final Supplier <Map <IidmVersion , Schema >> DEFAULT_SCHEMAS_SUPPLIER = Suppliers .memoize (() -> NetworkSerDe . createDefaultSchemas ( DefaultExtensionsSupplier . getInstance ()) );
94+ private static final Supplier <ConcurrentMap <IidmVersion , Schema >> DEFAULT_SCHEMAS_SUPPLIER = Suppliers .memoize (ConcurrentHashMap :: new );
9395 private static final int MAX_NAMESPACE_PREFIX_NUM = 100 ;
9496 private static final String XSD_RESOURCE_DIR = "/xsd/" ;
9597
@@ -177,10 +179,7 @@ private static void validate(InputStream is, IidmVersion version, ExtensionsSupp
177179 // XSD validation
178180 Schema schema ;
179181 if (extensionsSupplier == DefaultExtensionsSupplier .getInstance ()) {
180- schema = DEFAULT_SCHEMAS_SUPPLIER .get ().get (version );
181- if (schema == null ) {
182- throw new PowsyblException ("Schema not found: version=" + version );
183- }
182+ schema = DEFAULT_SCHEMAS_SUPPLIER .get ().computeIfAbsent (version , v -> createSchema (DefaultExtensionsSupplier .getInstance (), v ));
184183 } else {
185184 schema = createSchema (extensionsSupplier , version );
186185 }
@@ -193,15 +192,6 @@ private static void validate(InputStream is, IidmVersion version, ExtensionsSupp
193192 }
194193 }
195194
196- private static Map <IidmVersion , Schema > createDefaultSchemas (ExtensionsSupplier extensionsSupplier ) {
197- Map <IidmVersion , Schema > schemasByIIdmVersion = new EnumMap <>(IidmVersion .class );
198- for (IidmVersion version : IidmVersion .values ()) {
199- Schema schema = createSchema (extensionsSupplier , version );
200- schemasByIIdmVersion .put (version , schema );
201- }
202- return schemasByIIdmVersion ;
203- }
204-
205195 private static Schema createSchema (ExtensionsSupplier extensionsSupplier , IidmVersion version ) {
206196 Objects .requireNonNull (extensionsSupplier );
207197 Objects .requireNonNull (version );
0 commit comments