728170314226474669592326812ffffdf9c583f9
[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 {
9   public static final int NONE = 1; // default
10
11   public static final int COMPLEMENT = 2;
12
13   public static final int JOIN = 3;
14
15   public static final int ORDER = 4; // conj com ordem desconhecida
16
17   private int operator = NONE;
18
19   private java.util.List<GenBankLocation> units;
20
21   public GenBankLocations()
22   {
23     units = new java.util.ArrayList<GenBankLocation>();
24   }
25
26   @Override
27   public void setComplement(boolean complement)
28   {
29     super.setComplement(complement);
30     this.operator = COMPLEMENT;
31     if (units != null)
32     {
33       for (GenBankLocation o : units)
34       {
35         o.setComplement(complement);
36       }
37     }
38   }
39
40   @Override
41   public String toString()
42   {
43     StringBuilder sb = new StringBuilder();
44     if (getOperator() == COMPLEMENT)
45     {
46       sb.append("complement(");
47     }
48     else if (getOperator() == JOIN)
49     {
50       sb.append("join(");
51     }
52     else if (getOperator() == ORDER)
53     {
54       sb.append("order(");
55     }
56     if (units.size() > 0)
57     {
58       sb.append(units.get(0).toString());
59       for (int i = 1; i < units.size(); i++)
60       {
61         sb.append(",");
62         sb.append(units.get(i).toString());
63       }
64     }
65     if (getOperator() != NONE)
66     {
67       sb.append(")");
68     }
69     return sb.toString();
70   }
71
72   /**
73    * @return the units
74    */
75   public java.util.List<GenBankLocation> getUnits()
76   {
77     return units;
78   }
79
80   /**
81    * @param units
82    *          the units to set
83    */
84   public void setUnits(java.util.List<GenBankLocation> units)
85   {
86     this.units = units;
87   }
88
89   @Override
90   public int getMinor()
91   {
92     if (units.size() > 0)
93     {
94       return units.get(0).getMinor();
95     }
96     return 0;
97   }
98
99   @Override
100   public int getMajor()
101   {
102     int ind = units.size();
103     if (ind > 0)
104     {
105       return units.get(ind - 1).getMajor();
106     }
107     return 0;
108   }
109
110   /**
111    * @return the operator
112    */
113   public int getOperator()
114   {
115     return operator;
116   }
117
118   /**
119    * @param operator
120    *          the operator to set
121    */
122   public void setOperator(int operator)
123   {
124     this.operator = operator;
125   }
126
127 }