org.rythmengine.internal.LoopUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rythm-engine Show documentation
Show all versions of rythm-engine Show documentation
A strong typed high performance Java Template engine with .Net Razor like syntax
/**
* Copyright (C) 2013-2016 The Rythm Engine project
* for LICENSE and other details see:
* https://github.com/rythmengine/rythmengine
*/
package org.rythmengine.internal;
import org.rythmengine.utils.RawData;
import org.rythmengine.utils.S;
/**
* Used to help track loop state
*/
public class LoopUtil {
private final Object obj;
private final boolean isFirst;
private final boolean isLast;
public LoopUtil(boolean isFirst, boolean isLast) {
this.isFirst = isFirst;
this.isLast = isLast;
this.obj = null;
}
public LoopUtil(boolean isFirst, boolean isLast, Object obj) {
this.isFirst = isFirst;
this.isLast = isLast;
this.obj = obj;
}
public RawData sep(String sep) {
return postSep(sep);
}
public RawData preSep(String sep) {
String result = "";
if (null != obj) {
result += S.escape(obj);
}
return RawData.valueOf(result);
}
public RawData postSep(String sep) {
String result = "";
if (null != obj) {
result += S.escape(obj);
}
return RawData.valueOf(result + (isLast ? "" : sep));
}
}