Permalink
Browse files

rolling back again

  • Loading branch information...
1 parent c735539 commit 53e7b32a6492e3dbdddeedb111285e791950b92f @musketyr musketyr committed Aug 30, 2013
Showing with 14 additions and 73 deletions.
  1. +14 −73 core/src/main/groovyx/gaelyk/query/CoercedQueryResultList.java
@@ -1,16 +1,10 @@
package groovyx.gaelyk.query;
-import groovy.lang.Closure;
import groovyx.gaelyk.extensions.DatastoreExtensions;
-import java.io.Serializable;
-import java.util.AbstractList;
-import java.util.Collection;
-import java.util.Comparator;
+import java.util.ArrayList;
import java.util.List;
-import org.codehaus.groovy.runtime.DefaultGroovyMethods;
-
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Index;
@@ -24,21 +18,21 @@
*
* @param <T> coerced class
*/
-class CoercedQueryResultList<T> extends AbstractList<T> implements QueryResultListWithQuery<T>, Serializable {
+class CoercedQueryResultList<T> extends ArrayList<T> implements QueryResultListWithQuery<T> {
- private static final String ERROR_MESSAGE = "You cannot modify this list. Copy the list by calling .collect() method first or use non-mutating version if you want do so";
- private static final long serialVersionUID = 3169182603336643619L;
- private final Query query;
- private final QueryResultList<Entity> originalList;
- private final Class<T> coercedClass;
+ private static final long serialVersionUID = 7330407587796412338L;
+ private final Cursor cursor;
+ private final List<Index> indexList;
+ private final Query query;
private CoercedQueryResultList(Query query, QueryResultList<Entity> originalList, Class<T> coercedClass){
- if(originalList == null) {
- throw new IllegalArgumentException("Original list cannot be null!");
+ super(originalList.size());
+ for (Entity entity : originalList){
+ add(coercedClass.cast(DatastoreExtensions.asType(entity, coercedClass)));
}
- this.query = query;
- this.originalList = originalList;
- this.coercedClass = coercedClass;
+ this.cursor = originalList.getCursor();
+ this.indexList = originalList.getIndexList();
+ this.query = query;
}
/**
@@ -52,68 +46,15 @@ private CoercedQueryResultList(Query query, QueryResultList<Entity> originalList
}
@Override public Cursor getCursor() {
- return originalList.getCursor();
+ return cursor;
}
@Override public List<Index> getIndexList() {
- return originalList.getIndexList();
+ return indexList;
}
@Override public Query getQuery() {
return query;
}
- @Override public T get(int index) {
- return coercedClass.cast(DatastoreExtensions.asType(originalList.get(index), coercedClass));
- }
-
- @Override public int size() {
- return originalList.size();
- }
-
- @Override public T set(int index, T element) {
- throw new UnsupportedOperationException(ERROR_MESSAGE);
- }
-
- @Override public void add(int index, T element) {
- throw new UnsupportedOperationException(ERROR_MESSAGE);
- }
-
- @Override public T remove(int index) {
- throw new UnsupportedOperationException(ERROR_MESSAGE);
- }
-
- public List<T> collect() {
- return DefaultGroovyMethods.collect(this);
- }
-
-
- public Collection<T> unique() {
- return DefaultGroovyMethods.unique(this, false);
- }
-
- public Collection<T> unique(Closure closure) {
- return DefaultGroovyMethods.unique(this, false, closure);
- }
-
- public Collection<T> unique(Comparator<T> comparator) {
- return DefaultGroovyMethods.unique(this, false, comparator);
- }
-
- public List<T> sort() {
- return DefaultGroovyMethods.sort(this, false);
- }
-
- public List<T> sort(Closure closure) {
- return DefaultGroovyMethods.sort(this, false, closure);
- }
-
- public List<T> sort(Comparator<T> comparator) {
- return DefaultGroovyMethods.sort(this, false, comparator);
- }
-
- public List<T> reverse() {
- return DefaultGroovyMethods.reverse(this, false);
- }
-
}

0 comments on commit 53e7b32

Please sign in to comment.