原文地址:http://www.ibm.com/developerworks/rational/library/programmatically-modify-rational-datapools/index.html

The Java code snippet in Listing 7 displays a simple example of reading a TPTP format datapool.

Listing 7. TPTP datapool, example

// set the Datapool File value
File inputTptpFile = new File(
"/Datapool_Workspace/Common/datapool/TPTP_Datapool.datapool");
System.out.println("Read a TPTP (RPT/RST) format Datapool: " +
inputTptpFile.getAbsolutePath());
try {
// create an IDatapoolFactory object
IDatapoolFactory tptpDatapoolFactory = new Common_DatapoolFactoryImpl();
// create an Datapool object
IDatapool tptpDatapool =
(IDatapool) tptpDatapoolFactory.load(inputTptpFile, true);
// capture the Datapool column header values
int datapoolColumnCount = tptpDatapool.getVariableCount();
String[] header = new String[datapoolColumnCount];
aStringBuilder.append("\nHEADER  :: ");
for (int i = 0; i < datapoolColumnCount; i++) {
header[i] = tptpDatapool.getVariable(i).getName();
aStringBuilder.append(header[i] + " :: ");
}
System.out.println(aStringBuilder.toString());
// Create an IDatapoolIterator object and populate with
//    the Datapool as an iterator
IDatapoolIterator tptpDatapoolIterator = tptpDatapoolFactory.
open(tptpDatapool,
"org.eclipse.hyades.datapool.iterator.DatapoolIteratorSequentialPrivate");
// initialize datapool iterator
tptpDatapoolIterator.dpInitialize(tptpDatapool, 0);
int count = 1; // int counter for demonstration purposes only
while(!tptpDatapoolIterator.dpDone()) {
// reset the temporary container for captured values
aStringBuilder.setLength(0);
aStringBuilder.append("ROW #" + count + "  :: ");
String[] nextRow = new String[datapoolColumnCount];
for (int i = 0; i < datapoolColumnCount; i++) {
/* NOTE: this example assumes value to be of type String
*    value can be captured via:
*    IDatapool.getVariable(int).getSuggestedType() */
nextRow[i] = tptpDatapoolIterator.dpCurrent().getCell(
header[i]).getStringValue();
aStringBuilder.append(nextRow[i] + " :: ");
}
tptpDatapoolIterator.dpNext();
count++;
System.out.println(aStringBuilder.toString());
// unload the Datapool
tptpDatapoolFactory.unload(tptpDatapool);
}
} catch (DatapoolException e) {
e.printStackTrace();
}

This is a simple approach to capturing the contents of a TPTP format datapool and, in this case, writing it to the console. At this point, you can iterate through your datapool, using the values as you see fit, or build in logic to perform a search for specific values. Field types can also be captured to ensure integrity of data types when updating the values.

Updating a TPTP datapool

The datapool reader program uses this class:
org.eclipse.hyades.execution.runtime.datapool.IDatapool

To extend the above program that reads a datapool to directly edit the datapool, use this class:
org.eclipse.hyades.edit.datapool.IDatapool

This is part of the TPTP internal API (see the Public API Specification for reference).

Minor modifications to this code will give you the ability to perform modifications to the datapool. The first item of note to perform anedit rather than a read is changing the references in the import section of the program.

Listing 8. TPTP datapool edit imports

        /* NOTE: To update a Datapool the edit version of the classes must be used */
import org.eclipse.hyades.edit.datapool.IDatapool;
import org.eclipse.hyades.edit.datapool.IDatapoolFactory;
//import org.eclipse.hyades.execution.runtime.datapool.IDatapool;
//import org.eclipse.hyades.execution.runtime.datapool.IDatapoolFactory;

The edit classes behave slightly different from the runtime classes. The first notable change is located at the start of the try or catch block, as the example in Listing 9 shows.

Listing 9. TPTP datapool edit instantiation

        try {
// create an org.eclipse.hyades.edit.datapool.IDatapoolFactory object
IDatapoolFactory tptpDatapoolFactory = new Common_DatapoolFactoryImpl();
// create an org.eclipse.hyades.edit.datapool.IDatapool object
IDatapool tptpDatapool = (IDatapool) tptpDatapoolFactory.loadForEdit(
inputTptpFile, true);

When creating the IDatapool object, the file is loaded through the loadForEdit(File, Boolean) method. Also, when creating the IDatapoolIterator, different behavior is found in the edit classes (Listing 10).

Listing 10. TPTP datapool edit iterator

                /* Create an IDatapoolIterator object and populate with the Datapool
*     as an iterator
* NOTE: for edit variations of the IDatapool* objects the IDatapoolFactory
*     must be cast to "Common_DatapoolFactoryImpl" to make the appropriate
* open(IDatapool, String) method visible*/
IDatapoolIterator tptpDatapoolIterator =
((Common_DatapoolFactoryImpl)tptpDatapoolFactory).open(tptpDatapool,
"org.eclipse.hyades.datapool.iterator.DatapoolIteratorSequentialPrivate");

As the comment states, the IDatapoolFactory must be cast to Common_DatapoolFactoryImpl to provide access to the open(IDatapool, String) method. The code snippet in Listing 1 illustrates the capture of a specific cell in the datapool, and then changing the value.

Listing 11. TPTP datapool edit iteration

                for (int i = 0; i < datapoolColumnCount; i++) {
// look for the last column in the Datapool -- to be updated
if (i + 1 == tptpDatapool.getVariableCount()) {
// create a new value
String newCellValue = "Updated value for row " + count +
" at " + dateFormat.format(new Date().getTime());
// capture the cell as an IDatapoolCell
IDatapoolCell aCell = (IDatapoolCell)tptpDatapoolIterator.
dpCurrent().getCell(header[i]);
aCell.setCellValue(newCellValue);
// sleep to demonstrate timestamp update in Datapool
Thread.sleep(1000);
}
nextRow[i] = tptpDatapoolIterator.dpCurrent().
getCell(header[i]).getStringValue();

After processing the datapool, perform a save and unload on the datapool (Listing 12).

Listing 12. TPTP datapool edit finalization

                // save updates to the Datapool file
tptpDatapoolFactory.save(tptpDatapool);
tptpDatapoolFactory.unload(tptpDatapool);

如何使用TPTP中的IDatapool相关推荐

  1. TPTP测试项目的性能

    TPTP 及其各子项目简介 TPTP(Eclipse Test & Performance Tools Platform) 是 Eclipse 基金会下的一个开源子项目,提供了一组基于 Ecl ...

  2. 使用 Eclipse TPTP 测试 Web 应用的方法与扩展

    王 俊华, 软件工程师, IBM 王俊华从事测试自动化工具开发以及 WebSphere Commerce 客户化工作.爱好开源软件.棒球.阅读.音乐. 任 鑫崎, 高级软件工程师, 北京秒针信息咨询有 ...

  3. [Java性能剖析] TPTP性能剖析介绍

    TPTP(Test & Performance Tool Platform)是Eclipse的又一测试/性能剖析的力作,本篇重点关注远程JVM的性能剖析功能.     1.我们先看一下TPTP ...

  4. GNU Make 使用手册(于凤昌中译版)

    GNU Make 使用手册(中译版) 翻译:于凤昌 GNU make Version 3.79 April 2000 Richard M. Stallman and Roland McGrath 1 ...

  5. Eclipse 开源详细介绍

    Eclipse 生态系统非常大,有时候甚至达到了恐怖的地步.Eclipse Foundation 监管着大约 100 个项目,Galileo 只代表那些项目的一个缩影.Galileo 发行版系列展示 ...

  6. 面试:第十二章:所有总结

    Java基础 java基本类型哪些,所占字节 byte :1个字节 short :2个字节 char :2个字节 int :4个字节 long :8个字节 float :4个字节 double :8个 ...

  7. linux内核分析(转自某位大哥网上的笔记)

    启动 当PC启动时,Intel系列的CPU首先进入的是实模式,并开始执行位于地址0xFFFF0处的代码,也就是ROM-BIOS起始位置的代码.BIOS先进行一系列的系统自检,然后初始化位于地址0的中断 ...

  8. ECLIPSE中添加TPTP插件

    转自:http://blog.csdn.net/sinboy/article/details/1536625 程序在实际应用当中,大数据量时对系统本身的影响是一个不得不面对的问题. 最早在使用Jbui ...

  9. 目标检测中召回率(Recall),精确率(Precision),平均正确率(Average_precision(AP) ),交除并(Intersection-over-Union(IoU))

    前言 在训练YOLO v2的过程中,系统会显示出一些评价训练效果的值,如Recall,IoU等等.为了怕以后忘了,现在把自己对这几种度量方式的理解记录一下.  这一文章首先假设一个测试集,然后围绕这一 ...

最新文章

  1. Requests 2.18.1文档
  2. 深入理解Spring Redis的使用 (一)、Spring Redis基本使用
  3. 计算机程序设计vb课后题,《VB程序设计》课后题答案
  4. http发送jsonn报文get/post请求
  5. IO is frozen on database xxx, No user action is required
  6. iPhone:你知道这 13 年我是怎么过的吗?
  7. 如何阻止通过Outlook用户发送WORD或EXCEL变成带Winmail.dat文件附件的邮件
  8. vscode 不支持的客户端_Windows平台上有哪些你不知道的神器?
  9. matlab实现将彩色图像(R,G,B)色分量的直方图匹配,并计算其相关性
  10. ghost还原固态硬盘_固态硬盘到底能不能使用Ghost软件?终于说明白了
  11. JS实现文件的上传与下载
  12. java html加密_能提供加密与解密
  13. 服务器ilo作用,iLO远程管理功能应用
  14. 利用Cydia Substrate Hook移动MM支付
  15. 【网络重置】WLAN消失/网络适配器黄色感叹号/无法识别无线网卡/解决方法汇总/Win10家庭版(个人留档)
  16. Java知识复习清单
  17. mysql 手动写时间_MySQL如何在范围内填写缺失日期?
  18. 微信朋友圈能评论表情包了,来斗图啊!
  19. LabVIEW 调用 BarTender 进行标签打印
  20. 【2023校招刷题】笔试及面试中常考知识点、手撕代码总结

热门文章

  1. 弹性与智能—下一代移动网络系统(RINGS)
  2. 6-1 判断顺序表是否有序(Java语言描述 )
  3. PP-YOLOE论文解析
  4. 云服务器哪家好?云服务器评测对比
  5. 动态规划java实现数塔问题_动态规划入门_数塔问题
  6. 03从变量PS1到centos7配置文件到变量。转义字符介绍
  7. lr背景虚化_【教程】人像后期LR+PS超详细流程+思路分析
  8. ocs_lisence加密
  9. 1. STM32学习 STM32综述
  10. 【新华三】华三设备NTP无法同步