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

org.aksw.commons.collections.PredicateFromConverter Maven / Gradle / Ivy

There is a newer version: 0.9.9
Show newest version
package org.aksw.commons.collections;

import java.util.function.Predicate;

import com.google.common.base.Converter;

public class PredicateFromConverter
    implements Predicate
{
    protected Converter converter;

    public PredicateFromConverter(Converter converter) {
        super();
        this.converter = converter;
    }

    @Override
    public boolean test(Object raw) {
        boolean result;
        try {
            @SuppressWarnings("unchecked")
            T casted = (T)raw;
            converter.convert(casted);
            result = true;
        } catch(Exception e) {
            result = false;
        }
        return result;
    }

    public static  Predicate create(Converter converter) {
        return new PredicateFromConverter(converter);
    }
}