The following for is equivalent, but adding the logic tests around it
Query query = new Query();
if (form.getType() != null) {
query.addCriteria(Criteria.where("type")
.is(form.getType());
}
if (form.getMinBedrooms() != 0) {
query.addCriteira(Criteria.where("bedrooms")
.is(form.getMinBedRooms())
}
And so on. So just work with the Query object and add your conditions.