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

org.rythmengine.internal.LoopUtil Maven / Gradle / Ivy

Go to download

A strong typed high performance Java Template engine with .Net Razor like syntax

There is a newer version: 1.4.2
Show newest version
/**
 * 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));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy