/src/com/google/appengine/datanucleus/query/StreamingMergeJoinResult.java

http://datanucleus-appengine.googlecode.com/ · Java · 77 lines · 36 code · 12 blank · 29 comment · 1 complexity · 04ebf8e23985ed6fe405dbfaaffc0d91 MD5 · raw file

  1. /**********************************************************************
  2. Copyright (c) 2009 Google Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. **********************************************************************/
  13. package com.google.appengine.datanucleus.query;
  14. import com.google.appengine.api.datastore.Entity;
  15. import com.google.appengine.datanucleus.Utils;
  16. import java.util.AbstractList;
  17. import java.util.Iterator;
  18. import java.util.ListIterator;
  19. import java.util.NoSuchElementException;
  20. /**
  21. * An {@link AbstractList} implementation that streams merge join entity results.
  22. *
  23. * @author Max Ross <maxr@google.com>
  24. */
  25. class StreamingMergeJoinResult extends AbstractList<Entity> {
  26. /** Delegate for lazy loading of results. */
  27. private final LazyResult<Entity> lazyResult;
  28. /**
  29. * Constructs a StreamingMergeJoinResult.
  30. * @param lazyEntities The result of the query.
  31. */
  32. public StreamingMergeJoinResult(Iterable<Entity> lazyEntities) {
  33. this.lazyResult = new LazyResult<Entity>(lazyEntities, Utils.<Entity>identity(), false);
  34. }
  35. @Override
  36. public boolean equals(Object o) {
  37. return this == o;
  38. }
  39. @Override
  40. public Entity get(int index) {
  41. return lazyResult.get(index);
  42. }
  43. /**
  44. * @throws NoSuchElementException if there are no more elements
  45. * to resolve.
  46. */
  47. void resolveNext() {
  48. lazyResult.resolveNext();
  49. }
  50. @Override
  51. public Iterator<Entity> iterator() {
  52. return lazyResult.listIterator();
  53. }
  54. @Override
  55. public ListIterator<Entity> listIterator() {
  56. return lazyResult.listIterator();
  57. }
  58. @Override
  59. public int size() {
  60. return lazyResult.size();
  61. }
  62. }