[英]Castor Mapping Arrays
我有一個具有構造函數的類:
public ContEmpirical(double xs[], double fs[]) {
Check.check(xs.length == fs.length + 1 && fs.length > 0,
"Empirical distribution array mismatch");
this.xs = new double[xs.length];
this.xs = xs;
this.cs = new double[xs.length];
double fTotal = 0.0;
for (int i = 0; i < fs.length; i++)
fTotal += fs[i];
cs[0] = 0;
for (int i = 0; i < fs.length; i++)
cs[i + 1] = cs[i] + fs[i] / fTotal;
}
屬性:
private double xs[], cs[];
private double fs[]; // this attribute i added to make castors life easier since it always wants to map constructor arg to class attribute.
我擁有的映射文件是:
<class name="tools.ContEmpirical">
<description xmlns="">
Mapping for class tools.ContEmpirical
</description>
<map-to xml="ContEmpirical"/>
<field name="xs" type="double" collection="array" set-method="%1" get-method="getXs" required="true">
<bind-xml node="attribute"/>
</field>
<field name="fs" type="double" collection="array" set-method="%2" get-method="getFs" required="true">
<bind-xml node="attribute"/>
</field></class>
但是,當我嘗試封送ContEmpirical的實例時,我得到了以下XML:
<ContEmpirical xs="0.2 0.3 0.4 0.8"/>
當我真的應該得到這樣的東西時:
<ContEmpirical xs="0.2 0.3 0.4 0.8" fs="0.2 0.3 0.4 0.8"/>
映射中缺少我嗎?
您可以發布ContEmpirical類嗎? 您是否正在將fs數組初始化為字段級別的內容?
更新:我一定錯過了一些東西。 您說過您“期望”輸出xml中的fs。 但是該類是否具有名為fs的屬性? 從您發布的構造函數代碼中,永遠不會在內部分配fs(盡管有一個名為fs的參數用於計算cs)。
因此,實際上,您的對象只有xs和cs變量,並且在XML中,如果您聲明cs的映射,則應該得到cs。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.