FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/equalshashcode/ComposedEquality.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
equalshashcode
/
ComposedEquality.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (62 loc) · 1.67 KB
Breadcrumbs
OnJava8-Examples
/
equalshashcode
/
ComposedEquality.java
Copy path
File metadata and controls
64 lines (62 loc) · 1.67 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
// equalshashcode/ComposedEquality.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.
import
java
.
util
.*;
class
Part
{
String
ss
;
double
dd
;
Part
(
String
ss
,
double
dd
) {
this
.
ss
=
ss
;
this
.
dd
=
dd
;
}
@
Override
public
boolean
equals
(
Object
rval
) {
return
rval
instanceof
Part
&&
Objects
.
equals
(
ss
, ((
Part
)
rval
).
ss
) &&
Objects
.
equals
(
dd
, ((
Part
)
rval
).
dd
);
}
}
public
class
ComposedEquality
extends
SuccinctEquality
{
Part
part
;
public
ComposedEquality
(
int
i
,
String
s
,
double
d
) {
super
(
i
,
s
,
d
);
part
=
new
Part
(
s
,
d
);
System
.
out
.
println
(
"made 'ComposedEquality'"
);
}
@
Override
public
boolean
equals
(
Object
rval
) {
return
rval
instanceof
ComposedEquality
&&
super
.
equals
(
rval
) &&
Objects
.
equals
(
part
,
((
ComposedEquality
)
rval
).
part
);
}
public
static
void
main
(
String
[]
args
) {
Equality
.
testAll
( (
i
,
s
,
d
) ->
new
ComposedEquality
(
i
,
s
,
d
));
}
}
/* Output:
made 'Equality'
made 'SuccinctEquality'
made 'ComposedEquality'
made 'Equality'
made 'SuccinctEquality'
made 'ComposedEquality'
made 'Equality'
made 'SuccinctEquality'
made 'ComposedEquality'
-- Testing null --
null instanceof Equality: false
Expected false, got false
-- Testing same object --
same object instanceof Equality: true
Expected true, got true
-- Testing different type --
different type instanceof Equality: false
Expected false, got false
-- Testing same values --
same values instanceof Equality: true
Expected true, got true
-- Testing different values --
different values instanceof Equality: true
Expected false, got false
*/
Back
|
FazBrowse Home
|
New Git URL