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

liqp.filters.Compact Maven / Gradle / Ivy

Go to download

A Java implementation of the Liquid templating engine backed up by an ANTLR grammar.

The newest version!
package liqp.filters;

import liqp.TemplateContext;

import java.util.ArrayList;
import java.util.List;

public class Compact extends Filter {

    @Override
    public Object apply(Object value, TemplateContext context, Object... params) {

        if (!super.isArray(value)) {
            return value;
        }

        Object[] values = super.asArray(value, context);
        List compacted = new ArrayList();

        for (Object obj : values) {
            if (obj != null) {
                compacted.add(obj);
            }
        }

        return compacted.toArray();
    }
}