Coverage Report - org.jtheque.films.stats.services.impl.StatsService
 
Classes in this File Line Coverage Branch Coverage Complexity
StatsService
0 %
0/19
0 %
0/4
1.4
 
 1  
 package org.jtheque.films.stats.services.impl;
 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.core.managers.Managers;
 20  
 import org.jtheque.core.managers.language.ILanguageManager;
 21  
 import org.jtheque.films.stats.services.able.IStatsService;
 22  
 import org.jtheque.films.stats.services.impl.utils.StatsCalculator;
 23  
 import org.jtheque.films.stats.services.impl.utils.StatsInformations;
 24  
 import org.jtheque.utils.bean.Duration;
 25  
 
 26  
 import java.util.Arrays;
 27  
 
 28  
 /**
 29  
  * A service to manage stats.
 30  
  *
 31  
  * @author Baptiste Wicht
 32  
  */
 33  0
 public final class StatsService implements IStatsService {
 34  0
     private final ILanguageManager resources = Managers.getManager(ILanguageManager.class);
 35  
 
 36  
     /**
 37  
      * The stats calculator.
 38  
      */
 39  
     private StatsInformations stats;
 40  
 
 41  
     /**
 42  
      * Indicate if the title is up to date or not.
 43  
      */
 44  
     private boolean titlesUpToDate;
 45  
 
 46  
     /**
 47  
      * The titles for the headers.
 48  
      */
 49  
     private String[] titles;
 50  
 
 51  
     /**
 52  
      * Return the calculator.
 53  
      *
 54  
      * @return The stats calculator.
 55  
      */
 56  
     private StatsInformations getCalculator() {
 57  0
         if (stats == null) {
 58  0
             stats = StatsCalculator.getInstance();
 59  0
             stats.generateStats();
 60  
         }
 61  
 
 62  0
         return stats;
 63  
     }
 64  
 
 65  
     @Override
 66  
     public void refreshStats() {
 67  0
         getCalculator().generateStats();
 68  
 
 69  0
         titlesUpToDate = false;
 70  0
     }
 71  
 
 72  
     @Override
 73  
     public String[] getTitles() {
 74  0
         if (!titlesUpToDate) {
 75  0
             titles = new String[3];
 76  
 
 77  0
             titles[0] = getCalculator().getNumberOfRealizers() + " " +
 78  
                     resources.getMessage("stats.view.realizers").toLowerCase(resources.getCurrentLocale());
 79  0
             titles[1] = getCalculator().getNumberOfActors() + " " +
 80  
                     resources.getMessage("stats.view.actors").toLowerCase(resources.getCurrentLocale());
 81  0
             titles[2] = getCalculator().getNumberOfFilms() + " " +
 82  
                     resources.getMessage("stats.view.films").toLowerCase(resources.getCurrentLocale()) +
 83  
                     " (" + new Duration(getCalculator().getTotalDurationOfFilms()).toString() + ')';
 84  
 
 85  0
             titlesUpToDate = true;
 86  
         }
 87  
 
 88  0
         return Arrays.copyOf(titles, titles.length);
 89  
     }
 90  
 
 91  
     @Override
 92  
     public StatsInformations getInformations() {
 93  0
         return getCalculator();
 94  
     }
 95  
 
 96  
     /**
 97  
      * Set the stats.
 98  
      *
 99  
      * @param stats The stats informations.
 100  
      */
 101  
     public void setStats(StatsInformations stats) {
 102  0
         this.stats = stats;
 103  0
     }
 104  
 }