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

Appearance settings

Commit fac8dc7

Browse filesBrowse files
author
Guruprasad Kulkarni
committed
In Progress COmpletable Future and Streams Improvement
1 parent ff7691a commit fac8dc7
Copy full SHA for fac8dc7

File tree

Expand file treeCollapse file tree

2 files changed

+90
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+90
-0
lines changed

‎CompletableFutureAdditions.java

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* CompletableFutureAdditions
3+
*/
4+
public class CompletableFutureAdditions {
5+
public static void main(String[] args) {
6+
7+
}
8+
9+
}

‎StreamsImprovements.java

Copy file name to clipboard
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.time.Duration;
2+
import java.time.LocalDate;
3+
import java.time.Month;
4+
import java.time.Period;
5+
import java.time.temporal.ChronoUnit;
6+
import java.time.temporal.TemporalField;
7+
import java.util.Objects;
8+
import java.util.Random;
9+
10+
/**
11+
* StreamsImprovements
12+
*/
13+
14+
public class StreamsImprovements {
15+
public static void main(String[] args) {
16+
getBooks().
17+
}
18+
19+
20+
21+
/**
22+
* New recommendation from Joshua Bloch -- If you know that the callers of your method are happy using Stream as a return, use it!!!!
23+
*/
24+
private static Stream<Book> getBooks() {
25+
Book ef3e = new Book("Effective Java 3rd Edition", "Joshua Bloch", "978-0-13-468599-1", LocalDate.of(2017, Month.DECEMBER, 20));
26+
Book cjs9fi = new Book("Core Java SE 9 for the Impatient, 2nd Edition", "Cay S. Horstmann", "978-0-13-469472-6", LocalDate.of(2017, Month.SEPTEMBER, 15));
27+
Book j9fp = new Book("Java 9 for Programmers, 4th Edition", "Paul J. Deitel, Harvey Deitel", "978-0-13-477756-6", LocalDate.of(2017, Month.MAY, 11));
28+
Book ej2ne = new Book("Effective Java 2nd Edition", "Joshua Bloch", "ISBN-13: 978-0-321-35668-0", LocalDate.of(2008, Month.MAY, 8));
29+
Book rwjeep = new Book("Real World Java EE Patterns--Rethinking Best Practices", "Adam Bien", "978-1-300-14931-6", LocalDate.of(2012, Month.SEPTEMBER, 5));
30+
Book rwjeenh = new Book("Real World Java EE Night Hacks - Dissecting the Business Tier", "Adam Bien", "978-0-557-07832-5", LocalDate.of(2008, Month.MAY, 8));
31+
return Stream.of(ef3e, cjs9fi, j9fp, ej2ne, rwjeep, rwjeenh);
32+
}
33+
34+
}
35+
36+
class Book {
37+
private final String name;
38+
private final String author;
39+
private final String isbn;
40+
private final LocalDate publishDate;
41+
42+
public Book(String name, String author, String isbn, LocalDate publishDate) {
43+
this.name = name;
44+
this.author = author;
45+
this.isbn = isbn;
46+
this.publishDate = publishDate;
47+
}
48+
49+
public Period getBookAgeinMonths() {
50+
return Period.between(publishDate, LocalDate.now());
51+
}
52+
53+
/**
54+
* @return the name
55+
*/
56+
public String getName() {
57+
return name;
58+
}
59+
60+
/**
61+
* @return the isbn
62+
*/
63+
public String getIsbn() {
64+
return isbn;
65+
}
66+
67+
/**
68+
* @return the publishDate
69+
*/
70+
public LocalDate getPublishDate() {
71+
return publishDate;
72+
}
73+
74+
/**
75+
* @return the author
76+
*/
77+
public String getAuthor() {
78+
return author;
79+
}
80+
81+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.