001: /* DataTableBean.java
002: *
003: * DDSteps - Data Driven JUnit Test Steps
004: * Copyright (C) 2005 Jayway AB
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License version 2.1 as published by the Free Software Foundation.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, visit
017: * http://www.opensource.org/licenses/lgpl-license.php
018: */
019: package org.ddsteps.dataset.bean;
020:
021: import java.util.Iterator;
022: import java.util.LinkedHashMap;
023:
024: import org.apache.commons.lang.Validate;
025: import org.ddsteps.dataset.DataRow;
026: import org.ddsteps.dataset.DataTable;
027:
028: /**
029: * Keeps rows in a list. The rows will be ordered as inserted.
030: *
031: * @author Adam
032: * @version $Id: DataTableBean.java,v 1.4 2006/03/10 15:30:36 adamskogman Exp $
033: */
034: public class DataTableBean implements DataTable {
035:
036: private final LinkedHashMap rows;
037:
038: private String name;
039:
040: /**
041: * Set up default bean.
042: */
043: public DataTableBean() {
044: rows = new LinkedHashMap();
045: }
046:
047: /**
048: * @see org.ddsteps.dataset.DataTable#getRowCount()
049: */
050: public int getRowCount() {
051: return rows.size();
052: }
053:
054: /**
055: * @see org.ddsteps.dataset.DataTable#rowIterator()
056: */
057: public Iterator rowIterator() {
058: return rows.values().iterator();
059: }
060:
061: /**
062: * Adds a row LAST in the table.
063: *
064: * @param row
065: * Not null. Must have a rowId, that must not change.
066: * @throws IllegalArgumentException
067: * If a DataValue has a header that has not been added to this
068: * table.
069: */
070: public void addRow(DataRow row) {
071: Validate.notNull(row);
072:
073: rows.put(row.getId(), row);
074: }
075:
076: /**
077: * @return Returns the name.
078: */
079: public String getName() {
080: Validate.notEmpty(name);
081: return name;
082: }
083:
084: /**
085: * @param name
086: * The name to set.
087: */
088: public void setName(String name) {
089: Validate.notEmpty(name);
090: this .name = name;
091: }
092:
093: /**
094: *
095: * @see org.ddsteps.dataset.DataTable#findRowById(java.lang.String)
096: */
097: public DataRow findRowById(String rowId) {
098:
099: return (DataRow) rows.get(rowId);
100:
101: }
102: }
|