Package ch.hsr.geohash.util

Source Code of ch.hsr.geohash.util.BoundingBoxGeoHashIterator

package ch.hsr.geohash.util;

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

import ch.hsr.geohash.GeoHash;

/**
* Iterate over all of the values within a bounding box at a particular
* resolution
*/
public class BoundingBoxGeoHashIterator implements Iterator<GeoHash> {
  private TwoGeoHashBoundingBox boundingBox;
  private GeoHash current;

  public BoundingBoxGeoHashIterator(TwoGeoHashBoundingBox bbox) {
    this.boundingBox = bbox;
    this.current = bbox.getBottomLeft();
  }

  public TwoGeoHashBoundingBox getBoundingBox() {
    return boundingBox;
  }

  @Override
  public boolean hasNext() {
    return current.compareTo(boundingBox.getTopRight()) <= 0;
  }

  @Override
  public GeoHash next() {
    GeoHash rv = current;
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    current = rv.next();
    while (hasNext() && !boundingBox.getBoundingBox().contains(current.getPoint())) {
      current = current.next();
    }
    return rv;
  }

  @Override
  public void remove() {
    throw new UnsupportedOperationException();
  }
}
TOP

Related Classes of ch.hsr.geohash.util.BoundingBoxGeoHashIterator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.