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

io.github.oliviercailloux.j_voting.preferences.classes.ImmutableAntiSymmetricPreferenceImpl Maven / Gradle / Ivy

The newest version!
package io.github.oliviercailloux.j_voting.preferences.classes;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.graph.EndpointPair;
import com.google.common.graph.Graph;

import io.github.oliviercailloux.j_voting.Alternative;
import io.github.oliviercailloux.j_voting.Voter;
import io.github.oliviercailloux.j_voting.preferences.ImmutableAntiSymmetricPreference;

public class ImmutableAntiSymmetricPreferenceImpl extends ImmutablePreferenceImpl
		implements ImmutableAntiSymmetricPreference {

	private static final Logger LOGGER = LoggerFactory.getLogger(ImmutableAntiSymmetricPreferenceImpl.class.getName());

	/**
	 * 
	 * @param voter  not null 
	 * @param graph  not null  directed graph with ordered Alternatives
	 * @return new ImmutableAntiSymmetricPreference
	 */
	public static ImmutableAntiSymmetricPreferenceImpl asImmutableAntiSymmetricPreference(Voter voter,
			Graph graph) {
		Preconditions.checkNotNull(voter);
		Preconditions.checkNotNull(graph);
		return new ImmutableAntiSymmetricPreferenceImpl(voter, graph);
	}

	/**
	 * @param voter  not null 
	 * @param graph  not null  directed graph with ordered Alternatives
	 */
	private ImmutableAntiSymmetricPreferenceImpl(Voter voter, Graph graph) {
		super(voter, graph);
		for (EndpointPair edge : super.asGraph().edges()) {
			if (super.asGraph().hasEdgeConnecting(edge.nodeV(), edge.nodeU()) && !edge.nodeV().equals(edge.nodeU()))
				throw new IllegalArgumentException("Two Alternatives can't be ranked ex-æquo");
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy