https://code.google.com/p/joquery/
Поддерживает различные возможности,
Данная коллекция
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);