Coverage Report - org.jtheque.films.services.impl.utils.DataUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DataUtils
0 %
0/10
0 %
0/8
3
 
 1  
 package org.jtheque.films.services.impl.utils;
 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.films.persistence.od.able.Film;
 20  
 import org.jtheque.primary.od.able.Data;
 21  
 import org.jtheque.primary.od.able.Lending;
 22  
 
 23  
 /**
 24  
  * An utility class for Data.
 25  
  *
 26  
  * @author Baptiste Wicht
 27  
  */
 28  
 public final class DataUtils {
 29  
     /**
 30  
      * Construct a new DataUtils. This class isn't instanciable.
 31  
      */
 32  
     private DataUtils() {
 33  0
         super();
 34  0
     }
 35  
 
 36  
     /**
 37  
      * Return the data with the searched temporary id in the collection.
 38  
      *
 39  
      * @param id         The id searched.
 40  
      * @param collection The collection in which we must search.
 41  
      * @param <T>        The specialized type of Data.
 42  
      * @return The good data or <code>null</code> if we doesn't find it.
 43  
      */
 44  
     public static <T extends Data> T getDataByTemporaryId(int id, Iterable<T> collection) {
 45  0
         for (T data : collection) {
 46  0
             if (data.getTemporaryContext().getId() == id) {
 47  0
                 return data;
 48  
             }
 49  
         }
 50  
 
 51  0
         return null;
 52  
     }
 53  
 
 54  
     /**
 55  
      * Return the lending for the specified film.
 56  
      *
 57  
      * @param film       The film for which we want the lending.
 58  
      * @param collection The collection of lendings.
 59  
      * @return The good lending or <code>null</code> if we don't find one.
 60  
      */
 61  
     public static Lending getLendingForFilm(Film film, Iterable<Lending> collection) {
 62  0
         for (Lending lending : collection) {
 63  0
             if (lending.getTheOther() == film.getId()) {
 64  0
                 return lending;
 65  
             }
 66  
         }
 67  
 
 68  0
         return null;
 69  
     }
 70  
 }