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

com.arextest.diff.handler.parse.JSONParse Maven / Gradle / Ivy

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

import com.arextest.diff.factory.TaskThreadFactory;
import com.arextest.diff.model.RulesConfig;
import com.arextest.diff.model.log.NodeEntity;
import com.arextest.diff.utils.JSONParseUtil;
import com.arextest.diff.utils.NameConvertUtil;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class JSONParse {

  public Map> doHandler(RulesConfig rulesConfig, Object baseObj,
      Object testObj) throws ExecutionException, InterruptedException {

    CompletableFuture, String>> mapCompletableFuture1 =
        CompletableFuture.supplyAsync(
            () -> this.getJSONParseResult(baseObj,
                rulesConfig), TaskThreadFactory.jsonObjectThreadPool);
    CompletableFuture, String>> mapCompletableFuture2 =
        CompletableFuture.supplyAsync(
            () -> this.getJSONParseResult(testObj,
                rulesConfig), TaskThreadFactory.jsonObjectThreadPool);
    CompletableFuture.allOf(mapCompletableFuture1, mapCompletableFuture2).join();

    return JSONParseUtil.getTotalParses(mapCompletableFuture1.get(), mapCompletableFuture2.get());
  }

  public Map, String> getJSONParseResult(Object obj, RulesConfig rulesConfig) {

    StringAndCompressParse stringAndCompressParse = new StringAndCompressParse();
    stringAndCompressParse.setNameToLower(rulesConfig.isNameToLower());
    stringAndCompressParse.setPluginJarUrl(rulesConfig.getPluginJarUrl());
    stringAndCompressParse.setTransFormConfigMap(rulesConfig.getTransformConfigMap());
    stringAndCompressParse.getJSONParse(obj, obj);
    // Convert field names in JSONObject to lowercase
    if (rulesConfig.isNameToLower()) {
      NameConvertUtil.nameConvert(obj);
    }
    return stringAndCompressParse.getOriginal();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy