Coverage Report - org.jtheque.primary.view.impl.sort.SorterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
SorterFactory
0 %
0/16
0 %
0/6
1.667
 
 1  
 package org.jtheque.primary.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 java.util.ArrayList;
 20  
 import java.util.Collection;
 21  
 
 22  
 /**
 23  
  * A factory for Sorter objects.
 24  
  *
 25  
  * @author Baptiste Wicht
 26  
  */
 27  
 public final class SorterFactory {
 28  
         private final Collection<Sorter> sorters;
 29  
 
 30  0
         private static final SorterFactory INSTANCE = new SorterFactory();
 31  
 
 32  
         /**
 33  
          * Utility class, cannot be instanciated.
 34  
          */
 35  
         private SorterFactory(){
 36  0
                 super();
 37  
 
 38  0
                 sorters = new ArrayList<Sorter>(10);
 39  0
         }
 40  
 
 41  
         /**
 42  
          * Return the unique instance of the class.
 43  
          *
 44  
          * @return The singleton of the class.
 45  
          */
 46  
         public static SorterFactory getInstance(){
 47  0
                 return INSTANCE;
 48  
         }
 49  
 
 50  
         /**
 51  
          * Add a sorter to manage.
 52  
          *
 53  
          * @param sorter The sorter to add.
 54  
          */
 55  
         public void addSorter(Sorter sorter){
 56  0
                 sorters.add(sorter);
 57  0
         }
 58  
 
 59  
         /**
 60  
          * Remove a sorter to manage.
 61  
          *
 62  
          * @param sorter The sorter to remove.
 63  
          */
 64  
         public void removeSorter(Sorter sorter){
 65  0
                 sorters.remove(sorter);
 66  0
         }
 67  
 
 68  
         /**
 69  
          * Return the sorter for the specified content and sort types.
 70  
          *
 71  
          * @param content The content type.
 72  
          * @param sortType The sort type.
 73  
          *
 74  
          * @return The sorter of the specified or <code>null</code> if no sorter of this type exist.
 75  
          */
 76  
         public Sorter getSorter(String content, String sortType){
 77  0
                 for (Sorter sorter : sorters){
 78  0
                         if (sorter.canSort(content, sortType)){
 79  0
                                 return sorter;
 80  
                         }
 81  
                 }
 82  
 
 83  0
                 return null;
 84  
         }
 85  
 
 86  
         /**
 87  
          * Remove the specified sorters.
 88  
          *
 89  
          * @param sorters The sorters to remove.
 90  
          */
 91  
         public void removeSorters(Sorter[] sorters){
 92  0
                 for (Sorter sorter : sorters){
 93  0
                         removeSorter(sorter);
 94  
                 }
 95  0
         }
 96  
 }