001/* 002 $Id: ParameterValueData.java 4428 2013-02-28 07:32:27Z olle $ 003 004 Copyright (C) 2006 Gregory Vincic, Olle Mansson 005 Copyright (C) 2007 Gregory Vincic 006 007 This file is part of Proteios. 008 Available at http://www.proteios.org/ 009 010 Proteios is free software; you can redistribute it and/or modify it 011 under the terms of the GNU General Public License as published by 012 the Free Software Foundation; either version 2 of the License, or 013 (at your option) any later version. 014 015 Proteios is distributed in the hope that it will be useful, but 016 WITHOUT ANY WARRANTY; without even the implied warranty of 017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 018 General Public License for more details. 019 020 You should have received a copy of the GNU General Public License 021 along with this program; if not, write to the Free Software 022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 023 02111-1307, USA. 024*/ 025package org.proteios.core.data; 026 027import java.util.Arrays; 028import java.util.List; 029 030/** 031 The base class for the different types of parameter values. 032 @author Nicklas, Samuel 033 @version 2.0 034 @see <a href="../../../../../../../development/overview/data/parameters.html">Parameters overview</a> 035 @hibernate.class table="`ParameterValues`" discriminator-value="-1" lazy="true" batch-size="10" 036 @hibernate.discriminator column="`discriminator`" type="int" 037 @base.modified $Date: 2013-02-28 08:32:27 +0100 (Thu, 28 Feb 2013) $ 038*/ 039public abstract class ParameterValueData<T> 040 extends BasicData 041{ 042 ParameterValueData() 043 {} 044 045 @SuppressWarnings("unchecked") 046 ParameterValueData(T... values) 047 { 048 replaceValues(Arrays.asList(values)); 049 } 050 051 /** 052 Get values of this parameter. Hibernate mapped in each subclass 053 to a bag containing all values for the parameter. 054 @return Collection of values. 055 */ 056 public abstract List<T> getValues(); 057 058 /** 059 Set values of this parameter. 060 @param values Collection of values. 061 */ 062 abstract void setValues(List<T> values); 063 064 /** 065 Replace the values in the database with the new 066 values in the specified list. It is expected that 067 the list contains only objects of the correct type. 068 */ 069 @SuppressWarnings("unchecked") 070 public void replaceValues(List<?> values) 071 { 072 List<T> current = getValues(); 073 current.clear(); 074 current.addAll((List<T>) values); 075 } 076 077 /** 078 Replace the current list with a single new value. 079 It is expected that the value is of the correct type. 080 */ 081 @SuppressWarnings("unchecked") 082 public void setSingleValue(Object value) 083 { 084 List<T> current = getValues(); 085 current.clear(); 086 current.add((T) value); 087 } 088}