Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ngoch/json-stat.java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

143 Commits

Repository files navigation

Implementation of JSON Stat in Java - http://json-stat.org

Status

Build Status Maven Central Javadoc Gitter Chat

Usage

Add json stat dependency into your project

<dependency>
 <groupId>no.ssb.jsonstat</groupId>
 <artifactId>json-stat-java</artifactId>
 <version>0.2.2</version>
</dependency>

Register the module

class Example {
 static {
 mapper = new ObjectMapper();
 mapper.registerModule(new JsonStatModule());
 }
}

Create a new json stat data set

class Example {
 static {
 Dataset.Builder builder = Dataset.create().withLabel("My dataset");
 builder.withDimension(
 Dimension.create("year")
 .withRole(Dimension.Roles.TIME)
 .withIndexedLabels(ImmutableMap.of("2003", "2003", "2004", "2004", "2005", "2005")
 )
 );
 builder.withDimension(
 Dimension.create("month").withRole(Dimension.Roles.TIME)
 .withIndexedLabels(ImmutableMap.of("may", "may", "june", "june", "july", "july")
 )
 );
 builder.withDimension(
 Dimension.create("week").withTimeRole()
 .withIndexedLabels(ImmutableMap.of("30", "30", "31", "31", "32", "32")
 )
 );
 builder.withDimension(
 Dimension.create("population").withMetricRole()
 .withIndexedLabels(ImmutableMap.of(
 "A", "active population",
 "E", "employment",
 "U", "unemployment",
 "I", "inactive population",
 "T", "population 15 years old and over"))
 );
 builder.withDimension(
 Dimension.create("amount").withMetricRole()
 .withIndexedLabels(ImmutableMap.of("millions", "millions"))
 );
 builder.withDimension(
 Dimension.create("percent").withMetricRole()
 .withIndexedLabels(ImmutableMap.of("%", "percent"))
 );
 Dataset dataset = builder.withMapper(
 dimensions -> newArrayList(
 dimensions.hashCode(),
 dimensions.hashCode())
 );
 }
}

Deserialize a dataset

class Example {
 static {
 mapper = new ObjectMapper();
 mapper.registerModule(new JsonStatModule());
 Dataset.Builder builder = mapper.readValue("{ ... }", Dataset.Builder.class);
 // Or
 Dataset dataset = mapper.readValue("{ ... }", Dataset.class);
 }
}

About

Implementation of JSON Stat in Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%

AltStyle によって変換されたページ (->オリジナル) /