用于3行值的集合类型,其中2个必须相乘

时间:2021-06-02 21:47:19

i am returning results from a sql query which contains multiple rows of three columns. Column1(a rate) must be multiplied by column2(a numerical value). Column 3 consists of five different possible values. Each value will indicate a condition that column1 and column2 must adhere to( basically column3 will be another value (like an exchange rate)- but it has not yet been determined, so I would like to group this value with the result of the other two. Obviously a collection of some sort ought to be used, but i am not sure which will allow me to efficiently deal with multiplying column1 by column2 and noting the value for column3 and multiplying this at a later date. So far, I have something like this: (obviously ill probably need a for loop)

我将返回包含多行三列的SQL查询的结果。 Column1(速率)必须乘以column2(数值)。第3列包含五个不同的可能值。每个值都表示column1和column2必须遵守的条件(基本上column3将是另一个值(如汇率) - 但尚未确定,所以我想将此值与其他两个值的结果组合在一起显然应该使用某种类型的集合,但我不确定哪个允许我有效地处理第2列乘以column2并注意column3的值并在以后将其相乘。到目前为止,我有类似的东西。这个:(显然病了可能需要一个for循环)

double value= "column1";
double rate= "column2";
double currency= "column3";

Finalamount setValue(value);
Finalamount setRate(rate);
Finalamount setCurrency(currency);

Collection <Finalamount> col = new ArrayList();

2 个解决方案

#1


0  

You ought to write a custom class that abstracts all this away from clients. It'll document and encapsulate what needs to be done and simply handles it so it's all set when clients get the query results back.

您应该编写一个自定义类,将所有这些从客户端抽象出来。它将记录并封装需要完成的工作并简单地处理它,以便在客户端获得查询结果时全部设置。

#2


0  

Looks like you're already on the right track. Just type your array list and give it a better name:

看起来你已经走上了正轨。只需键入您的数组列表并为其指定一个更好的名称:

Collection <Finalamount> finalAmounts = new ArrayList<Finalamount>();

#1


0  

You ought to write a custom class that abstracts all this away from clients. It'll document and encapsulate what needs to be done and simply handles it so it's all set when clients get the query results back.

您应该编写一个自定义类,将所有这些从客户端抽象出来。它将记录并封装需要完成的工作并简单地处理它,以便在客户端获得查询结果时全部设置。

#2


0  

Looks like you're already on the right track. Just type your array list and give it a better name:

看起来你已经走上了正轨。只需键入您的数组列表并为其指定一个更好的名称:

Collection <Finalamount> finalAmounts = new ArrayList<Finalamount>();