Filter.java

/**
 *
 * This file is part of TRIO.
 *
 * TRIO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TRIO is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with TRIO.  If not, see <http://www.gnu.org/licenses/>.
 */
package eu.diversify.trio.filter;

import eu.diversify.trio.core.System;
import java.util.Set;

/**
 * Filtering components in a system
 */
public abstract class Filter {

    public abstract Set<String> resolve(System system);

    /**
     * Logical conjunction of filters
     *
     * @param other the left operand of the logical conjunction
     * @return an object representing the logical conjunction of filters;
     */
    public final Filter and(Filter other) {
        return new And(this, other);
    }

    /**
     * Logical disjunction between filters
     *
     * @param other the right operand of the disjunction
     * @return an object that represent the disjunction
     */
    public final Filter or(Filter other) {
        return new Or(this, other);
    }

    /**
     * Logical negation operator
     *
     * @return the negation as a separate object
     */
    public final Filter not() {
        return new Not(this);
    }

    @Override
    public final boolean equals(Object object) {
        if (object == null) {
            return false;
        }
        if (object instanceof Filter) {
            Filter other = (Filter) object;
            return toString().equals(other.toString());
        }
        return false;
    }

    @Override
    public final int hashCode() {
        return toString().hashCode();
    }
    
    @Override
    public abstract String toString();
}