Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nshmp-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Seismic Hazard Model Project
nshmp-lib
Commits
ce23c546
Commit
ce23c546
authored
3 years ago
by
Powers, Peter M.
Browse files
Options
Downloads
Patches
Plain Diff
models additions
parent
22314a8f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!194
Updates for tree-info.json change
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/gov/usgs/earthquake/nshmp/model/Models.java
+61
-6
61 additions, 6 deletions
src/main/java/gov/usgs/earthquake/nshmp/model/Models.java
with
61 additions
and
6 deletions
src/main/java/gov/usgs/earthquake/nshmp/model/Models.java
+
61
−
6
View file @
ce23c546
/**
*
*/
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
();
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment