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

io.virtdata.libbasics.core.stathelpers.ElemProbD Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.libbasics.core.stathelpers;

import java.util.Comparator;

/**
 * A simple wrapper type for "Event Probability", where the event is identified by a unique int,
 * and the probability is represented with double precision floating-point.
 */
public class ElemProbD implements Comparable> {
    private T element;
    private double probability;

    public ElemProbD(T element, double probability) {
        this.element = element;
        this.probability = probability;
    }

    public double getProbability() {
        return probability;
    }

    public T getElement() {
        return element;
    }

    @Override
    public int compareTo(ElemProbD other) {
        return Double.compare(probability, other.getProbability());
    }

    public static Comparator DESCENDING_PROBABILTY = (Comparator) (o1, o2) -> Double.compare(o2.probability,o1.probability);

    public void setProbability(double probability) {
        this.probability = probability;
    }

    @Override
    public String toString() {
        return element.toString() + ":" + getProbability();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy