1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.api.criteria;
17
18 import org.apache.commons.lang.builder.EqualsBuilder;
19 import org.apache.commons.lang.builder.HashCodeBuilder;
20 import org.apache.commons.lang.builder.ToStringBuilder;
21 import org.kuali.rice.core.api.mo.ModelBuilder;
22 import org.kuali.rice.core.api.mo.ModelObjectComplete;
23
24 import java.io.Serializable;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28
29 public final class GenericQueryResults<T> implements QueryResults<T> {
30
31 private final List<T> results;
32 private final Integer totalRowCount;
33 private final boolean moreResultsAvailable;
34
35 private GenericQueryResults(Builder<T> builder) {
36 this.results = builder.getResults() != null ? Collections.unmodifiableList(new ArrayList<T>(builder.getResults())) : Collections.<T>emptyList();
37 this.totalRowCount = builder.getTotalRowCount();
38 this.moreResultsAvailable = builder.isMoreResultsAvailable();
39 }
40
41 @Override
42 public List<T> getResults() {
43 return results;
44 }
45
46 @Override
47 public Integer getTotalRowCount() {
48 return totalRowCount;
49 }
50
51 @Override
52 public boolean isMoreResultsAvailable() {
53 return moreResultsAvailable;
54 }
55
56 @Override
57 public int hashCode() {
58 return HashCodeBuilder.reflectionHashCode(this);
59 }
60
61 @Override
62 public boolean equals(Object obj) {
63 return EqualsBuilder.reflectionEquals(obj, this);
64 }
65
66 @Override
67 public String toString() {
68 return ToStringBuilder.reflectionToString(this);
69 }
70
71 public static final class Builder<T> implements ModelBuilder, QueryResults<T>, Serializable {
72
73 private List<T> results;
74 private Integer totalRowCount;
75 private boolean moreResultsAvailable;
76
77 public static <T> Builder create() {
78 return new Builder<T>();
79 }
80
81 private Builder() {
82 this.results = new ArrayList<T>();
83 this.moreResultsAvailable = false;
84 }
85
86 @Override
87 public GenericQueryResults<T> build() {
88 return new GenericQueryResults<T>(this);
89 }
90
91 public List<T> getResults() {
92 return this.results;
93 }
94
95 public void setResults(List<T> results) {
96 if (results == null) {
97 throw new IllegalArgumentException("results is null");
98 }
99
100 this.results = Collections.unmodifiableList(new ArrayList<T>(results));
101 }
102
103 public Integer getTotalRowCount() {
104 return this.totalRowCount;
105 }
106
107 public void setTotalRowCount(Integer totalRowCount) {
108 if (totalRowCount != null && totalRowCount < 0) {
109 throw new IllegalArgumentException("totalRowCount < 0");
110 }
111
112 this.totalRowCount = totalRowCount;
113 }
114
115 public boolean isMoreResultsAvailable() {
116 return this.moreResultsAvailable;
117 }
118
119 public void setMoreResultsAvailable(boolean moreResultsAvailable) {
120 this.moreResultsAvailable = moreResultsAvailable;
121 }
122 }
123 }