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

org.spongepowered.api.data.value.WeightedCollectionValue Maven / Gradle / Ivy

The newest version!
/*
 * This file is part of SpongeAPI, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered 
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.api.data.value;

import org.spongepowered.api.data.Key;
import org.spongepowered.api.util.weighted.TableEntry;
import org.spongepowered.api.util.weighted.WeightedTable;

import java.util.List;
import java.util.Random;
import java.util.function.Supplier;

public interface WeightedCollectionValue extends CollectionValue, WeightedTable>  {

    /**
     * Constructs a mutable {@link WeightedCollectionValue} of the appropriate type based
     * on the given {@link Key} and the element.
     *
     * @param key The key
     * @param element The element
     * @param  The element type
     * @return The constructed mutable value
     */
    static  WeightedCollectionValue.Mutable mutableOf(Key> key, WeightedTable element) {
        return Value.mutableOf(key, element);
    }

    /**
     * Constructs a mutable {@link WeightedCollectionValue} of the appropriate type based
     * on the given {@link Key} and the element.
     *
     * @param key The key
     * @param element The element
     * @param  The element type
     * @return The constructed mutable value
     */
    static  WeightedCollectionValue.Mutable mutableOf(Supplier>> key, WeightedTable element) {
        return WeightedCollectionValue.mutableOf(key.get(), element);
    }

    /**
     * Constructs an immutable {@link WeightedCollectionValue} of the appropriate type based
     * on the given {@link Key} and the element.
     *
     * @param key The key
     * @param element The element
     * @param  The element type
     * @return The constructed immutable value
     */
    static  WeightedCollectionValue.Immutable immutableOf(Key> key, WeightedTable element) {
        return Value.immutableOf(key, element);
    }

    /**
     * Constructs an immutable {@link WeightedCollectionValue} of the appropriate type based
     * on the given {@link Key} and the element.
     *
     * @param key The key
     * @param element The element
     * @param  The element type
     * @return The constructed immutable value
     */
    static  WeightedCollectionValue.Immutable immutableOf(Supplier>> key, WeightedTable element) {
        return WeightedCollectionValue.immutableOf(key.get(), element);
    }

    @Override
    Key> key();

    /**
     * Selects random valued from this list based on their weight.
     *
     * 

An empty list will be returned if there are no * entries in the weighted table.

* * @param random The random object to use for selection * @return The selected values */ List get(Random random); @Override WeightedCollectionValue.Mutable asMutable(); @Override WeightedCollectionValue.Mutable asMutableCopy(); @Override WeightedCollectionValue.Immutable asImmutable(); /** * Represents a particular type of {@link org.spongepowered.api.data.value.CollectionValue.Immutable} that is * backed by a {@link WeightedTable}. * * @param The type of weighted object */ interface Immutable extends WeightedCollectionValue, CollectionValue.Immutable, WeightedTable, Immutable, Mutable> { @Override WeightedCollectionValue.Mutable asMutable(); @Override default WeightedCollectionValue.Mutable asMutableCopy() { return this.asMutable(); } @Override default WeightedCollectionValue.Immutable asImmutable() { return this; } } /** * Represents a particular type of {@link org.spongepowered.api.data.value.CollectionValue.Mutable} that is backed by * a {@link WeightedTable}. * * @param The type of weighted object */ interface Mutable extends WeightedCollectionValue, CollectionValue.Mutable, WeightedTable, Mutable, Immutable> { @Override default WeightedCollectionValue.Mutable asMutable() { return this; } @Override default WeightedCollectionValue.Mutable asMutableCopy() { return this.copy(); } @Override WeightedCollectionValue.Immutable asImmutable(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy