Skip to content

Commit 9c3b694

Browse files
committed
refactoring findOIData() to compute mask1D in general, see new FitsTableFilter base class
1 parent 8d8a8a9 commit 9c3b694

7 files changed

Lines changed: 383 additions & 155 deletions

File tree

src/main/java/fr/jmmc/oitools/model/Granule.java

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,6 @@ public enum GranuleField {
4444
TARGET, INS_MODE, NIGHT;
4545
}
4646

47-
public final static Matcher<Granule> MATCHER_LIKE = new Matcher<Granule>() {
48-
49-
@Override
50-
public boolean match(final Granule pattern, final Granule candidate) {
51-
if (pattern == candidate) {
52-
return true;
53-
}
54-
if ((pattern.getTarget() != null) && (candidate.getTarget() != null)) {
55-
if (!pattern.getTarget().equals(candidate.getTarget())) {
56-
return false;
57-
}
58-
}
59-
if ((pattern.getInsMode() != null) && (candidate.getInsMode() != null)) {
60-
if (!pattern.getInsMode().equals(candidate.getInsMode())) {
61-
return false;
62-
}
63-
}
64-
if ((pattern.getNight() != null) && (candidate.getNight() != null)) {
65-
if (!pattern.getNight().equals(candidate.getNight())) {
66-
return false;
67-
}
68-
}
69-
if (pattern.hasDistinctStaNames() && candidate.hasDistinctStaNames()) {
70-
if (!Granule.match(pattern.getDistinctStaNames(), candidate.getDistinctStaNames())) {
71-
return false;
72-
}
73-
}
74-
if (pattern.hasDistinctMjdRanges() && candidate.hasDistinctMjdRanges()) {
75-
if (!Range.matchRanges(pattern.getDistinctMjdRanges(), candidate.getDistinctMjdRanges())) {
76-
return false;
77-
}
78-
}
79-
if (pattern.hasDistinctWavelengthRanges() && (candidate.getInsMode() != null)) {
80-
if (!Range.matchRange(pattern.getDistinctWavelengthRanges(), candidate.getInsMode().getWavelengthRange())) {
81-
return false;
82-
}
83-
}
84-
return true;
85-
}
86-
};
87-
8847
/* members */
8948
private Target target;
9049
private InstrumentMode insMode;
@@ -94,8 +53,6 @@ public boolean match(final Granule pattern, final Granule candidate) {
9453
private Set<String> distinctStaNames = null;
9554
/** distinct MJD values */
9655
private Set<Range> distinctMjdRanges = null;
97-
/** distinct Wavelength values */
98-
private Set<Range> distinctWavelengthRanges = null;
9956

10057
public Granule() {
10158
this(null, null, null);
@@ -171,7 +128,7 @@ public boolean equals(Object obj) {
171128

172129
public boolean isEmpty() {
173130
return (this.target == null) && (this.insMode == null) && (this.night == null)
174-
&& !hasDistinctStaNames() && !hasDistinctMjdRanges() && !hasDistinctWavelengthRanges();
131+
&& !hasDistinctStaNames() && !hasDistinctMjdRanges();
175132
}
176133

177134
/* extra information (filters) */
@@ -197,23 +154,11 @@ public Set<Range> getDistinctMjdRanges() {
197154
return distinctMjdRanges;
198155
}
199156

200-
public boolean hasDistinctWavelengthRanges() {
201-
return (distinctWavelengthRanges != null) && !distinctWavelengthRanges.isEmpty();
202-
}
203-
204-
public Set<Range> getDistinctWavelengthRanges() {
205-
if (distinctWavelengthRanges == null) {
206-
distinctWavelengthRanges = new LinkedHashSet<Range>();
207-
}
208-
return distinctWavelengthRanges;
209-
}
210-
211157
@Override
212158
public String toString() {
213159
return "Granule{" + "target=" + target + ", insMode=" + insMode + ", night=" + night
214160
+ ", distinctStaNames=" + distinctStaNames
215161
+ ", distinctMjdRanges=" + distinctMjdRanges
216-
+ ", distinctWavelengthRanges=" + distinctWavelengthRanges
217162
+ '}';
218163
}
219164

@@ -231,13 +176,4 @@ public static <K> List<K> getSortedDistinctGranuleField(final Collection<Granule
231176
Collections.sort(sorted, GranuleComparator.getComparator(field));
232177
return sorted;
233178
}
234-
235-
public static boolean match(final Set<String> selected, final Set<String> candidates) {
236-
for (String sel : selected) {
237-
if (candidates.contains(sel)) {
238-
return true;
239-
}
240-
}
241-
return false;
242-
}
243179
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*******************************************************************************
2+
* JMMC project ( http://www.jmmc.fr ) - Copyright (C) CNRS.
3+
******************************************************************************/
4+
package fr.jmmc.oitools.model;
5+
6+
import fr.jmmc.oitools.model.range.Range;
7+
import java.util.Set;
8+
9+
/**
10+
*
11+
*/
12+
public final class GranuleMatcher implements Matcher<Granule> {
13+
14+
private final static GranuleMatcher MATCHER_LIKE = new GranuleMatcher(null);
15+
16+
public static GranuleMatcher getInstance(final Set<Range> distinctWavelengthRanges) {
17+
if (distinctWavelengthRanges == null || distinctWavelengthRanges.isEmpty()) {
18+
return MATCHER_LIKE;
19+
}
20+
return new GranuleMatcher(distinctWavelengthRanges);
21+
}
22+
23+
/** distinct Wavelength values */
24+
private final Set<Range> distinctWavelengthRanges;
25+
26+
private GranuleMatcher(final Set<Range> distinctWavelengthRanges) {
27+
this.distinctWavelengthRanges = distinctWavelengthRanges;
28+
}
29+
30+
public boolean isEmpty() {
31+
return !hasDistinctWavelengthRanges();
32+
}
33+
34+
@Override
35+
public boolean match(final Granule pattern, final Granule candidate) {
36+
if (pattern == candidate) {
37+
return true;
38+
}
39+
if ((pattern.getTarget() != null) && (candidate.getTarget() != null)) {
40+
if (!pattern.getTarget().equals(candidate.getTarget())) {
41+
return false;
42+
}
43+
}
44+
if ((pattern.getInsMode() != null) && (candidate.getInsMode() != null)) {
45+
if (!pattern.getInsMode().equals(candidate.getInsMode())) {
46+
return false;
47+
}
48+
}
49+
if ((pattern.getNight() != null) && (candidate.getNight() != null)) {
50+
if (!pattern.getNight().equals(candidate.getNight())) {
51+
return false;
52+
}
53+
}
54+
if (pattern.hasDistinctStaNames() && candidate.hasDistinctStaNames()) {
55+
if (!match(pattern.getDistinctStaNames(), candidate.getDistinctStaNames())) {
56+
return false;
57+
}
58+
}
59+
if (pattern.hasDistinctMjdRanges() && candidate.hasDistinctMjdRanges()) {
60+
if (!Range.matchRanges(pattern.getDistinctMjdRanges(), candidate.getDistinctMjdRanges())) {
61+
return false;
62+
}
63+
}
64+
if (hasDistinctWavelengthRanges() && (candidate.getInsMode() != null)) {
65+
if (!Range.matchRange(getDistinctWavelengthRanges(), candidate.getInsMode().getWavelengthRange())) {
66+
return false;
67+
}
68+
}
69+
return true;
70+
}
71+
72+
public boolean hasDistinctWavelengthRanges() {
73+
return (distinctWavelengthRanges != null) && !distinctWavelengthRanges.isEmpty();
74+
}
75+
76+
public Set<Range> getDistinctWavelengthRanges() {
77+
return distinctWavelengthRanges;
78+
}
79+
80+
@Override
81+
public String toString() {
82+
return "GranuleMatcher{"
83+
+ ", distinctWavelengthRanges=" + distinctWavelengthRanges
84+
+ '}';
85+
}
86+
87+
public static boolean match(final Set<String> selected, final Set<String> candidates) {
88+
for (String sel : selected) {
89+
if (candidates.contains(sel)) {
90+
return true;
91+
}
92+
}
93+
return false;
94+
}
95+
96+
}

0 commit comments

Comments
 (0)