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

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

There is a newer version: 0.2.15
Show newest version
package com.arextest.diff.utils;

import com.arextest.diff.model.key.ListSortEntity;
import com.arextest.diff.model.key.ReferenceEntity;
import com.arextest.diff.model.pathparse.ExpressionNodeEntity;
import com.arextest.diff.model.pathparse.ExpressionNodeType;
import com.arextest.diff.model.pathparse.expression.EqualsExpression;
import com.arextest.diff.model.pathparse.expression.PathExpression;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public class FieldToLowerUtil {

  public static  Map, V> mapKeyToLower(Map, V> map) {
    if (map == null) {
      return null;
    }
    Map, V> result = new HashMap<>();
    map.forEach((k, v) -> {
      if (k != null && v != null) {
        result.put(k.stream().map(String::toLowerCase).collect(Collectors.toList()), v);
      }
    });
    return result;
  }

  public static List> listListToLower(List> lists) {
    if (lists == null || lists.isEmpty()) {
      return null;
    }
    List> result = new ArrayList<>();
    lists.forEach(item -> {
      result.add(item.stream()
          .map(String::toLowerCase)
          .collect(Collectors.toList()));
    });
    return result;
  }

  public static List> expressionNodeListToLower(
      List> expressionNodeLists) {
    if (expressionNodeLists == null || expressionNodeLists.isEmpty()) {
      return expressionNodeLists;
    }

    for (List expressionNodeEntities : expressionNodeLists) {
      for (ExpressionNodeEntity expressionNodeEntity : expressionNodeEntities) {
        switch (expressionNodeEntity.getNodeType()) {
          case ExpressionNodeType.NAME_NODE:
            expressionNodeEntity.setNodeName(expressionNodeEntity.getNodeName().toLowerCase());
            break;
          case ExpressionNodeType.EXPRESSION_NODE:
            PathExpression expression = expressionNodeEntity.getExpression();
            if (expression instanceof EqualsExpression) {
              EqualsExpression equalsExpression = (EqualsExpression) expression;
              equalsExpression.setLeftValue(listToLower(equalsExpression.getLeftValue()));
            }
            break;
          default:
            break;
        }
      }
    }
    return expressionNodeLists;
  }


  public static Set setToLower(Collection collection) {
    if (collection == null) {
      return null;
    }
    return collection.stream().filter(Objects::nonNull)
        .map(String::toLowerCase)
        .collect(Collectors.toSet());
  }

  public static List listToLower(Collection collection) {
    if (collection == null) {
      return null;
    }
    return collection.stream().filter(Objects::nonNull)
        .map(String::toLowerCase)
        .collect(Collectors.toList());
  }

  public static void referenceToLower(List referenceEntities) {
    referenceEntities.forEach(item -> {
      item.setPkNodePath(listToLower(item.getPkNodePath()));
      item.setPkNodeListPath(listToLower(item.getPkNodeListPath()));
      item.setFkNodePath(listToLower(item.getFkNodePath()));
    });
  }

  public static void keyConfigToLower(List keyEntities) {
    keyEntities.forEach(item -> {
      item.setListNodepath(listToLower(item.getListNodepath()));
      item.setKeys(listListToLower(item.getKeys()));
      item.setReferenceNodeRelativePath(listToLower(item.getReferenceNodeRelativePath()));
    });
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy