package impl.manipulators;
import Sight.Agents.*;
import Sight.Agents.Prototypes.*;
import Sight.Agents.Signals.*;
import Sight.dds.*;
import java.io.*;
import Sight.Agents.util.*;
public class numberFilter extends Wrapper implements Serializable, Fast {
public class Request extends Sight.Request implements java.io.Serializable {
public CharSequence Min;
public CharSequence Max;
public CharSequence test_value;
public Sight.Agents.Request submit() { return Sight.Agents.Request.submit(Public, this, getKey()); };
public Sight.Agents.Request submit(String key)
{ return Sight.Agents.Request.submit(Public, this, key); };
};
public static Request getDefaultRequest() {
return Public.getRequest(); }
private Request getRequest() { return new Request(); };
public dStructure getRequestDds() {
return new Sight.dds.Records(true,
new dField[] {
new dField("Min","CharSequence","Minimal allowed value, leave empty if not restricted",""),
new dField("Max","CharSequence","Maximal allowed value, leave empty if not restricted",""),
new dField("test_value","CharSequence","Value to check for belonging to the interval above",""),
}
);
}
public dStructure getResultDds() {
return new Sight.dds.Records(false,
new dField[] {
new dField("Min","CharSequence","Minimal allowed value, leave empty if not restricted",""),
new dField("Max","CharSequence","Maximal allowed value, leave empty if not restricted",""),
new dField("test_value","CharSequence","Value to check for belonging to the interval above","")
}
);
}
public static class Record extends Sight.Record implements Serializable {
public CharSequence Min;
public CharSequence Max;
public CharSequence test_value;
};
public static class Result extends Sight.Result implements Serializable {
public Record[] a;
public CharSequence getReportForRecord(Object ro, int level)
{ Record r = (Record) ro;
switch (level) {
case 0: return " "+r.test_value+", belongs to ["+r.Min+".."+r.Max+"]";
case 1: return " "+r.test_value+", belongs to ["+r.Min+".."+r.Max+"]";
default:
{
StringBuffer b = new StringBuffer(r.test_value+" Belongs to ["+r.Min+".."+r.Max+"] ");
return b;
}
}
};
}
public Object go(Object o_request) throws Exception
{
Request request = (Request) o_request;
Result result = new Result();
Record record = new Record();
double min = Double.MIN_VALUE;
double max = Double.MAX_VALUE;
double x = 0;
try {
}
catch (Exception ex) {
}
try {
min = Double.parseDouble(request.Min.toString().trim());
}
catch (Exception ex) {
}
try {
max = Double.parseDouble(request.Max.toString().trim());
}
catch (Exception ex) {
}
try {
x = Double.parseDouble(request.test_value.toString().trim());
}
catch (Exception ex) {
throw new FatalAgentException(request.test_value+" not a number.");
}
String pPattern = "["+request.Min+".."+request.Max+"]";
if ( !(x>=min && x<=max) )
{ p(request.test_value+" is outside "+pPattern);
return EMPTY;
} else
p(request.test_value+" BELONGS TO "+pPattern);
result.a = new Record[1];
result.a[0] = record;
record.test_value = request.test_value;
record.Min = request.Min;
record.Max = request.Max;
result.setAgentSignature("<b><i>Number filter "+pPattern+"</i></b> ");
return result;
};
final Result EMPTY;
public numberFilter() {
setDescription("Check the numeric value for belonging to certain interval.");
setMasterURL("");
setWriteCache(false);
setReadCache(false);
EMPTY = new Result();
EMPTY.a = new Record[0];
};
public static numberFilter Public = new numberFilter();
public static Agent getAvailableAgent() { return Public; };
public static void main(String[] args) {
Sight.Agents.util.Pind.showConsoles();
try {
Request request = getDefaultRequest();
Sight.Agents.Request submission = request.submit();
Result response = (Result) submission.getResult();
System.out.println(response.getReport(2));
} catch (Exception exc)
{ if (exc!=null) System.out.println(exc.getMessage());
exc.printStackTrace();
};
}
;
}