Original 2.4
[marc4j.git] / src / org / marc4j / marc / impl / Verifier.java
1 // $Id: Verifier.java,v 1.2 2008/09/26 21:17:42 haschart 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.Collection;\r
24 import java.util.Iterator;\r
25 \r
26 import org.marc4j.marc.ControlField;\r
27 \r
28 /**\r
29  * Handles MARC checks on tags, data elements and <code>Record</code> objects.\r
30  * \r
31  * @author Bas Peters\r
32  * @version $Revision: 1.2 $\r
33  */\r
34 public class Verifier {\r
35 \r
36   private Verifier() {\r
37   }\r
38 \r
39   /**\r
40    * Returns true if the given <code>String</code> value identifies a tag for\r
41    * a control field (001 through 009).\r
42    */\r
43   public static boolean isControlField(String tag) {\r
44     if (tag.length() == 3 && tag.charAt(0) == '0' && tag.charAt(1) == '0' && tag.charAt(2) >= '0' && tag.charAt(2) <= '9')// if (Integer.parseInt(tag) < 10)\r
45       return true;\r
46     return false;\r
47   }\r
48 \r
49   /**\r
50    * Returns true if the given <code>String</code> value identifies a tag for\r
51    * a control number field (001).\r
52    */\r
53   public static boolean isControlNumberField(String tag){\r
54     if (tag.equals("001"))\r
55       return true;\r
56     return false;\r
57   }\r
58 /**\r
59    * Returns true if the given <code>Collection</code> contains an instance of\r
60    * a <code>ControlField</code> with a control number field tag (001).\r
61    * \r
62    * @param col\r
63    *          the collection of <code>ControlField</code> objects.\r
64    */\r
65   public static boolean hasControlNumberField(Collection col) {\r
66     Iterator i = col.iterator();\r
67     while (i.hasNext()) {\r
68       ControlField field = (ControlField) i.next();\r
69       String tag = field.getTag();\r
70       if (isControlNumberField(tag))\r
71         return true;\r
72     }\r
73     return false;\r
74   }\r
75 \r
76 }