com.spun.util.parser.ParserCommons Maven / Gradle / Ivy
package com.spun.util.parser;
import com.spun.util.ObjectUtils;
import com.spun.util.PhoneNumber;
import com.spun.util.parser.VelocityList.Item;
import com.spun.util.velocity.ParserDateUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
public class ParserCommons
{
public static TemplateStringUtils stringUtils = TemplateStringUtils.INSTANCE;
public static TemplateNumberUtils numberUtils = TemplateNumberUtils.INSTANCE;
public static TemplateDate today = TemplateDate.INSTANCE;
public static ParserCommons INSTANCE = new ParserCommons();
public static TemplateNumberUtils getNumberUtils()
{
return numberUtils;
}
public static Class> getClass(String clazz)
{
return ObjectUtils.throwAsError(() -> Class.forName(clazz));
}
public static Object createNew(String clazz)
{
return ObjectUtils.throwAsError(() -> getClass(clazz).newInstance());
}
public static Object getNull()
{
return null;
}
public static ParserDateUtils getDateUtils()
{
return ParserDateUtils.INSTANCE;
}
public static TemplateStringUtils getStringUtils()
{
return stringUtils;
}
public static String asJavascript(Object obj)
{
return TemplateStringUtils.toJavaScriptEncode(obj);
}
public static TemplateDate getToday()
{
return today;
}
public static TemplateDate asDate(Date date)
{
return new TemplateDate(date);
}
public static TemplateDouble asDouble(double number)
{
return new TemplateDouble(number);
}
public static PhoneNumber asPhoneNumber(String number)
{
return new PhoneNumber(number);
}
public static String asExcel(String text)
{
return TemplateStringUtils.formatExcelString(text);
}
public static boolean isNull(Object object)
{
return object == null;
}
public static PercentageAmount asPercentage(double d)
{
return new PercentageAmount(d);
}
public static TemplateDouble asDouble(Number number)
{
return new TemplateDouble(number.doubleValue());
}
public static List- > asArray(T[] array, int offset, int stepping)
{
return new VelocityList
(array, offset, stepping).getAll();
}
public static List- > asArray(T[] array, int offset, int stepping1, int stepping2)
{
return new VelocityList
(array, offset, new int[]{stepping1, stepping2}).getAll();
}
public static List- > asArray(Object nullObject)
{
if (nullObject != null)
{
if (nullObject.getClass().isArray())
{
return asArray((Object[]) nullObject);
}
else
{
throw new Error("Improper usage for" + nullObject);
}
}
return new VelocityList