FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java_upgrade/src/main/java/io/ProcessDictionary.java at master · FUTRFUNC/java_upgrade · GitHub
FUTRFUNC
/
java_upgrade
Public
forked from
kousen/java_upgrade
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
io
/
ProcessDictionary.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
94 lines (83 loc) · 3.77 KB
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
io
/
ProcessDictionary.java
Copy path
File metadata and controls
94 lines (83 loc) · 3.77 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package
io
;
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
FileReader
;
import
java
.
io
.
IOException
;
import
java
.
nio
.
file
.
Files
;
import
java
.
nio
.
file
.
Path
;
import
java
.
nio
.
file
.
Paths
;
import
java
.
util
.
Comparator
;
import
java
.
util
.
Map
;
import
java
.
util
.
stream
.
Collectors
;
import
java
.
util
.
stream
.
Stream
;
import
static
java
.
util
.
stream
.
Collectors
.
counting
;
import
static
java
.
util
.
stream
.
Collectors
.
groupingBy
;
public
class
ProcessDictionary
{
private
Path
dictionary
=
Paths
.
get
(
"/usr/share/dict/words"
);
public
void
printTenLongestWords
() {
System
.
out
.
println
(
"
\n
Ten Longest Words:"
);
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
dictionary
)) {
lines
.
filter
(
s
->
s
.
length
() >
20
)
.
sorted
(
Comparator
.
comparingInt
(
String
::
length
).
reversed
()
//.thenComparing(Comparator.reverseOrder()))
)
.
limit
(
10
)
.
forEach
(
w
->
System
.
out
.
printf
(
"%s (%d)%n"
,
w
,
w
.
length
()));
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
public
void
printWordsOfEachLength
() {
System
.
out
.
println
(
"
\n
List of words of each length:"
);
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
dictionary
)) {
lines
.
filter
(
s
->
s
.
length
() >
20
)
.
collect
(
Collectors
.
groupingBy
(
String
::
length
))
// Map<Integer,List<String>>
.
forEach
((
len
,
wordList
) ->
System
.
out
.
println
(
len
+
": "
+
wordList
));
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
public
void
printHowManyWordsOfEachLength
() {
System
.
out
.
println
(
"
\n
Number of words of each length:"
);
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
dictionary
)) {
lines
.
filter
(
s
->
s
.
length
() >
20
)
.
collect
(
Collectors
.
groupingBy
(
String
::
length
,
Collectors
.
counting
()))
// Map<Integer,Long>
.
forEach
((
len
,
num
) ->
System
.
out
.
printf
(
"%d: %d%n"
,
len
,
num
));
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
public
void
printSortedMapOfWords
() {
System
.
out
.
println
(
"
\n
Number of words of each length (desc order):"
);
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
dictionary
)) {
Map
<
Integer
,
Long
>
map
=
lines
.
filter
(
s
->
s
.
length
() >
20
)
.
collect
(
groupingBy
(
String
::
length
,
counting
()));
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByKey
(
Comparator
.
reverseOrder
()))
.
forEach
(
e
->
System
.
out
.
printf
(
"Length %d: %d words%n"
,
e
.
getKey
(),
e
.
getValue
()));
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
public
void
printSortedMapOfWordsUsingBufferedReader
() {
System
.
out
.
println
(
"
\n
Number of words of each length (desc order):"
);
try
(
Stream
<
String
>
lines
=
new
BufferedReader
(
new
FileReader
(
"/usr/share/dict/words"
)).
lines
()) {
Map
<
Integer
,
Long
>
map
=
lines
.
filter
(
s
->
s
.
length
() >
20
)
.
collect
(
groupingBy
(
String
::
length
,
counting
()));
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByKey
(
Comparator
.
reverseOrder
()))
.
forEach
(
e
->
System
.
out
.
printf
(
"Length %d: %d words%n"
,
e
.
getKey
(),
e
.
getValue
()));
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
) {
ProcessDictionary
processDictionary
=
new
ProcessDictionary
();
processDictionary
.
printTenLongestWords
();
processDictionary
.
printWordsOfEachLength
();
processDictionary
.
printHowManyWordsOfEachLength
();
processDictionary
.
printSortedMapOfWords
();
processDictionary
.
printSortedMapOfWordsUsingBufferedReader
();
}
}
Back
|
FazBrowse Home
|
New Git URL