1 | |
package org.jtheque.films.persistence.od; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
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.Film; |
24 | |
import org.jtheque.films.persistence.od.temp.FilmTemporaryContext; |
25 | |
import org.jtheque.films.utils.Constants; |
26 | |
import org.jtheque.utils.EqualsUtils; |
27 | |
|
28 | |
import javax.swing.Icon; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public final class FilmImpl extends Film { |
36 | |
private FilmImpl memento; |
37 | |
private boolean mementoState; |
38 | |
|
39 | |
private final FilmTemporaryContext temporaryContext; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public FilmImpl() { |
45 | 0 | super(); |
46 | |
|
47 | 0 | temporaryContext = new FilmTemporaryContext(); |
48 | 0 | } |
49 | |
|
50 | |
@Override |
51 | |
public FilmTemporaryContext getTemporaryContext() { |
52 | 0 | return temporaryContext; |
53 | |
} |
54 | |
|
55 | |
@Override |
56 | |
public String getAffichableText() { |
57 | 0 | return getTitle(); |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public String toString() { |
62 | 0 | return getAffichableText(); |
63 | |
} |
64 | |
|
65 | |
@Override |
66 | |
public int hashCode() { |
67 | 0 | return Managers.getManager(IPropertiesManager.class).hashCode(this); |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public boolean equals(Object obj) { |
72 | 0 | if (this == obj) { |
73 | 0 | return true; |
74 | |
} |
75 | |
|
76 | 0 | if(EqualsUtils.areObjectIncompatible(this, obj)){ |
77 | 0 | return false; |
78 | |
} |
79 | |
|
80 | 0 | final Film other = (Film) obj; |
81 | |
|
82 | 0 | if(EqualsUtils.areNotEquals(getTitle(), other.getTitle())){ |
83 | 0 | return false; |
84 | |
} |
85 | |
|
86 | 0 | if(EqualsUtils.areNotEquals(getActors(), other.getActors())){ |
87 | 0 | return false; |
88 | |
} |
89 | |
|
90 | 0 | if(EqualsUtils.areNotEquals(getYear(), other.getYear())){ |
91 | 0 | return false; |
92 | |
} |
93 | |
|
94 | 0 | if(EqualsUtils.areNotEquals(getKinds(), other.getKinds())){ |
95 | 0 | return false; |
96 | |
} |
97 | |
|
98 | 0 | if(EqualsUtils.areNotEquals(getComment(), other.getComment())){ |
99 | 0 | return false; |
100 | |
} |
101 | |
|
102 | 0 | if(EqualsUtils.areNotEquals(getDuration(), other.getDuration())){ |
103 | 0 | return false; |
104 | |
} |
105 | |
|
106 | 0 | if(EqualsUtils.areNotEquals(getDuration(), other.getDuration())){ |
107 | 0 | return false; |
108 | |
} |
109 | |
|
110 | 0 | if(EqualsUtils.areNotEquals(getTheLending(), other.getTheLending())){ |
111 | 0 | return false; |
112 | |
} |
113 | |
|
114 | 0 | if(EqualsUtils.areNotEquals(getImage(), other.getImage())){ |
115 | 0 | return false; |
116 | |
} |
117 | |
|
118 | 0 | if(EqualsUtils.areNotEquals(getTheLanguage(), other.getTheLanguage())){ |
119 | 0 | return false; |
120 | |
} |
121 | |
|
122 | 0 | if(EqualsUtils.areNotEquals(getNote(), other.getNote())){ |
123 | 0 | return false; |
124 | |
} |
125 | |
|
126 | 0 | if(EqualsUtils.areNotEquals(getTheRealizer(), other.getTheRealizer())){ |
127 | 0 | return false; |
128 | |
} |
129 | |
|
130 | 0 | if(EqualsUtils.areNotEquals(getResume(), other.getResume())){ |
131 | 0 | return false; |
132 | |
} |
133 | |
|
134 | 0 | return !EqualsUtils.areNotEquals(getTheType(), other.getTheType()); |
135 | |
|
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
public Icon getIcon() { |
140 | 0 | return Managers.getManager(IResourceManager.class).getIcon(Constants.IMAGE_BASENAME, Constants.FILM_ICON, ImageType.PNG); |
141 | |
} |
142 | |
|
143 | |
@Override |
144 | |
public void saveToMemento() { |
145 | 0 | mementoState = true; |
146 | |
|
147 | 0 | memento = Managers.getManager(IPropertiesManager.class).createMemento(this); |
148 | |
|
149 | 0 | if (memento == null) { |
150 | 0 | mementoState = false; |
151 | |
} |
152 | 0 | } |
153 | |
|
154 | |
@Override |
155 | |
public void restoreMemento() { |
156 | 0 | if (mementoState) { |
157 | 0 | Managers.getManager(IPropertiesManager.class).restoreMemento(this, memento); |
158 | |
} |
159 | 0 | } |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
public boolean hasLending() { |
167 | 0 | return getTheLending() != null; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
public boolean hasType() { |
176 | 0 | return getTheType() != null; |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
public boolean hasKinds() { |
185 | 0 | return getKinds().isEmpty(); |
186 | |
} |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public boolean hasActors() { |
194 | 0 | return getActors().isEmpty(); |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
public boolean hasLanguage() { |
203 | 0 | return getTheLanguage() != null; |
204 | |
} |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public boolean hasRealizer() { |
212 | 0 | return getTheRealizer() != null; |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public boolean hasResume() { |
221 | 0 | return getResume() != null && !getResume().isEmpty(); |
222 | |
} |
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
public boolean hasComment() { |
230 | 0 | return getComment() != null && !getComment().isEmpty(); |
231 | |
} |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
public boolean hasImage() { |
239 | 0 | return getImage() != null && !getImage().isEmpty(); |
240 | |
} |
241 | |
} |