2010-03-05 89 views
0

我有一個具有構造函數的類:蓖麻映射陣列

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"/> 

有什麼事我是從映射失蹤?

回答

0

你可以發佈ContEmpirical類嗎?你是否將fs數組初始化爲字段級別的東西?

更新:我必須錯過一些東西。你說你在輸出xml中「期望」fs。但是這個類是否有一個名爲fs的屬性?從你發佈的構造函數代碼,fs永遠不會在內部分配(有一個稱爲fs的參數,但用於計算cs)。

所以,真的,你的對象只有一個xs和cs變量,並且在你的xml中,如果你聲明cs的映射,你應該得到cs。

+0

已添加到原始帖子。 – Babyangle86 2010-03-07 10:13:04

+0

看看第二個代碼blurb,我讓fs成爲getter和setter的一個屬性。 – Babyangle86 2010-03-10 21:29:15