Commit b4af14ab authored by h2b's avatar h2b

Iterating over arbitrary color sequences enabled.

parent 433c5ffd
......@@ -25,10 +25,9 @@ package de.h2b.scala.lib.simgraf
*
* @author h2b
*/
class ColorIterator private (val exclude: Seq[Color]) extends Iterator[Color] {
class ColorIterator private (val colors: Seq[Color]) extends Iterator[Color] {
private val colorSeq = ColorIterator.stdSeq.diff(exclude)
private val n = colorSeq.size
private val n = colors.size
require(n>0, "no colors left to iterate")
......@@ -38,7 +37,7 @@ class ColorIterator private (val exclude: Seq[Color]) extends Iterator[Color] {
def next (): Color = {
i += 1
colorSeq((i-1)%n)
colors((i-1)%n)
}
/**
......@@ -47,7 +46,7 @@ class ColorIterator private (val exclude: Seq[Color]) extends Iterator[Color] {
* Although this iterator is of infinite size, this version of `toSeq`
* terminates and returns the underlying color sequence.
*/
override def toSeq: Seq[Color] = colorSeq
override def toSeq: Seq[Color] = colors
}
......@@ -58,16 +57,31 @@ object ColorIterator {
private val stdSeq = Seq(Black, Blue, Red, Green, Gray, Cyan, Magenta, Yellow,
DarkGray, Orange, Pink, LightGray, White)
@deprecated("use ColorIterator.excluding instead", "SimGraf 1.4.0")
def apply (exclude: Color*): ColorIterator = excluding(exclude: _*)
/**
* Returns an iterator over all colors defined in the `Color` companion object
* except for the ones specified.
* Returns an iterator over all standard colors defined in the `Color`
* companion object except for the ones specified.
*
* Beware, that the resulting color sequence must not be empty.
*
* @param exclude colors to be excluded from the iteration
* @param exclude colors to be excluded from this iteration
* @return a new color iterator over standard colors
* @throws IllegalArgumentException if the resulting color sequence is empty
*/
def apply (exclude: Color*): ColorIterator = new ColorIterator(exclude)
def excluding (exclude: Color*): ColorIterator = {
val colors = ColorIterator.stdSeq.diff(exclude)
new ColorIterator(colors)
}
/**
* Returns an iterator over all specified colors.
*
* @param colors
* @return a new color iterator over specified colors
* @throws IllegalArgumentException if the color sequence is empty
*/
def over (colors: Color*): ColorIterator = new ColorIterator(colors)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment