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

com.arextest.diff.utils.IgnoreUtil Maven / Gradle / Ivy

The newest version!
package com.arextest.diff.utils;

import com.arextest.diff.model.enumeration.Constant;
import com.arextest.diff.model.log.NodeEntity;
import com.arextest.diff.model.pathparse.ExpressionNodeEntity;
import com.arextest.diff.model.pathparse.ExpressionNodeType;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * Created by rchen9 on 2022/9/22.
 */
public class IgnoreUtil {


  public static boolean ignoreProcessor(List fuzzyNodePath, List nodePath,
      List> exclusions,
      List> expressionExclusions,
      Set ignoreNodeSet) {
    if (ignoreNodeProcessor(fuzzyNodePath, ignoreNodeSet)) {
      return true;
    }

    if (exclusions != null && !exclusions.isEmpty()) {
      for (List ignoreNodePath : exclusions) {
        if (ignoreMatch(fuzzyNodePath, ignoreNodePath)) {
          return true;
        }
      }
    }

    if (expressionExclusions != null && !expressionExclusions.isEmpty()) {
      for (List ignoreNodePath : expressionExclusions) {
        if (ignoreExpressionMatch(nodePath, ignoreNodePath)) {
          return true;
        }
      }
    }

    return false;
  }


  private static boolean ignoreMatch(List pathInList,
      List ignoreNodePath) {

    int size = ignoreNodePath.size();
    if (size > pathInList.size()) {
      return false;
    }

    for (int i = 0; i < size; i++) {
      if (!Objects.equals(ignoreNodePath.get(i).getNodeName(), pathInList.get(i)) &&
          !Objects.equals(ignoreNodePath.get(i).getNodeName(), Constant.DYNAMIC_PATH)) {
        return false;
      }
    }
    return true;
  }

  private static boolean ignoreNodeProcessor(List nodePath, Set ignoreNodeSet) {

    if (ignoreNodeSet == null || ignoreNodeSet.isEmpty()) {
      return false;
    }

    if (nodePath == null || nodePath.isEmpty()) {
      return false;
    }

    for (String nodeName : nodePath) {
      if (ignoreNodeSet.contains(nodeName)) {
        return true;
      }
    }
    return false;
  }

  private static boolean ignoreExpressionMatch(List nodePath,
      List expressionNodeEntityListNodePath) {

    int size = expressionNodeEntityListNodePath.size();
    if (size > nodePath.size()) {
      return false;
    }
    for (int i = 0; i < size; i++) {
      ExpressionNodeEntity expressionNodeEntity = expressionNodeEntityListNodePath.get(i);
      NodeEntity nodeEntity = nodePath.get(i);
      if (expressionNodeEntity.getNodeType() == ExpressionNodeType.INDEX_NODE) {
        if (nodeEntity.getNodeName() != null) {
          return false;
        }
        if (expressionNodeEntity.getIndex() != nodeEntity.getIndex()) {
          return false;
        }
      } else if (expressionNodeEntity.getNodeType() == ExpressionNodeType.NAME_NODE) {
        if (nodeEntity.getNodeName() == null) {
          return false;
        }
        if (!Objects.equals(expressionNodeEntity.getNodeName(), nodePath.get(i).getNodeName())) {
          return false;
        }

      } else {
        return false;
      }
    }
    return true;
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy