interface Processable<E>
{
public E first();
public E last();
public List<E> processables();
public E get(int index);
}
所以,我想要做的就是這 這裏是一個什麼樣的查詢應該做擴展和實現接口
final WidgetItem item = Inventory.select().identify("Bones").note().first();
class Query: ObjectQuery, Processable<E>
{
public E
}
}
一個例子,但有錯誤在 「E」
我試圖做的,但在Java中
public abstract class Query<E, Q extends Query<E, Q>> implements Processable<E> {
private final List<Filter<E>> filters;
public Query() {
this.filters = new LinkedList<>();
}
@SafeVarargs
public final Q filter(final Filter<E>... filters) {
Collections.addAll(this.filters, filters);
return (Q) this;
}
protected final Filter<E> notThat(final Filter<E> filter) {
return new Filter<E>() {
@Override
public boolean accepts(final E e) {
return !filter.accepts(e);
}
};
}
/**
* @param e
* the element
* @return true if all of the filters accepted the element
*/
public final boolean accepts(final E e) {
for (final Filter<E> filter : filters) {
if (!filter.accepts(e))
return false;
}
return true;
}
/**
* @return a List of elements after filtering them all
*/
public final List<E> all() {
final List<E> processables = processables();
final ListIterator<E> iterator = processables.listIterator();
while (iterator.hasNext()) {
if (!accepts(iterator.next()))
iterator.remove();
}
return processables;
}
public final E first() {
final List<E> all = processables();
return all.size() > 0 ? all.get(0) : null;
}
public final E last() {
final List<E> all = processables();
final int idx = all.size() - 1;
return idx >= 0 ? all.get(idx) : null;
}
public final E get(final int index) {
final List<E> all = processables();
return all.size() > index ? all.get(index) : null;
}
}
此外,我收到一個錯誤,列出所有= IProcessable;這是列表
您的接口方法需要丟失「public」訪問器。 – 2015-01-21 02:37:17