Coverage Report - org.jtheque.films.persistence.od.impl.FilmImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
FilmImpl
0 %
0/34
0 %
0/14
1.1
 
 1  
 package org.jtheque.films.persistence.od.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.properties.IPropertiesManager;
 21  
 import org.jtheque.core.managers.resource.IResourceManager;
 22  
 import org.jtheque.core.managers.resource.ImageType;
 23  
 import org.jtheque.core.utils.db.EntityUtils;
 24  
 import org.jtheque.films.persistence.od.able.Film;
 25  
 import org.jtheque.films.services.able.IActorService;
 26  
 import org.jtheque.films.utils.Constants;
 27  
 import org.jtheque.primary.od.able.Kind;
 28  
 import org.jtheque.primary.od.able.Person;
 29  
 import org.jtheque.utils.bean.HashCodeUtils;
 30  
 
 31  
 import javax.swing.Icon;
 32  
 import java.util.Set;
 33  
 
 34  
 /**
 35  
  * A Film implementation.
 36  
  *
 37  
  * @author Baptiste Wicht
 38  
  */
 39  0
 public final class FilmImpl extends AbstractFilm {
 40  
     private Film memento;
 41  
     private boolean mementoState;
 42  
 
 43  
     private final FilmTemporaryContext temporaryContext;
 44  
 
 45  
     /**
 46  
      * Construct a new FilmImpl.
 47  
      */
 48  
     public FilmImpl() {
 49  0
         super();
 50  
 
 51  0
         temporaryContext = new FilmTemporaryContext();
 52  0
     }
 53  
 
 54  
     @Override
 55  
     public FilmTemporaryContext getTemporaryContext() {
 56  0
         return temporaryContext;
 57  
     }
 58  
 
 59  
     @Override
 60  
     public String getDisplayableText() {
 61  0
         return getTitle();
 62  
     }
 63  
 
 64  
     @Override
 65  
     public String toString() {
 66  0
         return getDisplayableText();
 67  
     }
 68  
 
 69  
     @Override
 70  
     public int hashCode() {
 71  0
         return HashCodeUtils.hashCode(this);
 72  
     }
 73  
 
 74  
     @Override
 75  
     public boolean equals(Object obj) {
 76  0
         return Managers.getManager(IPropertiesManager.class).areEquals(
 77  
                 this, obj,
 78  
                 "title", "actors", "year", "kinds", "comment", "duration", "theLending", "image", "theLanguage",
 79  
                 "note", "theRealizer", "resume", "theType", "kinds");
 80  
 
 81  
     }
 82  
 
 83  
     @Override
 84  
     public Icon getIcon() {
 85  0
         return Managers.getManager(IResourceManager.class).getIcon(Constants.IMAGE_BASE_NAME, Constants.FILM_ICON, ImageType.PNG);
 86  
     }
 87  
 
 88  
     @Override
 89  
     public void saveToMemento() {
 90  0
         mementoState = true;
 91  
 
 92  0
         memento = Managers.getManager(IPropertiesManager.class).createMemento(this);
 93  
 
 94  0
         if (memento == null) {
 95  0
             mementoState = false;
 96  
         }
 97  0
     }
 98  
 
 99  
     @Override
 100  
     public void restoreMemento() {
 101  0
         if (mementoState) {
 102  0
             Managers.getManager(IPropertiesManager.class).restoreMemento(this, memento);
 103  
         }
 104  0
     }
 105  
 
 106  
     /**
 107  
      * Indicate if the film is in lending or not.
 108  
      *
 109  
      * @return <code>true</code> if the film has a lending else <code>false</code>
 110  
      */
 111  
     @Override
 112  
     public boolean hasType() {
 113  0
         return getTheType() != null;
 114  
     }
 115  
 
 116  
     /**
 117  
      * Indicate if the film has kinds or not.
 118  
      *
 119  
      * @return <code>true</code> if the film has kinds else <code>false</code>
 120  
      */
 121  
     @Override
 122  
     public boolean hasKinds() {
 123  0
         return getKinds().isEmpty();
 124  
     }
 125  
 
 126  
     /**
 127  
      * Indicate if the film has actors or not.
 128  
      *
 129  
      * @return <code>true</code> if the film has actors else <code>false</code>
 130  
      */
 131  
     @Override
 132  
     public boolean hasActors() {
 133  0
         return getActors().isEmpty();
 134  
     }
 135  
 
 136  
     /**
 137  
      * Indicate if the film has a language or not.
 138  
      *
 139  
      * @return <code>true</code> if the film has a language else <code>false</code>
 140  
      */
 141  
     @Override
 142  
     public boolean hasLanguage() {
 143  0
         return getTheLanguage() != null;
 144  
     }
 145  
 
 146  
     /**
 147  
      * Indicate if the film has a realizer or not.
 148  
      *
 149  
      * @return <code>true</code> if the film has a realizer else <code>false</code>
 150  
      */
 151  
     @Override
 152  
     public boolean hasRealizer() {
 153  0
         return getTheRealizer() != null;
 154  
     }
 155  
 
 156  
     @Override
 157  
     public void addActors(Set<Person> actors) {
 158  0
         getActors().addAll(actors);
 159  0
     }
 160  
 
 161  
     @Override
 162  
     public void addKinds(Set<Kind> kinds) {
 163  0
         getKinds().addAll(kinds);
 164  0
     }
 165  
 
 166  
     @Override
 167  
     public void addActor(Person actor) {
 168  0
         assert actor.getType().equals(IActorService.PERSON_TYPE) : "The person must of type Actor";
 169  
 
 170  0
         getActors().add(actor);
 171  0
     }
 172  
 
 173  
     @Override
 174  
     public void addKind(Kind kind) {
 175  0
         getKinds().add(kind);
 176  0
     }
 177  
 
 178  
     @Override
 179  
     public boolean containsActor(Person actor) {
 180  0
         return EntityUtils.containsID(getActors(), actor.getId());
 181  
     }
 182  
 
 183  
     @Override
 184  
     public boolean containsKind(Kind kind) {
 185  0
         return getKinds().contains(kind);
 186  
     }
 187  
 }