1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.qedeq.kernel.se.dto.module;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.qedeq.base.utility.EqualsUtility;
22 import org.qedeq.kernel.se.base.module.Author;
23 import org.qedeq.kernel.se.base.module.AuthorList;
24
25
26
27
28
29
30
31 public class AuthorListVo implements AuthorList {
32
33
34 private final List list;
35
36
37
38
39 public AuthorListVo() {
40 this.list = new ArrayList();
41 }
42
43
44
45
46
47
48 public final void add(final AuthorVo author) {
49 list.add(author);
50 }
51
52 public final int size() {
53 return list.size();
54 }
55
56 public final Author get(final int index) {
57 return (Author) list.get(index);
58 }
59
60 public boolean equals(final Object obj) {
61 if (!(obj instanceof AuthorListVo)) {
62 return false;
63 }
64 final AuthorListVo otherList = (AuthorListVo) obj;
65 if (size() != otherList.size()) {
66 return false;
67 }
68 for (int i = 0; i < size(); i++) {
69 if (!EqualsUtility.equals(get(i), otherList.get(i))) {
70 return false;
71 }
72 }
73 return true;
74 }
75
76 public int hashCode() {
77 int hash = 0;
78 for (int i = 0; i < size(); i++) {
79 hash = hash ^ (i + 1);
80 if (get(i) != null) {
81 hash = hash ^ get(i).hashCode();
82 }
83 }
84 return hash;
85 }
86
87 public String toString() {
88 final StringBuffer buffer = new StringBuffer("List of authors:\n");
89 for (int i = 0; i < size(); i++) {
90 if (i != 0) {
91 buffer.append("\n");
92 }
93 buffer.append((i + 1) + ":\t");
94 buffer.append(get(i) != null ? get(i).toString() : null);
95 }
96 return buffer.toString();
97 }
98
99 }