1 // $Id: DataFieldImpl.java,v 1.6 2006/08/04 12:31:41 bpeters Exp $
\r
3 * Copyright (C) 2004 Bas Peters
\r
5 * This file is part of MARC4J
\r
7 * MARC4J is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU Lesser General Public
\r
9 * License as published by the Free Software Foundation; either
\r
10 * version 2.1 of the License, or (at your option) any later version.
\r
12 * MARC4J is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
15 * Lesser General Public License for more details.
\r
17 * You should have received a copy of the GNU Lesser General Public
\r
18 * License along with MARC4J; if not, write to the Free Software
\r
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 package org.marc4j.marc.impl;
\r
23 import java.util.ArrayList;
\r
24 import java.util.Iterator;
\r
25 import java.util.List;
\r
27 import org.marc4j.marc.DataField;
\r
28 import org.marc4j.marc.IllegalAddException;
\r
29 import org.marc4j.marc.Subfield;
\r
32 * Represents a data field in a MARC record.
\r
34 * @author Bas Peters
\r
35 * @version $Revision: 1.6 $
\r
37 public class DataFieldImpl extends VariableFieldImpl implements DataField {
\r
45 private List subfields;
\r
48 * Creates a new <code>DataField</code>.
\r
50 public DataFieldImpl() {
\r
51 subfields = new ArrayList();
\r
55 * Creates a new <code>DataField</code> and sets the tag name and the
\r
56 * first and second indicator.
\r
61 * the first indicator
\r
63 * the second indicator
\r
65 public DataFieldImpl(String tag, char ind1, char ind2) {
\r
68 this.setIndicator1(ind1);
\r
69 this.setIndicator2(ind2);
\r
73 * Sets the first indicator.
\r
76 * the first indicator
\r
78 public void setIndicator1(char ind1) {
\r
83 * Returns the first indicator
\r
85 * @return char - the first indicator
\r
87 public char getIndicator1() {
\r
92 * Sets the second indicator.
\r
95 * the second indicator
\r
97 public void setIndicator2(char ind2) {
\r
102 * Returns the second indicator
\r
104 * @return char - the second indicator
\r
106 public char getIndicator2() {
\r
111 * Adds a <code>Subfield</code>.
\r
114 * the <code>Subfield</code> object
\r
115 * @throws IllegalAddException
\r
116 * when the parameter is not a <code>Subfield</code> instance
\r
118 public void addSubfield(Subfield subfield) {
\r
119 if (subfield instanceof SubfieldImpl)
\r
120 subfields.add(subfield);
\r
122 throw new IllegalAddException("Subfield");
\r
126 * Inserts a <code>Subfield</code> at the specified position.
\r
129 * the position within the list
\r
131 * the <code>Subfield</code> object
\r
132 * @throws IllegalAddException
\r
133 * when the parameter is not a <code>Subfield</code> instance
\r
135 public void addSubfield(int index, Subfield subfield) {
\r
136 subfields.add(index, subfield);
\r
140 * Removes a <code>Subfield</code>.
\r
142 public void removeSubfield(Subfield subfield) {
\r
143 subfields.remove(subfield);
\r
147 * Returns the list of <code>Subfield</code> objects.
\r
149 * @return List - the list of <code>Subfield</code> objects
\r
151 public List getSubfields() {
\r
155 public List getSubfields(char code) {
\r
156 List retSubfields = new ArrayList();
\r
157 Iterator i = subfields.iterator();
\r
158 while (i.hasNext()) {
\r
159 Subfield sf = (Subfield) i.next();
\r
160 if (sf.getCode() == code)
\r
161 retSubfields.add(sf);
\r
163 return retSubfields;
\r
166 public Subfield getSubfield(char code) {
\r
167 Iterator i = subfields.iterator();
\r
168 while (i.hasNext()) {
\r
169 Subfield sf = (Subfield) i.next();
\r
170 if (sf.getCode() == code)
\r
176 public boolean find(String pattern) {
\r
177 Iterator i = subfields.iterator();
\r
178 while (i.hasNext()) {
\r
179 Subfield sf = (Subfield) i.next();
\r
180 if (sf.find(pattern))
\r
187 * Returns a string representation of this data field.
\r
193 * 245 10$aSummerland /$cMichael Chabon.
\r
196 * @return String - a string representation of this data field
\r
198 public String toString() {
\r
199 StringBuffer sb = new StringBuffer();
\r
200 sb.append(super.toString());
\r
202 sb.append(getIndicator1());
\r
203 sb.append(getIndicator2());
\r
204 Iterator i = getSubfields().iterator();
\r
205 while (i.hasNext()) {
\r
206 Subfield sf = (Subfield) i.next();
\r
207 sb.append(sf.toString());
\r
209 return sb.toString();
\r
212 public void setId(Long id) {
\r
216 public Long getId() {
\r