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
42 private static final long serialVersionUID = -1804044736102463060L;
\r
50 private List<Subfield> subfields;
\r
53 * Creates a new <code>DataField</code>.
\r
55 public DataFieldImpl() {
\r
56 subfields = new ArrayList<Subfield>();
\r
60 * Creates a new <code>DataField</code> and sets the tag name and the
\r
61 * first and second indicator.
\r
66 * the first indicator
\r
68 * the second indicator
\r
70 public DataFieldImpl(String tag, char ind1, char ind2) {
\r
73 this.setIndicator1(ind1);
\r
74 this.setIndicator2(ind2);
\r
78 * Sets the first indicator.
\r
81 * the first indicator
\r
83 public void setIndicator1(char ind1) {
\r
88 * Returns the first indicator
\r
90 * @return char - the first indicator
\r
92 public char getIndicator1() {
\r
97 * Sets the second indicator.
\r
100 * the second indicator
\r
102 public void setIndicator2(char ind2) {
\r
107 * Returns the second indicator
\r
109 * @return char - the second indicator
\r
111 public char getIndicator2() {
\r
116 * Adds a <code>Subfield</code>.
\r
119 * the <code>Subfield</code> object
\r
120 * @throws IllegalAddException
\r
121 * when the parameter is not a <code>Subfield</code> instance
\r
123 public void addSubfield(Subfield subfield) {
\r
124 if (subfield instanceof SubfieldImpl)
\r
125 subfields.add(subfield);
\r
127 throw new IllegalAddException("Subfield");
\r
131 * Inserts a <code>Subfield</code> at the specified position.
\r
134 * the position within the list
\r
136 * the <code>Subfield</code> object
\r
137 * @throws IllegalAddException
\r
138 * when the parameter is not a <code>Subfield</code> instance
\r
140 public void addSubfield(int index, Subfield subfield) {
\r
141 subfields.add(index, subfield);
\r
145 * Removes a <code>Subfield</code>.
\r
147 public void removeSubfield(Subfield subfield) {
\r
148 subfields.remove(subfield);
\r
152 * Returns the list of <code>Subfield</code> objects.
\r
154 * @return List - the list of <code>Subfield</code> objects
\r
156 public List<Subfield> getSubfields() {
\r
160 public List<Subfield> getSubfields(char code) {
\r
161 List<Subfield> retSubfields = new ArrayList<Subfield>();
\r
162 Iterator<Subfield> i = subfields.iterator();
\r
163 while (i.hasNext()) {
\r
164 Subfield sf = (Subfield) i.next();
\r
165 if (sf.getCode() == code)
\r
166 retSubfields.add(sf);
\r
168 return retSubfields;
\r
171 public Subfield getSubfield(char code) {
\r
172 Iterator<Subfield> i = subfields.iterator();
\r
173 while (i.hasNext()) {
\r
174 Subfield sf = (Subfield) i.next();
\r
175 if (sf.getCode() == code)
\r
181 public boolean find(String pattern) {
\r
182 Iterator<Subfield> i = subfields.iterator();
\r
183 while (i.hasNext()) {
\r
184 Subfield sf = (Subfield) i.next();
\r
185 if (sf.find(pattern))
\r
192 * Returns a string representation of this data field.
\r
198 * 245 10$aSummerland /$cMichael Chabon.
\r
201 * @return String - a string representation of this data field
\r
203 public String toString() {
\r
204 StringBuffer sb = new StringBuffer();
\r
205 sb.append(super.toString());
\r
207 sb.append(getIndicator1());
\r
208 sb.append(getIndicator2());
\r
209 Iterator<Subfield> i = getSubfields().iterator();
\r
210 while (i.hasNext()) {
\r
211 Subfield sf = (Subfield) i.next();
\r
212 sb.append(sf.toString());
\r
214 return sb.toString();
\r
217 public void setId(Long id) {
\r
221 public Long getId() {
\r