View Javadoc
1   package info.ejava.examples.jaxrs.todos.dto;
2   
3   import java.io.Serializable;
4   import java.util.LinkedList;
5   import java.util.List;
6   
7   import javax.xml.bind.annotation.XmlRootElement;
8   
9   @XmlRootElement(name="todoListList", namespace="urn:ejava.jaxrs.todos")
10  public class TodoListListDTO implements Serializable {
11     private static final long serialVersionUID = 1L;
12     private List<TodoListDTO> todoLists;
13      
14      public TodoListListDTO() {}
15      public TodoListListDTO(List<TodoListDTO> todoLists) {
16          this.todoLists = todoLists;
17      }
18      
19      public List<TodoListDTO> getTodoLists() {
20          return todoLists;
21      }
22      public void setTodoLists(List<TodoListDTO> todoLists) {
23          this.todoLists = todoLists;
24      }    
25      public void withTodoList(TodoListDTO todoList) {
26          if (todoLists==null && todoList!=null) {
27              todoLists = new LinkedList<>();            
28          }
29          if (todoList!=null) {
30              todoLists.add(todoList);
31          }
32      }
33  
34      @Override
35      public String toString() {
36          StringBuilder builder = new StringBuilder();
37          builder.append("TodoList[todos=");
38          if (todoLists!=null) {
39              boolean first=true;
40              for (TodoListDTO todoList: todoLists) {
41                  if (!first) { builder.append(",").append(System.lineSeparator()); }
42                  builder.append(todoList);
43                  first=false;
44              }
45          }
46          builder.append("]");
47          return builder.toString();
48      }
49      
50      public int getCount() {
51          return todoLists==null ? 0 : todoLists.size();
52      }
53      public void setCount(int count) { //nothing to set        
54      }
55  }