Merge branch 'release/4.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.molecular / src / main / java / eu / etaxonomy / taxeditor / molecular / io / SequenceIDIterator.java
1 // $Id$
2 /**
3 * Copyright (C) 2016 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.molecular.io;
11
12 import java.util.Iterator;
13 import java.util.NoSuchElementException;
14
15 import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
16
17
18
19 /**
20 * Iterator implementation used internally be {@link CDMSequenceMatrixAdapter}.
21 *
22 * @author Ben Stöver
23 * @date 29.04.2016
24 */
25 class SequenceIDIterator implements Iterator<String> {
26 private boolean containsConsensus;
27 private int singleReadPos;
28 private int singleReadCount;
29
30
31 /**
32 * Creates a new instance of this class.
33 *
34 * @param singleReadCount the number of single read IDs to be returned by this iterator before the consensus sequence
35 */
36 public SequenceIDIterator(int singleReadCount, boolean containsConsensus) {
37 super();
38 this.containsConsensus = containsConsensus;
39 this.singleReadCount = singleReadCount;
40 this.singleReadPos = 0;
41 }
42
43
44 @Override
45 public boolean hasNext() {
46 return (singleReadPos < singleReadCount) || (containsConsensus && (singleReadPos <= singleReadCount));
47 }
48
49
50 @Override
51 public String next() {
52 if (singleReadPos < singleReadCount) {
53 return CDMSequenceMatrixAdapter.SINGLE_READ_SEQUENCE_ID_PREFIX + (singleReadPos++);
54 }
55 else if (containsConsensus && (singleReadPos == singleReadCount)) {
56 singleReadPos++;
57 return CDMSequenceMatrixAdapter.CONSENSUS_SEQUENCE_ID;
58 }
59 else {
60 throw new NoSuchElementException(Messages.SequenceIDIterator_NO_MORE_SEQUENCES);
61 }
62 }
63
64
65 @Override
66 public void remove() {
67 throw new UnsupportedOperationException(Messages.SequenceIDIterator_REMOVE_NOT_SUPPORTED);
68 }
69 }