2121
2222import fr .jmmc .oitools .model .range .Range ;
2323import fr .jmmc .oitools .util .GranuleComparator ;
24+ import fr .jmmc .oitools .util .StationNamesComparator ;
2425import java .util .ArrayList ;
2526import java .util .Collection ;
2627import java .util .Collections ;
2728import java .util .HashSet ;
2829import java .util .LinkedHashSet ;
29- import java .util .List ;
3030import java .util .Set ;
3131import java .util .logging .Logger ;
3232
@@ -44,15 +44,21 @@ public enum GranuleField {
4444 TARGET , INS_MODE , NIGHT ;
4545 }
4646
47+ public enum GranuleExtraField {
48+ DISTINCT_STA_NAMES , DISTINCT_STA_CONFS ;
49+ }
50+
4751 /* members */
4852 private Target target ;
4953 private InstrumentMode insMode ;
5054 private NightId night ;
5155 /* extra information (filters) */
52- /** Set of distinct staNames */
53- private Set <String > distinctStaNames = null ;
5456 /** MJD range */
5557 private Range mjdRange = null ;
58+ /** Set of distinct staNames */
59+ private Set <String > distinctStaNames = null ;
60+ /** Set of distinct staConfs */
61+ private Set <String > distinctStaConfs = null ;
5662
5763 public Granule () {
5864 this (null , null , null );
@@ -80,7 +86,7 @@ public NightId getNight() {
8086 return night ;
8187 }
8288
83- public Object getField (GranuleField field ) {
89+ public Object getField (final GranuleField field ) {
8490 switch (field ) {
8591 case TARGET :
8692 return getTarget ();
@@ -93,6 +99,17 @@ public Object getField(GranuleField field) {
9399 }
94100 }
95101
102+ public Set <String > getField (final GranuleExtraField field ) {
103+ switch (field ) {
104+ case DISTINCT_STA_NAMES :
105+ return getDistinctStaNames ();
106+ case DISTINCT_STA_CONFS :
107+ return getDistinctStaConfs ();
108+ default :
109+ return null ;
110+ }
111+ }
112+
96113 @ Override
97114 public int hashCode () {
98115 int hash = 7 ;
@@ -131,15 +148,8 @@ public boolean isEmpty() {
131148 }
132149
133150 /* extra information for specific filters (distinct staNames, mjd range) */
134- public boolean hasDistinctStaNames () {
135- return (distinctStaNames != null ) && !distinctStaNames .isEmpty ();
136- }
137-
138- public Set <String > getDistinctStaNames () {
139- if (distinctStaNames == null ) {
140- distinctStaNames = new LinkedHashSet <String >();
141- }
142- return distinctStaNames ;
151+ public Range getWavelengthRange () {
152+ return (getInsMode () != null ) ? getInsMode ().getWavelengthRange () : null ;
143153 }
144154
145155 public boolean hasMjdRange () {
@@ -153,7 +163,7 @@ public Range getMjdRange() {
153163 return mjdRange ;
154164 }
155165
156- public void updateMjdRange (final double mjd ) {
166+ void updateMjdRange (final double mjd ) {
157167 final Range r = getMjdRange ();
158168 if (mjd < r .getMin ()) {
159169 r .setMin (mjd );
@@ -163,31 +173,71 @@ public void updateMjdRange(final double mjd) {
163173 }
164174 }
165175
166- public void updateMjdRange (final Range other ) {
176+ void updateMjdRange (final Range other ) {
167177 updateMjdRange (other .getMin ());
168178 updateMjdRange (other .getMax ());
169179 }
170180
181+ public boolean hasDistinctStaNames () {
182+ return (distinctStaNames != null ) && !distinctStaNames .isEmpty ();
183+ }
184+
185+ public Set <String > getDistinctStaNames () {
186+ if (distinctStaNames == null ) {
187+ distinctStaNames = new LinkedHashSet <String >();
188+ }
189+ return distinctStaNames ;
190+ }
191+
192+ public boolean hasDistinctStaConfs () {
193+ return (distinctStaConfs != null ) && !distinctStaConfs .isEmpty ();
194+ }
195+
196+ public Set <String > getDistinctStaConfs () {
197+ if (distinctStaConfs == null ) {
198+ distinctStaConfs = new LinkedHashSet <String >();
199+ }
200+ return distinctStaConfs ;
201+ }
202+
171203 @ Override
172204 public String toString () {
173205 return "Granule{" + "target=" + target + ", insMode=" + insMode
174206 + ", night=" + night + ", mjdRange=" + mjdRange
175207 + ", distinctStaNames=" + distinctStaNames
208+ + ", distinctStaConfs=" + distinctStaConfs
176209 + '}' ;
177210 }
178211
179- public static <K > Set <K > getDistinctGranuleField (final Collection <Granule > granules , final GranuleField field ) {
212+ public static <K > HashSet <K > getDistinctGranuleField (final Collection <Granule > granules , final GranuleField field ) {
180213 final HashSet <K > values = new HashSet <K >();
181214 for (Granule g : granules ) {
182215 values .add ((K ) g .getField (field ));
183216 }
184217 return values ;
185218 }
186219
187- public static <K > List <K > getSortedDistinctGranuleField (final Collection <Granule > granules , final GranuleField field ) {
188- final Set <K > values = getDistinctGranuleField (granules , field );
189- final ArrayList <K > sorted = new ArrayList <K >(values );
190- Collections .sort (sorted , GranuleComparator .getComparator (field ));
191- return sorted ;
220+ public static <K > ArrayList <K > getSortedDistinctGranuleField (final Collection <Granule > granules , final GranuleField field ) {
221+ final HashSet <K > values = getDistinctGranuleField (granules , field );
222+ final ArrayList <K > sortedList = new ArrayList <K >(values );
223+ Collections .sort (sortedList , GranuleComparator .getComparator (field ));
224+ return sortedList ;
192225 }
226+
227+ public static HashSet <String > getDistinctGranuleField (final Collection <Granule > granules , final GranuleExtraField field ) {
228+ final HashSet <String > values = new HashSet <String >();
229+ for (Granule g : granules ) {
230+ final Set <String > set = g .getField (field );
231+ values .addAll (g .getField (field ));
232+ }
233+ return values ;
234+ }
235+
236+ public static ArrayList <String > getSortedDistinctGranuleField (final Collection <Granule > granules , final GranuleExtraField field ) {
237+ final HashSet <String > values = getDistinctGranuleField (granules , field );
238+ final ArrayList <String > sortedList = new ArrayList <String >(values );
239+ Collections .sort (sortedList , StationNamesComparator .INSTANCE );
240+ return sortedList ;
241+ }
242+
193243}
0 commit comments