1 19 20 package org.apache.cayenne.util; 21 22 import java.io.Serializable ; 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.List ; 26 27 import org.apache.cayenne.QueryResponse; 28 29 35 public class ListResponse implements QueryResponse, Serializable { 36 37 protected List objectList; 38 39 protected transient int currentIndex; 40 41 44 public ListResponse() { 45 this.objectList = new ArrayList (1); 46 } 47 48 public ListResponse(Object object) { 49 this.objectList = Collections.singletonList(object); 50 } 51 52 public ListResponse(List objectList) { 53 this.objectList = objectList; 54 } 55 56 public int size() { 57 return 1; 58 } 59 60 public boolean isList() { 61 if (currentIndex != 1) { 62 throw new IndexOutOfBoundsException ("Past iteration end: " + currentIndex); 63 } 64 65 return true; 66 } 67 68 public List currentList() { 69 if (currentIndex != 1) { 70 throw new IndexOutOfBoundsException ("Past iteration end: " + currentIndex); 71 } 72 73 return objectList; 74 } 75 76 public int[] currentUpdateCount() { 77 throw new IllegalStateException ("Current object is not an update count"); 78 } 79 80 public boolean next() { 81 return ++currentIndex <= 1; 82 } 83 84 public void reset() { 85 currentIndex = 0; 87 } 88 89 public List firstList() { 90 return objectList; 91 } 92 93 public int[] firstUpdateCount() { 94 return new int[0]; 95 } 96 } 97 | Popular Tags |