JAL-1479 minor refactor and housekeeping
[jalview.git] / src / jalview / viewmodel / seqfeatures / FeaturesDisplayed.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.viewmodel.seqfeatures;
22
23 import jalview.api.FeaturesDisplayedI;
24
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.Iterator;
28
29 public class FeaturesDisplayed implements FeaturesDisplayedI
30 {
31   private HashSet<String> featuresDisplayed = new HashSet<String>();
32
33   private HashSet<String> featuresRegistered = new HashSet<String>();
34
35   public FeaturesDisplayed(FeaturesDisplayedI featuresDisplayed2)
36   {
37     Iterator<String> fdisp = featuresDisplayed2.getVisibleFeatures();
38     String ftype;
39     while (fdisp.hasNext())
40     {
41       ftype = fdisp.next();
42       featuresDisplayed.add(ftype);
43       featuresRegistered.add(ftype);
44     }
45   }
46
47   public FeaturesDisplayed()
48   {
49     // TODO Auto-generated constructor stub
50   }
51
52   @Override
53   public Iterator<String> getVisibleFeatures()
54   {
55     return featuresDisplayed.iterator();
56   }
57
58   @Override
59   public boolean isVisible(String featureType)
60   {
61     return featuresDisplayed.contains(featureType);
62   }
63
64   @Override
65   public boolean areVisible(Collection<String> featureTypes)
66   {
67     return featuresDisplayed.containsAll(featureTypes);
68   }
69
70   @Override
71   public void clear()
72   {
73     featuresDisplayed.clear();
74     featuresRegistered.clear();
75   }
76
77   @Override
78   public void setAllVisible(Collection<String> makeVisible)
79   {
80     featuresDisplayed.addAll(makeVisible);
81     featuresRegistered.addAll(makeVisible);
82   }
83
84   @Override
85   public void setAllRegisteredVisible()
86   {
87     featuresDisplayed.addAll(featuresRegistered);
88   }
89
90   @Override
91   public void setVisible(String featureType)
92   {
93     featuresDisplayed.add(featureType);
94     featuresRegistered.add(featureType);
95   }
96
97   @Override
98   public boolean isRegistered(String type)
99   {
100     return featuresRegistered.contains(type);
101   }
102
103   @Override
104   public int getVisibleFeatureCount()
105   {
106     return featuresDisplayed.size();
107   }
108
109   @Override
110   public int getRegisteredFeaturesCount()
111   {
112     return featuresRegistered.size();
113   }
114 }