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

com.balajeetm.mystique.core.ChainMystTurn Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) Balajee TM 2016.
 * All rights reserved.
 * License -  @see 
 */

/*
 * Created on 25 Aug, 2016 by balajeetm
 * http://www.balajeetm.com
 */
package com.balajeetm.mystique.core;

import java.util.List;

import com.balajeetm.mystique.core.lever.MystiqueLever;
import com.balajeetm.mystique.core.util.MystiqueConstants;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;

import lombok.Setter;

/**
 * The Class ChainMystTurn.
 *
 * @author balajeetm
 */
public class ChainMystTurn implements MystTurn {

  /** The factory. */

  /**
   * Sets the factory.
   *
   * @param factory the new factory
   */
  @Setter private MystiqueFactory factory;

  /** The json lever. */
  private MystiqueLever jsonLever;

  /** Instantiates a new chain myst turn. */
  public ChainMystTurn() {
    jsonLever = MystiqueLever.getInstance();
  }

  /* (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.asJsonObject(turn, new JsonObject());
    JsonArray turnArray = jsonLever.asJsonArray(turn.get(MystiqueConstants.TURNS), new JsonArray());

    for (JsonElement turnObject : turnArray) {
      if (jsonLever.isObject(turnObject)) {
        JsonObject asJsonObject = turnObject.getAsJsonObject();
        MystTurn mystique = factory.getMystTurn(asJsonObject);
        if (null != mystique) {
          mystique.transform(source, deps, aces, asJsonObject, resultWrapper);
        }
      }
    }
    return transform;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy