Coverage Report - org.kuali.student.contract.model.util.ServicesFilterArrangeByKeys
 
Classes in this File Line Coverage Branch Coverage Complexity
ServicesFilterArrangeByKeys
0%
0/8
0%
0/2
2.667
ServicesFilterArrangeByKeys$CompareService
0%
0/8
0%
0/4
2.667
 
 1  
 /*
 2  
  * Copyright 2010 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may        obtain a copy of the License at
 7  
  *
 8  
  *         http://www.osedu.org/licenses/ECL-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.student.contract.model.util;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.Comparator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.kuali.student.contract.model.Service;
 24  
 
 25  
 /**
 26  
  *
 27  
  * @author nwright
 28  
  */
 29  
 public class ServicesFilterArrangeByKeys implements ServicesFilter
 30  
 {
 31  
 
 32  
  List<String> keys;
 33  
 
 34  
  public ServicesFilterArrangeByKeys (List<String> keys)
 35  0
  {
 36  0
   this.keys = keys;
 37  0
   for (int i = 0; i < keys.size (); i ++)
 38  
   {
 39  0
    keys.set (i, keys.get (i).toLowerCase ());
 40  
   }
 41  0
  }
 42  
 
 43  
  @Override
 44  
  public List<Service> filter (List<Service> services)
 45  
  {
 46  0
   List<Service> sorted = new ArrayList (services);
 47  0
   Collections.sort (sorted, new CompareService ());
 48  0
   return sorted;
 49  
  }
 50  
 
 51  0
  public class CompareService implements Comparator<Service>
 52  
  {
 53  
 
 54  
   public int compare (Service service1, Service service2)
 55  
   {
 56  0
    int index1 = keys.indexOf (service1.getKey ().toLowerCase ());
 57  0
    int index2 = keys.indexOf (service2.getKey ().toLowerCase ());
 58  0
    if (index1 < index2)
 59  
    {
 60  0
     return -1;
 61  
    }
 62  0
    if (index2 < index1)
 63  
    {
 64  0
     return +1;
 65  
    }
 66  0
    return 0;
 67  
   }
 68  
 
 69  
  }
 70  
 }