1 40 package org.dspace.browse; 41 42 import org.dspace.content.Collection; 43 import org.dspace.content.Community; 44 import org.dspace.content.Item; 45 import org.dspace.core.Context; 46 47 80 public class BrowseScope implements Cloneable 81 { 82 83 private Context context; 84 85 86 private Object scope; 87 88 89 private Object focus; 90 91 92 private int total; 93 94 95 private int numberBefore; 96 97 99 100 private int browseType; 101 102 103 private boolean ascending; 104 105 106 private Boolean sort; 107 108 121 public BrowseScope(Context context) 122 { 123 this.context = context; 124 scope = null; 125 focus = null; 126 total = 21; 127 numberBefore = 3; 128 } 129 130 133 public Object clone() 134 { 135 BrowseScope clone = new BrowseScope(context); 136 137 clone.scope = scope; 138 clone.focus = focus; 139 clone.total = total; 140 clone.numberBefore = numberBefore; 141 clone.browseType = browseType; 142 clone.ascending = ascending; 143 clone.sort = sort; 144 145 return clone; 146 } 147 148 151 public void setScopeAll() 152 { 153 scope = null; 154 } 155 156 162 public void setScope(Community community) 163 { 164 scope = community; 165 } 166 167 173 public void setScope(Collection collection) 174 { 175 scope = collection; 176 } 177 178 188 public void setFocus(Item item) 189 { 190 focus = item; 191 } 192 193 202 public void setFocus(String value) 203 { 204 focus = value.toLowerCase(); 205 } 206 207 218 public void setFocus(int item_id) 219 { 220 focus = new Integer (item_id); 221 } 222 223 226 public void noFocus() 227 { 228 focus = null; 229 } 230 231 237 public void setTotal(int n) 238 { 239 total = n; 240 } 241 242 245 public void setTotalAll() 246 { 247 setTotal(-1); 248 } 249 250 256 public void setNumberBefore(int n) 257 { 258 this.numberBefore = n; 259 } 260 261 265 270 public Context getContext() 271 { 272 return context; 273 } 274 275 280 public Object getScope() 281 { 282 return scope; 283 } 284 285 291 public Object getFocus() 292 { 293 return focus; 294 } 295 296 302 public int getTotal() 303 { 304 return total; 305 } 306 307 312 public int getNumberBefore() 313 { 314 return numberBefore; 315 } 316 317 321 public boolean hasNoLimit() 322 { 323 return total == -1; 324 } 325 326 329 public boolean hasFocus() 330 { 331 return focus != null; 332 } 333 334 338 341 boolean focusIsItem() 342 { 343 return (focus instanceof Item) || (focus instanceof Integer ); 344 } 345 346 349 boolean focusIsString() 350 { 351 return (focus instanceof String ); 352 } 353 354 357 int getFocusItemId() 358 { 359 if (!focusIsItem()) 360 { 361 throw new IllegalArgumentException ("Focus is not an Item"); 362 } 363 364 if (focus instanceof Integer ) 365 { 366 return ((Integer ) focus).intValue(); 367 } 368 369 return ((Item) focus).getID(); 370 } 371 372 375 String getFocusValue() 376 { 377 return (String ) focus; 378 } 379 380 383 boolean isCollectionScope() 384 { 385 if (scope == null) 386 { 387 return false; 388 } 389 390 return scope instanceof Collection; 391 } 392 393 396 boolean isCommunityScope() 397 { 398 if (scope == null) 399 { 400 return false; 401 } 402 403 return scope instanceof Community; 404 } 405 406 409 boolean isAllDSpaceScope() 410 { 411 return scope == null; 412 } 413 414 418 421 int getBrowseType() 422 { 423 return browseType; 424 } 425 426 void setBrowseType(int type) 427 { 428 browseType = type; 429 } 430 431 435 Boolean getSortByTitle() 436 { 437 return sort; 438 } 439 440 void setSortByTitle(Boolean s) 441 { 442 this.sort = s; 443 } 444 445 449 boolean getAscending() 450 { 451 return ascending; 452 } 453 454 void setAscending(boolean a) 455 { 456 this.ascending = a; 457 } 458 459 468 public boolean equals(Object obj) 469 { 470 if (!(obj instanceof BrowseScope)) 471 { 472 return false; 473 } 474 475 BrowseScope other = (BrowseScope) obj; 476 477 return _equals(scope, other.scope) && _equals(focus, other.focus) 478 && _equals(sort, other.sort) && (total == other.total) 479 && (browseType == other.browseType) 480 && (ascending == other.ascending) 481 && (numberBefore == other.numberBefore); 482 } 483 484 private boolean _equals(Object first, Object second) 485 { 486 if ((first == null) && (second == null)) 487 { 488 return true; 489 } 490 491 if ((first != null) && (second == null)) 492 { 493 return false; 494 } 495 496 if ((first == null) && (second != null)) 497 { 498 return false; 499 } 500 501 return first.equals(second); 502 } 503 504 507 public int hashCode() 508 { 509 return new StringBuffer ().append(scope).append(focus).append(total) 510 .append(numberBefore).append(browseType).append(ascending) 511 .append(sort).toString().hashCode(); 512 } 513 } 514 | Popular Tags |