脚轮映射阵列

发布于 2024-08-23 14:53:44 字数 1606 浏览 9 评论 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"/>

我有什么东西吗?映射中缺失?

I've got a class that has constructor:

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;
}

Attributes:

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.

The mapping File i have is:

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

Yet when i try to marshall an instance of ContEmpirical I get this XML:

<ContEmpirical xs="0.2 0.3 0.4 0.8"/>

When really I should be getting something like this:

<ContEmpirical xs="0.2 0.3 0.4 0.8" fs="0.2 0.3 0.4 0.8"/>

Is there something I'm missing from the mapping?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2024-08-30 14:53:44

你能发布 ContEmpirical 课程吗?您是否将 fs 数组初始化为字段级别的内容?

更新:我一定错过了一些东西。您说您“期望”输出 xml 中的 fs 。但是这个类有一个名为 fs 的属性吗?从您发布的构造函数代码来看,fs 从未在内部分配(有一个名为 fs 的参数,但它用于计算 cs)。

所以实际上,你的对象只有一个 xs 和 cs 变量,并且在你的 xml 中,如果你声明 cs 的映射,你应该得到 cs。

Can you post the ContEmpirical class? Are you initialising the fs array to something in the field level?

UPDATE: I must be missing something. You said you "expect" fs in the output xml. But does the class have an attribute named fs? From the constructor code you have posted, fs is never assigned internally (there is a parameter called fs though which is used for computing cs).

So really, your object has only a xs and cs variable and in your xml if you declare mapping for cs you should get cs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文