View Javadoc
1   package fr.ifremer.tutti.persistence.entities.data;
2   
3   /*
4    * #%L
5    * Tutti :: Persistence
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.base.Preconditions;
26  import com.google.common.primitives.Ints;
27  import fr.ifremer.tutti.persistence.TuttiPersistence;
28  import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
29  
30  import java.io.Serializable;
31  
32  /**
33   * To define a sample category in application.
34   *
35   * It just wrap the underligned category, his order and his label.
36   *
37   * @author Tony Chemit - chemit@codelutin.com
38   * @since 2.4
39   */
40  public class SampleCategoryModelEntry implements Comparable<SampleCategoryModelEntry>, Serializable {
41  
42      private static final long serialVersionUID = 1L;
43  
44      protected String code;
45  
46      protected String label;
47  
48      protected Integer categoryId;
49  
50      protected int order;
51  
52      protected transient Caracteristic caracteristic;
53  
54      public void load(TuttiPersistence service) {
55          Preconditions.checkNotNull(code, "Can't have a null code");
56          Preconditions.checkNotNull(categoryId, "Can't have a null category id");
57          caracteristic = service.getCaracteristic(categoryId);
58          Preconditions.checkNotNull(caracteristic, "Could not find category if id: " + categoryId);
59      }
60  
61      public String getCode() {
62          return code;
63      }
64  
65      public void setCode(String code) {
66          this.code = code;
67      }
68  
69      public String getLabel() {
70          return label;
71      }
72  
73      public void setLabel(String label) {
74          this.label = label;
75      }
76  
77      public Caracteristic getCaracteristic() {
78          return caracteristic;
79      }
80  
81      public void setCaracteristic(Caracteristic caracteristic) {
82          this.caracteristic = caracteristic;
83      }
84  
85      public Integer getCategoryId() {
86          return categoryId;
87      }
88  
89      public void setCategoryId(Integer categoryId) {
90          this.categoryId = categoryId;
91      }
92  
93      public int getOrder() {
94          return order;
95      }
96  
97      public void setOrder(int order) {
98          this.order = order;
99      }
100 
101     @Override
102     public int compareTo(SampleCategoryModelEntry o) {
103         return Ints.compare(order, o.getOrder());
104     }
105 
106     @Override
107     public String toString() {
108         return categoryId + "," + label + "," + code;
109     }
110 }