001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2011, 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.Section;
023 import org.qedeq.kernel.se.base.module.SectionList;
024
025
026 /**
027 * List of sections.
028 *
029 * @author Michael Meyling
030 */
031 public class SectionListVo implements SectionList {
032
033 /** Contains all sections. */
034 private final List list;
035
036 /**
037 * Constructs an empty section list.
038 */
039 public SectionListVo() {
040 this.list = new ArrayList();
041
042 }
043
044 /**
045 * Add section to this list.
046 *
047 * @param section Section to add.
048 */
049 public final void add(final SectionVo section) {
050 list.add(section);
051 }
052
053 public final int size() {
054 return list.size();
055 }
056
057 public final Section get(final int index) {
058 return (Section) list.get(index);
059 }
060
061 public boolean equals(final Object obj) {
062 if (!(obj instanceof SectionListVo)) {
063 return false;
064 }
065 final SectionListVo otherList = (SectionListVo) obj;
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("List of sections:\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 }
|