1515import edu .ie3 .datamodel .exceptions .ParsingException ;
1616import edu .ie3 .datamodel .models .profile .BdewStandardLoadProfile ;
1717import edu .ie3 .datamodel .models .value .PValue ;
18- import java .io .Serializable ;
18+ import java .io .* ;
1919import java .time .Month ;
2020import java .time .ZonedDateTime ;
2121import java .util .*;
2828/** Load values for a {@link BdewStandardLoadProfile} */
2929public final class BdewLoadValues implements LoadValues <BdewStandardLoadProfile > {
3030 public final BdewScheme scheme ;
31- private final HashMap <BdewKey , Double > values ;
31+ private transient Map <BdewKey , Double > values ;
3232
33- public BdewLoadValues (BdewScheme scheme , HashMap <BdewKey , Double > values ) {
33+ public BdewLoadValues (BdewScheme scheme , Map <BdewKey , Double > values ) {
3434 this .scheme = scheme ;
35- this .values = values ;
35+ this .values = Collections . unmodifiableMap ( values ) ;
3636 }
3737
3838 /**
@@ -153,7 +153,22 @@ public static double dynamization(double load, int t) {
153153 return round (load * rndFactor * 1e1 ) / 1e1 ; // rounded to 1 decimal place
154154 }
155155
156- public sealed interface BdewKey {
156+ // custom serialization (needed for the values)
157+
158+ @ Serial
159+ private void writeObject (ObjectOutputStream out ) throws IOException {
160+ out .defaultWriteObject ();
161+ out .writeObject (values );
162+ }
163+
164+ @ Serial
165+ @ SuppressWarnings ("unchecked" )
166+ private void readObject (ObjectInputStream in ) throws IOException , ClassNotFoundException {
167+ in .defaultReadObject ();
168+ this .values = Collections .unmodifiableMap ((Map <BdewKey , Double >) in .readObject ());
169+ }
170+
171+ public sealed interface BdewKey extends Serializable {
157172
158173 /**
159174 * Returns the abbreviation of either a {@link BdewSeason} for {@link BdewScheme#BDEW1999} or
@@ -313,7 +328,7 @@ public enum DayType {
313328 }
314329
315330 /** Scheme for underlying values of a {@link BdewLoadValues}. */
316- public enum BdewScheme implements Scheme {
331+ public enum BdewScheme implements Scheme , Serializable {
317332 BDEW1999 (BdewKey .getKeys (BdewSeason .values (), Bdew1999Key ::new )),
318333 BDEW2025 (BdewKey .getKeys (Month .values (), Bdew2025Key ::new ));
319334
@@ -337,7 +352,7 @@ public boolean isAccepted(BdewKey key) {
337352 *
338353 * @param <V> type of value
339354 */
340- public static final class BdewMap <V > implements Serializable {
355+ public static final class BdewMap <V > {
341356 private final Map <BdewKey , V > values ;
342357
343358 public BdewMap (Map <BdewKey , V > values ) {
@@ -440,7 +455,7 @@ public Collection<V> values() {
440455 * @return the new {@link BdewMap}
441456 * @param <R> type of new values
442457 */
443- public <R > HashMap <BdewKey , R > map (Function <V , R > mapper ) {
458+ public <R > Map <BdewKey , R > map (Function <V , R > mapper ) {
444459 HashMap <BdewKey , R > map = new HashMap <>();
445460 values .forEach ((key , value ) -> map .put (key , mapper .apply (value )));
446461 return map ;
0 commit comments