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

com.oracle.coherence.common.util.MutableOptions Maven / Gradle / Ivy

There is a newer version: 24.09
Show newest version
/*
 * Copyright (c) 2020 Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */
package com.oracle.coherence.common.util;

/**
 * A mutable collection of zero or more values, typically called an option,
 * internally arranged as a map, keyed by the concrete type of each option in
 * the collection.
 *
 * @param   the base type of the options in the collection
 *
 * @author Jonathan Knight  2020.11.04
 * @since 20.12
 */
public class MutableOptions
        extends Options
    {
    // ----- constructors ---------------------------------------------------

    /**
     * Create an options collection of the specified option type.
     *
     * @param clsType  the type of option this in this options collection
     */
    public MutableOptions(Class clsType)
        {
        super(clsType);
        }

    // ----- MutableOptions methods ------------------------------------------------

    /**
     * Adds an option to the collection, replacing an
     * existing option of the same concrete type if one exists.
     *
     * @param option  the option to add
     *
     * @return the {@link Options} to permit fluent-style method calls
     */
    public MutableOptions add(T option)
        {
        Class clz = getClassOf(option);

        m_mapOptions.put(clz, option);

        return this;
        }

    /**
     * Adds an array of options to the collection, replacing
     * existing options of the same concrete type where they exist.
     *
     * @param aOptions  the options to add
     *
     * @return the {@link Options} to permit fluent-style method calls
     */
    public Options addAll(T[] aOptions)
        {
        if (aOptions != null)
            {
            for (T option : aOptions)
                {
                add(option);
                }
            }

        return this;
        }

    /**
     * Adds all of the options in the specified {@link Options}
     * to this collection, replacing existing options of the same concrete
     * type where they exist.
     *
     * @param options  the {@link Options} to add
     *
     * @return the {@link Options} to permit fluent-style method calls
     */
    public Options addAll(Options options)
        {
        for (T option : options.asArray())
            {
            add(option);
            }

        return this;
        }
    }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy