com.balajeetm.mystique.core.NowFunction 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
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.Date;
import com.balajeetm.mystique.core.util.MystiqueConstants;
import com.balajeetm.mystique.util.gson.lever.JsonLever;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
/**
* The Class NowFunction.
*
* @author balajeetm
*/
public class NowFunction implements MystiqueFunction {
/** The json lever. */
private JsonLever jsonLever;
/**
* Gets the single instance of NowFunction.
*
* @return single instance of NowFunction
*/
public static NowFunction getInstance() {
return Creator.INSTANCE;
}
// Efficient Thread safe Lazy Initialization
// works only if the singleton constructor is non parameterized
/** The Class Creator. */
private static class Creator {
/** The instance. */
private static NowFunction INSTANCE = new NowFunction();
}
/** Instantiates a new now function. */
private NowFunction() {
jsonLever = JsonLever.getInstance();
}
/* (non-Javadoc)
* @see com.futuresight.util.mystique.MystFunction#execute(com.google.gson.JsonElement, com.google.gson.JsonObject)
*/
@Override
public JsonElement execute(JsonElement source, JsonObject turn) {
turn = jsonLever.asJsonObject(turn, new JsonObject());
String outFormat =
jsonLever.asString(turn.get(MystiqueConstants.OUTFORMAT), MystiqueConstants.LONG);
return TransformFunction.getInstance().getFormattedDate(new Date(), outFormat);
}
}