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

マッピングに欠けているものはありますか?

4

1 に答える 1

0

ContEmpirical クラスを投稿できますか? fs 配列をフィールド レベルで何かに初期化していますか?

更新: 何かが欠けているに違いありません。出力xmlでfsを「期待する」と言いました。しかし、クラスには fs という名前の属性がありますか? あなたが投稿したコンストラクターコードから、 fs が内部的に割り当てられることはありません( cs の計算に使用される fs というパラメーターがあります)。

したがって、実際には、オブジェクトには xs 変数と cs 変数しかなく、xml で cs のマッピングを宣言すると、cs を取得する必要があります。

于 2010-03-06T16:45:06.833 に答える