Coverage Report - org.jtheque.films.view.impl.sort.ByCountrySorter
 
Classes in this File Line Coverage Branch Coverage Complexity
ByCountrySorter
0 %
0/17
0 %
0/8
2
 
 1  
 package org.jtheque.films.view.impl.sort;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.primary.controller.able.IPrincipalController;
 20  
 import org.jtheque.primary.od.able.Country;
 21  
 import org.jtheque.primary.od.able.Data;
 22  
 import org.jtheque.primary.od.able.Person;
 23  
 import org.jtheque.primary.services.able.ICountriesService;
 24  
 import org.jtheque.primary.view.impl.models.tree.Category;
 25  
 import org.jtheque.primary.view.impl.models.tree.JThequeTreeModel;
 26  
 import org.jtheque.primary.view.impl.models.tree.TreeElement;
 27  
 import org.jtheque.primary.view.impl.sort.Sorter;
 28  
 
 29  
 import java.util.HashMap;
 30  
 import java.util.Map;
 31  
 
 32  
 /**
 33  
  * This class sort by country.
 34  
  *
 35  
  * @author Baptiste Wicht
 36  
  */
 37  
 public final class ByCountrySorter implements Sorter {
 38  
     private final IPrincipalController<? extends Person> controller;
 39  
 
 40  
     /**
 41  
      * Construct a new ByCountrySorter.
 42  
      *
 43  
      * @param controller The principal controller.
 44  
      */
 45  0
     public ByCountrySorter(IPrincipalController<? extends Person> controller) {
 46  0
         this.controller = controller;
 47  0
     }
 48  
 
 49  
     @Override
 50  
     public boolean canSort(String content, String sortType) {
 51  0
         return content.equals(controller.getDataType()) && sortType.equals(ICountriesService.DATA_TYPE);
 52  
     }
 53  
 
 54  
     @Override
 55  
     public void sort(JThequeTreeModel model) {
 56  0
         TreeElement root = model.getRoot();
 57  
 
 58  0
         Map<Country, Category> groups = new HashMap<Country, Category>(controller.getDisplayList().size() / 4);
 59  
 
 60  0
         for (Data data : controller.getDisplayList()) {
 61  0
             Person person = (Person) data;
 62  
 
 63  0
             Country country = person.getTheCountry();
 64  
 
 65  0
             if (!groups.containsKey(country)) {
 66  0
                 Category category = new Category(country.getDisplayableText());
 67  
 
 68  0
                 root.add(category);
 69  0
                 groups.put(country, category);
 70  
             }
 71  
 
 72  0
             groups.get(country).add(person);
 73  0
         }
 74  
 
 75  0
         model.setRootElement(root);
 76  0
     }
 77  
 }