01: /* DataRowBean.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:
24: import org.apache.commons.lang.Validate;
25: import org.ddsteps.dataset.DataRow;
26: import org.ddsteps.dataset.DataValue;
27:
28: /**
29: * Keeps values in a map
30: *
31: * @author Adam
32: * @version $Id: DataRowBean.java,v 1.1 2005/12/03 12:51:40 adamskogman Exp $
33: */
34: public class DataRowBean implements DataRow {
35:
36: private final LinkedHashMap values;
37:
38: private String id;
39:
40: /**
41: * Default.
42: */
43: public DataRowBean() {
44: // Usually quite many
45: values = new LinkedHashMap(100);
46: }
47:
48: /**
49: * @see org.ddsteps.dataset.DataRow#iterator()
50: */
51: public Iterator iterator() {
52: return values.values().iterator();
53: }
54:
55: /**
56: * Adds or replaces a value (as identified by the name).
57: *
58: * @param value
59: * The value, not null.
60: *
61: * @return Old value if any, null if new name.
62: */
63: public DataValue addValue(DataValue value) {
64:
65: Validate.notNull(value);
66: Validate.notNull(value.getName());
67:
68: return (DataValue) values.put(value.getName(), value);
69:
70: }
71:
72: /**
73: * @return Returns the id.
74: */
75: public String getId() {
76: Validate.notNull(id);
77: return id;
78: }
79:
80: /**
81: * @param id
82: * The id to set. Not Null.
83: */
84: public void setId(String id) {
85: Validate.notNull(id);
86: this.id = id;
87: }
88: }
|