Original 2.4
[marc4j.git] / src / org / marc4j / marc / impl / SubfieldImpl.java
1 // $Id: SubfieldImpl.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.Subfield;\r
27 \r
28 /**\r
29  * Represents a subfield in a MARC record.\r
30  * \r
31  * @author Bas Peters\r
32  * @version $Revision: 1.4 $\r
33  */\r
34 public class SubfieldImpl implements Subfield {\r
35 \r
36     private Long id;\r
37     \r
38     private char code;\r
39 \r
40     private String data;\r
41 \r
42     /**\r
43      * Creates a new <code>Subfield</code>.\r
44      */\r
45     public SubfieldImpl() {\r
46     }\r
47 \r
48     /**\r
49      * Creates a new <code>Subfield</code> and sets the data element\r
50      * identifier.\r
51      * \r
52      * @param code\r
53      *            the data element identifier\r
54      */\r
55     public SubfieldImpl(char code) {\r
56         this.setCode(code);\r
57     }\r
58 \r
59     /**\r
60      * Creates a new <code>Subfield</code> and sets the data element\r
61      * identifier and the data element.\r
62      * \r
63      * @param code\r
64      *            the data element identifier\r
65      * @param data\r
66      *            the data element\r
67      */\r
68     public SubfieldImpl(char code, String data) {\r
69         this.setCode(code);\r
70         this.setData(data);\r
71     }\r
72 \r
73     public void setCode(char code) {\r
74         this.code = code;\r
75     }\r
76 \r
77     public char getCode() {\r
78         return code;\r
79     }\r
80 \r
81     public void setData(String data) {\r
82         this.data = data;\r
83     }\r
84 \r
85     public String getData() {\r
86         return data;\r
87     }\r
88 \r
89     public boolean find(String pattern) {\r
90         Pattern p = Pattern.compile(pattern);\r
91         Matcher m = p.matcher(getData());\r
92         return m.find();\r
93     }\r
94 \r
95     /**\r
96      * Returns a string representation of this subfield.\r
97      * \r
98      * <p>\r
99      * Example:\r
100      * \r
101      * <pre>\r
102      * $aSummerland /\r
103      * </pre>\r
104      * \r
105      * @return String - a string representation of this subfield\r
106      */\r
107     public String toString() {\r
108         return "$" + getCode() + getData();\r
109     }\r
110     \r
111     public void setId(Long id) {\r
112         this.id = id;\r
113     }\r
114 \r
115     public Long getId() {\r
116         return id;\r
117     }\r
118 \r
119 }\r