1 package de.fhdw.wtf.context.model;
2
3 import de.fhdw.wtf.persistence.meta.StringValue;
4
5
6
7
8
9 public final class Str extends AnyValue {
10
11
12
13
14 private final StringBuilder value;
15
16
17
18
19
20
21
22 private Str(final StringBuilder value) {
23 this.value = value;
24 }
25
26
27
28
29
30
31
32 public Str(final StringValue value) {
33 this(value.getValue());
34 }
35
36
37
38
39
40
41
42 public Str(final String value) {
43 this(new StringBuilder(value));
44 }
45
46
47
48
49 public Str() {
50 this.value = new StringBuilder();
51 }
52
53
54
55
56
57
58
59
60 public Str concat(final Str tail) {
61 final StringBuilder nw = new StringBuilder(this.value);
62 nw.append(tail.value.substring(0));
63 return new Str(nw);
64 }
65
66
67
68
69
70
71
72
73
74
75
76 public Str substring(final int from, final int to) {
77 final StringBuilder res = new StringBuilder(this.value.substring(from, to));
78 return new Str(res);
79 }
80
81
82
83
84
85
86
87
88 public boolean lessEq(final Str other) {
89 return this.value.substring(0).compareTo(other.value.substring(0)) <= 0;
90 }
91
92 @Override
93 public boolean equals(final Object obj) {
94 if (obj instanceof Str) {
95 final Str other = (Str) obj;
96 return this.value.toString().equals(other.value.toString());
97 }
98 return false;
99 }
100
101 @Override
102 public int hashCode() {
103 return this.value.hashCode();
104 }
105
106 @Override
107 public String toString() {
108 return this.value.toString();
109 }
110
111 }