All Downloads are FREE. Search and download functionalities are using the official Maven repository.

overflowdb.DummyEdgeIterator Maven / Gradle / Ivy

There is a newer version: 1.115
Show newest version
package overflowdb;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class DummyEdgeIterator implements Iterator {
  private final Object[] array;
  private int current;
  private final int begin;
  private final int exclusiveEnd;
  private final int strideSize;
  private final Direction direction;
  private final String label;
  private final NodeRef thisRef;

  public DummyEdgeIterator(Object[] array, int begin, int exclusiveEnd, int strideSize,
                           Direction direction, String label, NodeRef thisRef) {
    this.array = array;
    this.begin = begin;
    this.current = begin;
    this.exclusiveEnd = exclusiveEnd;
    this.strideSize = strideSize;
    this.direction = direction;
    this.label = label;
    this.thisRef = thisRef;
  }

  @Override
  public boolean hasNext() {
    /* there may be holes, e.g. if an edge was removed */
    while (current < exclusiveEnd && array[current] == null) {
      current += strideSize;
    }
    return current < exclusiveEnd;
  }

  @Override
  public OdbEdge next() {
    if (!hasNext()) throw new NoSuchElementException();

    NodeRef otherRef = (NodeRef) array[current];
    OdbEdge dummyEdge;
    if (direction == Direction.OUT) {
      dummyEdge = thisRef.get().instantiateDummyEdge(label, thisRef, otherRef);
      dummyEdge.setOutBlockOffset(current - begin);
    } else {
      dummyEdge = thisRef.get().instantiateDummyEdge(label, otherRef, thisRef);
      dummyEdge.setInBlockOffset(current - begin);
    }
    current += strideSize;
    return dummyEdge;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy