1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # This module beef up the clock module by allowing a clock to be comparable.
16 # It show the usage of class refinement
22 # Clock are now comparable
25 # Comparaison of a clock make only sense with an other clock
26 redef type OTHER: Clock
30 # Note: < is the only abstract method of Comparable.
31 # All other operators and methods rely on < and ==.
32 return self.total_minutes
< o
.total_minutes
36 var c1
= new Clock(8, 12)
37 var c2
= new Clock(8, 13)
38 var c3
= new Clock(9, 13)
40 print
"{c1}<{c2}? {c1<c2}"
41 print
"{c1}<={c2}? {c1<=c2}"
42 print
"{c1}>{c2}? {c1>c2}"
43 print
"{c1}>={c2}? {c1>=c2}"
44 print
"{c1}<=>{c2}? {c1<=>c2}"
45 print
"{c1},{c2}? max={c1.max(c2)} min={c1.min(c2)}"
46 print
"{c1}.is_between({c2}, {c3})? {c1.is_between(c2, c3)}"
47 print
"{c2}.is_between({c1}, {c3})? {c2.is_between(c1, c3)}"
53 print
"{c1}<{c2}? {c1<c2}"
54 print
"{c1}<={c2}? {c1<=c2}"
55 print
"{c1}>{c2}? {c1>c2}"
56 print
"{c1}>={c2}? {c1>=c2}"
57 print
"{c1}<=>{c2}? {c1<=>c2}"
58 print
"{c1},{c2}? max={c1.max(c2)} min={c1.min(c2)}"
59 print
"{c1}.is_between({c2}, {c3})? {c1.is_between(c2, c3)}"
60 print
"{c2}.is_between({c1}, {c3})? {c2.is_between(c1, c3)}"