Skip to content

Commit f90e1fb

Browse files
committed
Merge pull request AdoptOpenJDK#3 from karianna/master
Fixes AdoptOpenJDK#1 and AdoptOpenJDK#2 + some Javadoc patches
2 parents d97e737 + af89eeb commit f90e1fb

5 files changed

Lines changed: 35 additions & 40 deletions

File tree

pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
</plugins>
2929
</build>
3030

31-
3231
<dependencies>
33-
3432
<dependency>
3533
<groupId>junit</groupId>
3634
<artifactId>junit</artifactId>
@@ -49,7 +47,5 @@
4947
<version>1.3</version>
5048
<scope>test</scope>
5149
</dependency>
52-
53-
5450
</dependencies>
5551
</project>

src/main/java/org/adoptopenjdk/lambda/setupcheck/ConfigureYourLambdaBuildOfJdk.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import static java.util.Arrays.asList;
55

66
/**
7-
*
8-
*
9-
* Lambda Tutorial -- Adopt Open JDK
7+
* Utility class to warn users if they have an incorrect environment
108
* @author Graham Allan grundlefleck at gmail dot com
119
*/
1210
public class ConfigureYourLambdaBuildOfJdk {

src/main/java/org/adoptopenjdk/lambda/tutorial/exercise1/Shapes.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void colorAll(List<Shape> shapes, Color newColor) {
3535
* Example:
3636
* given a list containing [BLUE shape, GREEN shape, BLACK shape]
3737
* when this method is called with that list and an empty StringBuilder
38-
* then the StringBuilder's toString method will return "[BLUE][GREEN][BLACK]"
38+
* then the StringBuilder's toString method will return "[a BLUE shape][a GREEN shape][a BLACK shape]"
3939
*
4040
* @see Shape#toString()
4141
*/
@@ -47,14 +47,15 @@ public static void makeStringOfAllColors(List<Shape> shapes, StringBuilder strin
4747
* Changes the color of each given shape to newColor, appending a String representation of the color of all the
4848
* shapes, as they were before they were changed.
4949
*
50-
*
5150
* Example:
5251
* given a list containing [BLUE shape, GREEN shape, BLACK shape]
5352
* when this method is called with that list, the color RED, and an empty StringBuilder
5453
* then the list will contain [RED shape, RED shape, RED shape]
55-
* and the StringBuilder's toString method will return "[BLUE][GREEN][BLACK]"
54+
* and the StringBuilder's toString method will return "[a BLUE shape][a GREEN shape][a BLACK shape]"
5655
*
57-
* This operation is performed in one pass over the <code>shapes</code> List.
56+
* This operation is performed in one pass over the <code>shapes</code> List. Note that syntactically a
57+
* lambda is similar toan ordinary Java code block. Therefore multiple statements separated by ; are
58+
* perfectly legal e.g. <code> (x -> { x.doSomething(); y.doSomethingElse(); });</code>
5859
*
5960
* @see Shape#setColor(Color)
6061
* @see Shape#toString()

src/test/java/org/adoptopenjdk/lambda/tutorial/Exercise_1_Test.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.adoptopenjdk.lambda.tutorial;
22

3-
43
import org.adoptopenjdk.lambda.tutorial.exercise1.Color;
54
import org.adoptopenjdk.lambda.tutorial.exercise1.Shape;
65
import org.adoptopenjdk.lambda.tutorial.exercise1.Shapes;
@@ -22,44 +21,51 @@
2221
import static org.hamcrest.Matchers.everyItem;
2322
import static org.hamcrest.Matchers.hasSize;
2423

25-
2624
/**
2725
* Exercise 1 - Internal vs External iteration.
28-
*
26+
* <p>
2927
* As described in Brian Goetz's State of the Lambda - Libraries Edition[0], Java's collection classes provide a way for
3028
* clients to enumerate the members of a collection. Currently, this is iteration is "External" - that is, the
3129
* collection can be iterated in sequence, by the client code.
32-
*
30+
* </p>
31+
* <p>
3332
* This refers to the trusty "for loop":
34-
*
35-
* for (Shape s: shapes) {
33+
* <pre>
34+
* {@code
35+
* for (Shape s: shapes) {
3636
* s.setColor(RED)
37-
* }
38-
*
37+
* }
38+
* }
39+
* </pre>
40+
* </p>
41+
* <p>
3942
* JDK 8, with lambdas and an updated Collections library, will allow "Internal" iteration. In this case, the collection
4043
* receives some code, and decides how to apply that to its elements. This has several benefits, including:
4144
* - allowing the collection to decide how to handle executing given code, including opening the door to parallelism and laziness
4245
* - leads to a style where operations can be pipelined, into a more fluent, readable style.
43-
*
46+
* </p>
47+
* <p>
4448
* Internal iteration, using lambda expression syntax, turns the above for loop into:
45-
*
46-
* shapes.forEach(s -> s.setColor(RED))
47-
*
48-
* Where "s -> s.setColor(RED)" is a lambda expression, which is passed into forEach, and invoked inside forEach. Lambda
49+
* <pre>
50+
* {@code
51+
* shapes.forEach(s -> s.setColor(RED))
52+
* }
53+
* </pre>
54+
* Where <code>s -> s.setColor(RED)</code> is a lambda expression, which is passed into forEach, and invoked inside forEach. Lambda
4955
* expressions have a type, called a "Functional Interface". In this case the lambda is of type Consumer. Consumer declares
50-
* a single method, "void accept(T t)". This is all hidden by the Java compiler, and unless you extract the lambda to a
51-
* variable, or write a method which accepts a lambda, you don't really need to know about it.
52-
*
53-
* The below tests can be made to pass using for loops. Try to make them pass without using a for loop.
54-
*
56+
* a single method, <code>void accept(T t)</code>. This is all hidden by the Java compiler, and unless you extract the lambda
57+
* to a variable, or write a method which accepts a lambda, you don't really need to know about it.
58+
* </p>
59+
* <p>
60+
* The tests below can be made to pass using for loops. Try to make them pass without using a for loop.
61+
* </p>
5562
* [0] http://cr.openjdk.java.net/~briangoetz/lambda/sotc3.html
56-
*
63+
*
5764
* @see java.lang.Iterable#forEach
5865
* @see Shape
5966
* @see Shapes
6067
* @see Color
6168
*
62-
* Lambda Tutorial -- Adopt Open JDK
6369
* @author Graham Allan grundlefleck at gmail dot com
6470
*/
6571
@SuppressWarnings("unchecked")
@@ -110,7 +116,6 @@ public void buildStringRepresentingAllShapes() {
110116
assertThat(builder.toString(), equalTo("[a RED shape][a BLACK shape][a YELLOW shape]"));
111117
}
112118

113-
114119
/**
115120
* Use forEach to change the color, and build a string showing the old colors of each shape.
116121
*
@@ -131,17 +136,12 @@ public void changeColorOfAllShapes_AND_buildStringShowingAllTheOldColors() {
131136

132137
assertThat(myShapes, hasSize(3));
133138
assertThat(myShapes, everyItem(hasColor(GREEN)));
134-
assertThat(builder.toString(), equalTo("[BLUE][BLACK][YELLOW]"));
139+
assertThat(builder.toString(), equalTo("[a BLUE shape][a BLACK shape][a YELLOW shape]"));
135140
}
136141

137-
138-
139-
// Test helpers
142+
// ----- Test helpers -----
140143

141144
private static Matcher<Shape> hasColor(Color color) {
142145
return FeatureMatchers.from(Matchers.is(color), "has color", "color", Shape::getColor);
143146
}
144147
}
145-
146-
147-

src/test/java/org/adoptopenjdk/lambda/tutorial/Exercise_2_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static Matcher<RegisteredVoter> aVoterWithId(String name) {
226226
}
227227

228228
private static Matcher<Ballot> spoiled() {
229-
return FeatureMatchers.from(equalTo(true), "a spoiled ballot", "isSpoiled", b -> b.isSpoiled);
229+
return FeatureMatchers.from(equalTo(Boolean.TRUE), "a spoiled ballot", "isSpoiled", b -> b.isSpoiled);
230230
}
231231

232232
}

0 commit comments

Comments
 (0)