LiteratureItemListVo.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
004  *
005  * "Hilbert II" is free software; you can redistribute
006  * it and/or modify it under the terms of the GNU General Public
007  * License as published by the Free Software Foundation; either
008  * version 2 of the License, or (at your option) any later version.
009  *
010  * This program is distributed in the hope that it will be useful,
011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013  * GNU General Public License for more details.
014  */
015 
016 package org.qedeq.kernel.se.dto.module;
017 
018 import java.util.ArrayList;
019 import java.util.List;
020 
021 import org.qedeq.base.utility.EqualsUtility;
022 import org.qedeq.kernel.se.base.module.LiteratureItem;
023 import org.qedeq.kernel.se.base.module.LiteratureItemList;
024 
025 
026 /**
027  * List of literature references.
028  *
029  @author  Michael Meyling
030  */
031 public class LiteratureItemListVo implements LiteratureItemList {
032 
033     /** Contains all list elements. */
034     private final List list;
035 
036     /**
037      * Constructs an empty list of authors.
038      */
039     public LiteratureItemListVo() {
040         this.list = new ArrayList();
041 
042     }
043 
044     /**
045      * Add literature reference to list.
046      *
047      @param   item    Add this reference.
048      */
049     public final void add(final LiteratureItemVo item) {
050         list.add(item);
051     }
052 
053     public final int size() {
054         return list.size();
055     }
056 
057     public final LiteratureItem get(final int index) {
058         return (LiteratureItemlist.get(index);
059     }
060 
061     public boolean equals(final Object obj) {
062         if (!(obj instanceof LiteratureItemListVo)) {
063             return false;
064         }
065         final LiteratureItemListVo otherList = (LiteratureItemListVoobj;
066         if (size() != otherList.size()) {
067             return false;
068         }
069         for (int i = 0; i < size(); i++) {
070             if (!EqualsUtility.equals(get(i), otherList.get(i))) {
071                 return false;
072             }
073         }
074         return true;
075     }
076 
077     public int hashCode() {
078         int hash = 0;
079         for (int i = 0; i < size(); i++) {
080             hash = hash ^ (i + 1);
081             if (get(i!= null) {
082                 hash = hash ^ get(i).hashCode();
083             }
084         }
085         return hash;
086     }
087 
088     public String toString() {
089         final StringBuffer buffer = new StringBuffer("Bibliography:\n");
090         for (int i = 0; i < size(); i++) {
091             if (i != 0) {
092                 buffer.append("\n");
093             }
094             buffer.append((i + 1":\t");
095             buffer.append(get(i!= null ? get(i).toString() null);
096         }
097         return buffer.toString();
098     }
099 
100 }