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

com.alee.managers.settings.SettingsGroup Maven / Gradle / Ivy

The newest version!
/*
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebLookAndFeel library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebLookAndFeel library.  If not, see .
 */

package com.alee.managers.settings;

import com.alee.utils.TextUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Settings group data class.
 *
 * @author Mikle Garin
 * @see How to use SettingsManager
 * @see SettingsManager
 */
@XStreamAlias ( "SettingsGroup" )
@XStreamConverter ( SettingsConverter.class )
public class SettingsGroup implements Serializable
{
    /**
     * Identifier prefix.
     */
    private static final String ID_PREFIX = "SG";

    /**
     * Group identifier.
     */
    private String id;

    /**
     * Group name.
     */
    private String name;

    /**
     * Settings map.
     */
    private HashMap settings;

    /**
     * Constructs new {@link SettingsGroup}.
     */
    public SettingsGroup ()
    {
        this ( null );
    }

    /**
     * Constructs new {@link SettingsGroup}.
     *
     * @param name group name
     */
    public SettingsGroup ( final String name )
    {
        super ();
        this.id = TextUtils.generateId ( ID_PREFIX );
        this.name = name;
    }

    /**
     * Constructs new {@link SettingsGroup}.
     *
     * @param id   group identifier
     * @param name group name
     */
    public SettingsGroup ( final String id, final String name )
    {
        super ();
        this.id = id;
        this.name = name;
    }

    /**
     * Returns group identifier.
     *
     * @return group identifier
     */
    public String getId ()
    {
        return id;
    }

    /**
     * Sets group identifier.
     *
     * @param id new group identifier
     */
    public void setId ( final String id )
    {
        this.id = id;
    }

    /**
     * Returns group name.
     *
     * @return group name
     */
    public String getName ()
    {
        return name;
    }

    /**
     * Sets group name.
     *
     * @param name new group name
     */
    public void setName ( final String name )
    {
        this.name = name;
    }

    /**
     * Returns settings map.
     *
     * @return settings map
     */
    public Map settings ()
    {
        if ( settings == null )
        {
            settings = new HashMap ();
        }
        return settings;
    }

    /**
     * Sets settings map.
     *
     * @param settings new settings map
     */
    public void setSettings ( final HashMap settings )
    {
        this.settings = settings;
    }

    /**
     * Returns value for specified key.
     *
     * @param key key
     * @param  value type
     * @return value for specified key
     */
    public  T get ( final String key )
    {
        return ( T ) settings ().get ( key );
    }

    /**
     * Removes settings saved under the specified key.
     *
     * @param key settings key
     * @param  value type
     * @return settings previously saved under the specified key
     */
    public  T remove ( final String key )
    {
        return ( T ) settings ().remove ( key );
    }

    /**
     * Puts value under the specified key.
     *
     * @param key    key
     * @param object value
     * @param     value type
     * @return previous value for the specified key
     */
    public  T put ( final String key, final T object )
    {
        return ( T ) settings ().put ( key, object );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy