-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStockQuoteTest.java
More file actions
83 lines (52 loc) · 2.13 KB
/
StockQuoteTest.java
File metadata and controls
83 lines (52 loc) · 2.13 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
// Nikolay Pogrebnoy: у тебя есть вот такая структура данных
//
// stockquote
// id
// name
// rank int // smaller is better
// timestamp // возраст
//
// be able to get a list of all quotes where rank < some number
// be able to get a list of all quotes > 2 minutes old
// Nikolay Pogrebnoy: у етбя есть вон те вот данные
// Nikolay Pogrebnoy: тебе надо намутить к ним контейнер,
// с которого можно вынимать данные так как внизу написано
import jaba.util.*;
public class StockQuoteTest {
private PriorityQueue<StockQuote> priorityQueue = new new PriorityQueue<StockQuote>();
public void fillQueue() {
}
public void pri
public static void main(String[] args) {
}
}
class StockQuote implements Comparable<StockQuote> {
private static int counter = 0;
private int id = counter++;
private String name;
private int rank;
private Timestamp timestamp;
public StockQuote(String name, int rank) {
this.name = name;
this.rank = rank;
this.timestamp = new Timestamp(System.currentTimeMillis());
}
public StockQuote(String name, int rank, Timestamp timestamp) {
this.name = name;
this.rank = rank;
this.timestamp = timestamp;
}
public int getId() { return id; }
public String getName() { return name; }
public int getRank() { return rank; }
public Timestamp getTimestamp() { return timestamp; }
public void setRank(int rank) { this.rank = rank; }
public void setTimestamp(Timestamp timestamp) { this.timestamp = timestamp; }
public int compareTo(StockQuote obj) {
return this.rank < obj.rank ? 1 : (this.rank == obj.rank ? 0 : -1);
}
public String toString() {
return String.format("StockQuote { id : %1$d, name : %2$s, rank : %3$d, timestamp : %4$s }"
, id, name, rank, timestamp.toString());
}
}