Low Flying P..
7
支持不同的可能性,
鉴于收藏,
Collection testList = new ArrayList<>();
类型,
class Dto
{
private int id;
private String text;
public int getId()
{
return id;
}
public int getText()
{
return text;
}
}
过滤
Java 7
Filter query = CQ.filter(testList)
.where()
.property("id").eq().value(1);
Collection filtered = query.list();
Java 8
Filter query = CQ.filter(testList)
.where()
.property(Dto::getId)
.eq().value(1);
Collection filtered = query.list();
也,
Filter query = CQ.filter()
.from(testList)
.where()
.property(Dto::getId).between().value(1).value(2)
.and()
.property(Dto::grtText).in().value(new string[]{"a","b"});
排序(也适用于Java 7)
Filter query = CQ.filter(testList)
.orderBy()
.property(Dto::getId)
.property(Dto::getName)
Collection sorted = query.list();
分组(也适用于Java 7)
GroupQuery query = CQ.query(testList)
.group()
.groupBy(Dto::getId)
Collection> grouped = query.list();
连接(也可用于Java 7)
鉴于,
class LeftDto
{
private int id;
private String text;
public int getId()
{
return id;
}
public int getText()
{
return text;
}
}
class RightDto
{
private int id;
private int leftId;
private String text;
public int getId()
{
return id;
}
public int getLeftId()
{
return leftId;
}
public int getText()
{
return text;
}
}
class JoinedDto
{
private int leftId;
private int rightId;
private String text;
public JoinedDto(int leftId,int rightId,String text)
{
this.leftId = leftId;
this.rightId = rightId;
this.text = text;
}
public int getLeftId()
{
return leftId;
}
public int getRightId()
{
return rightId;
}
public int getText()
{
return text;
}
}
Collection leftList = new ArrayList<>();
Collection rightList = new ArrayList<>();
可以加入像,
Collection results = CQ.query().from(leftList)
.innerJoin(CQ.query().from(rightList))
.on(LeftFyo::getId, RightDto::getLeftId)
.transformDirect(selection -> new JoinedDto(selection.getLeft().getText()
, selection.getLeft().getId()
, selection.getRight().getId())
)
.list();
表达式
Filter query = CQ.filter()
.from(testList)
.where()
.exec(s -> s.getId() + 1).eq().value(2);