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

com.mitchellbosecke.pebble.extension.core.EmptyTest Maven / Gradle / Ivy

/*******************************************************************************
 * This file is part of Pebble.
 * 
 * Copyright (c) 2014 by Mitchell Bösecke
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 ******************************************************************************/
package com.mitchellbosecke.pebble.extension.core;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.mitchellbosecke.pebble.extension.Test;

public class EmptyTest implements Test {

    @Override
    public List getArgumentNames() {
        return null;
    }

    @Override
    public boolean apply(Object input, Map args) {
        boolean isEmpty = input == null;

        if (!isEmpty && input instanceof String) {
            String value = (String) input;
            isEmpty = "".equals(value.trim());
        }

        if (!isEmpty && input instanceof Collection) {
            isEmpty = ((Collection) input).isEmpty();
        }

        if (!isEmpty && input instanceof Map) {
            isEmpty = ((Map) input).isEmpty();
        }

        return isEmpty;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy