Skip to content

Instantly share code, notes, and snippets.

@fge
Created March 3, 2013 21:40
Show Gist options
  • Select an option

  • Save fge/5078434 to your computer and use it in GitHub Desktop.

Select an option

Save fge/5078434 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2013, Francis Galiegue <fgaliegue@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Lesser GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.fge.jsonschema;
import java.util.NoSuchElementException;
final class IntegerRange
extends Range<Integer>
{
private final int to;
private final int step;
private int next;
IntegerRange(final int from, final int to, final int step)
{
this.to = to;
this.step = step;
next = from;
}
@Override
public boolean hasNext()
{
return next <= to;
}
@Override
public Integer next()
{
if (!hasNext())
throw new NoSuchElementException();
final int ret = next;
next += step;
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment