-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.java
More file actions
34 lines (29 loc) · 885 Bytes
/
Copy pathMessage.java
File metadata and controls
34 lines (29 loc) · 885 Bytes
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
package test;
import java.util.Date;
public class Message {
public final byte[] data;
public final String asText;
public final double asDouble;
public final Date date;
// הבנאי הבסיסי שמקבל מחרוזת
public Message(String text) {
double tempDouble;
try {
tempDouble = Double.parseDouble(text);
} catch (NumberFormatException e) {
tempDouble = Double.NaN;
}
this.date = new Date();
this.asText = text;
this.data = text.getBytes();
this.asDouble = tempDouble;
}
// בנאי שמקבל מערך בתים
public Message(byte[] data) {
this(new String(data));
}
// בנאי שמקבל double
public Message(double number) {
this(String.valueOf(number));
}
}