English 中文(简体)
模拟报告的一个实例:使用单一州?
原标题:One instance of Report per instance of Simulation: use a singleton?

我的成文法有多种不同的模拟,每种模拟都载于自己的<条码>。 为了从<代码>Simulation中提取结果,我们首先必须请<编码>Simulation/code> 创建Report(作为>Simulations children)的范例。

尽管<代码>Simulation可包含许多事例Report,但制作过程非常昂贵,因此,如果已有一个“<>Report in that particular Simulation,我希望重新加以使用,而不是创建新的系统。

Report 例见我的代码中的许多不同类别。 我愿避免重复,首先检查的是<代码>Report是否已经存在,特别是Simulation,然后根据这一条,要么获得现有版本,要么作出新的改动。

I really only want there to be one instance of Report per Simulation -- kind of like a singleton...

我看到两个渠道:

  1. 提供一种“单一州”报告类别,允许在<代码>/code>上设定不超过1个<代码>。 这是可能的吗?

  2. 订立<条码>特殊编码,扩展<条码>,<条码>;<条码>特别编码/代码>包括一个包含<条码>的报告/代码>的单一吨。 这种高技能吗?

<代码>Simulation and Report> are from a commercial Java AP that we have a Award for; I can t changing their sources Code.

Doing my best to learn the ropes of Java and OOP...

问题回答

如果我正确理解你的问题,你真的希望这样做:

public class ReportManager {
    final static ConcurrentMap<Simulation, Report> reports = new ConcurrentHashMap<Simulation, Report>();

    public static Report getReportForSimulation(final Simulation simulation){
        if (!reports.containsKey(simulation)) reports.putIfAbsent(simulation, simulation.getReport());
        return reports.get(simulation);
    }
}

然后利用报告Manager检索报告。 在积极的方面,报告非常简单,但在消极方面,从理论上来说,它可能会在多面环境下产生多次报告,但会很少发生,而且你再次保证,至少所有读者都看到准确的报告。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签