Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RealizerImpl |
|
| 3.8;3.8 |
1 | package org.jtheque.films.persistence.od; | |
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 org.jtheque.core.managers.Managers; | |
20 | import org.jtheque.core.managers.resource.IResourceManager; | |
21 | import org.jtheque.core.managers.resource.ImageType; | |
22 | import org.jtheque.core.managers.properties.IPropertiesManager; | |
23 | import org.jtheque.films.persistence.od.abstraction.Realizer; | |
24 | import org.jtheque.films.persistence.od.temp.PersonTemporaryContext; | |
25 | import org.jtheque.films.utils.Constants; | |
26 | ||
27 | import javax.swing.Icon; | |
28 | ||
29 | /** | |
30 | * Cette classe repr�sente un r�alisateur et toutes ses donn�es. | |
31 | * | |
32 | * @author Baptiste Wicht | |
33 | */ | |
34 | 0 | public final class RealizerImpl extends Realizer { |
35 | private RealizerImpl memento; | |
36 | private boolean mementoState; | |
37 | ||
38 | private final PersonTemporaryContext temporaryContext; | |
39 | ||
40 | /** | |
41 | * Construct a new RealizerImpl. | |
42 | */ | |
43 | public RealizerImpl() { | |
44 | 0 | super(); |
45 | ||
46 | 0 | temporaryContext = new PersonTemporaryContext(); |
47 | 0 | } |
48 | ||
49 | @Override | |
50 | public PersonTemporaryContext getTemporaryContext() { | |
51 | 0 | return temporaryContext; |
52 | } | |
53 | ||
54 | @Override | |
55 | public String getAffichableText() { | |
56 | 0 | return getFirstName() + ' ' + getName(); |
57 | } | |
58 | ||
59 | @Override | |
60 | public String toString() { | |
61 | 0 | return getAffichableText(); |
62 | } | |
63 | ||
64 | @Override | |
65 | public int hashCode() { | |
66 | 0 | return Managers.getManager(IPropertiesManager.class).hashCode(this); |
67 | } | |
68 | ||
69 | @Override | |
70 | public boolean equals(Object obj) { | |
71 | 0 | if (this == obj) { |
72 | 0 | return true; |
73 | } | |
74 | ||
75 | 0 | if (obj == null) { |
76 | 0 | return false; |
77 | } | |
78 | ||
79 | 0 | if (getClass() != obj.getClass()) { |
80 | 0 | return false; |
81 | } | |
82 | ||
83 | 0 | final Realizer other = (Realizer) obj; |
84 | ||
85 | 0 | if (getName() == null) { |
86 | 0 | if (other.getName() != null) { |
87 | 0 | return false; |
88 | } | |
89 | 0 | } else if (!getName().equals(other.getName())) { |
90 | 0 | return false; |
91 | } | |
92 | ||
93 | 0 | if (getNote() == null) { |
94 | 0 | if (other.getNote() != null) { |
95 | 0 | return false; |
96 | } | |
97 | 0 | } else if (!getNote().equals(other.getNote())) { |
98 | 0 | return false; |
99 | } | |
100 | ||
101 | 0 | if (getTheCountry() == null) { |
102 | 0 | if (other.getTheCountry() != null) { |
103 | 0 | return false; |
104 | } | |
105 | 0 | } else if (!getTheCountry().equals(other.getTheCountry())) { |
106 | 0 | return false; |
107 | } | |
108 | ||
109 | 0 | if (getFirstName() == null) { |
110 | 0 | if (other.getFirstName() != null) { |
111 | 0 | return false; |
112 | } | |
113 | 0 | } else if (!getFirstName().equals(other.getFirstName())) { |
114 | 0 | return false; |
115 | } | |
116 | ||
117 | 0 | return true; |
118 | } | |
119 | ||
120 | @Override | |
121 | public Icon getIcon() { | |
122 | 0 | return Managers.getManager(IResourceManager.class).getIcon(Constants.IMAGE_BASENAME, Constants.PERSON_ICON, ImageType.PNG); |
123 | } | |
124 | ||
125 | @Override | |
126 | public void saveToMemento() { | |
127 | 0 | mementoState = true; |
128 | ||
129 | 0 | memento = Managers.getManager(IPropertiesManager.class).createMemento(this); |
130 | ||
131 | 0 | if (memento == null) { |
132 | 0 | mementoState = false; |
133 | } | |
134 | 0 | } |
135 | ||
136 | @Override | |
137 | public void restoreMemento() { | |
138 | 0 | if (mementoState) { |
139 | 0 | Managers.getManager(IPropertiesManager.class).restoreMemento(this, memento); |
140 | } | |
141 | 0 | } |
142 | ||
143 | /** | |
144 | * Indicate if the realizer has a country or not. | |
145 | * | |
146 | * @return <code>true</code> if the realizer has a country else <code>false</code>. | |
147 | */ | |
148 | public boolean hasCountry() { | |
149 | 0 | return getTheCountry() != null; |
150 | } | |
151 | } |