1 package de.tivsource.page.entity.location;
2
3 import javax.persistence.Column;
4 import javax.persistence.Embeddable;
5
6
7
8
9
10
11 @Embeddable
12 public class HourMinute implements Comparable<HourMinute> {
13
14 @Column(length=2)
15 private Integer hour;
16
17 @Column(length=2)
18 private Integer minute;
19
20 public Integer getHour() {
21 return hour;
22 }
23
24 public void setHour(Integer hour) {
25 this.hour = hour;
26 }
27
28 public Integer getMinute() {
29 return minute;
30 }
31
32 public void setMinute(Integer minute) {
33 this.minute = minute;
34 }
35
36 @Override
37 public int compareTo(HourMinute o) {
38
39 if(o.hour < hour) {
40 return 1;
41 }
42
43 if(o.hour > hour) {
44 return -1;
45 }
46
47 if(o.minute < minute) {
48 return 1;
49 }
50
51 if(o.minute > minute) {
52 return -1;
53 }
54 return 0;
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59
60 if(this == obj) {
61 return true;
62 }
63
64 if(obj == null) {
65 return false;
66 }
67
68 if (!(obj instanceof HourMinute)) {
69 return false;
70 }
71
72 HourMinute other = (HourMinute) obj;
73
74 if(this.hour.equals(other.hour) &&
75 this.minute.equals(other.minute)){
76 return true;
77 }
78 return false;
79 }
80
81 @Override
82 public int hashCode() {
83 int hash = 1;
84 hash = hash * 7 * (hour == null ? 0 : hour.hashCode());
85 hash = hash * 7 * (minute == null ? 0 : minute.hashCode());
86 return hash;
87 }
88
89 @Override
90 public String toString() {
91 String hourString = hour < 10 ? "0" + hour : hour.toString();
92 String minuteString = minute < 10 ? "0" + minute : minute.toString();
93 return hourString + ":" + minuteString;
94 }
95
96 }