JAL-1260 v2 patch from David Roldán-Martínez
[jalview.git] / src / jalview / io / xdb / genbank / GenBankLocations.java
1 package jalview.io.xdb.genbank;
2
3 /**
4  *
5  * @author Dieval Guizelini
6  */
7 public class GenBankLocations extends GenBankLocation {
8     public static final int NONE = 1; // default
9     public static final int COMPLEMENT = 2;
10     public static final int JOIN = 3;
11     public static final int ORDER = 4; // conj com ordem desconhecida
12     private int operator = NONE;
13     private java.util.List<GenBankLocation> units;
14
15     public GenBankLocations() {
16         units = new java.util.ArrayList<GenBankLocation>();
17     }
18
19     @Override
20     public void setComplement(boolean complement){
21         super.setComplement(complement);
22         this.operator = COMPLEMENT;
23         if (units != null) {
24             for (GenBankLocation o : units) {
25                 o.setComplement(complement);
26             }
27         }
28     }
29
30     @Override
31     public String toString() {
32         StringBuilder sb = new StringBuilder();
33         if (getOperator() == COMPLEMENT) {
34             sb.append("complement(");
35         } else if (getOperator() == JOIN) {
36             sb.append("join(");
37         } else if (getOperator() == ORDER) {
38             sb.append("order(");
39         }
40         if (units.size() > 0) {
41             sb.append(units.get(0).toString());
42             for (int i = 1; i < units.size(); i++) {
43                 sb.append(",");
44                 sb.append(units.get(i).toString());
45             }
46         }
47         if (getOperator() != NONE) {
48             sb.append(")");
49         }
50         return sb.toString();
51     }
52
53     /**
54      * @return the units
55      */
56     public java.util.List<GenBankLocation> getUnits() {
57         return units;
58     }
59
60     /**
61      * @param units the units to set
62      */
63     public void setUnits(java.util.List<GenBankLocation> units) {
64         this.units = units;
65     }
66
67     @Override
68     public int getMinor() {
69         if( units.size() > 0 ) {
70             return units.get(0).getMinor();
71         }
72         return 0;
73     }
74
75     @Override
76     public int getMajor() {
77         int ind = units.size();
78         if( ind > 0 ) {
79             return units.get(ind-1).getMajor();
80         }
81         return 0;
82     }
83
84     /**
85      * @return the operator
86      */
87     public int getOperator() {
88         return operator;
89     }
90
91     /**
92      * @param operator the operator to set
93      */
94     public void setOperator(int operator) {
95         this.operator = operator;
96     }
97
98 }