重复使用一种嵌套的前路的方法,该方法仅在内部循环中与某些线路不同
我有一种基本上看起来像这样的Java方法:
public static Map<String, List<MyObject>> myMappingMethod(List<A> listOfA, List<B> listOfB) {
final Map<String, List<MyObject>> results = new HashMap<>();
for (A objA : listOfA) {
if (!objA.meetsSomeCriteria()) {
continue;
}
for (B objB : listOfB) {
if (!objB.meetsSomeCriteria()) {
continue;
}
createFileWithIntermediateResultsFrom(objA, objB); // <-- seldomly needed
// create new List<MyObject> from objA and objB and add to results
}
}
return results;
}
现在我想基本上重复此方法,并忽略createfilewithintermediaTereSultsultsfrom(obja,objb);
部分原因通常不需要(我都不需要(但是可以)将其取出,因为它需要大约1%)。
如何避免复制并粘贴一行删除,也避免引入某种“调试” - 参数?
(如果可能的话,我不想将签名更改为myMappingMethod(list&lt&lt ; a&gt; list&lt; b&gt;
I have a java method that basically looks like this:
public static Map<String, List<MyObject>> myMappingMethod(List<A> listOfA, List<B> listOfB) {
final Map<String, List<MyObject>> results = new HashMap<>();
for (A objA : listOfA) {
if (!objA.meetsSomeCriteria()) {
continue;
}
for (B objB : listOfB) {
if (!objB.meetsSomeCriteria()) {
continue;
}
createFileWithIntermediateResultsFrom(objA, objB); // <-- seldomly needed
// create new List<MyObject> from objA and objB and add to results
}
}
return results;
}
Now I want to basically duplicate this method and leave out the the createFileWithIntermediateResultsFrom(objA, objB);
part cause usually I don't need that (but can't take it out, cause it is needed for like 1 %).
How to avoid copy&paste with one line deletion and also avoid introducing some kind of "debug"-parameter?
(If possible, I don't want to change the signature to myMappingMethod(List<A> listOfA, List<B> listOfB, boolean createDbgFile)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论