X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=srcjar%2Ffr%2Forsay%2Flri%2Fvarna%2Fmodels%2FBaseList.java;fp=srcjar%2Ffr%2Forsay%2Flri%2Fvarna%2Fmodels%2FBaseList.java;h=01ac0b1cee9f411ef6b2047fd68d9d6f8d24c772;hb=ec8f3cedf60fb1feed6d34de6b49f6bfa78b9dd8;hp=0000000000000000000000000000000000000000;hpb=056dad85a910551cc95e44d451a61f6b8c4dd35d;p=jalview.git diff --git a/srcjar/fr/orsay/lri/varna/models/BaseList.java b/srcjar/fr/orsay/lri/varna/models/BaseList.java new file mode 100644 index 0000000..01ac0b1 --- /dev/null +++ b/srcjar/fr/orsay/lri/varna/models/BaseList.java @@ -0,0 +1,200 @@ +package fr.orsay.lri.varna.models; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +import fr.orsay.lri.varna.models.rna.ModeleBase; + +public class BaseList { + private HashSet _bases = new HashSet(); + private String _caption; + + public BaseList( BaseList b) + { + _caption = b._caption; + _bases = new HashSet(b._bases); + } + + + public BaseList( String caption) + { + _caption = caption; + } + + + public BaseList( String caption, ModeleBase mb) + { + this(caption); + addBase(mb); + } + + public boolean contains(ModeleBase mb) + { + return _bases.contains(mb); + } + + + public String getCaption() + { + return _caption; + } + + public void addBase(ModeleBase b) + { + _bases.add(b); + } + + public void removeBase(ModeleBase b) + { + _bases.remove(b); + } + + + public void addBases(Collection mbs) + { + _bases.addAll(mbs); + } + + public ArrayList getBases() + { + return new ArrayList(_bases); + } + + public void clear() + { + _bases.clear(); + } + + public static Color getAverageColor(ArrayList cols) + { + int r=0,g=0,b=0; + for (Color c : cols) + { + r += c.getRed(); + g += c.getGreen(); + b += c.getBlue(); + } + if (cols.size()>0) + { + r /= cols.size(); + g /= cols.size(); + b /= cols.size(); + } + return new Color(r,g,b); + } + + public Color getAverageOutlineColor() + { + ArrayList cols = new ArrayList(); + for (ModeleBase mb : _bases) + { cols.add(mb.getStyleBase().getBaseOutlineColor()); } + return getAverageColor(cols); + } + + public Color getAverageNameColor() + { + ArrayList cols = new ArrayList(); + for (ModeleBase mb : _bases) + { cols.add(mb.getStyleBase().getBaseNameColor()); } + return getAverageColor(cols); + } + + public Color getAverageNumberColor() + { + ArrayList cols = new ArrayList(); + for (ModeleBase mb : _bases) + { cols.add(mb.getStyleBase().getBaseNumberColor()); } + return getAverageColor(cols); + } + + public Color getAverageInnerColor() + { + ArrayList cols = new ArrayList(); + for (ModeleBase mb : _bases) + { cols.add(mb.getStyleBase().getBaseInnerColor()); } + return getAverageColor(cols); + } + + public String getNumbers() + { + String result = ""; + boolean first = true; + for (ModeleBase mb:_bases) + { + if (!first) + { result += ","; } + else + { first = false; } + result += "" + mb.getBaseNumber(); + } + result += ""; + return result; + } + + public String getContents() + { + String result = ""; + boolean first = true; + for (ModeleBase mb:_bases) + { + if (!first) + { result += ","; } + else + { first = false; } + result += "" + mb.getContent(); + } + result += ""; + return result; + } + + public ArrayList getIndices() + { + ArrayList indices = new ArrayList(); + for (ModeleBase mb : _bases) + { + indices.add(mb.getIndex()); + } + return indices; + } + + /** + * Returns, in a new BaseList, the intersection of the current BaseList and of the argument. + * @param mb The base list to be used for the intersection + * @return The intersection of the current base list and the argument. + */ + + public BaseList retainAll(BaseList mb) + { + HashSet cp = new HashSet(); + cp.addAll(_bases); + cp.retainAll(mb._bases); + BaseList result = new BaseList("TmpIntersection"); + result.addBases(cp); + return result; + } + + /** + * Returns, in a new BaseList, the list consisting of the current BaseList minus the list passed as argument. + * @param mb The base list to be subtracted from the current one + * @return The current base list minus the list passed as argument. + */ + + public BaseList removeAll(BaseList mb) + { + HashSet cp = new HashSet(); + cp.addAll(_bases); + cp.removeAll(mb._bases); + BaseList result = new BaseList("TmpMinus"); + result.addBases(cp); + return result; + } + + public int size() + { + return _bases.size(); + } + + +}