~slub.team/goobi-production/bug-1013622

« back to all changes in this revision

Viewing changes to src/de/unigoettingen/sub/commons/util/datasource/ImageSourceIterator.java

  • Committer: Ralf Claussnitzer
  • Date: 2012-05-29 10:55:34 UTC
  • mfrom: (66.1.1 integrate-util)
  • Revision ID: ralf.claussnitzer@slub-dresden.de-20120529105534-t5u5vxj9x5v2vifb
fixes lp:1005844 integrate sub-commons util library

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is a contribution to the the ContentServer project, mainly for research purposes.
 
3
 * 
 
4
 * Copyright 2009, Christian Mahnke<cmahnke@gmail.com>.
 
5
 * 
 
6
 * Licensed under the Apache License, Version 2.0 (the “License”);
 
7
 * you may not use this file except in compliance with the License.
 
8
 * You may obtain a copy of the License at
 
9
 * 
 
10
 *  http://www.apache.org/licenses/LICENSE-2.0
 
11
 * 
 
12
 * Unless required by applicable law or agreed to in writing, software
 
13
 * distributed under the License is distributed on an “AS IS” BASIS,
 
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
 * See the License for the specific language governing permissions and
 
16
 * limitations under the License.
 
17
 */
 
18
 
 
19
package de.unigoettingen.sub.commons.util.datasource;
 
20
 
 
21
import java.io.IOException;
 
22
import java.util.Iterator;
 
23
import java.util.NoSuchElementException;
 
24
 
 
25
//Avoid logger as external dependency here, try to wrap System.out.* streams
 
26
//import org.apache.log4j.Logger;
 
27
 
 
28
public class ImageSourceIterator implements Iterator<Image>, Iterable<Image> {
 
29
        //protected static Logger logger = Logger.getLogger(ImageSourceIterator.class);
 
30
 
 
31
        ImageSource is = null;
 
32
        Integer pageNr = -1;
 
33
 
 
34
        /**
 
35
         * Instantiates a new image source iterator.
 
36
         * 
 
37
         * @param is the ImageSource
 
38
         */
 
39
        public ImageSourceIterator(ImageSource is) {
 
40
                this.is = is;
 
41
        }
 
42
 
 
43
        /* (non-Javadoc)
 
44
         * @see java.util.Iterator#hasNext()
 
45
         */
 
46
        public boolean hasNext() {
 
47
                if (pageNr < is.getNumberOfPages()) {
 
48
                        return true;
 
49
                }
 
50
                return false;
 
51
        }
 
52
 
 
53
        /* (non-Javadoc)
 
54
         * @see java.util.Iterator#next()
 
55
         */
 
56
        public Image next() {
 
57
                pageNr++;
 
58
                if (!hasNext()) {
 
59
                        throw new NoSuchElementException();
 
60
                }
 
61
                
 
62
                try {
 
63
                        return is.getImage(pageNr);
 
64
                } catch (IOException e) {
 
65
                        e.printStackTrace();
 
66
                        return null;
 
67
                }
 
68
        }
 
69
 
 
70
        /* (non-Javadoc)
 
71
         * @see java.util.Iterator#remove()
 
72
         */
 
73
        public void remove() {
 
74
                throw new UnsupportedOperationException();
 
75
        }
 
76
 
 
77
        /* (non-Javadoc)
 
78
         * @see java.lang.Iterable#iterator()
 
79
         */
 
80
        public Iterator<Image> iterator() {
 
81
                return this;
 
82
        }
 
83
}