de.tsl2.nano.bean.def.MultiOptionsWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.descriptor Show documentation
Show all versions of tsl2.nano.descriptor Show documentation
TSL2 Framework Descriptor (currency-handling, generic formatter, descriptors for beans, collections, actions and values)
/*
* 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]);
}
}
}