Coverage Report - org.jtheque.films.view.impl.models.list.SimpleModel
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleModel
0 %
0/21
N/A
1
 
 1  
 package org.jtheque.films.view.impl.models.list;
 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 javax.swing.DefaultListModel;
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 import java.util.List;
 23  
 
 24  
 /**
 25  
  * A simple list model.
 26  
  *
 27  
  * @author Baptiste Wicht
 28  
  */
 29  
 public final class SimpleModel<T> extends DefaultListModel {
 30  
     private static final long serialVersionUID = 627034111249354845L;
 31  
 
 32  
     private final List<T> objects;
 33  
 
 34  
     /**
 35  
      * Construct a new SimpleModel.
 36  
      */
 37  
     public SimpleModel() {
 38  0
         super();
 39  
 
 40  0
         objects = new ArrayList<T>(10);
 41  0
     }
 42  
 
 43  
     @Override
 44  
     public Object getElementAt(int index) {
 45  0
         return objects.get(index);
 46  
     }
 47  
 
 48  
     @Override
 49  
     public Object get(int index) {
 50  0
         return objects.get(index);
 51  
     }
 52  
 
 53  
     @Override
 54  
     public int getSize() {
 55  0
         return objects.size();
 56  
     }
 57  
 
 58  
     @Override
 59  
     public Object remove(int index) {
 60  0
         T actor = objects.remove(index);
 61  0
         fireIntervalRemoved(this, index, index);
 62  0
         return actor;
 63  
     }
 64  
 
 65  
     @Override
 66  
     public void addElement(Object obj) {
 67  0
         objects.add((T) obj);
 68  0
         fireIntervalAdded(this, getSize(), getSize());
 69  0
     }
 70  
 
 71  
     @Override
 72  
     public void removeAllElements() {
 73  0
         objects.clear();
 74  0
         fireContentsChanged(this, 0, getSize());
 75  0
     }
 76  
 
 77  
     @Override
 78  
     public boolean removeElement(Object obj) {
 79  0
         T t = (T) obj;
 80  
 
 81  0
         int index = objects.indexOf(t);
 82  0
         boolean remove = objects.remove(t);
 83  0
         fireIntervalRemoved(this, index, index);
 84  0
         return remove;
 85  
     }
 86  
 
 87  
     /**
 88  
      * Return the objects.
 89  
      *
 90  
      * @return A List containing all the objects of the model.
 91  
      */
 92  
     public Collection<T> getObjects() {
 93  0
         return objects;
 94  
     }
 95  
 }