sammyinny01
MIS
Hi,
I have a file database containing data values for several fields. The fields are specified in a separate meta data within the database in a format as:
fieldName, fieldType, fieldAggregationMethod
e.g., volume, long, sum
e.g., closePrice, float, last
e.g., numTrades, int, sum
The fieldType is always a basic type.
I need to read in these fields and allocate my arrays accordingly. Then I need to read the data values for each of these fields from a database, apply aggregation operation and return the values to the user.
I am thinking of setting up an aggregation method factory for the different aggregation operations.
But I am not sure how to handle field types. How do I allocate arrays based on the its specified type, return the right type from my functions, set type within the field, casting operation, etc. Is there a base class for the basic types in Java.
e.g, if I do something like:
if (type.equals("float"))
Object field1 = Float.valueOf(value);
Now how do I call my aggregation operation on field1?
something like
public Float sum(Float f1, Float f2) {
return f1 + f2;
}
I am thinking I need a wrapper around the existing java wrapper type classes and have those handle all these operations. Something like:
public interface Value {
public Object value();
public Object aggregate(Operation op);
}
public class DoubleValue implements Value {
Double d;
public Double(String s) {
// get d from s
}
public Object value() {
return d;
}
public Object aggregate(Operation op) {
return op.apply(d);
}
}
then have a factory construct the right type for me.
Is there an existing framework or example I could use for this? This looks like a common problem and I am sure there must be a good design pattern out there.
I want to avoid using reflection as much as possible as it is expensive, ugly, and error-prone.
Please share your experience and thoughts.
thanks,
Sam
I have a file database containing data values for several fields. The fields are specified in a separate meta data within the database in a format as:
fieldName, fieldType, fieldAggregationMethod
e.g., volume, long, sum
e.g., closePrice, float, last
e.g., numTrades, int, sum
The fieldType is always a basic type.
I need to read in these fields and allocate my arrays accordingly. Then I need to read the data values for each of these fields from a database, apply aggregation operation and return the values to the user.
I am thinking of setting up an aggregation method factory for the different aggregation operations.
But I am not sure how to handle field types. How do I allocate arrays based on the its specified type, return the right type from my functions, set type within the field, casting operation, etc. Is there a base class for the basic types in Java.
e.g, if I do something like:
if (type.equals("float"))
Object field1 = Float.valueOf(value);
Now how do I call my aggregation operation on field1?
something like
public Float sum(Float f1, Float f2) {
return f1 + f2;
}
I am thinking I need a wrapper around the existing java wrapper type classes and have those handle all these operations. Something like:
public interface Value {
public Object value();
public Object aggregate(Operation op);
}
public class DoubleValue implements Value {
Double d;
public Double(String s) {
// get d from s
}
public Object value() {
return d;
}
public Object aggregate(Operation op) {
return op.apply(d);
}
}
then have a factory construct the right type for me.
Is there an existing framework or example I could use for this? This looks like a common problem and I am sure there must be a good design pattern out there.
I want to avoid using reflection as much as possible as it is expensive, ugly, and error-prone.
Please share your experience and thoughts.
thanks,
Sam