| 1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org |
| 2 | * |
| 3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. |
| 4 | * |
| 5 | * "Hilbert II" is free software; you can redistribute |
| 6 | * it and/or modify it under the terms of the GNU General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program 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 | |
| 16 | package org.qedeq.kernel.se.dto.module; |
| 17 | |
| 18 | import org.qedeq.base.utility.EqualsUtility; |
| 19 | import org.qedeq.kernel.se.base.module.ChapterList; |
| 20 | import org.qedeq.kernel.se.base.module.Header; |
| 21 | import org.qedeq.kernel.se.base.module.LiteratureItemList; |
| 22 | import org.qedeq.kernel.se.base.module.Qedeq; |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * A complete QEDEQ module. This is the root value object. |
| 27 | * |
| 28 | * @author Michael Meyling |
| 29 | */ |
| 30 | public class QedeqVo implements Qedeq { |
| 31 | |
| 32 | /** Header of module. */ |
| 33 | private Header header; |
| 34 | |
| 35 | /** All module chapters. */ |
| 36 | private ChapterListVo chapterList; |
| 37 | |
| 38 | /** Bibliography. */ |
| 39 | private LiteratureItemList literatureItemList; |
| 40 | |
| 41 | /** |
| 42 | * Constructs a new empty qedeq module. |
| 43 | */ |
| 44 | public QedeqVo() { |
| 45 | // nothing to do |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Set header for this module. |
| 50 | * |
| 51 | * @param header Module header. |
| 52 | */ |
| 53 | public final void setHeader(final HeaderVo header) { |
| 54 | this.header = header; |
| 55 | } |
| 56 | |
| 57 | public final Header getHeader() { |
| 58 | return header; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Set chapter list of this module. |
| 63 | * |
| 64 | * @param chapters Chapter list. |
| 65 | */ |
| 66 | public final void setChapterList(final ChapterListVo chapters) { |
| 67 | this.chapterList = chapters; |
| 68 | } |
| 69 | |
| 70 | public final ChapterList getChapterList() { |
| 71 | return chapterList; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Add chapter to this module. |
| 76 | * |
| 77 | * @param chapter Chapter to add. |
| 78 | */ |
| 79 | public final void addChapter(final ChapterVo chapter) { |
| 80 | if (chapterList == null) { |
| 81 | chapterList = new ChapterListVo(); |
| 82 | } |
| 83 | chapterList.add(chapter); |
| 84 | } |
| 85 | |
| 86 | public LiteratureItemList getLiteratureItemList() { |
| 87 | return literatureItemList; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Set bibliography. |
| 92 | * |
| 93 | * @param literatureItemList Bibliography. |
| 94 | */ |
| 95 | public void setLiteratureItemList(final LiteratureItemListVo literatureItemList) { |
| 96 | this.literatureItemList = literatureItemList; |
| 97 | } |
| 98 | |
| 99 | public boolean equals(final Object obj) { |
| 100 | if (!(obj instanceof QedeqVo)) { |
| 101 | return false; |
| 102 | } |
| 103 | final QedeqVo other = (QedeqVo) obj; |
| 104 | return EqualsUtility.equals(getHeader(), other.getHeader()) |
| 105 | && EqualsUtility.equals(getChapterList(), other.getChapterList()) |
| 106 | && EqualsUtility.equals(getLiteratureItemList(), other.getLiteratureItemList()); |
| 107 | } |
| 108 | |
| 109 | public int hashCode() { |
| 110 | return (getHeader() != null ? getHeader().hashCode() : 0) |
| 111 | ^ (getChapterList() != null ? 1 ^ getChapterList().hashCode() : 0) |
| 112 | ^ (getLiteratureItemList() != null ? 2 ^ getLiteratureItemList().hashCode() : 0); |
| 113 | } |
| 114 | |
| 115 | public String toString() { |
| 116 | final StringBuffer buffer = new StringBuffer(); |
| 117 | buffer.append(getHeader() + "\n\n"); |
| 118 | buffer.append(getChapterList() + "\n\n"); |
| 119 | buffer.append(getLiteratureItemList()); |
| 120 | return buffer.toString(); |
| 121 | } |
| 122 | |
| 123 | } |