FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/reflection/Staff.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
/
reflection
/
Staff.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (62 loc) · 2.23 KB
Breadcrumbs
OnJava8-Examples
/
reflection
/
Staff.java
Copy path
File metadata and controls
63 lines (62 loc) · 2.23 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
// reflection/Staff.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
.*;
public
class
Staff
extends
ArrayList
<
Position
> {
public
void
add
(
String
title
,
Person
person
) {
add
(
new
Position
(
title
,
person
));
}
public
void
add
(
String
...
titles
) {
for
(
String
title
:
titles
)
add
(
new
Position
(
title
));
}
public
Staff
(
String
...
titles
) {
add
(
titles
); }
public
boolean
positionAvailable
(
String
title
) {
for
(
Position
position
:
this
)
if
(
position
.
getTitle
().
equals
(
title
) &&
position
.
getPerson
().
empty
)
return
true
;
return
false
;
}
public
void
fillPosition
(
String
title
,
Person
hire
) {
for
(
Position
position
:
this
)
if
(
position
.
getTitle
().
equals
(
title
) &&
position
.
getPerson
().
empty
) {
position
.
setPerson
(
hire
);
return
;
}
throw
new
RuntimeException
(
"Position "
+
title
+
" not available"
);
}
public
static
void
main
(
String
[]
args
) {
Staff
staff
=
new
Staff
(
"President"
,
"CTO"
,
"Marketing Manager"
,
"Product Manager"
,
"Project Lead"
,
"Software Engineer"
,
"Software Engineer"
,
"Software Engineer"
,
"Software Engineer"
,
"Test Engineer"
,
"Technical Writer"
);
staff
.
fillPosition
(
"President"
,
new
Person
(
"Me"
,
"Last"
,
"The Top, Lonely At"
));
staff
.
fillPosition
(
"Project Lead"
,
new
Person
(
"Janet"
,
"Planner"
,
"The Burbs"
));
if
(
staff
.
positionAvailable
(
"Software Engineer"
))
staff
.
fillPosition
(
"Software Engineer"
,
new
Person
(
"Bob"
,
"Coder"
,
"Bright Light City"
));
System
.
out
.
println
(
staff
);
}
}
/* Output:
[Position: President, Employee: Me Last The Top, Lonely
At, Position: CTO, Employee: <Empty>, Position:
Marketing Manager, Employee: <Empty>, Position: Product
Manager, Employee: <Empty>, Position: Project Lead,
Employee: Janet Planner The Burbs, Position: Software
Engineer, Employee: Bob Coder Bright Light City,
Position: Software Engineer, Employee: <Empty>,
Position: Software Engineer, Employee: <Empty>,
Position: Software Engineer, Employee: <Empty>,
Position: Test Engineer, Employee: <Empty>, Position:
Technical Writer, Employee: <Empty>]
*/
Back
|
FazBrowse Home
|
New Git URL