View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.model.container;
17  
18  import org.fourthline.cling.support.model.item.Item;
19  import org.fourthline.cling.support.model.item.Photo;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * @author Christian Bauer
26   */
27  public class PhotoAlbum extends Album {
28  
29      public static final Class CLASS = new Class("object.container.album.photoAlbum");
30  
31      public PhotoAlbum() {
32          setClazz(CLASS);
33      }
34  
35      public PhotoAlbum(Container other) {
36          super(other);
37      }
38  
39      public PhotoAlbum(String id, Container parent, String title, String creator, Integer childCount) {
40          this(id, parent.getId(), title, creator, childCount, new ArrayList<Photo>());
41      }
42  
43      public PhotoAlbum(String id, Container parent, String title, String creator, Integer childCount, List<Photo> photos) {
44          this(id, parent.getId(), title, creator, childCount, photos);
45      }
46  
47      public PhotoAlbum(String id, String parentID, String title, String creator, Integer childCount) {
48          this(id, parentID, title, creator, childCount, new ArrayList<Photo>());
49      }
50  
51      public PhotoAlbum(String id, String parentID, String title, String creator, Integer childCount, List<Photo> photos) {
52          super(id, parentID, title, creator, childCount);
53          setClazz(CLASS);
54          addPhotos(photos);
55      }
56  
57      public Photo[] getPhotos() {
58          List<Photo> list = new ArrayList<>();
59          for (Item item : getItems()) {
60              if (item instanceof Photo) list.add((Photo)item);
61          }
62          return list.toArray(new Photo[list.size()]);
63      }
64  
65      public void addPhotos(List<Photo> photos) {
66          addPhotos(photos.toArray(new Photo[photos.size()]));
67      }
68  
69      public void addPhotos(Photo[] photos) {
70          if (photos != null) {
71              for (Photo photo : photos) {
72                  photo.setAlbum(getTitle());
73                  addItem(photo);
74              }
75          }
76      }
77  
78  }