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

org.decision_deck.jmcda.structure.thresholds.ThresholdsUtils Maven / Gradle / Ivy

Go to download

The base classes of the J-MCDA project. Contains the main structure classes that define MCDA concepts such as alternatives and performance matrixes.

The newest version!
package org.decision_deck.jmcda.structure.thresholds;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import org.decision_deck.jmcda.structure.Criterion;

import com.google.common.base.Equivalence;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;

public class ThresholdsUtils {

    static public Thresholds getFilteredReadView(Thresholds delegate, Predicate criteriaPredicate) {
	return new ThresholdsReadFilter(delegate, criteriaPredicate);
    }

    static public Equivalence getEquivalence() {
	return new Equivalence() {
	    @Override
	    public boolean doEquivalent(Thresholds t1, Thresholds t2) {
		if (!t1.getCriteria().equals(t2.getCriteria())) {
		    return false;
		}
		if (!t1.getPreferenceThresholds().equals(t2.getPreferenceThresholds())) {
		    return false;
		}
		if (!t1.getIndifferenceThresholds().equals(t2.getIndifferenceThresholds())) {
		    return false;
		}
		if (!t1.getVetoThresholds().equals(t2.getVetoThresholds())) {
		    return false;
		}
		return true;
	    }

	    @Override
	    public int doHash(Thresholds t) {
		final int hashCode = Objects.hashCode(t.getPreferenceThresholds(), t.getIndifferenceThresholds(),
			t.getVetoThresholds());
		return hashCode;
	    }
	};
    }

    static public Predicate getPredicateIsEmpty() {
	return new Predicate() {
	    @Override
	    public boolean apply(Thresholds input) {
		return input.isEmpty();
	    }
	};
    }

    static public Set getAllCriteriaFromThresholds(Collection allThresholds) {
	final Set allCrits = Sets.newLinkedHashSet();
	for (Thresholds thresholds : allThresholds) {
	    final Set criteria = thresholds.getCriteria();
	    allCrits.addAll(criteria);
	}
	return allCrits;
    }

    static public Thresholds getReadView(Thresholds delegate) {
	return new ThresholdsReadFilter(delegate, Predicates. alwaysTrue());
    }

    static public Thresholds newThresholds() {
	return new ThresholdsImpl();
    }

    static public Thresholds newThresholds(Map preferenceThresholds,
	    Map indifferenceThresholds, Map vetoThresholds) {
	return new ThresholdsImpl(preferenceThresholds == null ? ImmutableMap. of()
		: preferenceThresholds, indifferenceThresholds == null ? ImmutableMap. of()
		: indifferenceThresholds, vetoThresholds == null ? ImmutableMap. of()
		: vetoThresholds);
    }

    static public Thresholds newThresholds(Thresholds source) {
	return new ThresholdsImpl(source);
    }

    /**
     * Retrieves a thresholds object which views all preference and indifference thresholds bound to the given set of
     * criteria as zeroes. The returned object is a read-only view. Changes in the given set are reflected in the
     * returned thresholds. The returned object has no vetoes thresholds.
     * 
     * @param criteria
     *            not null.
     * @return a read-only view of thresholds.
     */
    static public Thresholds getZeroes(Set criteria) {
	return new ThresholdsZeroes(criteria);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy