/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program 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 Lesser General Public License for more details.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors.. All rights reserved.
*/
package org.pentaho.reporting.engine.classic.core.util;
import java.io.Serializable;
import org.pentaho.reporting.engine.classic.core.DataRow;
import org.pentaho.reporting.libraries.base.util.LinkedMap;
/**
* Todo: Document Me
*
* @author Thomas Morgner
*/
public class ReportParameterValues implements Cloneable, Serializable, DataRow
{
private LinkedMap linkedMap;
public ReportParameterValues()
{
this.linkedMap = new LinkedMap();
}
public ReportParameterValues(final ReportParameterValues values)
{
if (values == null)
{
throw new NullPointerException();
}
try
{
this.linkedMap = (LinkedMap) values.linkedMap.clone();
}
catch (CloneNotSupportedException e)
{
throw new IllegalStateException("Should never happen");
}
}
public Object put(final String col, final Object value)
{
if (col == null)
{
throw new NullPointerException();
}
return linkedMap.put(col, value);
}
/**
* Returns the value of the function, expression or column using its specific name. The given name is translated into
* a valid column number and the the column is queried. For functions and expressions, the <code>getValue()</code>
* method is called and for columns from the tablemodel the tablemodel method <code>getValueAt(row, column)</code>
* gets called.
*
* @param col the item index.
* @return the value.
*/
public Object get(final String col)
{
return linkedMap.get(col);
}
public String[] getColumnNames()
{
return (String[]) linkedMap.keys(new String[linkedMap.size()]);
}
/**
* Checks whether the value contained in the column has changed since the last advance-operation.
*
* @param name the name of the column.
* @return always false, as parameters are considered static during the report processing.
*/
public boolean isChanged(final String name)
{
return false;
}
public Object clone() throws CloneNotSupportedException
{
final ReportParameterValues o = (ReportParameterValues) super.clone();
o.linkedMap = (LinkedMap) linkedMap.clone();
return o;
}
public void putAll(final DataRow dataRow)
{
if (dataRow == null)
{
throw new NullPointerException();
}
final String[] names = dataRow.getColumnNames();
for (int i = 0; i < names.length; i++)
{
final String name = names[i];
put(name, dataRow.get(name));
}
}
public void clear()
{
linkedMap.clear();
}
}