Created
August 11, 2011 13:23
-
-
Save proppy/1139631 to your computer and use it in GitHub Desktop.
Convert Iterable<Entity> to Entity<Key>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
import com.google.appengine.api.datastore.Entity; | |
import com.google.appengine.api.datastore.Key; | |
public class EntityToKeyIterable implements Iterable<Key> { | |
Iterable<Entity> iterable; | |
public EntityToKeyIterable(Iterable<Entity> iterable) { | |
this.iterable = iterable; | |
} | |
@Override | |
public Iterator<Key> iterator() { | |
return new EntityToKeyIterator(iterable.iterator()); | |
} | |
protected class EntityToKeyIterator implements Iterator<Key> { | |
Iterator<Entity> it; | |
public EntityToKeyIterator(Iterator<Entity> it) { | |
this.it = it; | |
} | |
@Override | |
public boolean hasNext() { | |
return it.hasNext(); | |
} | |
@Override | |
public Key next() { | |
return it.next().getKey(); | |
} | |
@Override | |
public void remove() { | |
it.remove(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment