-
Notifications
You must be signed in to change notification settings - Fork 0
/
Work.java
170 lines (142 loc) · 4.37 KB
/
Work.java
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package it.valsecchi.quickagenda.data.component;
import it.valsecchi.quickagenda.data.Utility;
import java.text.ParseException;
import java.util.Calendar;
/**
* Classe che rappresenta un singolo lavoro (ad esempio un cantiere, un
* appartamento);
*
* @author Davide Valsecchi
* @version 1.0
*/
public class Work {
/** Codice di 8 cifre */
private String ID;
/**
* L'hash identifica in modo univoco l'oggetto.Ricavata unendo
* (clienteid,indirizzo,iniziolavori, finelavori)
*/
private String hash;
/** ID del cliente a cui appartiene il lavoro */
private String costumerID;
/**Nome del lavoro,identificativo*/
private String nome;
private String indirizzo;
private Calendar inizioLavori;
private Calendar fineLavori;
private boolean completed = false;
/** Costruttore di Word */
public Work(String id, String costumerid, String _nome,String _indirizzo,
Calendar iniziolavori, Calendar finelavori, boolean _completed) {
ID = id;
costumerID = costumerid;
nome = _nome;
indirizzo = _indirizzo;
inizioLavori = iniziolavori;
fineLavori = finelavori;
completed = _completed;
// si crea l'hash unendo (clienteid,nome,indirizzo,iniziolavori)
hash = Utility.getHash(costumerID +nome+ indirizzo + Utility.formatCalendarToString(iniziolavori));
}
/** Costruttore di Work con Hash */
public Work(String id, String costumerid, String _nome,String _indirizzo,
Calendar iniziolavori, Calendar finelavori, boolean _completed,String _hash) {
ID = id;
hash = _hash;
costumerID = costumerid;
nome = _nome;
indirizzo = _indirizzo;
inizioLavori = iniziolavori;
fineLavori = finelavori;
completed = _completed;
}
/**
* Metodo statico che restituisce l'hash di un Work identificato dai dati
* parametro.
*/
public static String calculateWorkHash(String costumereid,String nome,
String indirizzo, Calendar inizio) {
return Utility.getHash(costumereid + nome+ indirizzo + Utility.formatCalendarToString(inizio));
}
/**
* Metodo che ricalcola l'hash della Work. La assegna al Work e la restituisce.
* @return restituisce la nuova hash del Work
*/
public String recalculateWorkHash(){
this.hash = Utility.getHash(this.costumerID+this.nome+this.indirizzo+this.getInizioLavoriString());
return hash;
}
/** Metodo che calcola l'arco di tempo in cui il lavoro è stato attivo */
public long getWorkNumberOfDays() {
long start = inizioLavori.getTimeInMillis();
long end = fineLavori.getTimeInMillis();
long dif = end - start;
return dif / (86400000);
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getIndirizzo() {
return indirizzo;
}
public void setIndirizzo(String indirizzo) {
this.indirizzo = indirizzo;
}
public Calendar getInizioLavori() {
return inizioLavori;
}
/** Metodo che restituisce l'InizioLavori come stringa già formattata*/
public String getInizioLavoriString(){
return Utility.formatCalendarToString(this.inizioLavori);
}
public void setInizioLavori(Calendar inizioLavori) {
this.inizioLavori = inizioLavori;
}
/**
* Metodo che imposta l'InizioLavori accettando come parametro una stringa nel formato "dd/MM/yy".
* @param inizioLavori stringa che rappresenta la data
* @throws ParseException
*/
public void setInizioLavori(String inizioLavori) throws ParseException{
this.inizioLavori = Utility.parseStringToCalendar(inizioLavori);
}
public Calendar getFineLavori() {
return fineLavori;
}
/** Metodo che restituisce il FineLavori come stringa già formattata*/
public String getFineLavoriString(){
return Utility.formatCalendarToString(this.fineLavori);
}
public void setFineLavori(Calendar fineLavori) {
this.fineLavori = fineLavori;
}
/**
* Metodo che imposta il FineLavori accettando come parametro una stringa nel formato "dd/MM/yy".
* @param fineLavori stringa che rappresenta la data
* @throws ParseException
*/
public void setFineLavori(String fineLavori) throws ParseException{
this.fineLavori= Utility.parseStringToCalendar(fineLavori);
}
public boolean isCompleted() {
return completed;
}
public void setCompleted(boolean completed) {
this.completed = completed;
}
public String getID() {
return ID;
}
public String getHash() {
return hash;
}
public String getCostumerID() {
return costumerID;
}
public void setCostumerID(String costumerID){
this.costumerID= costumerID;
}
}