Skip to content
Snippets Groups Projects
Commit ce23c546 authored by Powers, Peter M.'s avatar Powers, Peter M.
Browse files

models additions

parent 22314a8f
No related branches found
No related tags found
1 merge request!194Updates for tree-info.json change
/**
*
*/
package gov.usgs.earthquake.nshmp.model; package gov.usgs.earthquake.nshmp.model;
import static java.util.stream.Collectors.toList;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/** /**
* Factory class for querying source models. * Factory class for querying source models.
* *
* @author U.S. Geological Survey * @author U.S. Geological Survey
*
*/ */
public class Models { public class Models {
void trees(HazardModel model) { static final Gson GSON = new GsonBuilder()
// return an object that can be serialized to JSON .setPrettyPrinting()
.create();
public static void main(String[] args) {
HazardModel model = ModelLoader.load(Path.of("../nshm-conus"));
List<?> trees = trees(model);
String out = GSON.toJson(trees);
System.out.println(out);
}
/**
* Returns a serializable list of source logic tree groups.
*
* @param model to extract logic tree data from
*/
public static List<?> trees(HazardModel model) {
return model.trees().asMap().entrySet().stream()
.map(Models::toTreeGroup)
.collect(toList());
}
private static TreeGroup toTreeGroup(Entry<TectonicSetting, Collection<SourceTree>> entry) {
return new TreeGroup(
entry.getKey(),
entry.getValue().stream()
.map(Tree::new)
.collect(toList()));
}
static final class TreeGroup {
final TectonicSetting setting;
final List<Tree> trees;
TreeGroup(TectonicSetting setting, List<Tree> trees) {
this.setting = setting;
this.trees = trees;
}
}
static final class Tree {
final int id;
final String name;
final SourceType type;
Tree(SourceTree tree) {
this.id = tree.id();
this.name = tree.name();
this.type = tree.type();
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment