UartBus source documentation
uint8_t.java
1 package eu.javaexperience.electronic.uartbus.rpc.datatype;
2 
3 public class uint8_t extends Number
4 {
5  public final short value;
6 
7  public uint8_t(short value)
8  {
9  this.value = value;
10  }
11 
12  public uint8_t(Number value)
13  {
14  this.value = value.shortValue();
15  }
16 
17  @Override
18  public int intValue()
19  {
20  return value;
21  }
22 
23  @Override
24  public long longValue()
25  {
26  return value;
27  }
28 
29  @Override
30  public float floatValue()
31  {
32  return value;
33  }
34 
35  @Override
36  public double doubleValue()
37  {
38  return value;
39  }
40 
41  @Override
42  public String toString()
43  {
44  return "uint8_t: "+value;
45  }
46 
47  @Override
48  public boolean equals(Object obj)
49  {
50  if(!(obj instanceof Number))
51  {
52  return false;
53  }
54 
55  Number n = (Number) obj;
56 
57  double d = n.doubleValue();
58 
59  //check number is integer (i mean number without fraction)
60  if(Math.floor(d) != d)
61  {
62  return false;
63  }
64 
65  long l = n.longValue();
66 
67  //btw -128 and 127 or 0 and 255
68  if(-128 <= l && l <= 255)
69  {
70  if(l < 0)
71  {
72  l = 0xff & l;
73  }
74 
75  return l == value;
76  }
77  return false;
78  }
79 
80  @Override
81  public int hashCode()
82  {
83  return 0xff & value;
84  }
85 }