lrgs.common.SearchCriteria Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opendcs Show documentation
Show all versions of opendcs Show documentation
A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.
The newest version!
package lrgs.common;
import java.io.File;
import java.io.Serializable;
import java.io.IOException;
import java.io.Reader;
import java.io.FileWriter;
import java.io.LineNumberReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.StringTokenizer;
import lrgs.ldds.DdsVersion;
import lrgs.ldds.SearchCritLocalFilter;
import ilex.util.IDateFormat;
import ilex.util.TextUtil;
public class SearchCriteria implements Serializable
{
public static final String defaultName = "searchcrit";
// ================================================
// Attributes
// ================================================
private String LrgsSince;
private String LrgsUntil;
private String DapsSince;
private String DapsUntil;
private boolean ascendingTimeOnly = false;
private boolean realtimeSettlingDelay = false;
/**
The constants ACCEPT, REJECT, EXCLUSIVE are used for several of
the criteria.
*/
public static final char UNSPECIFIED = '\0';
public static final char ACCEPT = 'A';
public static final char REJECT = 'R';
public static final char EXCLUSIVE = 'O';
public static final char YES = 'Y';
public static final char NO = 'N';
/**
Set DomsatEmail to 'Y' to accept DOMSAT e-mail messages,
'N' to filter them out, or 'O' if you only want e-mail
messages.
*/
public char DomsatEmail;
/**
Set DomsatRetrans to 'Y' to accept DOMSAT Retranmitted messages,
'N' to filter them out, or 'O' if you only want Retransmitted
messages.
*/
public char Retrans;
/**
Set DapsStatus to 'Y' to accept DAPS Status messages,
'N' to filter them out, or 'O' if you only want DAPS status
messages.
*/
public char DapsStatus;
/**
Set GlobalBul to 'Y' to accept DOMSAT Global Bulletins,
'N' to filter them out, or 'O' if you only want bulletins.
messages.
*/
public char GlobalBul;
/**
Set DcpBul to 'Y' to accept DOMSAT DCP Bulletins,
'N' to filter them out, or 'O' if you only want DCP bulletins.
messages.
*/
public char DcpBul;
/**
* NetlistNames is a vector containing String objects. Each string is
* the name of a network list to be loaded.
* Use the addNetworkList() method to add String objects to the vector.
* For display and editing, access the vector methods directly.
* Clients can manage this vector directly.
*/
public ArrayList NetlistFiles;
/**
The DcpNames vector holds a list of explicit DCP names
that were entered. No processing is done in the SearchCriteria
class on the validity of the names.
You can manipulate the vector directly. Each object in the vector
should implement the toString() method.
*/
public ArrayList DcpNames;
/**
The user can explicitely specify DCP addresses as part of the criteria.
This vector must only hold DcpAddress objects. You can add, remove,
and edit objects by manipulating the vector directly.
*/
public ArrayList ExplicitDcpAddrs;
public int channels[];
public static final int CHANNEL_AND=0x200;
/* This bit determines how channel specs */
/* are combined with DCP address specs. */
/// list of data sources to accept data from
public static final int MAX_SOURCES = 12;
public int sources[] = new int[MAX_SOURCES];
public int numSources = 0;
public char spacecraft;
public static final char SC_EAST = 'E';
public static final char SC_WEST = 'W';
public static final char SC_ANY = 'A';
public int seqStart, seqEnd;
public static String lineSep = System.getProperty("line.separator");
public String baudRates = null;
public boolean single = false;
public char parityErrors = ACCEPT;
private SearchCritLocalFilter localFilter = null;
/**
Initialize empty search criteria object.
*/
public SearchCriteria()
{
clear();
}
/**
Initialize search criteria object by parsing the named
file.
*/
public SearchCriteria(File f)
throws IOException, SearchSyntaxException
{
this();
parseFile(f);
}
/**
* Copy constructor
*/
public SearchCriteria(SearchCriteria rhs)
{
this();
LrgsSince = rhs.LrgsSince;
LrgsUntil = rhs.LrgsUntil;
DapsSince = rhs.DapsSince;
DapsUntil = rhs.DapsUntil;
DomsatEmail = rhs.DomsatEmail;
Retrans = rhs.Retrans;
DapsStatus = rhs.DapsStatus;
GlobalBul = rhs.GlobalBul;
DcpBul = rhs.DcpBul;
NetlistFiles = new ArrayList();
NetlistFiles.addAll(rhs.NetlistFiles);
DcpNames = (rhs.DcpNames == null) ? null :
(ArrayList)rhs.DcpNames.clone();
ExplicitDcpAddrs = (rhs.ExplicitDcpAddrs == null) ? null :
(ArrayList)rhs.ExplicitDcpAddrs.clone();
channels = rhs.channels == null ? null : (int[])rhs.channels.clone();
numSources = rhs.numSources;
for(int i=0; i();
DcpNames = new ArrayList();
ExplicitDcpAddrs = new ArrayList();
channels = null;
for(int i=0; i 0
|| DcpNames.size() > 0
|| ExplicitDcpAddrs.size() > 0
|| channels != null)
{
return false;
}
for(int i=0; i idx && ln.charAt(idx+1) != ' ')
{
ln = ln.substring(0,idx+1) + ' ' + ln.substring(idx+1);
}
}
StringTokenizer st = new StringTokenizer(ln);
if (!st.hasMoreTokens())
{
continue;
}
String kw = st.nextToken(); // Keyword followed by colon
if (kw.charAt(0) == '#') // skip comment lines.
{
continue;
}
// Else try to parse the line.
if (kw.equalsIgnoreCase("DRS_SINCE:")
|| kw.equalsIgnoreCase("LRGS_SINCE:")
|| kw.equalsIgnoreCase("DRSSINCE:")
|| kw.equalsIgnoreCase("LRGSSINCE:"))
{
setLrgsSince(ln.substring(kw.length()).trim());
}
else if (kw.equalsIgnoreCase("DRS_UNTIL:")
|| kw.equalsIgnoreCase("LRGS_UNTIL:")
|| kw.equalsIgnoreCase("DRSUNTIL:")
|| kw.equalsIgnoreCase("LRGSUNTIL:"))
{
setLrgsUntil(ln.substring(kw.length()).trim());
}
else if (kw.equalsIgnoreCase("DAPS_SINCE:")
|| kw.equalsIgnoreCase("DAPSSINCE:"))
{
setDapsSince(ln.substring(kw.length()).trim());
}
else if (kw.equalsIgnoreCase("DAPS_UNTIL:")
|| kw.equalsIgnoreCase("DAPSUNTIL:"))
{
setDapsUntil(ln.substring(kw.length()).trim());
}
else if (kw.equalsIgnoreCase("NETWORKLIST:")
|| kw.equalsIgnoreCase("NETWORK_LIST:"))
{
if (!st.hasMoreTokens())
{
throw new SearchSyntaxException(
"Expected network list name.",
LrgsErrorCode.DBADNLIST);
}
addNetworkList(st.nextToken());
}
else if (kw.equalsIgnoreCase("DCP_NAME:"))
{
if (!st.hasMoreTokens())
{
throw new SearchSyntaxException("Expected DCP name.",
LrgsErrorCode.DBADDCPNAME);
}
addDcpName(st.nextToken());
}
else if (kw.equalsIgnoreCase("DCP_ADDRESS:")
|| kw.equalsIgnoreCase("DCPADDRESS:"))
{
if (!st.hasMoreTokens())
{
throw new SearchSyntaxException(
"Expected DCP address.", LrgsErrorCode.DBADADDR);
}
String tok = st.nextToken();
addDcpAddress(new DcpAddress(tok));
}
else if (kw.equalsIgnoreCase("ELECTRONIC_MAIL:"))
{
char c = '-';
if (st.hasMoreTokens())
{
c = st.nextToken().charAt(0);
}
if (c != ACCEPT && c != REJECT && c != EXCLUSIVE
&& c != YES && c != NO)
{
throw new SearchSyntaxException(
"Expected one of "+ACCEPT+", "+REJECT+", or "
+EXCLUSIVE, LrgsErrorCode.DBADEMAIL);
}
DomsatEmail = (c == YES) ? ACCEPT :
(c == NO ) ? REJECT : c;
}
else if (kw.equalsIgnoreCase("DAPS_STATUS:"))
{
char c = '-';
if (st.hasMoreTokens())
{
c = st.nextToken().charAt(0);
}
if (c != ACCEPT && c != REJECT && c != EXCLUSIVE
&& c != YES && c != NO)
{
throw new SearchSyntaxException(
"Expected "+ACCEPT+", "+REJECT+", or "+EXCLUSIVE,
LrgsErrorCode.DBADDAPSSTAT);
}
DapsStatus = c;
}
else if (kw.equalsIgnoreCase("RETRANSMITTED:"))
{
char c = '-';
if (st.hasMoreTokens())
{
c = st.nextToken().charAt(0);
}
if (c != ACCEPT && c != REJECT && c != EXCLUSIVE
&& c != YES && c != NO)
throw new SearchSyntaxException(
"Expected "+ACCEPT+", "+REJECT+", or "+EXCLUSIVE,
LrgsErrorCode.DBADRTRAN);
Retrans = (c == YES) ? ACCEPT :
(c == NO ) ? REJECT : c;
}
else if (kw.equalsIgnoreCase("GLOB_BUL:"))
{
char c = '-';
if (st.hasMoreTokens())
c = st.nextToken().charAt(0);
if (c != ACCEPT && c != REJECT && c != EXCLUSIVE
&& c != YES && c != NO)
throw new SearchSyntaxException(
"Expected "+ACCEPT+", "+REJECT+", or "+EXCLUSIVE,
LrgsErrorCode.DBADDAPSSTAT);
GlobalBul = (c == YES) ? ACCEPT :
(c == NO ) ? REJECT : c;
}
else if (kw.equalsIgnoreCase("DCP_BUL:"))
{
char c = '-';
if (st.hasMoreTokens())
c = st.nextToken().charAt(0);
if (c != ACCEPT && c != REJECT && c != EXCLUSIVE
&& c != YES && c != NO)
{
throw new SearchSyntaxException(
"Expected "+ACCEPT+", "+REJECT+", or "+EXCLUSIVE,
LrgsErrorCode.DBADDAPSSTAT);
}
DcpBul = (c == YES) ? ACCEPT :
(c == NO ) ? REJECT : c;
}
else if (kw.equalsIgnoreCase("CHANNEL:"))
{
if (!st.hasMoreTokens())
{
throw new SearchSyntaxException(
"Expected channel number",
LrgsErrorCode.DBADCHANNEL);
}
String t = st.nextToken();
if (t.length() == 1
&& (t.charAt(0) == '&' || t.charAt(0) == '|')
&& st.hasMoreTokens())
{
t = t + st.nextToken();
}
int hidx = t.indexOf("-");
if (hidx != -1)
{
try
{
int start = Integer.parseInt(t.substring(0, hidx));
int end = Integer.parseInt(t.substring(hidx+1));
for(int i=start; i 0)
{
boolean individual = true;
int start = channels[0];
if (channels.length > 1 && (start & CHANNEL_AND) != 0)
{
individual = false;
start &= (~CHANNEL_AND);
int last = start;
for(int i = 1; i < channels.length; ++i)
{
int c = channels[i];
if ((c & CHANNEL_AND) == 0
|| (c & (~CHANNEL_AND)) != last + 1)
{
individual = true;
break;
}
last = c & (~CHANNEL_AND);
}
ret.append("CHANNEL: " + start + "-" + last + lineSep);
}
if (individual)
{
for(int i = 0; i < channels.length; ++i)
{
ret.append("CHANNEL: "
+ ((channels[i] & CHANNEL_AND) != 0 ? '&' : '|')
+ (channels[i] & 0x1ff) + lineSep);
}
}
}
boolean atLeastOneGoesTypeSpecified = false;
boolean atLeastOneNonGoesTypeSpecified = false;
for(int i=0; i 0)
{
ret.append("BAUD: " + baudRates + lineSep);
}
if (protoVersion >= DdsVersion.version_9 && ascendingTimeOnly)
{
ret.append("ASCENDING_TIME: true" + lineSep);
}
if (protoVersion >= DdsVersion.version_9 && realtimeSettlingDelay)
{
ret.append("RT_SETTLE_DELAY: true" + lineSep);
}
if (protoVersion >= 11 && single)
{
ret.append("SINGLE: true" + lineSep);
}
if (protoVersion >= DdsVersion.version_12 && parityErrors != ACCEPT)
{
ret.append("PARITY_ERROR: " + parityErrors + lineSep);
needLocalFilter = true;
}
if (needLocalFilter)
{
localFilter = new SearchCritLocalFilter(this, protoVersion);
}
return ret.toString(); // string containing complete searchcrit file.
}
public SearchCritLocalFilter getSearchCritLocalFilter()
{
SearchCritLocalFilter ret = localFilter;
localFilter = null;
return ret;
}
/** Add a source by its numeric code */
public void addSource(int srcCode)
{
if (numSources >= MAX_SOURCES)
{
return;
}
for(int i=0; i