01: /* DataSetBean.java
02: *
03: * DDSteps - Data Driven JUnit Test Steps
04: * Copyright (C) 2005 Jayway AB
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License version 2.1 as published by the Free Software Foundation.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, visit
17: * http://www.opensource.org/licenses/lgpl-license.php
18: */
19: package org.ddsteps.dataset.bean;
20:
21: import java.util.Iterator;
22: import java.util.LinkedHashMap;
23: import java.util.Map;
24:
25: import org.apache.commons.lang.Validate;
26: import org.ddsteps.dataset.DataSet;
27: import org.ddsteps.dataset.DataTable;
28:
29: /**
30: * In-memory bean implementation of DataSet.
31: *
32: * @author Adam
33: * @version $Id: DataSetBean.java,v 1.1 2005/12/03 12:51:40 adamskogman Exp $
34: */
35: public class DataSetBean implements DataSet {
36:
37: /**
38: * Serial UID
39: */
40: private static final long serialVersionUID = -2928014347833526517L;
41:
42: /**
43: * Field: Map of String (tableName) to Table
44: */
45: protected final Map tables;
46:
47: /**
48: * Default constructor.
49: */
50: public DataSetBean() {
51: tables = new LinkedHashMap();
52: }
53:
54: /**
55: * @see org.ddsteps.dataset.DataSet#getTableNames()
56: */
57: public String[] getTableNames() {
58: return (String[]) tables.keySet().toArray(
59: new String[tables.size()]);
60: }
61:
62: /**
63: * @see org.ddsteps.dataset.DataSet#tableIterator()
64: */
65: public Iterator tableIterator() {
66: return tables.values().iterator();
67: }
68:
69: /**
70: * @see org.ddsteps.dataset.DataSet#getTable(java.lang.String)
71: */
72: public DataTable getTable(String tableName) {
73: return (DataTable) tables.get(tableName);
74: }
75:
76: /**
77: * Add a table to the set.
78: *
79: * @param table
80: * Not null.
81: * @return Old table by that name, if any, else null.
82: */
83: public DataTable addTable(DataTable table) {
84:
85: Validate.notNull(table);
86: String name = table.getName();
87: Validate.notNull(name);
88:
89: return (DataTable) tables.put(name, table);
90:
91: }
92:
93: }
|