-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRange.clcl
139 lines (109 loc) · 2.96 KB
/
Range.clcl
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
class Range<T:IIteratorable>
{
include MObjectBase;
head:T;
tail:T;
def initialize() {}
def initialize(head:T, tail:T) {
self.head = head;
self.tail = tail
}
def clone(): Range<T> {
result := Range<T>();
if(self.head.identifyWith(null).negative()) {
result.head = self.head.clone();
}
if(self.tail.identifyWith(null).negative()) {
result.tail = self.tail.clone();
}
return result;
}
def equals(right:Range<T>):bool {
return self.head.equals(right.head) && self.tail.equals(right.tail);
}
def isMember(value:T):bool {
return value.compare(self.head) >= 0 && value.compare(self.tail) < 0;
}
def toString(): String {
return "Range";
}
def compare(range:Range<T>): int {
head_cmp := self.head.compare(range.head);
tail_cmp := self.tail.compare(range.tail);
if(head_cmp == 0 && tail_cmp == 0) {
return 0;
}
elif(head_cmp == -1 && (tail_cmp == 0 || tail_cmp == -1)) {
return -1;
}
else {
return 1;
}
}
def add(right:Range<T>):Range<T> {
result := self.clone();
result.head = result.head.add(right.head);
result.tail = result.tail.add(right.tail);
return result;
}
def toSortableList(): SortableList<T> {
result := SortableList<T>();
for(p:=self.head(); p.compare(self.tail) < 0; p = p.next()) {
result.add(p);
}
return result;
}
def toList(): List<T> {
result := List<T>();
for(p:=self.head(); p.compare(self.tail) < 0; p = p.next()) {
result.add(p);
}
return result;
}
def toEqualableList(): EqualableList<T> {
result := EqualableList<T>();
for(p:=self.head(); p.compare(self.tail) < 0; p = p.next()) {
result.add(p);
}
return result;
}
}
module MListWithRange
{
def subList(range:Range<Integer>):SELF<T> {
return self.subList(range.head.value, range.tail.value);
}
def deleteWithRange(range:Range<Integer>):SELF<T> {
return self.deleteWithRange(range.head.value, range.tail.value);
}
def fill(range:Range<Integer>, item:T):SELF<T> {
return self.fill(range.head.value, range.tail.value, item);
}
}
inherit List <T:Object>
{
include MListWithRange;
}
inherit EqualableList<T:IEqualable>
{
include MListWithRange;
}
inherit SortableList<T:ISortable>
{
include MListWithRange;
}
inherit String
{
def subString(range:Range<Integer>): String {
return self.subString(range.head.value, range.tail.value);
}
def delete(range:Range<Integer>): String {
return self.delete(range.head.value, range.tail.value);
}
}
inherit Buffer
{
def subBuffer(range:Range<Integer>): Buffer {
return self.subBuffer(range.head.value, range.tail.value);
}
}