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

com.futuresight.util.mystique.ArrayToMapMystTurn Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
/*
 * Copyright (c) Balajee TM 2016.
 * All rights reserved.
 * License -  @see 
 */

/*
 * Created on 25 Aug, 2016 by balajeetm
 */
package com.futuresight.util.mystique;

import java.util.List;

import org.springframework.stereotype.Component;

import com.futuresight.util.mystique.lever.MysCon;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

/**
 * The Class ArrayToMapMystTurn.
 *
 * @author balajeetm
 */
@Component
public class ArrayToMapMystTurn extends AbstractMystTurn {

	/* (non-Javadoc)
	 * @see com.futuresight.util.mystique.AbstractMystique#transmute(java.util.List, com.google.gson.JsonObject, com.google.gson.JsonObject)
	 */
	@Override
	protected JsonElement transmute(List source, JsonObject deps, JsonObject aces, JsonObject turn) {
		JsonObject mapJson = new JsonObject();
		JsonElement elementSource = jsonLever.getFirst(source);

		if (null != elementSource) {
			turn = jsonLever.getAsJsonObject(turn, new JsonObject());
			JsonElement granularSource = getGranularSource(elementSource, turn, deps, aces);
			JsonArray inputArray = jsonLever.getAsJsonArray(granularSource, new JsonArray());
			JsonArray keyArray = jsonLever.getAsJsonArray(turn.get(MysCon.KEY));
			if (jsonLever.isNotNull(keyArray)) {
				JsonElement valueElement = turn.get(MysCon.VALUE);
				valueElement = jsonLever.isNull(valueElement) ? new JsonArray() : valueElement;

				for (JsonElement jsonElement : inputArray) {
					JsonElement keyField = jsonLever.getField(jsonElement, keyArray, deps, aces);
					String key = jsonLever.getAsString(keyField, MysCon.EMPTY);

					JsonElement finalValue = jsonLever.getSubset(jsonElement, deps, aces, valueElement);
					mapJson.add(key, finalValue);
				}
			}
		}

		return mapJson;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy