Make List type safe. Remove/suppress all warnings.
[marc4j.git] / src / org / marc4j / samples / CheckAgencyExample.java
1 // $Id: CheckAgencyExample.java,v 1.1 2006/08/04 12:39:58 bpeters Exp $\r
2 /**\r
3  * Copyright (C) 2002-2006 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.samples;\r
22 \r
23 import java.io.InputStream;\r
24 import java.util.List;\r
25 \r
26 import org.marc4j.MarcReader;\r
27 import org.marc4j.MarcStreamReader;\r
28 import org.marc4j.marc.DataField;\r
29 import org.marc4j.marc.Record;\r
30 import org.marc4j.marc.VariableField;\r
31 \r
32 /**\r
33  * Demostrates the use of the find method.\r
34  * \r
35  * @author Bas Peters\r
36  * @version $Revision: 1.1 $\r
37  */\r
38 public class CheckAgencyExample {\r
39 \r
40     public static void main(String args[]) throws Exception {\r
41 \r
42         InputStream input = ReadMarcExample.class\r
43                 .getResourceAsStream("resources/summerland.mrc");\r
44 \r
45         MarcReader reader = new MarcStreamReader(input);\r
46         while (reader.hasNext()) {\r
47             Record record = reader.next();\r
48 \r
49             // check if the cataloging agency is DLC\r
50             List<VariableField> result = record.find("040", "DLC");\r
51             if (result.size() > 0)\r
52                 System.out.println("Agency for this record is DLC");\r
53 \r
54             // there is no specific find for a specific subfield\r
55             // so to check if it is the orignal cataloging agency\r
56             DataField field = (DataField) result.get(0);\r
57             String agency = field.getSubfield('a').getData();\r
58             if (agency.matches("DLC"))\r
59                 System.out.println("DLC is the original agency");\r
60         }\r
61     }\r
62 }\r