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
|
|
16
|
|
17
|
/**
|
18
|
* Iterator implementation used internally be {@link CDMSequenceMatrixAdapter}.
|
19
|
*
|
20
|
* @author Ben Stöver
|
21
|
* @date 29.04.2016
|
22
|
*/
|
23
|
class SequenceIDIterator implements Iterator<String> {
|
24
|
private boolean containsConsensus;
|
25
|
private int singleReadPos;
|
26
|
private int singleReadCount;
|
27
|
|
28
|
|
29
|
/**
|
30
|
* Creates a new instance of this class.
|
31
|
*
|
32
|
* @param singleReadCount the number of single read IDs to be returned by this iterator before the consensus sequence
|
33
|
*/
|
34
|
public SequenceIDIterator(int singleReadCount, boolean containsConsensus) {
|
35
|
super();
|
36
|
this.containsConsensus = containsConsensus;
|
37
|
this.singleReadCount = singleReadCount;
|
38
|
this.singleReadPos = 0;
|
39
|
}
|
40
|
|
41
|
|
42
|
@Override
|
43
|
public boolean hasNext() {
|
44
|
return (singleReadPos < singleReadCount) || (containsConsensus && (singleReadPos <= singleReadCount));
|
45
|
}
|
46
|
|
47
|
|
48
|
@Override
|
49
|
public String next() {
|
50
|
if (singleReadPos < singleReadCount) {
|
51
|
return CDMSequenceMatrixAdapter.SINGLE_READ_SEQUENCE_ID_PREFIX + (singleReadPos++);
|
52
|
}
|
53
|
else if (containsConsensus && (singleReadPos == singleReadCount)) {
|
54
|
singleReadPos++;
|
55
|
return CDMSequenceMatrixAdapter.CONSENSUS_SEQUENCE_ID;
|
56
|
}
|
57
|
else {
|
58
|
throw new NoSuchElementException("There are no more sequence IDs availble from this iterator.");
|
59
|
}
|
60
|
}
|
61
|
|
62
|
|
63
|
@Override
|
64
|
public void remove() {
|
65
|
throw new UnsupportedOperationException("This iterator does not support removing elements.");
|
66
|
}
|
67
|
}
|