java - 在简单的速度报告中实现递归
问题描述
我正在生成速度报告。我目前遍历一组文档 (ID),对于其中的每一个,我都可以获得一个关系列表。
我想做的是为每个这些 ID 调用相同的函数以查看是否有任何进一步的关系:
我考虑了一个while循环,但后来发现不支持。
## Loop through the selection of documents
#foreach( $vDoc in $documentList )
## for each document obtain a list of all upostream relationships
#foreach($h1 in $relDao.getUpstreamDocumentIds($vDoc.document.id))
## Need recursion in here....
## need to keep getting the upstream IDs until the size is zero and then return that ID
#end
#end
解决方案
这是一种实现速度递归的方法。我们可以使用宏,定义一个宏并递归地使用它和一个基本情况
片段相同。根据要求进行修改。
## ***Call the macro for the first time***
#reportMacro($documentList)
## ***This is the definition of the macro***
#macro(reportMacro $documentList)
{
## Loop through the selection of documents
#foreach( $vDoc in $documentList )
## for each document obtain a list of all upostream relationships
#foreach($h1 in $relDao.getUpstreamDocumentIds($vDoc.document.id))
#if("$h1" != "" && ${h1.size()} > 0)
## ***Recursively call the macro ***
#reportMacro($h1)
#else
this marks end of recursion do some operations here if needed ...
#end
#end
#end
}
#end
推荐阅读
- tableau-api - Tableau,需要从 Sybase 中提取数据以与 SQL Server 合并
- java - Akka 快速入门:发生了非法反射访问操作
- server - Trigger command not working in sign as non-operator
- xslt - 生成现有 XML 文件的副本(不包括匹配几个不同 XPath 表达式的元素)的最干净的方法是什么?
- r - 如何使用 R 获取 Play Store 应用程序的所有评论?
- azure - Azure ARM 模板 DependentOn 文件共享
- javascript - 如何处理两个函数onClick
- python - 直接使用带有偏移别名的 Pandas 日期偏移
- reactjs - React 测试库中的 QuerySelectorAll?
- reactjs - 在 useEffect 中调度使用