// Path: src/main/java/org/sonar/plugins/stash/StashPlugin.java
// public enum IssueType {
//   CONTEXT,
//   REMOVED,
//   ADDED,
// }


import com.google.common.collect.Range;
import java.util.Collections;
import java.util.Objects;
import java.util.ArrayList;
import java.util.List;
import org.sonar.plugins.stash.StashPlugin.IssueType;

package org.sonar.plugins.stash.issue;



/**
 * This class is a representation of the Stash Diff view.
 * <p>
 * Purpose is to check if a SonarQube issue belongs to the Stash diff view before posting.
 * Indeed, Stash Diff view displays only comments which belong to this view.
 */
public class StashDiffReport {

  public static final int VICINITY_RANGE_NONE = 0;

  private List<StashDiff> diffs;

  public StashDiffReport() {
    this.diffs = new ArrayList<>();
  }

  public List<StashDiff> getDiffs() {
    return Collections.unmodifiableList(diffs);
  }

  public void add(StashDiff diff) {
    diffs.add(diff);
  }

  public void add(StashDiffReport report) {
    diffs.addAll(report.getDiffs());
  }

  private static boolean inVicinityOfChangedDiff(StashDiff diff, long destination, int range) {
    if (range <= 0) {
      return false;
    }
    long lower = Math.min(diff.getSource(), diff.getDestination());
    long upper = Math.max(diff.getSource(), diff.getDestination());
    return Range.closed(lower - range, upper + range).contains(destination);
  }

  private static boolean isChangedDiff(StashDiff diff, long destination) {
    return diff.getDestination() == destination;
  }

  private static boolean lineIsChangedDiff(StashDiff diff) {

// Path: src/main/java/org/sonar/plugins/stash/StashPlugin.java
// public enum IssueType {
//   CONTEXT,
//   REMOVED,
//   ADDED,
// }


// Path: src/main/java/org/sonar/plugins/stash/issue/StashDiffReport.java
import com.google.common.collect.Range;
import java.util.Collections;
import java.util.Objects;
import java.util.ArrayList;
import java.util.List;
import org.sonar.plugins.stash.StashPlugin.IssueType;

package org.sonar.plugins.stash.issue;



/**
 * This class is a representation of the Stash Diff view.
 * <p>
 * Purpose is to check if a SonarQube issue belongs to the Stash diff view before posting.
 * Indeed, Stash Diff view displays only comments which belong to this view.
 */
public class StashDiffReport {

  public static final int VICINITY_RANGE_NONE = 0;

  private List<StashDiff> diffs;

  public StashDiffReport() {
    this.diffs = new ArrayList<>();
  }

  public List<StashDiff> getDiffs() {
    return Collections.unmodifiableList(diffs);
  }

  public void add(StashDiff diff) {
    diffs.add(diff);
  }

  public void add(StashDiffReport report) {
    diffs.addAll(report.getDiffs());
  }

  private static boolean inVicinityOfChangedDiff(StashDiff diff, long destination, int range) {
    if (range <= 0) {
      return false;
    }
    long lower = Math.min(diff.getSource(), diff.getDestination());
    long upper = Math.max(diff.getSource(), diff.getDestination());
    return Range.closed(lower - range, upper + range).contains(destination);
  }

  private static boolean isChangedDiff(StashDiff diff, long destination) {
    return diff.getDestination() == destination;
  }

  private static boolean lineIsChangedDiff(StashDiff diff) {

    return !diff.getType().equals(IssueType.CONTEXT);
