1 package fr.orsay.lri.varna.models;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.HashSet;
8 import fr.orsay.lri.varna.models.rna.ModeleBase;
10 public class BaseList {
11 private HashSet<ModeleBase> _bases = new HashSet<ModeleBase>();
12 private String _caption;
14 public BaseList( BaseList b)
16 _caption = b._caption;
17 _bases = new HashSet<ModeleBase>(b._bases);
21 public BaseList( String caption)
27 public BaseList( String caption, ModeleBase mb)
33 public boolean contains(ModeleBase mb)
35 return _bases.contains(mb);
39 public String getCaption()
44 public void addBase(ModeleBase b)
49 public void removeBase(ModeleBase b)
55 public void addBases(Collection<? extends ModeleBase> mbs)
60 public ArrayList<ModeleBase> getBases()
62 return new ArrayList<ModeleBase>(_bases);
70 public static Color getAverageColor(ArrayList<Color> cols)
85 return new Color(r,g,b);
88 public Color getAverageOutlineColor()
90 ArrayList<Color> cols = new ArrayList<Color>();
91 for (ModeleBase mb : _bases)
92 { cols.add(mb.getStyleBase().getBaseOutlineColor()); }
93 return getAverageColor(cols);
96 public Color getAverageNameColor()
98 ArrayList<Color> cols = new ArrayList<Color>();
99 for (ModeleBase mb : _bases)
100 { cols.add(mb.getStyleBase().getBaseNameColor()); }
101 return getAverageColor(cols);
104 public Color getAverageNumberColor()
106 ArrayList<Color> cols = new ArrayList<Color>();
107 for (ModeleBase mb : _bases)
108 { cols.add(mb.getStyleBase().getBaseNumberColor()); }
109 return getAverageColor(cols);
112 public Color getAverageInnerColor()
114 ArrayList<Color> cols = new ArrayList<Color>();
115 for (ModeleBase mb : _bases)
116 { cols.add(mb.getStyleBase().getBaseInnerColor()); }
117 return getAverageColor(cols);
120 public String getNumbers()
123 boolean first = true;
124 for (ModeleBase mb:_bases)
130 result += "" + mb.getBaseNumber();
136 public String getContents()
139 boolean first = true;
140 for (ModeleBase mb:_bases)
146 result += "" + mb.getContent();
152 public ArrayList<Integer> getIndices()
154 ArrayList<Integer> indices = new ArrayList<Integer>();
155 for (ModeleBase mb : _bases)
157 indices.add(mb.getIndex());
163 * Returns, in a new BaseList, the intersection of the current BaseList and of the argument.
164 * @param mb The base list to be used for the intersection
165 * @return The intersection of the current base list and the argument.
168 public BaseList retainAll(BaseList mb)
170 HashSet<ModeleBase> cp = new HashSet<ModeleBase>();
172 cp.retainAll(mb._bases);
173 BaseList result = new BaseList("TmpIntersection");
179 * Returns, in a new BaseList, the list consisting of the current BaseList minus the list passed as argument.
180 * @param mb The base list to be subtracted from the current one
181 * @return The current base list minus the list passed as argument.
184 public BaseList removeAll(BaseList mb)
186 HashSet<ModeleBase> cp = new HashSet<ModeleBase>();
188 cp.removeAll(mb._bases);
189 BaseList result = new BaseList("TmpMinus");
196 return _bases.size();