package org.sonar.plugins.switchoffviolations.pattern;

import com.google.common.collect.Sets;

import java.util.Set;

/**
 * 
 */
public class LineRange {
  int from, to;

  public LineRange(int from, int to) {
    if (to < from) {
      throw new IllegalArgumentException("Line range is not valid: " + from + " must be greater than " + to);
    }
    this.from = from;
    this.to = to;
  }

  // SONAR-OFF
  public boolean in(int lineId) {
    return from <= lineId && lineId <= to;
  }
  // FOO-OFF

  public Set<Integer> toLines() {
    Set<Integer> lines = Sets.newLinkedHashSet();
    // SONAR-ON
    for (int index = from; index <= to; index++) {
      lines.add(index);
    }
    // FOO-ON
    return lines;
  }

}