01: /*
02: * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
03: * Institute of Technology. All rights reserved.
04: *
05: * Redistribution and use in source and binary forms, with or without
06: * modification, are permitted provided that the following conditions are
07: * met:
08: *
09: * - Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: *
12: * - Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * - Neither the name of the Hewlett-Packard Company nor the name of the
17: * Massachusetts Institute of Technology nor the names of their
18: * contributors may be used to endorse or promote products derived from
19: * this software without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32: * DAMAGE.
33: */
34: package org.dspace.checker;
35:
36: import java.util.Collections;
37: import java.util.EmptyStackException;
38: import java.util.List;
39: import java.util.Stack;
40:
41: /**
42: * Really simple dispatcher that just iterates over a pre-defined list of ids.
43: *
44: * @author Jim Downing
45: * @author Grace Carpenter
46: * @author Nathan Sarr
47: *
48: */
49: public class ListDispatcher implements BitstreamDispatcher {
50: /**
51: * List of Integer ids.
52: */
53: Stack bitstreams = new Stack();
54:
55: /**
56: * Blanked off, no-op constructor. Do not use.
57: */
58: private ListDispatcher() {
59: ;
60: }
61:
62: /**
63: * Main constructor.
64: *
65: * @param bitstreamIds
66: * List of Integer ids to dispatch.
67: */
68: public ListDispatcher(List bitstreamIds) {
69: Collections.reverse(bitstreamIds);
70: bitstreams.addAll(bitstreamIds);
71: }
72:
73: /**
74: * @see org.dspace.checker.BitstreamDispatcher#next()
75: */
76: public synchronized int next() {
77: try {
78: return ((Integer) bitstreams.pop()).intValue();
79: } catch (EmptyStackException e) {
80: return SENTINEL;
81: }
82: }
83: }
|