• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package co.nstant.in.cbor.model;
2 
3 import java.util.Objects;
4 
5 public class SimpleValue extends Special {
6 
7     private final SimpleValueType simpleValueType;
8 
9     public static final SimpleValue FALSE = new SimpleValue(
10             SimpleValueType.FALSE);
11     public static final SimpleValue TRUE = new SimpleValue(SimpleValueType.TRUE);
12     public static final SimpleValue NULL = new SimpleValue(SimpleValueType.NULL);
13     public static final SimpleValue UNDEFINED = new SimpleValue(
14             SimpleValueType.UNDEFINED);
15 
16     private final int value;
17 
SimpleValue(SimpleValueType simpleValueType)18     public SimpleValue(SimpleValueType simpleValueType) {
19         super(SpecialType.SIMPLE_VALUE);
20         this.value = simpleValueType.getValue();
21         this.simpleValueType = simpleValueType;
22     }
23 
SimpleValue(int value)24     public SimpleValue(int value) {
25         super(value <= 23 ? SpecialType.SIMPLE_VALUE
26                 : SpecialType.SIMPLE_VALUE_NEXT_BYTE);
27         this.value = value;
28         this.simpleValueType = SimpleValueType.ofByte(value);
29     }
30 
getSimpleValueType()31     public SimpleValueType getSimpleValueType() {
32         return simpleValueType;
33     }
34 
getValue()35     public int getValue() {
36         return value;
37     }
38 
39     @Override
equals(Object object)40     public boolean equals(Object object) {
41         if (object instanceof SimpleValue) {
42             SimpleValue other = (SimpleValue) object;
43             return super.equals(object) && value == other.value;
44         }
45         return false;
46     }
47 
48     @Override
hashCode()49     public int hashCode() {
50         return super.hashCode() ^ Objects.hashCode(value);
51     }
52 
53     @Override
toString()54     public String toString() {
55         return simpleValueType.toString();
56     }
57 
58 }
59