Original 2.4
[marc4j.git] / src / org / marc4j / marc / impl / ControlFieldImpl.java
1 // $Id: ControlFieldImpl.java,v 1.4 2006/08/04 12:31:41 bpeters Exp $\r
2 /**\r
3  * Copyright (C) 2004 Bas Peters\r
4  *\r
5  * This file is part of MARC4J\r
6  *\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
11  *\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
16  *\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
20  */\r
21 package org.marc4j.marc.impl;\r
22 \r
23 import java.util.regex.Matcher;\r
24 import java.util.regex.Pattern;\r
25 \r
26 import org.marc4j.marc.ControlField;\r
27 \r
28 /**\r
29  * Represents a control field in a MARC record.\r
30  * \r
31  * @author Bas Peters\r
32  * @version $Revision: 1.4 $\r
33  */\r
34 public class ControlFieldImpl extends VariableFieldImpl implements ControlField {\r
35 \r
36     private Long id;\r
37     \r
38     private String data;\r
39 \r
40     /**\r
41      * Creates a new <code>ControlField</code>.\r
42      */\r
43     public ControlFieldImpl() {\r
44     }\r
45 \r
46     /**\r
47      * Creates a new <code>ControlField</code> and sets the tag name.\r
48      */\r
49     public ControlFieldImpl(String tag) {\r
50         this.setTag(tag);\r
51     }\r
52 \r
53     /**\r
54      * Creates a new <code>ControlField</code> and sets the tag name and the\r
55      * data element.\r
56      * \r
57      */\r
58     public ControlFieldImpl(String tag, String data) {\r
59         this.setTag(tag);\r
60         this.setData(data);\r
61     }\r
62 \r
63     public void setData(String data) {\r
64         this.data = data;\r
65     }\r
66 \r
67     public String getData() {\r
68         return data;\r
69     }\r
70 \r
71     /**\r
72      * Returns a string representation of this control field.\r
73      * \r
74      * <p>\r
75      * Example:\r
76      * \r
77      * <pre>\r
78      *     001 12883376\r
79      * </pre>\r
80      * \r
81      * @return String - a string representation of this control field\r
82      */\r
83     public String toString() {\r
84         return super.toString() + " " + getData();\r
85     }\r
86 \r
87     public boolean find(String pattern) {\r
88         Pattern p = Pattern.compile(pattern);\r
89         Matcher m = p.matcher(getData());\r
90         return m.find();\r
91     }\r
92 \r
93     public void setId(Long id) {\r
94         this.id = id;\r
95     }\r
96 \r
97     public Long getId() {\r
98         return id;\r
99     }\r
100 \r
101 }