MCPcopy Create free account
hub / github.com/GateNLP/gate-core / iterator

Method iterator

src/main/java/gate/relations/RelationSet.java:536–591  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

534 }
535
536 @Override
537 public Iterator<Relation> iterator() {
538
539 final Set<Relation> copy = new HashSet<Relation>(indexById.values());
540
541 return new Iterator<Relation>() {
542 private Relation nextElement, currentElement;
543
544 private boolean hasNext;
545
546 private Iterator<Relation> iterator = copy.iterator();
547
548 {
549 nextMatch();
550 }
551
552 @Override
553 public boolean hasNext() {
554 return hasNext;
555 }
556
557 @Override
558 public Relation next() {
559 if(!hasNext) {
560 throw new NoSuchElementException();
561 }
562
563 return (currentElement = nextMatch());
564 }
565
566 private Relation nextMatch() {
567 Relation oldMatch = nextElement;
568
569 while(iterator.hasNext()) {
570 Relation o = iterator.next();
571
572 if(indexById.containsValue(o)) {
573 hasNext = true;
574 nextElement = o;
575
576 return oldMatch;
577 }
578 }
579
580 hasNext = false;
581
582 return oldMatch;
583 }
584
585 @Override
586 public void remove() {
587 if(currentElement != null) deleteRelation(currentElement);
588 }
589
590 };
591 }
592
593 @Override

Callers 1

retainAllMethod · 0.95

Calls 3

nextMatchMethod · 0.95
iteratorMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected