1 23 24 package org.apache.slide.search; 25 26 import java.util.Comparator ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.Set ; 30 import java.util.SortedSet ; 31 import java.util.TreeSet ; 32 33 42 public class SearchQueryResult { 43 44 public final static int STATUS_OK = 0; 45 public final static int STATUS_BAD_QUERY = 1; 46 public final static int STATUS_INVALID_SCOPE = 2; 47 public final static int STATUS_PARTIAL_RESULT = 3; 48 public final static int STATUS_UNPROCESSABLE_ENTITY = 4; 49 public final static int STATUS_BAD_GATEWAY = 5; 50 public final static int STATUS_FORBIDDEN = 6; 51 52 private int status; 53 private String description; 54 private String href; 55 56 private Set result; 57 63 public void setStatus(int status) { 64 this.status = status; 65 } 66 67 73 public int getStatus() { 74 return status; 75 } 76 77 83 public void setDescription(String description) { 84 this.description = description; 85 } 86 87 93 public String getDescription() { 94 return description; 95 } 96 97 103 public void setHref (String href) { 104 this.href = href; 105 } 106 112 public String getHref () { 113 return href; 114 } 115 116 122 public void add (SearchQueryResult subResultSet) { 123 result.addAll (subResultSet.getResultSet()); 124 } 125 126 130 public SearchQueryResult () { 131 this (null, null); 132 } 133 134 139 public SearchQueryResult (Set result) { 140 this (result, null); 141 } 142 143 147 public SearchQueryResult (Comparator comparator) { 148 this (null, comparator); 149 } 150 151 157 public SearchQueryResult (Set result, Comparator comparator) { 158 if (comparator == null) { 159 if (result == null) 160 this.result = new HashSet (); 161 else 162 this.result = result; 163 } 164 else { 165 this.result = new TreeSet (comparator); 166 if (result != null) 167 this.result.addAll (result); 168 } 169 status = STATUS_OK; 170 description = ""; 171 } 172 173 174 public SearchQueryResult (Set result, Comparator comparator, int limit) { 175 this (result, comparator); 176 if (this.result.size() > limit) { 177 SortedSet tmp = new TreeSet (comparator); 178 Iterator it = this.result.iterator(); 179 for (int i = 0; i < limit; i++) { 180 tmp.add (it.next()); 181 } 182 this.result = tmp; 183 } 184 } 185 186 192 public Iterator iterator () { 193 return result.iterator(); 194 } 195 196 202 Set getResultSet () { 203 return result; 204 } 205 } 206 | Popular Tags |