4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
AltEntityAdditionalAttribute.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: AltEntityAdditionalAttribute.java
5  * Description: Class representing additional attribute of entity in alternative attribute
6  */
7 
8 /**
9  * @file AltEntityAdditionalAttribute.java
10  *
11  * @brief Class representing additional attribute of entity in alternative attribute
12  * @author Jan Paulovcak
13  */
14 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.alternative;
15 
16 import java.io.Serializable;
17 import javax.persistence.Basic;
18 import javax.persistence.Column;
19 import javax.persistence.Entity;
20 import javax.persistence.GeneratedValue;
21 import javax.persistence.GenerationType;
22 import javax.persistence.Id;
23 import javax.persistence.JoinColumn;
24 import javax.persistence.ManyToOne;
25 import javax.persistence.NamedQueries;
26 import javax.persistence.NamedQuery;
27 import javax.persistence.Table;
28 import javax.validation.constraints.NotNull;
29 import javax.validation.constraints.Size;
30 import javax.xml.bind.annotation.XmlRootElement;
31 
32 /**
33  * Class representing additional attribute of entity in alternative attribute
34  *
35  * @brief Class representing additional attribute of entity in alternative attribute
36  * @author Jan Paulovcak
37  */
38 @Entity
39 @Table(name = "altEntityAdditionalAttribute")
40 @XmlRootElement
41 @NamedQueries({
42  @NamedQuery(name = "AltEntityAdditionalAttribute.findAll", query = "SELECT s FROM AltEntityAdditionalAttribute s"),
43  @NamedQuery(name = "AltEntityAdditionalAttribute.findById", query = "SELECT s FROM AltEntityAdditionalAttribute s WHERE s.id = :id"),
44  @NamedQuery(name = "AltEntityAdditionalAttribute.findByName", query = "SELECT s FROM AltEntityAdditionalAttribute s WHERE s.name = :name"),
45  @NamedQuery(name = "AltEntityAdditionalAttribute.findByStringValue", query = "SELECT s FROM AltEntityAdditionalAttribute s WHERE s.stringValue = :stringValue"),
46  @NamedQuery(name = "AltEntityAdditionalAttribute.findByAlternativeAttId", query = "SELECT s FROM AltEntityAdditionalAttribute s WHERE s.alternativeAttId = :alternativeAttId")})
47 public class AltEntityAdditionalAttribute implements Serializable, Comparable<Object>{
48  private static final long serialVersionUID = 1L;
49 
50  /** Id of attribute */
51  @Id
52  @GeneratedValue(strategy = GenerationType.IDENTITY)
53  @Basic(optional = false)
54  @Column(name = "id")
55  private Integer id;
56 
57  /** Name of attribute */
58  @Basic(optional = false)
59  @NotNull
60  @Size(min = 1, max = 255)
61  @Column(name = "name")
62  private String name;
63 
64  /** Type of attribute */
65  @Basic(optional = false)
66  @NotNull
67  @Column(name = "type")
68  private String type;
69 
70  /** Value of attribute */
71  @Basic(optional = true)
72  @Size(min = 0, max = 255)
73  @Column(name = "stringValue")
74  private String stringValue;
75 
76  /** Attribute priority (for order) */
77  @Column(name = "priority")
78  protected Integer priority;
79 
80  /** Id of alternative attribute to which this additional attribute belongs */
81  @Basic(optional = false)
82  @Column(name = "alternativeAttId", nullable = false, insertable = false, updatable = false)
83  private int alternativeAttId;
84 
85  /** Alternative attribute to which this additional attribute belongs */
86  @ManyToOne(optional = false)
87  @JoinColumn(name = "alternativeAttId", referencedColumnName = "id")
88  private AlternativeAttribute alternativeAttribute;
89 
90  /**
91  * Constructor
92  */
94  }
95 
96  /**
97  * Constructor
98  *
99  * @param name Name of attribute
100  * @param stringValue Value of attribute
101  * @param refAlternativeAttribute Entity attribute of suggestion to which this additional attribute belongs
102  */
103  public AltEntityAdditionalAttribute(String name, String stringValue, AlternativeAttribute refAlternativeAttribute) {
104  this.name = name;
105  this.stringValue = stringValue;
106  this.alternativeAttribute = refAlternativeAttribute;
107  }
108 
109  /**
110  * Constructor
111  *
112  * @param name Name of attribute
113  * @param type Type of attribute
114  * @param stringValue Value of attribute
115  * @param refAlternativeAttribute Entity attribute of alternative to which this additional attribute belongs
116  */
117  public AltEntityAdditionalAttribute(String name, String type, String stringValue, AlternativeAttribute refAlternativeAttribute) {
118  this.name = name;
119  this.type = type;
120  this.stringValue = stringValue;
121  this.alternativeAttribute = refAlternativeAttribute;
122  }
123 
124  /**
125  * Gets id of attribute
126  *
127  * @return Returns id of attribute
128  */
129  public Integer getId() {
130  return id;
131  }
132 
133  /**
134  * Sets id of attribute
135  *
136  * @param id Id of attribute
137  */
138  public void setId(Integer id) {
139  this.id = id;
140  }
141 
142  /**
143  * Gets name of attribute
144  *
145  * @return Returns name of attribute
146  */
147  public String getName() {
148  return name;
149  }
150 
151  /**
152  * Sets name of attribute
153  *
154  * @param name Name of attribute
155  */
156  public void setName(String name) {
157  this.name = name;
158  }
159 
160  /**
161  * Gets type of attribute
162  *
163  * @return Returns type of attribute
164  */
165  public String getType() {
166  return type;
167  }
168 
169  /**
170  * Sets type of attribute
171  *
172  * @param type New type of attribute
173  */
174  public void setType(String type) {
175  this.type = type;
176  }
177 
178  /**
179  * Gets value of attribute
180  *
181  * @return Returns value of attribute
182  */
183  public String getStringValue() {
184  return stringValue;
185  }
186 
187  /**
188  * Sets value of attribute
189  *
190  * @param stringValue Value of attribute
191  */
192  public void setStringValue(String stringValue) {
193  this.stringValue = stringValue;
194  }
195 
196  /**
197  * Gets id of alternative attribute to which this additional attribute belongs
198  *
199  * @return Returns id of alternative attribute to which this additional attribute belongs
200  */
201  public int getAlternativeAttId() {
202  return alternativeAttId;
203  }
204 
205  /**
206  * Sets id of alternative attribute to which this additional attribute belongs
207  *
208  * @param alternativeAttId Id of alternative attribute to which this additional attribute belongs
209  */
210  public void setAlternativeAttId(int alternativeAttId) {
211  this.alternativeAttId = alternativeAttId;
212  }
213 
214  /**
215  * Gets alternative attribute to which this additional attribute belongs
216  *
217  * @return Returns alternative attribute to which this additional attribute belongs
218  */
220  return alternativeAttribute;
221  }
222 
223  /**
224  * Sets alternative attribute to which this additional attribute belongs
225  *
226  * @param refAlternativeAttribute Alternative attribute to which this additional attribute belongs
227  */
228  public void setRefAlternativeAttribute(AlternativeAttribute refAlternativeAttribute) {
229  this.alternativeAttribute = refAlternativeAttribute;
230  }
231 
232  /**
233  * Gets attribute priority
234  *
235  * @return Returns attribute priority
236  */
237  public Integer getPriority() {
238  return priority;
239  }
240 
241  /**
242  * Sets attribute priority
243  *
244  * @param priority Attribute priority
245  */
246  public void setPriority(Integer priority) {
247  this.priority = priority;
248  }
249 
250  /**
251  * Compares additional attributes according to priority
252  *
253  * @param o Object to compare with
254  * @return Returns a negative integer, zero, or a positive integer as this
255  * object is less than, equal to, or greater than the specified object.
256  */
257  @Override
258  public int compareTo(Object o) {
259  if (o == null) {
260  return 1;
261  }
262  if (!(o instanceof AltEntityAdditionalAttribute)) {
263  throw new UnsupportedOperationException("Not supported yet.");
264  }
265  AltEntityAdditionalAttribute other = (AltEntityAdditionalAttribute) o;
266 
267  if (this.priority == null && other.getPriority() == null) {
268  return 0;
269  }
270 
271  if (this.priority == null && other.getPriority() != null) {
272  return -1;
273  }
274 
275  if (this.priority != null && other.getPriority() == null) {
276  return 1;
277  }
278 
279  return this.priority.compareTo(other.getPriority());
280  }
281 
282  @Override
283  public String toString() {
284  return "cz.vutbr.fit.knot.annotations.modules.suggestionManager.alternative.AltEntityAdditionalAttribute[ id=" + id + " ]";
285  }
286 } // public class AltEntityAdditionalAttribute
AltEntityAdditionalAttribute(String name, String type, String stringValue, AlternativeAttribute refAlternativeAttribute)
Class representing additional attribute of entity in alternative attribute.
AltEntityAdditionalAttribute(String name, String stringValue, AlternativeAttribute refAlternativeAttribute)