2010-03-05 79 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