All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.bjurr.violations.git.data.DiffsPerFile Maven / Gradle / Ivy

The newest version!
package se.bjurr.violations.git.data;

import static java.lang.Integer.MAX_VALUE;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

public class DiffsPerFile {

  private final Map patchPerFile;

  public DiffsPerFile(final Map patchPerFile) {
    this.patchPerFile = patchPerFile;
  }

  public Optional findPatchString(final String file) {
    Integer pathLength = MAX_VALUE;
    String patchString = null;
    for (final Entry candidate : patchPerFile.entrySet()) {
      final String candidateFile = candidate.getKey();
      if (candidateFile.endsWith(file) || file.endsWith(candidateFile)) {
        final Integer candidatePathLength = candidateFile.length();
        if (candidatePathLength < pathLength) {
          patchString = candidate.getValue();
          pathLength = candidatePathLength;
        }
      }
    }
    return Optional.ofNullable(patchString);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy