FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/onjava/CollectionMethodDifferences.java at master · BruceEckel/OnJava8-Examples · GitHub
BruceEckel
/
OnJava8-Examples
Public
Notifications
You must be signed in to change notification settings
Fork
1.1k
Star
3.2k
Code
Issues
15
Pull requests
3
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
onjava
/
CollectionMethodDifferences.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
117 lines (116 loc) · 4.36 KB
Breadcrumbs
OnJava8-Examples
/
onjava
/
CollectionMethodDifferences.java
Copy path
File metadata and controls
117 lines (116 loc) · 4.36 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// onjava/CollectionMethodDifferences.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.CollectionMethodDifferences}
package
onjava
;
import
java
.
lang
.
reflect
.*;
import
java
.
util
.*;
import
java
.
util
.
stream
.*;
public
class
CollectionMethodDifferences
{
static
Set
<
String
>
methodSet
(
Class
<?>
type
) {
return
Arrays
.
stream
(
type
.
getMethods
())
.
map
(
Method
::
getName
)
.
collect
(
Collectors
.
toCollection
(
TreeSet
::
new
));
}
static
void
interfaces
(
Class
<?>
type
) {
System
.
out
.
print
(
"Interfaces in "
+
type
.
getSimpleName
() +
": "
);
System
.
out
.
println
(
Arrays
.
stream
(
type
.
getInterfaces
())
.
map
(
Class
::
getSimpleName
)
.
collect
(
Collectors
.
toList
()));
}
static
Set
<
String
>
object
=
methodSet
(
Object
.
class
);
static
{
object
.
add
(
"clone"
); }
static
void
difference
(
Class
<?>
superset
,
Class
<?>
subset
) {
System
.
out
.
print
(
superset
.
getSimpleName
() +
" extends "
+
subset
.
getSimpleName
() +
", adds: "
);
Set
<
String
>
comp
=
Sets
.
difference
(
methodSet
(
superset
),
methodSet
(
subset
));
comp
.
removeAll
(
object
);
// Ignore 'Object' methods
System
.
out
.
println
(
comp
);
interfaces
(
superset
);
}
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
(
"Collection: "
+
methodSet
(
Collection
.
class
));
interfaces
(
Collection
.
class
);
difference
(
Set
.
class
,
Collection
.
class
);
difference
(
HashSet
.
class
,
Set
.
class
);
difference
(
LinkedHashSet
.
class
,
HashSet
.
class
);
difference
(
TreeSet
.
class
,
Set
.
class
);
difference
(
List
.
class
,
Collection
.
class
);
difference
(
ArrayList
.
class
,
List
.
class
);
difference
(
LinkedList
.
class
,
List
.
class
);
difference
(
Queue
.
class
,
Collection
.
class
);
difference
(
PriorityQueue
.
class
,
Queue
.
class
);
System
.
out
.
println
(
"Map: "
+
methodSet
(
Map
.
class
));
difference
(
HashMap
.
class
,
Map
.
class
);
difference
(
LinkedHashMap
.
class
,
HashMap
.
class
);
difference
(
SortedMap
.
class
,
Map
.
class
);
difference
(
TreeMap
.
class
,
Map
.
class
);
}
}
/* Output:
Collection: [add, addAll, clear, contains, containsAll,
equals, forEach, hashCode, isEmpty, iterator,
parallelStream, remove, removeAll, removeIf, retainAll,
size, spliterator, stream, toArray]
Interfaces in Collection: [Iterable]
Set extends Collection, adds: []
Interfaces in Set: [Collection]
HashSet extends Set, adds: []
Interfaces in HashSet: [Set, Cloneable, Serializable]
LinkedHashSet extends HashSet, adds: []
Interfaces in LinkedHashSet: [Set, Cloneable,
Serializable]
TreeSet extends Set, adds: [headSet,
descendingIterator, descendingSet, pollLast, subSet,
floor, tailSet, ceiling, last, lower, comparator,
pollFirst, first, higher]
Interfaces in TreeSet: [NavigableSet, Cloneable,
Serializable]
List extends Collection, adds: [replaceAll, get,
indexOf, subList, set, sort, lastIndexOf, listIterator]
Interfaces in List: [Collection]
ArrayList extends List, adds: [trimToSize,
ensureCapacity]
Interfaces in ArrayList: [List, RandomAccess,
Cloneable, Serializable]
LinkedList extends List, adds: [offerFirst, poll,
getLast, offer, getFirst, removeFirst, element,
removeLastOccurrence, peekFirst, peekLast, push,
pollFirst, removeFirstOccurrence, descendingIterator,
pollLast, removeLast, pop, addLast, peek, offerLast,
addFirst]
Interfaces in LinkedList: [List, Deque, Cloneable,
Serializable]
Queue extends Collection, adds: [poll, peek, offer,
element]
Interfaces in Queue: [Collection]
PriorityQueue extends Queue, adds: [comparator]
Interfaces in PriorityQueue: [Serializable]
Map: [clear, compute, computeIfAbsent,
computeIfPresent, containsKey, containsValue, entrySet,
equals, forEach, get, getOrDefault, hashCode, isEmpty,
keySet, merge, put, putAll, putIfAbsent, remove,
replace, replaceAll, size, values]
HashMap extends Map, adds: []
Interfaces in HashMap: [Map, Cloneable, Serializable]
LinkedHashMap extends HashMap, adds: []
Interfaces in LinkedHashMap: [Map]
SortedMap extends Map, adds: [lastKey, subMap,
comparator, firstKey, headMap, tailMap]
Interfaces in SortedMap: [Map]
TreeMap extends Map, adds: [descendingKeySet,
navigableKeySet, higherEntry, higherKey, floorKey,
subMap, ceilingKey, pollLastEntry, firstKey, lowerKey,
headMap, tailMap, lowerEntry, ceilingEntry,
descendingMap, pollFirstEntry, lastKey, firstEntry,
floorEntry, comparator, lastEntry]
Interfaces in TreeMap: [NavigableMap, Cloneable,
Serializable]
*/
Back
|
FazBrowse Home
|
New Git URL