我想为非回归测试提供差异报告.我的程序是基于Java的,但我没有发现任何API满足我的需求.
所以我使用的是一个外部工具(CSDiff),它将2个文件作为参数并返回HTML报告.这很好,很容易设置.
现在我唯一的问题是HTML报告需要使用一些调整,我正在搞乱报告,尝试将其转换为不同的东西(隐藏一些部分,改变样式,......)
有人知道具有强大命令行支持的diff工具,允许生成自定义报告吗?不错的报告选项将是2个窗格视图,正则表达式过滤,简单的样式选项...类似于HTML中的vim diff视图会很棒.
我已经在stackoverflow中阅读了有关diff工具的内容,但我找不到我正在寻找的东西.
非常感谢
我想使用一个使用泛型参数的方法,并在类层次结构上返回泛型结果.
编辑:没有 SupressWarnings("未选中")答案允许:-)
这是一个说明我的问题的示例代码:
import java.util.*;
public class GenericQuestion {
interface Function<F, R> {R apply(F data);}
static class Fruit {int id; String name; Fruit(int id, String name) {
this.id = id; this.name = name;}
}
static class Apple extends Fruit {
Apple(int id, String type) { super(id, type); }
}
static class Pear extends Fruit {
Pear(int id, String type) { super(id, type); }
}
public static void main(String[] args) {
List<Apple> apples = Arrays.asList(
new Apple(1,"Green"), new …Run Code Online (Sandbox Code Playgroud) 我正在使用Vaadin框架,它对截取事件的支持很少,我不知道会话或UI何时被激活,所以我不能将它们的ID放在MDC中.
通常我会:
public void onSessionBegin(){
MDC.put("session", VaadinSession.getCurrent().toString()); //<-- String is immutable
}
public void onSessionEnd(){
MDC.remove("session");
}
Run Code Online (Sandbox Code Playgroud)
但我没有这样的事件,所以我想:
// in the servlet init or wherever
MDC.put("session", new Object(){
public String toString() {
VaadinSession.getCurrent().toString()
};
}); //<-- This is mutable and will be evaluated each time
Run Code Online (Sandbox Code Playgroud)
这样,无论多少时间都会改变会话,在日志中我会得到当前的一个.
这可能吗?如何使用自定义MDC实现替换logback MDC实现?我应该编辑slf4j和logback的来源吗?
在 J2EE 应用程序中,我们在 weblogic 中使用 EJB2。
为了避免浪费时间构建初始上下文和查找 EJB Home 接口,我正在考虑服务定位器模式。
但在网络上进行了一些搜索后,我发现即使这种模式经常被推荐用于 InitialContext 缓存,但对于 EJB Home 缓存也存在一些负面意见。
问题:
我有一个闭包来查找名称与模式匹配并包含给定String的所有文件:
def path = "path/to/logs"
def namePatten = ~/.*.log/
def contentPattern ~/.*ERROR.*/
def result = []
new File(path).eachDirRecurse { File dir ->
dir.eachFileMatch(namePattern) { File f ->
f.eachLine { String l ->
if(l.matches(contentPattern)) {
result.add(f)
return
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我很确定我可以有更短的东西(嘿,否则我可以使用普通的java :))
我试图找到一种方法来写这个有点像:
result = new File(path).eachFileRecurse.filter(filePattern).grep(contentPattern)
正如我将使用番石榴或类似的流畅的界面收集工具.
你是如何以简洁但仍然可读的方式编写这个闭包的?
我需要 Kotlin 中的一个集合来仅包含实现给定接口的元素。
例如:包含动物集合的地图:
interface Animal { val name: String }
data class Monkey(override val name: String): Animal
data class Snake(override val name: String): Animal
Run Code Online (Sandbox Code Playgroud)
从阅读的文档和博客做题,我写了这个代码,使用泛型的关键字:
class Test {
private val data = HashMap<String, ArrayList<in Animal>>()
init {
data.put("Monkeys", arrayListOf(Monkey("Kong"), Monkey("Cheetah")))
data.put("Snakes", arrayListOf(Snake("Monthy"), Snake("Kaa")))
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想在 Test 类中添加一个方法来读取“数据”的内容,例如将其打印到控制台:
fun printAll() {
data.forEach { collectionName: String, animals: ArrayList<in Animal> ->
println(collectionName)
animals.forEach { animal: Animal ->
println("\t$animal")
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我有一个编译错误:
Error:(27, 21) Kotlin: Type inference failed: Cannot …Run Code Online (Sandbox Code Playgroud) 有没有人知道如何在intellij中设置一个实时模板来做专门的setter - 我正在使用v5,但我很乐意接受更新版本的知识) -
我的第一个需求是firePropertyChange setter:
public final static String $PROPERTY$ = "$property$"
public void set$Property$($TYPE$ $property$) {
Object oldValue = this.$property$;
this.$property$ = $property$;
firePropertyChange($PROPERTY$, oldValue, $property$);
}
Run Code Online (Sandbox Code Playgroud)
我有一个半工作版本,使用如下定义的变量生成实现:$ property $ - > completeSmart()$ PROPERTY $ - > completeSmart()
我的第二个需求是一个构建器样式的setter,它调用常规setter然后在set之后返回:
public $THIS_TYPE$ with$Property$($TYPE$ $property$) {
set$Property$($property$);
return this;
}
Run Code Online (Sandbox Code Playgroud)
对于这个我没有什么好的东西:我仍然需要打字很多!
有什么建议吗?
在一个小型的Java swing 2D游戏中,创建棋盘视图的最佳解决方案是什么?
我知道这是主观的,我不想打架.我只需要一些线索来弄清楚自己应该走哪条路.我已经开始了一个侧面项目,我已经使用了1),感觉有些不对劲.
使用maven1,我使用extend标签告诉我的孩子项目使用他们的父配置.
在父项中声明的所有依赖项都可用于扩展(子项)项目.
现在使用maven2我正在使用继承/组合功能,我必须在每个子项目中重新声明我的依赖项(减去版本号).(参见how-to-share-common-properties-among-maven-projects)
有没有办法告诉maven我想在所有孩子中分享我的一些依赖?
我正在使用Spring框架,我不知道如何做这个简单的事情:我想为bean提供一个String,字符串是多个部分,一些固定和其他变量串联的结果
例如,它可能是这样的:
"myReportFile_20102101_1832.txt"
- 第一部分是固定部分 - 第二部分是具有当前日期时间的时间戳 - 最后一部分是另一个固定部分
如何用最简单的方法实现这一目标?
非常感谢.