2
|
1 |
package horaris;
|
|
2 |
|
|
3 |
public class Tempo
|
|
4 |
{
|
|
5 |
String s;
|
14
|
6 |
private int horoj;
|
|
7 |
private int minutoj;
|
2
|
8 |
|
14
|
9 |
public Tempo(String tempo)
|
2
|
10 |
{
|
14
|
11 |
fromStr(tempo);
|
2
|
12 |
}
|
|
13 |
|
|
14 |
private void fromStr(String _s)
|
|
15 |
{
|
|
16 |
s = _s;
|
|
17 |
int colon = s.indexOf(':');
|
|
18 |
|
|
19 |
horoj = Integer.parseInt(s.substring(0,colon));
|
|
20 |
minutoj = Integer.parseInt(s.substring(colon+1));
|
|
21 |
}
|
|
22 |
|
|
23 |
/* 1: this later than t2
|
|
24 |
* 0: this equal to t2
|
|
25 |
* -1: this earlier than t2 */
|
|
26 |
public int compareTo(Tempo t2)
|
|
27 |
{
|
|
28 |
if (horoj > t2.horoj)
|
|
29 |
return 1;
|
|
30 |
else if (horoj == t2.horoj && minutoj > t2.minutoj)
|
|
31 |
return 1;
|
|
32 |
else if (horoj == t2.horoj && minutoj == t2.minutoj)
|
|
33 |
return 0;
|
|
34 |
else
|
|
35 |
return -1;
|
|
36 |
}
|
|
37 |
|
|
38 |
public String toString()
|
|
39 |
{
|
|
40 |
return s;
|
|
41 |
}
|
|
42 |
}
|