Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CleanUpUnitCapacity 
 | 
{ 
 | 
  Description: 'Find sets of equivalent unit capacities in consecutive periods and remove all but the first one' 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Clean up unit capacity 
 | 
    // Get a sorted set of all unit capacities of this unit 
 | 
    sorteducs := selectsortedset( this, UnitCapacity, uc,  
 | 
                                  true,  
 | 
                                  uc.Start() ); 
 | 
     
 | 
    head := null( UnitCapacity ); 
 | 
     
 | 
    // Traverse the sorted set of unit capacities 
 | 
    traverse( sorteducs, Elements, uc ) 
 | 
    { 
 | 
      // Check if there's any unit capacity is selected, if there's none, set the current unit capacity as selected 
 | 
      if( isnull( head ) ) 
 | 
      { 
 | 
        head := uc; 
 | 
      } 
 | 
     
 | 
      // Get the index of the selected unit capacity in the sorted set 
 | 
      headpos := sorteducs.Find( head ); 
 | 
      // Get the next unit capacity after the selected unit capacity in the sorted set 
 | 
      nextuc := guard( sorteducs.Element( headpos + 1 ), null( UnitCapacity ) ); 
 | 
     
 | 
      // Check if there's any next unit capacity 
 | 
      if( not isnull( nextuc ) ) 
 | 
      { 
 | 
        // Check if the next unit capacity has the same data as the selected one 
 | 
        // If the data is the same, remove the next unit capacity from the sorted set and dataset 
 | 
        if( head.HasSameData( nextuc ) ) 
 | 
        { 
 | 
          sorteducs.Remove( nextuc ); 
 | 
          nextuc.Delete(); 
 | 
        } 
 | 
        // Else, set the next unit capacity as the selected one 
 | 
        else 
 | 
        { 
 | 
          head := nextuc; 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |