Mittwoch, 29. Oktober 2014

How to create a simple Java Builder with help of Notepad ++ regexp

1. copy member:
private int id;
private String comment;
private String targetId;
private String targetName;
private String targetSource;
private String tool;
private String action;
private Date time;

2. Run this Search/Replace in Notepad++
Search:
\S+ (\S+) (\S)(\S+);
Replace:
public LogActionBuilder \2\3 \(\1 \2\3\) { this.logAction.set\U\2\E\3\(\2\3\); return this;}



Create a nice and fluent builder:

public LogActionBuilder id(int id) {
this.logAction.setId(id);
return this;
}

public LogActionBuilder comment(String comment) {
this.logAction.setComment(comment);
return this;
}