1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package net.sf.webphotos.model; |
17 | |
|
18 | |
import java.util.Collection; |
19 | |
import java.util.Date; |
20 | |
import java.util.HashSet; |
21 | |
import java.util.Iterator; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class AlbumVOBuilder { |
28 | |
|
29 | |
private String nmalbum; |
30 | |
private String descricao; |
31 | |
private Date dtInsercao; |
32 | |
private CategoryVO categoriasVO; |
33 | |
private HashSet<PhotoVO> photoVOs; |
34 | |
private Integer key; |
35 | |
|
36 | 0 | AlbumVOBuilder() { |
37 | 0 | photoVOs = new HashSet<PhotoVO>(); |
38 | 0 | key = 0; |
39 | 0 | } |
40 | |
|
41 | |
AlbumVOBuilder(Integer key) { |
42 | 0 | this(); |
43 | 0 | this.key = key; |
44 | 0 | } |
45 | |
|
46 | |
public AlbumVOBuilder withAlbumName(String nmalbum) { |
47 | 0 | this.nmalbum = nmalbum; |
48 | 0 | return this; |
49 | |
} |
50 | |
|
51 | |
public AlbumVOBuilder withDescription(String descricao) { |
52 | 0 | this.descricao = descricao; |
53 | 0 | return this; |
54 | |
} |
55 | |
|
56 | |
public AlbumVOBuilder withCreationDate(Date dtInsercao) { |
57 | 0 | this.dtInsercao = dtInsercao; |
58 | 0 | return this; |
59 | |
} |
60 | |
|
61 | |
public AlbumVOBuilder withCategory(CategoryVO categoriasVO) { |
62 | 0 | this.categoriasVO = categoriasVO; |
63 | 0 | return this; |
64 | |
} |
65 | |
|
66 | |
public AlbumVOBuilder withPhoto(PhotoVO photoVO) { |
67 | 0 | this.photoVOs.add(photoVO); |
68 | 0 | return this; |
69 | |
} |
70 | |
|
71 | |
public AlbumVOBuilder withPhotos(Collection<PhotoVO> photoVOs) { |
72 | 0 | this.photoVOs.addAll(photoVOs); |
73 | 0 | return this; |
74 | |
} |
75 | |
|
76 | |
public AlbumVO build() { |
77 | 0 | final AlbumVO albumVO = (key > 0 ? |
78 | |
new AlbumVO(key, nmalbum, descricao, dtInsercao, categoriasVO, photoVOs) : |
79 | |
new AlbumVO(nmalbum, descricao, dtInsercao, categoriasVO, photoVOs)); |
80 | 0 | for (Iterator<PhotoVO> it = photoVOs.iterator(); it.hasNext();) { |
81 | 0 | PhotoVO photoVO = it.next(); |
82 | 0 | photoVO.setAlbum(albumVO); |
83 | 0 | } |
84 | 0 | return albumVO; |
85 | |
} |
86 | |
|
87 | |
} |