<commit_before>package joms.geotools.tileapi

import geoscript.geom.Bounds
import geoscript.geom.Geometry
import geoscript.layer.Grid
import geoscript.layer.ImageTile
import geoscript.layer.Tile
import geoscript.layer.TileCursor
import geoscript.layer.TileLayer
import groovy.json.JsonBuilder
import groovy.xml.MarkupBuilder

/**
 * Created by gpotts on 3/18/15.
 */
class TileCacheTileLayerIterator {
   TileLayer layer
   int minLevel
   int maxLevel
   Bounds    bounds

   // gives us an aoi to clip all tiles to
   //
   Geometry regionOfInterest

   private int currentLevel=-1
   private TileCursor tiles

   //private minLevelIndex
   //private maxLevelIndex

   void reset()
   {
      currentLevel = -1
    //  minLevelIndex = 0
    //  maxLevelIndex = (maxLevel-minLevel) + 1
   }
   Bounds getBounds(def z)
   {
      if(!bounds&&regionOfInterest)
      {
         bounds = regionOfInterest.bounds
      }
      if(!bounds)
      {
         tiles = layer.tiles(minLevel);
      }
      else
      {
         tiles = layer.tiles(bounds, minLevel);
      }

      tiles.bounds
   }
   private boolean nextValidLevel()
   {
      boolean result = false

      for(;;)
      {
         if(currentLevel<0) currentLevel=minLevel
         else ++currentLevel

         if(currentLevel <= maxLevel)
         {
            if(!bounds)
            {
               tiles = layer?.tiles(currentLevel);
            }
            else
            {
               tiles = layer?.tiles(bounds, currentLevel);
            }
            if(tiles?.hasNext())
            {
               result = true
               break
            }
         }
         else
         {
            result = false
            break
         }
      }

      result
   }

   Tile nextTile()
   {
      Tile    result = null
<commit_msg>Added empty check while searching levels<commit_after>package joms.geotools.tileapi

import geoscript.geom.Bounds
import geoscript.geom.Geometry
import geoscript.layer.Grid
import geoscript.layer.ImageTile
import geoscript.layer.Tile
import geoscript.layer.TileCursor
import geoscript.layer.TileLayer
import groovy.json.JsonBuilder
import groovy.xml.MarkupBuilder

/**
 * Created by gpotts on 3/18/15.
 */
class TileCacheTileLayerIterator {
   TileLayer layer
   int minLevel
   int maxLevel
   Bounds    bounds

   // gives us an aoi to clip all tiles to
   //
   Geometry regionOfInterest

   private int currentLevel=-1
   private TileCursor tiles

   //private minLevelIndex
   //private maxLevelIndex

   void reset()
   {
      currentLevel = -1
    //  minLevelIndex = 0
    //  maxLevelIndex = (maxLevel-minLevel) + 1
   }
   Bounds getBounds(def z)
   {
      if(!bounds&&regionOfInterest)
      {
         bounds = regionOfInterest.bounds
      }
      if(!bounds)
      {
         tiles = layer.tiles(minLevel);
      }
      else
      {
         tiles = layer.tiles(bounds, minLevel);
      }

      tiles.bounds
   }
   private boolean nextValidLevel()
   {
      boolean result = false

      for(;;)
      {
         if(currentLevel<0) currentLevel=minLevel
         else ++currentLevel

         if(currentLevel <= maxLevel)
         {
            if(!bounds)
            {
               tiles = layer?.tiles(currentLevel);
            }
            else
            {

               tiles = layer?.tiles(bounds, currentLevel);
            }
            if(!tiles?.empty)
            {
               result = true
               break
            }
         }
         else
         {
            result = false
            break
         }
      }

      result
   }

   Tile nextTile()
   {
      Tile    result = null

{'fraction_non_alphanumeric': 0.08176100628930817, 'fraction_numerical': 0.005468963631391851, 'mean_word_length': 1.6184681460272012, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '424618', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1046, 'n_words': 231}