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

com.github.elibracha.compare.HeadersDiff Maven / Gradle / Ivy

There is a newer version: 2.3.6
Show newest version
package com.github.elibracha.compare;

import com.github.elibracha.model.ChangedHeader;
import com.github.elibracha.model.ChangedHeaders;
import com.github.elibracha.model.DiffContext;
import com.github.elibracha.utils.ChangedUtils;

import io.swagger.v3.oas.models.headers.Header;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/** Created by adarsh.sharma on 28/12/17. */
public class HeadersDiff {
  private OpenApiDiff openApiDiff;

  public HeadersDiff(OpenApiDiff openApiDiff) {
    this.openApiDiff = openApiDiff;
  }

  public Optional diff(
      Map left, Map right, DiffContext context) {
    MapKeyDiff headerMapDiff = MapKeyDiff.diff(left, right);
    List sharedHeaderKeys = headerMapDiff.getSharedKey();

    Map changed = new LinkedHashMap<>();
    for (String headerKey : sharedHeaderKeys) {
      Header oldHeader = left.get(headerKey);
      Header newHeader = right.get(headerKey);
      openApiDiff
          .getHeaderDiff()
          .diff(oldHeader, newHeader, context)
          .ifPresent(changedHeader -> changed.put(headerKey, changedHeader));
    }
    return ChangedUtils.isChanged(
        new ChangedHeaders(left, right, context)
            .setIncreased(headerMapDiff.getIncreased())
            .setMissing(headerMapDiff.getMissing())
            .setChanged(changed));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy