Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab_reactive_java
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
rtbdp
labs
lab_reactive_java
Commits
5bb02d6a
Commit
5bb02d6a
authored
7 years ago
by
José Paumard
Browse files
Options
Downloads
Patches
Plain Diff
Added an example for the Stream.takeWhile method.
parent
48496304
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
LambdaLab/test/exercises/E_IntermediateStreams.java
+27
-1
27 additions, 1 deletion
LambdaLab/test/exercises/E_IntermediateStreams.java
LambdaLab/test/solutions/E_IntermediateStreams.java
+30
-1
30 additions, 1 deletion
LambdaLab/test/solutions/E_IntermediateStreams.java
with
57 additions
and
2 deletions
LambdaLab/test/exercises/E_IntermediateStreams.java
+
27
−
1
View file @
5bb02d6a
...
...
@@ -6,19 +6,23 @@ import java.math.BigInteger;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.AbstractCollection
;
import
java.util.AbstractList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
import
java.util.stream.LongStream
;
import
java.util.stream.Stream
;
import
org.junit.After
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
...
@@ -208,6 +212,28 @@ public class E_IntermediateStreams {
// Use Stream.reduce() and think about the order of the arguments.
// </editor-fold>
/**
* Create a list containing all the super classes of ArrayList.
*/
@Test
public
void
e8_selectTheSuperClassesOfArrayList
()
{
Class
<?>
origin
=
ArrayList
.
class
;
List
<
String
>
result
=
null
;
// TODO
assertEquals
(
Arrays
.
asList
(
ArrayList
.
class
,
AbstractList
.
class
,
AbstractCollection
.
class
,
Object
.
class
),
result
);
}
// Hint:
// <editor-fold defaultstate="collapsed">
// There is a getSuperClass() method on the Class class.
// Creating a stream of these classes can be made with Stream.iterate().
// Then you need to close that stream when the current class is null.
// Java 9 added the takeWhile() method on the stream interface.
// </editor-fold>
// ========================================================
// END OF EXERCISES
...
...
This diff is collapsed.
Click to expand it.
LambdaLab/test/solutions/E_IntermediateStreams.java
+
30
−
1
View file @
5bb02d6a
...
...
@@ -6,19 +6,23 @@ import java.math.BigInteger;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.AbstractCollection
;
import
java.util.AbstractList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
import
java.util.stream.LongStream
;
import
java.util.stream.Stream
;
import
org.junit.After
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
...
@@ -262,6 +266,31 @@ public class E_IntermediateStreams {
// Use Stream.reduce() and think about the order of the arguments.
// </editor-fold>
/**
* Create a list containing all the super classes of ArrayList.
*/
@Test
public
void
e8_selectTheSuperClassesOfArrayList
()
{
Class
<?>
origin
=
ArrayList
.
class
;
//TODO//List<String> result = null;
//BEGINREMOVE
Stream
<
Class
<?>>
stream
=
Stream
.<
Class
<?>>
iterate
(
origin
,
clazz
->
clazz
.
getSuperclass
());
List
<
Class
<?>>
result
=
stream
.
takeWhile
(
clazz
->
clazz
!=
null
).
collect
(
Collectors
.
toList
());
//ENDREMOVE
assertEquals
(
Arrays
.
asList
(
ArrayList
.
class
,
AbstractList
.
class
,
AbstractCollection
.
class
,
Object
.
class
),
result
);
}
// Hint:
// <editor-fold defaultstate="collapsed">
// There is a getSuperClass() method on the Class class.
// Creating a stream of these classes can be made with Stream.iterate().
// Then you need to close that stream when the current class is null.
// Java 9 added the takeWhile() method on the stream interface.
// </editor-fold>
// ========================================================
// END OF EXERCISES
...
...
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