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

de.tsl2.nano.bean.def.MultiOptionsWrapper Maven / Gradle / Ivy

Go to download

TSL2 Framework Descriptor (currency-handling, generic formatter, descriptors for beans, collections, actions and values)

There is a newer version: 2.5.1
Show newest version
/*
 * File: $HeadURL$
 * Id  : $Id$
 * 
 * created by: Thomas Schneider
 * created on: Jul 28, 2010
 * 
 * Copyright: (c) Thomas Schneider 2010, all rights reserved
 */
package de.tsl2.nano.bean.def;

import java.util.Collection;

import de.tsl2.nano.core.cls.IValueAccess;

/**
 * see {@link MultiOptionsWrapper} but works on real enums.
 * 
 * @author Thomas Schneider
 * @version $Revision$
 */
public class MultiOptionsWrapper extends OptionsWrapper {
    /** valueset, should be a set */
    Collection valueset;

    /**
     * constructor
     * 
     * @param ovalue must hold a collection as value
     * @param enumType enum class
     */
    @SuppressWarnings("unchecked")
    public MultiOptionsWrapper(IValueAccess ovalue, Class enumType) {
        super(ovalue, enumType);
        valueset = (Collection) ovalue.getValue();
    }

    /**
     * constructor
     * 
     * @param ovalue must hold a collection as value
     * @param enumType enum class
     */
    @SuppressWarnings("unchecked")
    public MultiOptionsWrapper(IValueAccess ovalue, E[] enumConstants) {
        super(ovalue, enumConstants);
        valueset = (Collection) ovalue.getValue();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean hasValue(int index) {
        return valueset.contains(getEnumConstants()[index]);
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    @Override
    protected void setValue(int index, boolean value) {
        if (value) {
            valueset.add(getEnumConstants()[index]);
        } else {
            valueset.remove(getEnumConstants()[index]);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy