package com.infinityraider.agricraft.api.v1.stat;

import com.infinityraider.agricraft.api.v1.AgriApi;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.text.ITextComponent;

import javax.annotation.Nonnull;
import java.util.function.Consumer;

public interface IAgriStatsMap {
    int getValue(IAgriStat stat);

    default int getSum() {
        int sum = 0;
        for(IAgriStat stat : AgriApi.getStatRegistry().all()) {
            sum += this.getValue(stat);
        }
        return sum;
    }

    default double getAverage() {
        return (this.getSum() + 0.0) / AgriApi.getStatRegistry().all().size();
    }

    boolean writeToNBT(@Nonnull CompoundNBT tag);

    boolean readFromNBT(@Nonnull CompoundNBT tag);

    default boolean equalStats(IAgriStatsMap other) {
        if(this == other) {
            return true;
        }
        for(IAgriStat stat : AgriApi.getStatRegistry().all()) {
            if(this.getValue(stat) != other.getValue(stat)) {
                return false;
            }
        }
        return true;
    }

    default void addTooltips(@Nonnull Consumer<ITextComponent> consumer) {
        AgriApi.getStatRegistry().stream().forEach(stat -> stat.addTooltip(consumer, this.getValue(stat)));
    }
}

package com.infinityraider.agricraft.api.v1.stat;

import com.infinityraider.agricraft.api.v1.AgriApi;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.text.ITextComponent;

import javax.annotation.Nonnull;
import java.util.function.Consumer;

/**
 * Interface representing the AgriCraft stats of a crop or seed, can be retrieved from any IAgriStatProvider.
 * Examples of IAgriStatProviders are IAgriCrops, AgriSeeds, and IAgriGenomes
 */
public interface IAgriStatsMap {
    /**
     * Fetches the value of a certain stat
     * @param stat the stat
     * @return the value
     */
    int getValue(IAgriStat stat);

    /**
     * @return the sum of all values of all stats
     */
    default int getSum() {
        int sum = 0;
        for(IAgriStat stat : AgriApi.getStatRegistry().all()) {
            sum += this.getValue(stat);
        }
        return sum;
    }

    /**
     * @return the average of all values of all stats
     */
    default double getAverage() {
        return (this.getSum() + 0.0) / AgriApi.getStatRegistry().all().size();
    }

    /**
     * Serializes the stats map to an NBT tag
     * @param tag the tag to write to
     * @return true if the serialization was successful
     */
    boolean writeToNBT(@Nonnull CompoundNBT tag);


    /**
     * Deserializes the stats map from an NBT tag
     * @param tag the tag to read from
     * @return true if the deserialization was successful
     */
    boolean readFromNBT(@Nonnull CompoundNBT tag);

    /**
     * Checks if the stats are equal
     * @param other another stats map
     * @return true if all stats contain equal values in both stats maps
     */
    default boolean equalStats(IAgriStatsMap other) {
        if(this == other) {
            return true;
        }
        for(IAgriStat stat : AgriApi.getStatRegistry().all()) {
            if(this.getValue(stat) != other.getValue(stat)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Adds tooltips for the stats
     * @param consumer function to consume the tooltips
     */
    default void addTooltips(@Nonnull Consumer<ITextComponent> consumer) {
        AgriApi.getStatRegistry().stream().forEach(stat -> stat.addTooltip(consumer, this.getValue(stat)));
    }
}

Add docs to IAgriStatsMap