4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
Alternative.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: Alternative.java
5  * Description: Class representing alternative of suggestion.
6  */
7 
8 /**
9  * @file Alternative.java
10  *
11  * @brief Class representing alternative of suggestion.
12  */
13 
14 package cz.vutbr.fit.knot.annotations.modules.suggestionManager.alternative;
15 
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.Iterator;
29 import java.util.List;
30 import javax.persistence.*;
31 import javax.validation.constraints.NotNull;
32 import javax.validation.constraints.Size;
33 import javax.xml.bind.annotation.XmlRootElement;
34 
35 /**
36  * Class representing alternative of suggestion.
37  *
38  * @brief Class representing alternative of suggestion.
39  * @author Marek Kopecky
40  */
41 @Entity
42 @Table(name = "alternative")
43 @XmlRootElement
44 @NamedQueries({
45  @NamedQuery(name = "Alternative.findAll", query = "SELECT a FROM Alternative a"),
46  @NamedQuery(name = "Alternative.findById", query = "SELECT a FROM Alternative a WHERE a.id = :id"),
47  @NamedQuery(name = "Alternative.findByAlternativeOf", query = "SELECT a FROM Alternative a WHERE a.alternativeOf = :alternativeOf AND a.used = 0"),
48  @NamedQuery(name = "Alternative.findByType", query = "SELECT a FROM Alternative a WHERE a.type = :type"),
49  @NamedQuery(name = "Alternative.findByCreated", query = "SELECT a FROM Alternative a WHERE a.created = :created"),
50  @NamedQuery(name = "Alternative.findByAuthorName", query = "SELECT a FROM Alternative a WHERE a.authorName = :authorName"),
51  @NamedQuery(name = "Alternative.findByAuthorAddress", query = "SELECT a FROM Alternative a WHERE a.authorAddress = :authorAddress"),
52  @NamedQuery(name = "Alternative.findBySource", query = "SELECT a FROM Alternative a WHERE a.source = :source"),
53  @NamedQuery(name = "Alternative.findBySourceDocumentID", query = "SELECT a FROM Alternative a WHERE a.sourceDocumentId = :sourceDocumentId"),
54  @NamedQuery(name = "Alternative.findBySourceDocumentIDNoNested", query = "SELECT a FROM Alternative a WHERE a.sourceDocumentId = :sourceDocumentId AND a.nestedIn IS NULL"),
55  @NamedQuery(name = "Alternative.findByNestedIn", query = "SELECT a FROM Alternative a WHERE a.nestedIn = :nestedIn"),
56  @NamedQuery(name = "Alternative.deleteById", query = "DELETE FROM Alternative a WHERE a.id = :id")
57 })
58 public class Alternative implements Serializable, SecSuggestion {
59  private static final long serialVersionUID = 1L;
60 
61  /** Id of alternative */
62  @Id
63  @GeneratedValue(strategy = GenerationType.IDENTITY)
64  @Basic(optional = false)
65  @Column(name = "id")
66  private Integer id;
67 
68  /** Id of type of alternative */
69  @Basic(optional = false)
70  @NotNull
71  @Column(name = "type", nullable=false, insertable=false, updatable=false)
72  private int type;
73 
74  /** Date of creation */
75  @Basic(optional = true)
76  @Column(name = "created")
77  @Temporal(TemporalType.TIMESTAMP)
78  private Date created;
79 
80  /** URI of alternative author (user) */
81  @Basic(optional = true)
82  @Size(min = 1, max = 255)
83  @Column(name = "authorIdStr")
84  private String authorIdStr;
85 
86  /** Name of alternative author (user) */
87  @Size(max = 40)
88  @Column(name = "authorName")
89  private String authorName;
90 
91  /** E-mail of alternative author (user) */
92  @Size(max = 255)
93  @Column(name = "authorAddress")
94  private String authorAddress;
95 
96  /** URI of annotated copy of document to which this alternative belongs */
97  @Basic(optional = false)
98  @NotNull
99  @Size(min = 1, max = 255)
100  @Column(name = "source")
101  private String source;
102 
103  /** Id of annotated copy of document to which this alternative belongs */
104  @Basic(optional = false)
105  @NotNull
106  @Column(name = "sourceDocumentId", nullable=false, insertable=false, updatable=false)
107  private int sourceDocumentId;
108 
109  /** Textual content of alternative */
110  @Basic(optional = false)
111  @Lob
112  @Column(name = "content")
113  private String content;
114 
115  /** Confidence of suggestion */
116  @Basic(optional = false)
117  @Column(name = "confidence")
118  private Integer confidence;
119 
120  /** Id of alternative author (user) */
121  @Column(name = "authorId", insertable=false, updatable=false)
122  private String autorId;
123 
124  /** If this alternative is nested, here is id of parent annotation */
125  @Column(name = "nestedIn", insertable=false, updatable=false)
126  private String nestedIn;
127 
128  /** Main suggestion */
129  @Column(name = "alternativeOf", insertable=false, updatable=false)
130  private String alternativeOf;
131 
132  /** Was alternative used? */
133  @Column(name = "used")
134  private Boolean used;
135 
136  /** Type of alternative */
137  @OneToOne(optional = false)
138  @JoinColumn(name = "type", referencedColumnName = "id")
139  private AnnotType annotType;
140 
141  /** Annotated copy of document to which this alternative belongs */
142  @OneToOne(optional = false)
143  @JoinColumn(name = "sourceDocumentId", referencedColumnName = "id")
144  private AnnotDocument sourceDocument;
145 
146  /** List of attributes of alternative */
147  @OneToMany(mappedBy = "refAlternative", cascade = CascadeType.ALL,
148  targetEntity = AlternativeAttribute.class)
149  private List<AlternativeAttribute> attributes;
150 
151  /** List of alternative fragments */
152  @OneToMany(mappedBy = "refAlternative", cascade = CascadeType.ALL,
153  targetEntity = AlternativeFragment.class)
154  private List<AlternativeFragment> fragments;
155 
156  /** Author of alternative (user) */
157  @OneToOne(optional = true)
158  @JoinColumn(name = "authorId", referencedColumnName = "id")
159  private User user;
160 
161  /** If this alternative is nested, here is parent suggestion */
162  @OneToOne(optional = true)
163  @JoinColumn(name = "nestedIn", referencedColumnName = "id")
164  private Alternative nestedInAlternative;
165 
166  /** Id of main suggestion */
167  @OneToOne(optional = true)
168  @JoinColumn(name = "alternativeOf", referencedColumnName = "id")
169  private Suggestion alternativeOfSuggestion;
170 
171  /** If this alternative is nested, here is parent annotation */
172  @Transient
173  private Annotation nestedInAnnot;
174 
175  /** Identifier of entity from SEC API (to detect same suggestions on more places) */
176  @Basic(optional = true)
177  @Column(name = "SAEntityIdentifier")
178  private String SAEntityIdentifier;
179 
180  /** Temporary id to identify targets of links in alternatives from client */
181  @Transient
182  private String tmpId;
183 
184 
185  /**
186  * Constructor
187  */
188  public Alternative() {
189  }
190 
191  /**
192  * Constructor
193  *
194  * @param type Type of alternative
195  * @param content Textual content of alternative
196  * @param nestedIn If this alternative is nested, then parent alternative, null otherwise
197  */
198  public Alternative(AnnotType type, String content, String nestedIn) {
199  this.used = false;
200  this.annotType = type;
201  this.content = content;
202  this.nestedIn = nestedIn;
203  this.attributes = new ArrayList<AlternativeAttribute>();
204  this.fragments = new ArrayList<AlternativeFragment>();
205  this.confidence = SuggestionManager.INITIAL_CONFIDENCE;
206  }
207 
208  /**
209  * Constructor
210  *
211  * @param id Id of alternative
212  * @param authorIdStr URI of alternative author (user)
213  * @param authorName Name of alternative author (user)
214  * @param authorAddress E-mail of alternative author (user)
215  * @param sourceDocument Annotated copy of document to which this alternative belongs
216  * @param content Textual content of alternative
217  * @param nestedIn If this alternative is nested, then parent alternative, null otherwise
218  */
219  public Alternative(Integer id, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, String nestedIn) {
220  this.used = false;
221  this.id = id;
222  this.authorIdStr = authorIdStr;
223  this.authorName = authorName;
224  this.authorAddress = authorAddress;
225  this.sourceDocument = sourceDocument;
226  if (sourceDocument != null) {
227  this.source = sourceDocument.getUriForAnnot();
228  }
229  this.content = content;
230  this.nestedIn = nestedIn;
231  this.nestedInAlternative = null;
232  this.attributes = new ArrayList<AlternativeAttribute>();
233  this.fragments = new ArrayList<AlternativeFragment>();
234  this.confidence = SuggestionManager.INITIAL_CONFIDENCE;
235  }
236 
237  /**
238  * Constructor
239  *
240  * @param annotType Type of alternative
241  * @param created Date of creation
242  * @param authorIdStr URI of alternative author (user)
243  * @param authorName Name of alternative author (user)
244  * @param authorAddress E-mail of alternative author (user)
245  * @param sourceDocument Annotated copy of document to which this alternative belongs
246  * @param content Textual content of alternative
247  */
248  public Alternative(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content) {
249  this.used = false;
250  this.annotType = annotType;
251  this.created = created;
252  this.authorIdStr = authorIdStr;
253  this.authorName = authorName;
254  this.authorAddress = authorAddress;
255  this.sourceDocument = sourceDocument;
256  if (sourceDocument != null) {
257  this.source = sourceDocument.getUriForAnnot();
258  }
259  this.content = content;
260  this.nestedInAlternative = null;
261  this.attributes = new ArrayList<AlternativeAttribute>();
262  this.fragments = new ArrayList<AlternativeFragment>();
263  this.confidence = SuggestionManager.INITIAL_CONFIDENCE;
264  }
265 
266  /**
267  * Constructor
268  *
269  * @param annotType Type of alternative
270  * @param created Date of creation
271  * @param authorIdStr URI of alternative author (user)
272  * @param authorName Name of alternative author (user)
273  * @param authorAddress E-mail of alternative author (user)
274  * @param sourceDocument Annotated copy of document to which this alternative belongs
275  * @param content Textual content of alternative
276  * @param nestedInAlternative If this alternative is nested, then parent alternative, null otherwise
277  */
278  public Alternative(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, Alternative nestedInAlternative) {
279  this.used = false;
280  this.annotType = annotType;
281  this.created = created;
282  this.authorIdStr = authorIdStr;
283  this.authorName = authorName;
284  this.authorAddress = authorAddress;
285  this.sourceDocument = sourceDocument;
286  if (sourceDocument != null) {
287  this.source = sourceDocument.getUriForAnnot();
288  }
289  this.content = content;
290  this.nestedInAlternative = nestedInAlternative;
291  this.attributes = new ArrayList<AlternativeAttribute>();
292  this.fragments = new ArrayList<AlternativeFragment>();
293  this.confidence = SuggestionManager.INITIAL_CONFIDENCE;
294  }
295 
296  /**
297  * Gets id of alternative
298  *
299  * @return Returns id of alternative
300  */
301  public Integer getId() {
302  return id;
303  }
304 
305  /**
306  * Sets id of alternative
307  *
308  * @param id Id of alternative
309  */
310  public void setId(Integer id) {
311  this.id = id;
312  }
313  /**
314  * Gets confidence of alternative
315  *
316  * @return Returns confidence of alternative
317  */
318  public Integer getConfidence() {
319  return confidence;
320  }
321 
322  /**
323  * Sets confidence of alternative
324  *
325  * @param confidence Confidence of alternative
326  */
327  public void setConfidence(Integer confidence) {
328  this.confidence = confidence;
329  }
330 
331  /**
332  * Gets type of alternative
333  *
334  * @return Returns type of alternative
335  */
337  return annotType;
338  }
339 
340  /**
341  * Sets type of alternative
342  *
343  * @param annotType Type of alternative
344  */
345  public void setAnnotType(AnnotType annotType) {
346  this.annotType = annotType;
347  }
348 
349  /**
350  * Gets date of creation
351  *
352  * @return Returns date of creation
353  */
354  public Date getCreated() {
355  return created;
356  }
357 
358  /**
359  * Sets date of creation
360  *
361  * @param created Date of creation
362  */
363  public void setCreated(Date created) {
364  this.created = created;
365  }
366 
367  /**
368  * Gets author of alternative (user)
369  *
370  * @return Returns author of alternative (user)
371  */
372  public User getUser() {
373  return user;
374  }
375 
376  /**
377  * Sets author of alternative (user)
378  * URI is also set and if available, full name and e-mail too
379  *
380  * @param user Author of alternative (user)
381  */
382  public void setUser(User user) {
383  this.user = user;
384  if (user != null) {
385  authorIdStr = user.getURI();
386  if (user.getName() != null && !user.getName().contentEquals("")) {
387  authorName = user.getName();
388  }
389  if (user.getEmail() != null && !user.getEmail().contentEquals("")) {
390  authorAddress = user.getEmail();
391  }
392  }
393  }
394 
395  /**
396  * Gets URI of author of alternative (user)
397  *
398  * @return Returns URI of author of alternative (user)
399  */
400  public String getAuthorIdStr() {
401  return authorIdStr;
402  }
403 
404  /**
405  * Sets URI of author of alternative (user)
406  *
407  * @param authorIdStr URI of author of alternative (user)
408  */
409  public void setAuthorIdStr(String authorIdStr) {
410  this.authorIdStr = authorIdStr;
411  }
412 
413  /**
414  * Gets name of author of alternative (user)
415  *
416  * @return Returns name of author of alternative (user)
417  */
418  public String getAuthorName() {
419  return authorName;
420  }
421 
422  /**
423  * Sets name of author of alternative (user)
424  *
425  * @param authorName Name of author of alternative (user)
426  */
427  public void setAuthorName(String authorName) {
428  this.authorName = authorName;
429  }
430 
431  /**
432  * Gets e-mail of author of alternative (user)
433  *
434  * @return Returns e-mail of author of alternative (user)
435  */
436  public String getAuthorAddress() {
437  return authorAddress;
438  }
439 
440  /**
441  * Sets e-mail of author of alternative (user)
442  *
443  * @param authorAddress E-mail of author of alternative (user)
444  */
445  public void setAuthorAddress(String authorAddress) {
446  this.authorAddress = authorAddress;
447  }
448 
449  /**
450  * Gets annotated copy of document to which this alternative belongs
451  *
452  * @return Returns annotated copy of document to which this alternative belongs
453  */
454  public String getSource() {
455  return source;
456  }
457 
458  /**
459  * Sets annotated copy of document to which this alternative belongs
460  *
461  * @param source Annotated copy of document to which this alternative belongs
462  */
463  public void setSource(String source) {
464  this.source = source;
465  }
466 
467  /**
468  * Gets id of annotated copy of document to which this alternative belongs
469  *
470  * @return Returns id of annotated copy of document to which this alternative belongs
471  */
472  public Integer getSourceDocumentId() {
473  return sourceDocumentId;
474  }
475 
476  /**
477  * Sets id of annotated copy of document to which this alternative belongs
478  *
479  * @param sourceDocumentId id of annotated copy of document to which this alternative belongs
480  */
481  public void setSourceDocumentId(Integer sourceDocumentId) {
482  this.sourceDocumentId = sourceDocumentId;
483  }
484 
485  /**
486  * Gets id of type of alternative
487  *
488  * @return Returns id of type of alternative
489  */
490  public Integer getType() {
491  return type;
492  }
493 
494  /**
495  * Sets id of type of alternative
496  *
497  * @param type id of type of alternative
498  */
499  public void setType(Integer type) {
500  this.type = type;
501  }
502 
503  /**
504  * Gets textual content of alternative
505  *
506  * @return Returns textual content of alternative
507  */
508  public String getContent() {
509  return content;
510  }
511 
512  /**
513  * Sets textual content of alternative
514  *
515  * @param content Textual content of alternative
516  */
517  public void setContent(String content) {
518  this.content = content;
519  }
520 
521  /**
522  * Gets id of annotation author (user)
523  *
524  * @return Returns id of annotation author (user)
525  */
526  public String getAutorId() {
527  return autorId;
528  }
529 
530  /**
531  * Sets id of annotation author (user)
532  *
533  * @param autorId id of annotation author (user)
534  */
535  public void setAutorId(String autorId) {
536  this.autorId = autorId;
537  }
538 
539  /**
540  * Gets annotated copy of document to which this alternative belongs
541  *
542  * @return Returns annotated copy of document to which this alternative belongs
543  */
545  return sourceDocument;
546  }
547 
548  /**
549  * Sets annotated copy of document to which this alternative belongs
550  * (if document is not null, his URI is also set)
551  *
552  * @param sourceDocument Annotated copy of document to which this alternative belongs
553  */
554  public void setSourceDocument(AnnotDocument sourceDocument) {
555  this.sourceDocument = sourceDocument;
556  if (sourceDocument != null) {
557  this.source = sourceDocument.getUriForAnnot();
558  }
559  }
560 
561  /**
562  * Gets URI of alternative in which is this alternative nested
563  *
564  * @return Returns URI of alternative in which is this alternative nested
565  */
566  public String getNestedIn() {
567  return nestedIn;
568  }
569 
570  /**
571  * Sets URI of alternative in which is this alternative nested
572  *
573  * @param nestedIn URI of alternative in which is this alternative nested
574  */
575  public void setNestedIn(String nestedIn) {
576  this.nestedIn = nestedIn;
577  }
578 
579  /**
580  * Gets list of alternative attributes
581  *
582  * @return Returns list of alternative attributes
583  */
584  public List<AlternativeAttribute> getAttributes() {
585  return attributes;
586  }
587 
588  /**
589  * Sets list of alternative attributes
590  *
591  * @param attributes List of alternative attributes
592  */
593  public void setAttributes(ArrayList<AlternativeAttribute> attributes) {
594  this.attributes = attributes;
595  }
596 
597  /**
598  * Adds an attribute to list of alternative attributes
599  *
600  * @param attribute Attribute to add
601  */
602  public void addAttribute(AlternativeAttribute attribute) {
603  this.attributes.add(attribute);
604  }
605 
606  /**
607  * Gets list of suggested fragments
608  *
609  * @return Returns list of suggested fragments
610  */
611  @Override
612  public List getFragments() {
613  return fragments;
614  }
615 
616  /**
617  * Gets list of suggested fragments as ArrayList
618  *
619  * @return Returns list of suggested fragments as ArrayList
620  */
621  public ArrayList<AlternativeFragment> getFragmentsAL() {
622  return new ArrayList<AlternativeFragment>(fragments);
623  }
624 
625  /**
626  * Sets list of suggested fragments
627  *
628  * @param fragments List of suggested fragments
629  */
630  public void setFragments(ArrayList<AlternativeFragment> fragments) {
631  this.fragments = fragments;
632  }
633 
634  /**
635  * Adds fragment to the list of suggested fragments
636  *
637  * @param fragment Suggested fragment
638  */
639  public void addFragment(AlternativeFragment fragment) {
640  if(fragments == null){
641  fragments = new ArrayList<AlternativeFragment>();
642  }
643  fragments.add(fragment);
644  }
645 
646  /**
647  * Adds fragment to the list of suggested fragments
648  *
649  * @param fragment Suggested fragment
650  */
651  @Override
652  public void addSecFragment(SecFragment fragment) {
653  if (fragment instanceof AlternativeFragment) {
654  fragments.add((AlternativeFragment) fragment);
655  }
656  }
657 
658  /**
659  * Gets parent suggestion of nested suggestion
660  *
661  * @return If this suggestion is nested, returns parent annotation, null otherwise
662  */
664  return nestedInAlternative;
665  }
666 
667  /**
668  * Sets parent suggestion of nested suggestion
669  *
670  * @param nestedInAlternative If this annotation is nested, then parent annotation, null otherwise
671  */
672  public void setNestedInAlternative(Alternative nestedInAlternative) {
673  this.nestedInAlternative = nestedInAlternative;
674  }
675 
676  /**
677  * Gets main suggestion
678  *
679  * @return Main suggestion
680  */
682  return alternativeOfSuggestion;
683  }
684 
685  /**
686  * Sets main suggestion
687  *
688  * @param alternativeOfSuggestion Main suggestion
689  */
690  public void setAlternativeOfSuggestion(Suggestion alternativeOfSuggestion) {
691  this.alternativeOfSuggestion = alternativeOfSuggestion;
692  }
693 
694  /**
695  * Gets annotation in which is this alternative nested
696  *
697  * @return annotation in which is this alternative nested
698  */
700  return nestedInAnnot;
701  }
702 
703  /**
704  * Sets annotation in which is this suggestion nested
705  *
706  * @param nestedInAnnot Annotation in which is this suggestion nested
707  */
708  public void setNestedInAnnot(Annotation nestedInAnnot) {
709  this.nestedInAnnot = nestedInAnnot;
710  }
711 
712  /**
713  * Gets SEC API Entity Identifier (to detect same suggestions)
714  *
715  * @return isFromSECAPI SEC API Entity Identifier
716  */
717  public String getSAEntityIdentifier() {
718  return SAEntityIdentifier;
719  }
720 
721  /**
722  * Sets SEC API Entity Identifier
723  *
724  * @param SAEntityIdentifier SEC API Entity Identifier
725  */
726  @Override
727  public void setSAEntityIdentifier(String SAEntityIdentifier) {
728  this.SAEntityIdentifier = SAEntityIdentifier;
729  }
730 
731  /**
732  * Gets tmpId of this suggestion
733  * (warning - tmpId is in id field for suggestion - this is an auxiliary value)
734  *
735  * @return Returns tmpId of this suggestion
736  */
737  public String getTmpId() {
738  return tmpId;
739  }
740 
741  /**
742  * Sets tmpId of this suggestion
743  * (warning - tmpId is in id field for suggestion - this is an auxiliary value)
744  *
745  * @param tmpId tmpId of this suggestion
746  */
747  public void setTmpId(String tmpId) {
748  this.tmpId = tmpId;
749  }
750 
751  /**
752  * Gets whether alternative was used
753  *
754  * @return Returns whether alternative was used
755  */
756  public Boolean getUsed() {
757  return used;
758  }
759 
760  /**
761  * Sets whether alternative was used
762  *
763  * @param used If true, alternative was used, if false, it was not used
764  */
765  public void setUsed(Boolean used) {
766  this.used = used;
767  }
768 
769  /**
770  * Get hash code.
771  *
772  * @return Hash code
773  */
774  @Override
775  public int hashCode() {
776  int hash = 0;
777  hash += (id != null ? id.hashCode() : 0);
778  return hash;
779  }
780 
781  /**
782  * Compares this with other object and returns, whether objects are same type
783  * and have same id.
784  *
785  * @param object Object to compare with
786  * @return If object is same type and have same id, returns true, false otherwise
787  */
788  @Override
789  public boolean equals(Object object) {
790  if (!(object instanceof Alternative)) {
791  return false;
792  }
793  Alternative other = (Alternative) object;
794  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
795  return false;
796  }
797 
798  if(other.id == null && this.id == null){
799  if(!contentEquals(object)){
800  return false;
801  }
802  }
803 
804  return true;
805  }
806 
807  /**
808  * Compares this with other object and returns, whether objects are same type
809  * and have same id, but not go to deeper comparation if noLinek is set to true.
810  *
811  * @param object Object to compare with
812  * @param noLinked No trace links and compare them if is set to true
813  * @return If object is same type and have same id, returns true, false otherwise
814  */
815  public boolean equals(Object object, boolean noLinked){
816  if (!(object instanceof Alternative)) {
817  return false;
818  }
819  Alternative other = (Alternative) object;
820  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
821  return false;
822  }
823 
824  if(other.id == null && this.id == null){
825  if(!contentEquals(object,false,noLinked)){
826  return false;
827  }
828  }
829 
830  return true;
831  }
832 
833  /**
834  * Compares this with other object and returns, whether objects are same type
835  * and have same content (id is irelevant). Contents of fragments
836  * and attributes are also compared.
837  *
838  * @param obj Object to compare with
839  * @return If object is same type and have same content, returns true, false otherwise
840  */
841  public boolean contentEquals(Object obj) {
842  return contentEquals(obj,false,false);
843  }
844 
845  /**
846  * Compares this with other object and returns, whether objects are same type
847  * and have same content (id is irrelevant). Contents of fragments
848  * and attributes are also compared.
849  *
850  * @param obj Object to compare with
851  * @param withCreated If true, dates of creation will be compared, if false, dates will be omitted
852  * @param noLinked If true, links in attributes will be omitted, if false, links will be compared
853  * @return If object is same type and have same content, returns true, false otherwise
854  */
855  public boolean contentEquals(Object obj, boolean withCreated, boolean noLinked) {
856  if (obj == null) {
857  return false;
858  }
859  if (getClass() != obj.getClass()) {
860  return false;
861  }
862  final Alternative other = (Alternative) obj;
863  if (withCreated) {
864  if (this.created != other.created && (this.created == null || !this.created.equals(other.created))) {
865  return false;
866  }
867  }
868  if ((this.authorIdStr == null) ? (other.authorIdStr != null) : !this.authorIdStr.equals(other.authorIdStr)) {
869  return false;
870  }
871  if ((this.authorName == null) ? (other.authorName != null) : !this.authorName.equals(other.authorName)) {
872  return false;
873  }
874  if ((this.authorAddress == null) ? (other.authorAddress != null) : !this.authorAddress.equals(other.authorAddress)) {
875  return false;
876  }
877  if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) {
878  return false;
879  }
880  if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) {
881  return false;
882  }
883  if (this.annotType != other.annotType && (this.annotType == null || !this.annotType.equals(other.annotType))) {
884  return false;
885  }
886  if (this.sourceDocument != other.sourceDocument && (this.sourceDocument == null || !this.sourceDocument.equals(other.sourceDocument))) {
887  return false;
888  }
889 
890  if (this.attributes == null && other.attributes != null) {
891  return false;
892  } else if (this.attributes != null && other.attributes == null) {
893  return false;
894  } else if (this.attributes != other.attributes && this.attributes != null && other.attributes != null) {
895  if (this.attributes.size() != other.attributes.size()) {
896  return false;
897  }
898  Iterator<AlternativeAttribute> atIt = this.attributes.iterator();
899  while (atIt.hasNext()) {
900  AlternativeAttribute at = atIt.next();
901  boolean found = false;
902  Iterator<AlternativeAttribute> oAtIt = other.attributes.iterator();
903  while (oAtIt.hasNext()) {
904  AlternativeAttribute oAt = oAtIt.next();
905 
906  if (at.contentEquals(oAt,false)) {
907  found = true;
908  break;
909  }
910  }
911  if (!found) {
912  return false;
913  }
914  }
915  }
916  if (this.fragments == null && other.fragments != null) {
917  return false;
918  } else if (this.fragments != null && other.fragments == null) {
919  return false;
920  } else if (this.fragments != other.fragments && this.fragments != null && other.fragments != null) {
921  if (this.fragments.size() != other.fragments.size()) {
922  return false;
923  }
924  Iterator frIt = this.fragments.iterator();
925  while (frIt.hasNext()) {
926  AlternativeFragment fr = (AlternativeFragment) frIt.next();
927  boolean found = false;
928  Iterator oFrIt = other.fragments.iterator();
929  while (oFrIt.hasNext()) {
930  AlternativeFragment oFr = (AlternativeFragment) oFrIt.next();
931  if (fr.contentEquals(oFr)) {
932  found = true;
933  break;
934  }
935  }
936  if (!found) {
937  return false;
938  }
939  }
940  }
941  if (this.user != other.user && (this.user == null || !this.user.equals(other.user))) {
942  return false;
943  }
944  if (this.nestedInAlternative == null && other.nestedInAlternative != null) {
945  return false;
946  } else if (this.nestedInAlternative != null && other.nestedInAlternative == null) {
947  return false;
948  }
949  return true;
950  } // contentEquals()
951 
952 
953  /**
954  * Compares this with suggestion and returns, whether objects are same type
955  * and have same content (id is irrelevant). Contents of fragments
956  * and attributes are also compared.
957  *
958  * @param other Object to compare with
959  * @param linearizedFragments Linearized fragments of suggestion.
960  * @param testFragments If true, fragments will be compared, if false, fragments will be omitted
961  * @return
962  */
963  public boolean contentEqualsForSec(Suggestion other, ArrayList<SuggestionFragment> linearizedFragments, boolean testFragments) {
964  if (other == null) {
965  return false;
966  }
967  if ((this.content == null) ? (other.getContent() != null) : !this.content.equals(other.getContent())) {
968  return false;
969  }
970  if (this.annotType != other.getAnnotType() && (this.annotType == null || !this.annotType.equals(other.getAnnotType()))) {
971  return false;
972  }
973 
974  if (this.attributes == null && other.getAttributes() != null) {
975  return false;
976  } else if (this.attributes != null && other.getAttributes() == null) {
977  return false;
978  } else if (this.attributes != null && other.getAttributes() != null) {
979  if (this.attributes.size() != other.getAttributes().size()) {
980  return false;
981  }
982  Iterator<AlternativeAttribute> atIt = this.attributes.iterator();
983  while (atIt.hasNext()) {
984  AlternativeAttribute at = atIt.next();
985  boolean found = false;
986  Iterator<SugBaseAttribute> oAtIt = other.getAttributes().iterator();
987  if(oAtIt instanceof SugLinkedAttribute){
988  continue;
989  }
990  while (oAtIt.hasNext()) {
991  SugBaseAttribute oAt = oAtIt.next();
992 
993  if (at.contentEqualsForSec(oAt)) {
994  found = true;
995  break;
996  }
997  }
998  if (!found) {
999  return false;
1000  }
1001  }
1002  }
1003  if (testFragments) {
1004  if (this.fragments == null && linearizedFragments != null) {
1005  return false;
1006  } else if (this.fragments != null && linearizedFragments == null) {
1007  return false;
1008  } else if (this.fragments != null && linearizedFragments != null) {
1009  if (this.fragments.size() != linearizedFragments.size()) {
1010  return false;
1011  }
1012  Iterator frIt = this.fragments.iterator();
1013  while (frIt.hasNext()) {
1014  AlternativeFragment fr = (AlternativeFragment) frIt.next();
1015  boolean found = false;
1016  Iterator<SuggestionFragment> oFrIt = linearizedFragments.iterator();
1017  while (oFrIt.hasNext()) {
1018  SuggestionFragment oFr = oFrIt.next();
1019  if (fr.contentEqualsForSec(oFr)) {
1020  found = true;
1021  break;
1022  }
1023  }
1024  if (!found) {
1025  return false;
1026  }
1027  }
1028  }
1029  }
1030  return true;
1031  } // contentEqualsForSec()
1032 
1033  @Override
1034  public String toString() {
1035  return "cz.vutbr.fit.knot.annotations.modules.auggestionManager.alternative.Alternative[ id=" + id + " ]";
1036  }
1037 } // public class Alternative
void setAttributes(ArrayList< AlternativeAttribute > attributes)
Class representing annotated copy of document.
boolean contentEquals(Object obj, boolean withCreated, boolean noLinked)
Alternative(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, Alternative nestedInAlternative)
Alternative(Integer id, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, String nestedIn)
Alternative(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content)
Class provides offerining of suggestions with usage of local knowledge repository.
Class representing type of annotation.
Definition: AnnotType.java:58
Class representing user.
Definition: User.java:51
Class representing attribute of type AnnotationLink for prupose of suggestion.
Class representing suggestion of annotation.
Definition: Suggestion.java:87
boolean contentEqualsForSec(Suggestion other, ArrayList< SuggestionFragment > linearizedFragments, boolean testFragments)
Interface for SuggestionFragment and AlternativeFragment.