Skip to content

Commit

Permalink
now deserializes branches with random nodes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmilner committed Mar 1, 2024
1 parent fa94f2a commit 0b12d04
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Objects;

import org.opensha.commons.logicTree.LogicTreeLevel.FileBackedLevel;
import org.opensha.commons.logicTree.LogicTreeLevel.RandomlySampledLevel;
import org.opensha.commons.logicTree.LogicTreeNode.FileBackedNode;
import org.opensha.commons.logicTree.LogicTreeNode.RandomlySampledNode;
import org.opensha.commons.util.ClassUtils;
Expand Down Expand Up @@ -645,6 +646,14 @@ public void loadValueArray(JsonReader in, List<LogicTreeLevel<? extends LogicTre
level = new FileBackedLevel(
level.getName(), level.getShortName(), (FileBackedNode)value);
}
} else if (value instanceof RandomlySampledNode && level instanceof RandomlySampledLevel<?>) {
RandomlySampledLevel<?> randLevel = (RandomlySampledLevel<?>)level;
if (randLevel.getNodes().isEmpty())
randLevel.setNodes(List.of(value));
else
Preconditions.checkState(randLevel.isMember(value),
"Random level '%s' has node list, but our node ('%s' with seed %s) isn't a member",
level.getName(), value.getName(), ((RandomlySampledNode)value).getSeed());
}
}
levels.add(level);
Expand Down

0 comments on commit 0b12d04

Please sign in to comment.