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

org.decision_deck.jmcda.structure.weights.WeightsUtils 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.weights;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Comparator;
import java.util.Map;

import org.decision_deck.jmcda.structure.Criterion;

import com.google.common.base.Function;
import com.google.common.collect.Ordering;


public class WeightsUtils {

    static public Weights newWeights() {
	return WeightsImpl.create();
    }

    static public Weights newWeights(Weights source) {
	if (source instanceof WeightsImpl) {
	    return WeightsImpl.newWeights((WeightsImpl) source);
	}
	final Weights weights = newWeights();
	weights.putAll(source);
	return weights;
    }

    /**
     * 

* Returns a new weights object containing the same data than the source one, with possibly renamed criteria and * with a possibly different iteration order. *

*

* The returned object iteration order reflects the one from the given map keyset. The rename key set must equal the * source set of criteria, so that the order is completely defined. *

*

* To avoid renaming a given criterion, put a value equal to the key in the rename map. *

* * @param source * not null. * @param rename * not null, no null key or values. * @return not null. */ static public Weights newRenameAndReorder(Weights source, Function rename, Comparator newOrder) { checkNotNull(source); checkNotNull(rename); checkNotNull(newOrder); final Weights newWeights = WeightsUtils.newWeights(); for (Criterion sourceCriterion : Ordering.from(newOrder).sortedCopy(source.keySet())) { final Double weight = source.get(sourceCriterion); final Criterion renamedCriterion = rename.apply(sourceCriterion); checkArgument(renamedCriterion != null); checkArgument(!newWeights.containsKey(renamedCriterion)); newWeights.put(renamedCriterion, weight); } return newWeights; } /** *

* Returns a new weights object containing the same data than the source one, with possibly renamed criteria and * with a possibly different iteration order. *

*

* The returned object iteration order reflects the one from the given map keyset. The rename key set must equal the * source set of criteria, so that the order is completely defined. *

*

* To avoid renaming a given criterion, put a value equal to the key in the rename map. *

* * @deprecated The other one is more general. * @param source * not null. * @param rename * not null, no null key or values. * @return not null. */ @Deprecated static public Weights newRenameAndReorder(Weights source, Map rename) { checkNotNull(source); checkNotNull(rename); checkArgument(rename.keySet().equals(source.keySet())); final Weights newWeights = WeightsUtils.newWeights(); for (Criterion sourceCriterion : rename.keySet()) { final Double weight = source.get(sourceCriterion); final Criterion renamedCriterion = rename.get(sourceCriterion); checkArgument(renamedCriterion != null); checkArgument(!newWeights.containsKey(renamedCriterion)); newWeights.put(renamedCriterion, weight); } return newWeights; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy