forked from JorgenRingen/stream-lambda-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.idea | ||
/*.iml | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<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>com.github.javacodekata</groupId> | ||
<artifactId>stream-lambda</artifactId> | ||
<name>stream-lambda</name> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<scm> | ||
<connection>scm:git:git@github.com:JavaCodeKata/stream-lambda.git</connection> | ||
<url>scm:git:git@github.com:JavaCodeKata/stream-lambda.git</url> | ||
<developerConnection>scm:git:git@github.com:JavaCodeKata/stream-lambda.git</developerConnection> | ||
</scm> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>18.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/github/javacodekata/lambda/stream/ListTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.javacodekata.lambda.stream; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public class ListTransformer { | ||
|
||
private final List<String> values; | ||
|
||
private ListTransformer(List<String> values) { | ||
this.values = values; | ||
} | ||
|
||
public static ListTransformer of(List<String> values) { | ||
checkNotNull(values); | ||
return new ListTransformer(ImmutableList.copyOf(values)); | ||
} | ||
|
||
public List<String> getSortedStrings() { | ||
return values; | ||
} | ||
|
||
public List<Integer> getSortedIntegers() { | ||
return new LinkedList<>(); | ||
} | ||
|
||
public List<Integer> getSortedDescendingIntegers() { | ||
return new LinkedList<>(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/com/github/javacodekata/lambda/stream/ListTransformerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.javacodekata.lambda.stream; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class ListTransformerTest { | ||
|
||
private static final String[] strings = | ||
{ "a", "7", "4", "z", "T", "c", "10", "h", "2" }; | ||
|
||
private ListTransformer listTransformer; | ||
|
||
@Before | ||
public void setup() { | ||
this.listTransformer = ListTransformer.of(Arrays.asList(strings)); | ||
} | ||
|
||
@Test | ||
public void testGetSortedStrings() throws Exception { | ||
assertThat(listTransformer.getSortedStrings(), is(equalTo(Arrays.asList("10", "2", "4", "7", "T", "a", "c", "h", "z")))); | ||
} | ||
|
||
@Test | ||
public void testGetSortedIntegers() throws Exception { | ||
assertThat(listTransformer.getSortedIntegers(), is(equalTo(Arrays.asList(2, 4, 7, 10)))); | ||
} | ||
|
||
@Test | ||
public void testGetSortedDescendingIntegers() throws Exception { | ||
assertThat(listTransformer.getSortedDescendingIntegers(), is(equalTo(Arrays.asList(10, 7, 4, 2)))); | ||
} | ||
|
||
} |