-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.java
More file actions
100 lines (83 loc) · 2.14 KB
/
Copy pathTask.java
File metadata and controls
100 lines (83 loc) · 2.14 KB
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
/**
* This is from book done by Cris Z
* Task to be scheduled by the scheduling alogrithm.
*
* Each task is represented by
*
* String name - a task name, not necessarily unique
*
* int tid - unique task identifier
*
* int priority - the relative priority of a task where a higher number indicates
* higher relative priority.
*
* int burst - the CPU burst of this this task
*/
import java.util.concurrent.atomic.AtomicInteger;
public class Task
{
// the representation of each task
private String name;
private int tid;
private int priority;
private int burst;
/**
* We use an atomic integer to assign each task a unique task id.
*/
private static AtomicInteger tidAllocator = new AtomicInteger();
public Task(String name, int priority, int burst) {
this.name = name;
this.priority = priority;
this.burst = burst;
this.tid = tidAllocator.getAndIncrement();
}
/**
* Appropriate getters
*/
public String getName() {
return name;
}
public int getTid() {
return tid;
}
public int getPriority() {
return priority;
}
public int getBurst() {
return burst;
}
/**
* Appropriate setters
*/
public int setPriority(int priority) {
this.priority = priority;
return priority;
}
public int setBurst(int burst) {
this.burst = burst;
return burst;
}
/**
* We override equals() so we can use a
* Task object in Java collection classes.
*/
public boolean equals(Object other) {
if (other == this)
return true;
if (!(other instanceof Task))
return false;
/**
* Otherwise we are dealing with another Task.
* two tasks are equal if they have the same tid.
*/
Task rhs = (Task)other;
return (this.tid == rhs.tid) ? true : false;
}
public String toString() {
return
"Name: " + name + "\n" +
"Tid: " + tid + "\n" +
"Priority: " + priority + "\n" +
"Burst: " + burst + "\n";
}
}