我有一个文件,其中包含交易代理 Activity 的输出。例如:
222666:org.powertac.common.Order::171875::new::21::165482::-35.74395569719625::35.0
222666:org.powertac.common.Order::171876::new::21::165893::-35.74395569719625::35.0
Order
类定义为:
public Order (Broker broker, Timeslot timeslot,
double mWh, Double limitPrice)
{
super();
this.broker = broker;
this.timeslot = timeslot;
this.mWh = mWh;
this.limitPrice = limitPrice;
}
所以从我的文件中:
<id>:<package_name>::<execution_id>::<new object>::<args_list>
但是,有一些例子:
222665:org.powertac.genco.Genco::21::setCurrentCapacity::35.74395569719625
222665:org.powertac.genco.Genco::21::setInOperation::true
因此,我不必创建新
对象,而是必须使用35.7439..
参数调用方法setCurrentCapacity
。
我的目标是创建一个
Map<Integer, Object> map = new Map<Integer, Object>();
就是这样,Integer id
和 Object
之间的 Map
。因此,如果我想再次重现代理 Activity ,我只需处理 Map
对象。我想知道实现我的目标的最佳方法是什么。例如,我是否必须实际创建 Genco
对象,并在将其存储到 Map
之前将其转换为 Object
?如何设置函数调用?我的意思是,如何创建 Genco
对象并告诉它在 Map
中调用 setInOperation
?另外,这是什么意思以及我如何处理以下值:
300:org.powertac.du.DefaultBrokerService$LocalBroker::1::new::default broker
300:org.powertac.du.DefaultBrokerService$LocalBroker::1::setLocal::true
用 $
符号?
最佳答案
美元符号是类名中的有效字符,但按照惯例不鼓励使用它。在实践中,它可能出于多种原因出现。在您的场景中,LocalBroker
很可能是 DefaultBrokerService
的内部类。
来自JLS§3.8 :
The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.
关于java - 解析文件以在java中创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12135566/