Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
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
Quintiq file version 2.0
#parent: #root
StaticMethod CompareLexicographical (
  Numbers tuple1,
  Numbers tuple2
) const declarative remote as Number
{
  Description: 'Compare between 2 tuples on whether tuple1 > tuple2'
  TextBody:
  [*
    // Compare between 2 tuples on whether tuple1 > tuple2
    // Set the value to the number that represents equality
    value := Util::Compare_Equal();
    
    // Check if both tuple1 & tuple2 has any elements in it
    if( tuple1.Size() > 0 and tuple2.Size() > 0 )
    {
      tupledefaultvalue := 0;
      undecided := true;
      maxSize := maxvalue( tuple1.Size(), tuple2.Size() );
    
      // Loop as long as the index is within the max number of elements in either tuples
      // and the result remains undecided
      for( i := 0; i < maxSize and undecided; i++ )
      {
        // Get the element in the tuples
        v1 := ifexpr( tuple1.Size() > i, tuple1.Element( i ), tupledefaultvalue );
        v2 := ifexpr( tuple2.Size() > i, tuple2.Element( i ), tupledefaultvalue );
    
        // Check if tuple1 has element larger/less than the element in tuple2 at the same index
        if( v2 < v1 )
        {
          value := Util::Compare_Bigger();
          undecided := false;
        }
        else if( v2 > v1 )
        {
          value := Util::Compare_Smaller()
          undecided := false;      
        }
      }
    }
    
    return value;
  *]
}