[1] | 1 | package agents.anac.y2014.AgentYK;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.List;
|
---|
| 5 | import java.util.NoSuchElementException;
|
---|
| 6 |
|
---|
| 7 | import genius.core.Bid;
|
---|
| 8 | import genius.core.issue.Issue;
|
---|
| 9 |
|
---|
| 10 | public class PairBidElementIterator implements java.util.Iterator<PairBidElement>{
|
---|
| 11 | private Bid bid;
|
---|
| 12 | private List<Integer> issueNrs;
|
---|
| 13 | private int index1,index2;
|
---|
| 14 |
|
---|
| 15 | public PairBidElementIterator(Bid bid) {
|
---|
| 16 | this.bid = new Bid(bid);
|
---|
| 17 | this.issueNrs = new ArrayList<Integer>();
|
---|
| 18 | for(Issue issue:this.bid.getIssues()) {
|
---|
| 19 | this.issueNrs.add(issue.getNumber());
|
---|
| 20 | }
|
---|
| 21 | this.index1 = 0;
|
---|
| 22 | this.index2 = 1;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | @Override
|
---|
| 26 | public boolean hasNext() {
|
---|
| 27 | if(index1 <= (this.issueNrs.size() - 2) && index2 <= (this.issueNrs.size() - 1)) {
|
---|
| 28 | return true;
|
---|
| 29 | } else {
|
---|
| 30 | return false;
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | @Override
|
---|
| 35 | public PairBidElement next() throws NoSuchElementException{
|
---|
| 36 | if(this.hasNext()) {
|
---|
| 37 | int fstIssueNr = this.issueNrs.get(this.index1);
|
---|
| 38 | int sndIssueNr = this.issueNrs.get(this.index2);
|
---|
| 39 | try {
|
---|
| 40 | BidElement fst = new BidElement(fstIssueNr, this.bid.getValue(fstIssueNr));
|
---|
| 41 | BidElement snd = new BidElement(sndIssueNr, this.bid.getValue(sndIssueNr));
|
---|
| 42 | this.index2++;
|
---|
| 43 | if(this.index2 >= this.issueNrs.size()) {
|
---|
| 44 | this.index1++;
|
---|
| 45 | this.index2 = this.index1 + 1;
|
---|
| 46 | }
|
---|
| 47 | return new PairBidElement(fst, snd);
|
---|
| 48 | } catch(Exception e){}
|
---|
| 49 | } else {
|
---|
| 50 | throw new NoSuchElementException();
|
---|
| 51 | }
|
---|
| 52 | return null;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public void remove() throws UnsupportedOperationException {
|
---|
| 57 | throw new UnsupportedOperationException();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | }
|
---|