Skip to content
Snippets Groups Projects
Commit c9f5e74f authored by Joel Cavat's avatar Joel Cavat
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.hepia</groupId>
<artifactId>my-project</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- The plugin provides 2 goals to help execute system and Java programs. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>ch.hepia.App</mainClass>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
<!-- The Surefire Plugin is used during the test phase of the build lifecycle
to execute the unit tests of an application -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!-- Used to create a jar with all dependencies (mvn package will create it) -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package ch.hepia;
import javax.json.*;
import java.io.*;
public class App {
public App() {
ClassLoader classLoader = getClass().getClassLoader();
var url = classLoader.getResource("orders.json");
File file = new File(url.getFile());
try(InputStream input = new FileInputStream(file)) {
JsonReader reader = Json.createReader(input);
JsonArray orders = reader.readArray();
// List without duplicates :
orders.stream() // Stream<JsonValue>
.flatMap(
o -> o.asJsonObject().getJsonArray("vendors").stream().map( v -> v.asJsonObject().getString("slug"))
) // Stream<String> (slugs)
.distinct() // Stream<String> without duplicates
.forEach(System.out::println); // void
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new App();
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment