com.futuresight.util.mystique.ToggleMystTurn Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-mystique Show documentation
Show all versions of json-mystique Show documentation
Json Utility to transform Jsons
/*
* 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.beans.factory.annotation.Autowired;
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.JsonNull;
import com.google.gson.JsonObject;
/**
* The Class MultiTurnMystique.
*
* @author balajeetm
*/
@Component
public class ToggleMystTurn implements MystTurn {
/** The factory. */
@Autowired
private MystiqueFactory factory;
/** The json lever. */
@Autowired
private JsonLever jsonLever;
/* (non-Javadoc)
* @see com.futuresight.util.mystique.Mystique#transform(java.util.List, com.google.gson.JsonObject, com.google.gson.JsonElement, com.google.gson.JsonElement)
*/
@Override
public JsonElement transform(List source, JsonObject deps, JsonObject aces, JsonObject turn,
JsonObject resultWrapper) {
JsonElement transform = JsonNull.INSTANCE;
turn = jsonLever.getAsJsonObject(turn, new JsonObject());
JsonArray turnArray = jsonLever.getAsJsonArray(turn.get(MysCon.TURNS), new JsonArray());
for (JsonElement turnObject : turnArray) {
if (jsonLever.isJsonObject(turnObject)) {
JsonObject asJsonObject = turnObject.getAsJsonObject();
MystTurn mystique = factory.getMystTurn(asJsonObject);
if (null != mystique) {
transform = mystique.transform(source, deps, aces, asJsonObject, resultWrapper);
}
if (jsonLever.isNotNull(transform)) {
break;
}
}
}
return transform;
}
}