From 50f32ab70a47cf0d329bf65a596f94dbb413c76f Mon Sep 17 00:00:00 2001 From: Dennis Schafroth Date: Tue, 3 Jan 2012 15:41:24 +0100 Subject: [PATCH] Make List type safe. Remove/suppress all warnings. --- src/org/marc4j/ErrorHandler.java | 8 +-- src/org/marc4j/MarcException.java | 5 ++ src/org/marc4j/MarcPermissiveStreamReader.java | 6 +- src/org/marc4j/MarcStreamReader.java | 7 +- src/org/marc4j/MarcStreamWriter.java | 18 ++--- src/org/marc4j/MarcXmlHandler.java | 7 +- src/org/marc4j/MarcXmlWriter.java | 26 +++---- src/org/marc4j/RecordStack.java | 4 +- src/org/marc4j/converter/impl/AnselToUnicode.java | 20 ++++-- src/org/marc4j/converter/impl/CodeTable.java | 7 +- .../marc4j/converter/impl/CodeTableGenerator.java | 2 + .../marc4j/converter/impl/CodeTableHandler.java | 11 +++ .../marc4j/converter/impl/ReverseCodeTable.java | 5 ++ .../converter/impl/ReverseCodeTableHandler.java | 9 +++ src/org/marc4j/converter/impl/UnicodeToAnsel.java | 4 +- src/org/marc4j/marc/DataField.java | 4 +- src/org/marc4j/marc/IllegalAddException.java | 5 ++ src/org/marc4j/marc/MarcFactory.java | 3 +- src/org/marc4j/marc/Record.java | 16 ++--- src/org/marc4j/marc/VariableField.java | 3 +- src/org/marc4j/marc/impl/ControlFieldImpl.java | 5 ++ src/org/marc4j/marc/impl/DataFieldImpl.java | 23 ++++--- src/org/marc4j/marc/impl/LeaderImpl.java | 5 ++ src/org/marc4j/marc/impl/RecordImpl.java | 72 ++++++++++++-------- src/org/marc4j/marc/impl/SubfieldImpl.java | 5 ++ src/org/marc4j/marc/impl/VariableFieldImpl.java | 4 ++ src/org/marc4j/marc/impl/Verifier.java | 3 +- src/org/marc4j/samples/CheckAgencyExample.java | 3 +- src/org/marc4j/samples/DataFieldExample.java | 32 +++++---- .../marc4j/samples/PermissiveReaderExample.java | 6 +- .../marc4j/samples/RemoveLocalFieldsExample.java | 4 +- src/org/marc4j/samples/TagAnalysisExample.java | 10 +-- .../marc4j/samples/XercesSerializerExample.java | 10 +-- src/org/marc4j/test/ControlFieldTest.java | 1 + src/org/marc4j/test/DataFieldTest.java | 1 + src/org/marc4j/test/RecordTest.java | 11 +-- src/org/marc4j/test/RoundtripTest.java | 6 +- 37 files changed, 231 insertions(+), 140 deletions(-) diff --git a/src/org/marc4j/ErrorHandler.java b/src/org/marc4j/ErrorHandler.java index 63e5bc8..e201608 100644 --- a/src/org/marc4j/ErrorHandler.java +++ b/src/org/marc4j/ErrorHandler.java @@ -74,7 +74,7 @@ public class ErrorHandler { */ public final static int INFO = 0; - private List errors; + private List errors; private String curRecordID; private String curField; private String curSubfield; @@ -171,7 +171,7 @@ public class ErrorHandler { * * @return List - A list of all of the errors encountered for the current record. */ - public List getErrors() + public List getErrors() { if (errors == null || errors.size() == 0) return null; return(errors); @@ -202,7 +202,7 @@ public class ErrorHandler { { if (errors == null) { - errors = new LinkedList(); + errors = new LinkedList(); hasMissingID = false; } if (id != null && id.equals("unknown")) hasMissingID = true; @@ -231,7 +231,7 @@ public class ErrorHandler { { if (id != null) { - Iterator iter = errors.iterator(); + Iterator iter = errors.iterator(); while (iter.hasNext()) { Error err = (Error)(iter.next()); diff --git a/src/org/marc4j/MarcException.java b/src/org/marc4j/MarcException.java index 0fb40cd..1bb0cda 100644 --- a/src/org/marc4j/MarcException.java +++ b/src/org/marc4j/MarcException.java @@ -30,6 +30,11 @@ package org.marc4j; public class MarcException extends RuntimeException { /** + * + */ + private static final long serialVersionUID = -7600942667740838717L; + + /** * Create a new MarcException with no detail mesage. */ public MarcException() { diff --git a/src/org/marc4j/MarcPermissiveStreamReader.java b/src/org/marc4j/MarcPermissiveStreamReader.java index 1f0df96..e907194 100644 --- a/src/org/marc4j/MarcPermissiveStreamReader.java +++ b/src/org/marc4j/MarcPermissiveStreamReader.java @@ -27,15 +27,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.marc4j.Constants; -import org.marc4j.MarcException; -import org.marc4j.MarcReader; import org.marc4j.converter.CharConverter; import org.marc4j.converter.impl.AnselToUnicode; import org.marc4j.converter.impl.Iso5426ToUnicode; @@ -285,7 +281,7 @@ public class MarcPermissiveStreamReader implements MarcReader { { input.readFully(recordBuf); } - String tmp = new String(recordBuf); + //String tmp = new String(recordBuf); parseRecord(record, byteArray, recordBuf, recordLength); if (this.convertToUTF8) diff --git a/src/org/marc4j/MarcStreamReader.java b/src/org/marc4j/MarcStreamReader.java index 3fc1d9b..473450a 100644 --- a/src/org/marc4j/MarcStreamReader.java +++ b/src/org/marc4j/MarcStreamReader.java @@ -28,9 +28,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import org.marc4j.converter.CharConverter; import org.marc4j.converter.impl.AnselToUnicode; @@ -40,7 +37,6 @@ import org.marc4j.marc.Leader; import org.marc4j.marc.MarcFactory; import org.marc4j.marc.Record; import org.marc4j.marc.Subfield; -import org.marc4j.marc.VariableField; import org.marc4j.marc.impl.Verifier; /** @@ -216,7 +212,7 @@ public class MarcStreamReader implements MarcReader { for (int i = 0; i < size; i++) { - int fieldLength = getFieldLength(inputrec); + //int fieldLength = getFieldLength(inputrec); if (Verifier.isControlField(tags[i])) { byteArray = new byte[lengths[i] - 1]; @@ -301,6 +297,7 @@ public class MarcStreamReader implements MarcReader { return dataField; } + @SuppressWarnings("unused") private int getFieldLength(DataInputStream bais) throws IOException { bais.mark(9999); diff --git a/src/org/marc4j/MarcStreamWriter.java b/src/org/marc4j/MarcStreamWriter.java index 0023722..46274be 100644 --- a/src/org/marc4j/MarcStreamWriter.java +++ b/src/org/marc4j/MarcStreamWriter.java @@ -135,8 +135,8 @@ public class MarcStreamWriter implements MarcWriter { ByteArrayOutputStream dir = new ByteArrayOutputStream(); // control fields - List fields = record.getControlFields(); - Iterator i = fields.iterator(); + List fields = record.getControlFields(); + Iterator i = fields.iterator(); while (i.hasNext()) { ControlField cf = (ControlField) i.next(); @@ -148,16 +148,16 @@ public class MarcStreamWriter implements MarcWriter { } // data fields - fields = record.getDataFields(); - i = fields.iterator(); - while (i.hasNext()) { - DataField df = (DataField) i.next(); + List dataFields = record.getDataFields(); + Iterator di = dataFields.iterator(); + while (di.hasNext()) { + DataField df = di.next(); data.write(df.getIndicator1()); data.write(df.getIndicator2()); - List subfields = df.getSubfields(); - Iterator si = subfields.iterator(); + List subfields = df.getSubfields(); + Iterator si = subfields.iterator(); while (si.hasNext()) { - Subfield sf = (Subfield) si.next(); + Subfield sf = si.next(); data.write(Constants.US); data.write(sf.getCode()); data.write(getDataElement(sf.getData())); diff --git a/src/org/marc4j/MarcXmlHandler.java b/src/org/marc4j/MarcXmlHandler.java index 5b6bf38..c07d9f7 100644 --- a/src/org/marc4j/MarcXmlHandler.java +++ b/src/org/marc4j/MarcXmlHandler.java @@ -31,7 +31,6 @@ import org.marc4j.marc.Record; import org.marc4j.marc.Subfield; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; -import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; @@ -46,7 +45,7 @@ public class MarcXmlHandler implements ContentHandler { private RecordStack queue; - private InputSource input; + //private InputSource input; private StringBuffer sb; @@ -86,12 +85,12 @@ public class MarcXmlHandler implements ContentHandler { private static final String IND_2_ATTR = "ind2"; /** Hashset for mapping of element strings to constants (Integer) */ - private static final HashMap elementMap; + private static final HashMap elementMap; private MarcFactory factory = null; static { - elementMap = new HashMap(); + elementMap = new HashMap(); elementMap.put("collection", new Integer(COLLECTION_ID)); elementMap.put("leader", new Integer(LEADER_ID)); elementMap.put("record", new Integer(RECORD_ID)); diff --git a/src/org/marc4j/MarcXmlWriter.java b/src/org/marc4j/MarcXmlWriter.java index a28981a..7e52fc2 100644 --- a/src/org/marc4j/MarcXmlWriter.java +++ b/src/org/marc4j/MarcXmlWriter.java @@ -94,8 +94,8 @@ import com.ibm.icu.text.Normalizer; *

* In addition you can perform Unicode normalization. This is for example not * done by the MARC-8 to UCS/Unicode converter. With Unicode normalization text - * is transformed into the canonical composed form. For example "a´bc" - * is normalized to "ábc". To perform normalization set Unicode + * is transformed into the canonical composed form. For example "a�bc" + * is normalized to "�bc". To perform normalization set Unicode * normalization to true: *

* @@ -218,7 +218,7 @@ public class MarcXmlWriter implements MarcWriter { /** * Character encoding. Default is UTF-8. */ - private String encoding = "UTF8"; + //private String encoding = "UTF8"; private CharConverter converter = null; @@ -273,7 +273,7 @@ public class MarcXmlWriter implements MarcWriter { setIndent(indent); writer = new OutputStreamWriter(out, encoding); writer = new BufferedWriter(writer); - this.encoding = encoding; + // this.encoding = encoding; setHandler(new StreamResult(writer), null); } catch (UnsupportedEncodingException e) { throw new MarcException(e.getMessage(), e); @@ -487,9 +487,9 @@ public class MarcXmlWriter implements MarcWriter { handler.characters(temp, 0, temp.length); handler.endElement(Constants.MARCXML_NS_URI, LEADER, LEADER); - Iterator i = record.getControlFields().iterator(); - while (i.hasNext()) { - ControlField field = (ControlField) i.next(); + Iterator ci = record.getControlFields().iterator(); + while (ci.hasNext()) { + ControlField field = (ControlField) ci.next(); atts = new AttributesImpl(); atts.addAttribute("", "tag", "tag", "CDATA", field.getTag()); @@ -504,9 +504,9 @@ public class MarcXmlWriter implements MarcWriter { CONTROL_FIELD); } - i = record.getDataFields().iterator(); - while (i.hasNext()) { - DataField field = (DataField) i.next(); + Iterator di = record.getDataFields().iterator(); + while (di.hasNext()) { + DataField field = di.next(); atts = new AttributesImpl(); atts.addAttribute("", "tag", "tag", "CDATA", field.getTag()); atts.addAttribute("", "ind1", "ind1", "CDATA", String.valueOf(field @@ -519,9 +519,9 @@ public class MarcXmlWriter implements MarcWriter { handler.startElement(Constants.MARCXML_NS_URI, DATA_FIELD, DATA_FIELD, atts); - Iterator j = field.getSubfields().iterator(); - while (j.hasNext()) { - Subfield subfield = (Subfield) j.next(); + Iterator si = field.getSubfields().iterator(); + while (si.hasNext()) { + Subfield subfield = (Subfield) si.next(); atts = new AttributesImpl(); atts.addAttribute("", "code", "code", "CDATA", String .valueOf(subfield.getCode())); diff --git a/src/org/marc4j/RecordStack.java b/src/org/marc4j/RecordStack.java index 3346510..c8c212a 100644 --- a/src/org/marc4j/RecordStack.java +++ b/src/org/marc4j/RecordStack.java @@ -35,7 +35,7 @@ import org.marc4j.marc.Record; */ public class RecordStack { - private List list; + private List list; private RuntimeException re = null; private boolean eof = false; @@ -44,7 +44,7 @@ public class RecordStack { * */ public RecordStack() { - list = new ArrayList(); + list = new ArrayList(); } /** diff --git a/src/org/marc4j/converter/impl/AnselToUnicode.java b/src/org/marc4j/converter/impl/AnselToUnicode.java index b9d6c26..1d62ed5 100644 --- a/src/org/marc4j/converter/impl/AnselToUnicode.java +++ b/src/org/marc4j/converter/impl/AnselToUnicode.java @@ -44,15 +44,22 @@ import org.marc4j.converter.CharConverter; */ public class AnselToUnicode extends CharConverter { + @SuppressWarnings("rawtypes") class Queue extends Vector { /** + * + */ + private static final long serialVersionUID = 7414878465947143461L; + + /** * Puts an item into the queue. * * @param item * the item to be put into the queue. */ - public Object put(Object item) { + @SuppressWarnings("unchecked") + public Object put(Object item) { addElement(item); return item; @@ -63,7 +70,8 @@ public class AnselToUnicode extends CharConverter { */ public Object get() { Object obj; - int len = size(); + @SuppressWarnings("unused") + int len = size(); obj = peek(); removeElementAt(0); @@ -75,7 +83,8 @@ public class AnselToUnicode extends CharConverter { * Peeks at the front of the queue. */ public Object peek() { - int len = size(); + @SuppressWarnings("unused") + int len = size(); return elementAt(0); } @@ -151,6 +160,7 @@ public class AnselToUnicode extends CharConverter { } + @SuppressWarnings({ "rawtypes", "unchecked" }) private CodeTableInterface loadGeneratedTable(boolean loadMultibyte) { try @@ -218,7 +228,8 @@ public class AnselToUnicode extends CharConverter { private void checkMode(char[] data, CodeTracker cdt) { int extra = 0; int extra2 = 0; - int extra3 = 0; + @SuppressWarnings("unused") + int extra3 = 0; while (cdt.offset + extra + extra2< data.length && isEscape(data[cdt.offset])) { switch (data[cdt.offset + 1 + extra]) { case 0x28: // '(' @@ -519,6 +530,7 @@ public class AnselToUnicode extends CharConverter { return sb.toString(); } + @SuppressWarnings("unused") private int makeMultibyte(char[] data) { int[] chars = new int[3]; chars[0] = data[0] << 16; diff --git a/src/org/marc4j/converter/impl/CodeTable.java b/src/org/marc4j/converter/impl/CodeTable.java index 95c31fe..0973c8c 100644 --- a/src/org/marc4j/converter/impl/CodeTable.java +++ b/src/org/marc4j/converter/impl/CodeTable.java @@ -23,11 +23,8 @@ package org.marc4j.converter.impl; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import java.io.PrintStream; import java.net.URI; -import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.Vector; import javax.xml.parsers.SAXParser; @@ -48,10 +45,13 @@ import org.xml.sax.XMLReader; * */ public class CodeTable implements CodeTableInterface { + @SuppressWarnings("rawtypes") protected static HashMap charsets = null; + @SuppressWarnings("rawtypes") protected static HashMap combining = null; + @SuppressWarnings("rawtypes") public boolean isCombining(int i, int g0, int g1) { if (i <= 0x7E) { Vector v = (Vector) combining.get(new Integer(g0)); @@ -62,6 +62,7 @@ public class CodeTable implements CodeTableInterface { } } + @SuppressWarnings("rawtypes") public char getChar(int c, int mode) { if (c == 0x20) return (char) c; diff --git a/src/org/marc4j/converter/impl/CodeTableGenerator.java b/src/org/marc4j/converter/impl/CodeTableGenerator.java index bdeb663..023cc55 100644 --- a/src/org/marc4j/converter/impl/CodeTableGenerator.java +++ b/src/org/marc4j/converter/impl/CodeTableGenerator.java @@ -57,6 +57,7 @@ public class CodeTableGenerator extends CodeTable { ct.dumpTableAsSwitchStatement(System.out); } + @SuppressWarnings("rawtypes") private void dumpTableAsSwitchStatement(PrintStream output) { output.println("package org.marc4j.converter.impl;"); @@ -169,6 +170,7 @@ public class CodeTableGenerator extends CodeTable { output.println("}"); } + @SuppressWarnings("rawtypes") private void dumpPartialMultiByteTable(PrintStream output, StringBuffer buffer, Object keyArray[], HashMap map, int startByte, int endByte) { String startByteStr = "0x"+Integer.toHexString(startByte); diff --git a/src/org/marc4j/converter/impl/CodeTableHandler.java b/src/org/marc4j/converter/impl/CodeTableHandler.java index 9b8a371..5662566 100644 --- a/src/org/marc4j/converter/impl/CodeTableHandler.java +++ b/src/org/marc4j/converter/impl/CodeTableHandler.java @@ -47,10 +47,13 @@ import org.xml.sax.helpers.DefaultHandler; */ public class CodeTableHandler extends DefaultHandler { + @SuppressWarnings("rawtypes") private HashMap sets; + @SuppressWarnings("rawtypes") private HashMap charset; + @SuppressWarnings("rawtypes") private HashMap combiningchars; /** Data element identifier */ @@ -64,21 +67,26 @@ public class CodeTableHandler extends DefaultHandler { private boolean iscombining; + @SuppressWarnings("rawtypes") private Vector combining; /** Tag name */ + @SuppressWarnings("unused") private String tag; /** StringBuffer to store data */ private StringBuffer data; /** Locator object */ + @SuppressWarnings("unused") private Locator locator; + @SuppressWarnings("rawtypes") public HashMap getCharSets() { return sets; } + @SuppressWarnings("rawtypes") public HashMap getCombiningChars() { return combiningchars; } @@ -95,6 +103,7 @@ public class CodeTableHandler extends DefaultHandler { this.locator = locator; } + @SuppressWarnings("rawtypes") public void startElement(String uri, String name, String qName, Attributes atts) throws SAXParseException { if (name.equals("characterSet")) { @@ -122,6 +131,7 @@ public class CodeTableHandler extends DefaultHandler { } } + @SuppressWarnings("unchecked") public void endElement(String uri, String name, String qName) throws SAXParseException { if (name.equals("characterSet")) { @@ -154,6 +164,7 @@ public class CodeTableHandler extends DefaultHandler { data = null; } + @SuppressWarnings({ "unused", "rawtypes" }) public static void main(String[] args) { HashMap charsets = null; diff --git a/src/org/marc4j/converter/impl/ReverseCodeTable.java b/src/org/marc4j/converter/impl/ReverseCodeTable.java index 967eabd..45e6667 100644 --- a/src/org/marc4j/converter/impl/ReverseCodeTable.java +++ b/src/org/marc4j/converter/impl/ReverseCodeTable.java @@ -47,14 +47,17 @@ import org.xml.sax.helpers.DefaultHandler; * @see DefaultHandler */ public class ReverseCodeTable { + @SuppressWarnings("rawtypes") protected static Hashtable charset = null; + @SuppressWarnings("rawtypes") protected static Vector combining = null; public boolean isCombining(Character c) { return combining.contains(c); } + @SuppressWarnings("rawtypes") public Hashtable codeTableHash(Character c) { Hashtable chars = (Hashtable) charset.get(c); if (chars == null) { @@ -64,6 +67,7 @@ public class ReverseCodeTable { return chars; } + @SuppressWarnings("rawtypes") public static boolean inPreviousCharCodeTable(Character c, CodeTableTracker ctt) { Hashtable chars = (Hashtable) charset.get(c); @@ -82,6 +86,7 @@ public class ReverseCodeTable { } } + @SuppressWarnings("rawtypes") public static char getChar(Character c, CodeTableTracker ctt) { Hashtable chars = (Hashtable) charset.get(c); diff --git a/src/org/marc4j/converter/impl/ReverseCodeTableHandler.java b/src/org/marc4j/converter/impl/ReverseCodeTableHandler.java index 2f7fe5e..7f41646 100644 --- a/src/org/marc4j/converter/impl/ReverseCodeTableHandler.java +++ b/src/org/marc4j/converter/impl/ReverseCodeTableHandler.java @@ -47,8 +47,10 @@ import org.xml.sax.helpers.DefaultHandler; * @see DefaultHandler */ public class ReverseCodeTableHandler extends DefaultHandler { + @SuppressWarnings("rawtypes") private Hashtable charset; + @SuppressWarnings("rawtypes") private Vector combiningchars; private boolean useAlt = false; @@ -63,18 +65,22 @@ public class ReverseCodeTableHandler extends DefaultHandler { private boolean combining; /** Tag name */ + @SuppressWarnings("unused") private String tag; /** StringBuffer to store data */ private StringBuffer data; /** Locator object */ + @SuppressWarnings("unused") private Locator locator; + @SuppressWarnings("rawtypes") public Hashtable getCharSets() { return charset; } + @SuppressWarnings("rawtypes") public Vector getCombiningChars() { return combiningchars; } @@ -91,6 +97,7 @@ public class ReverseCodeTableHandler extends DefaultHandler { this.locator = locator; } + @SuppressWarnings("rawtypes") public void startElement(String uri, String name, String qName, Attributes atts) throws SAXParseException { if (name.equals("characterSet")) @@ -117,6 +124,7 @@ public class ReverseCodeTableHandler extends DefaultHandler { } } + @SuppressWarnings({ "unchecked", "rawtypes" }) public void endElement(String uri, String name, String qName) throws SAXParseException { if (name.equals("marc")) { @@ -160,6 +168,7 @@ public class ReverseCodeTableHandler extends DefaultHandler { data = null; } + @SuppressWarnings({ "rawtypes", "unused" }) public static void main(String[] args) { Hashtable charsets = null; diff --git a/src/org/marc4j/converter/impl/UnicodeToAnsel.java b/src/org/marc4j/converter/impl/UnicodeToAnsel.java index 6c13610..6e2ce5f 100644 --- a/src/org/marc4j/converter/impl/UnicodeToAnsel.java +++ b/src/org/marc4j/converter/impl/UnicodeToAnsel.java @@ -96,11 +96,13 @@ public class UnicodeToAnsel extends CharConverter { * @param data - the UCS/Unicode data in an array of char * @return String - the MARC-8 data */ + @SuppressWarnings("rawtypes") public String convert(char data[]) { StringBuffer sb = new StringBuffer(); CodeTableTracker ctt = new CodeTableTracker(); - boolean technique1 = false; + @SuppressWarnings("unused") + boolean technique1 = false; for (int i = 0; i < data.length; i++) { Character c = new Character(data[i]); diff --git a/src/org/marc4j/marc/DataField.java b/src/org/marc4j/marc/DataField.java index 146cb90..3af95f0 100644 --- a/src/org/marc4j/marc/DataField.java +++ b/src/org/marc4j/marc/DataField.java @@ -65,7 +65,7 @@ public interface DataField extends VariableField { * * @return List - the list of Subfield objects */ - public List getSubfields(); + public List getSubfields(); /** * Returns the list of Subfield objects for the goven @@ -75,7 +75,7 @@ public interface DataField extends VariableField { * the subfield code * @return List - the list of Subfield objects */ - public List getSubfields(char code); + public List getSubfields(char code); /** * Returns the first Subfield with the given code. diff --git a/src/org/marc4j/marc/IllegalAddException.java b/src/org/marc4j/marc/IllegalAddException.java index f0c5738..73a6a31 100644 --- a/src/org/marc4j/marc/IllegalAddException.java +++ b/src/org/marc4j/marc/IllegalAddException.java @@ -30,6 +30,11 @@ public class IllegalAddException extends IllegalArgumentException { /** + * + */ + private static final long serialVersionUID = 8756226018321264604L; + + /** * Creates a new Exception indicating that the addttion * of the supplied object is illegal. * diff --git a/src/org/marc4j/marc/MarcFactory.java b/src/org/marc4j/marc/MarcFactory.java index 2e87341..43d30f6 100644 --- a/src/org/marc4j/marc/MarcFactory.java +++ b/src/org/marc4j/marc/MarcFactory.java @@ -75,7 +75,8 @@ public abstract class MarcFactory { className = getFactoryClassName(loader, count++); if (className != null) { try { - Class t = (loader != null) ? loader.loadClass(className) : Class + @SuppressWarnings("rawtypes") + Class t = (loader != null) ? loader.loadClass(className) : Class .forName(className); return (MarcFactory) t.newInstance(); } catch (ClassNotFoundException e) { diff --git a/src/org/marc4j/marc/Record.java b/src/org/marc4j/marc/Record.java index 62b5aca..a4453fb 100644 --- a/src/org/marc4j/marc/Record.java +++ b/src/org/marc4j/marc/Record.java @@ -90,21 +90,21 @@ public interface Record extends Serializable { * * @return List - the variable fields */ - public List getVariableFields(); + public List getVariableFields(); /** * Returns a list of control fields * * @return List - the control fields */ - public List getControlFields(); + public List getControlFields(); /** * Returns a list of data fields * * @return List - the data fields */ - public List getDataFields(); + public List getDataFields(); /** * Returns the control number field or null if no control @@ -137,7 +137,7 @@ public interface Record extends Serializable { * * @return List - the variable fields */ - public List getVariableFields(String tag); + public List getVariableFields(String tag); /** * Returns a list of variable fields for the given tags. @@ -153,7 +153,7 @@ public interface Record extends Serializable { * * @return List - the variable fields */ - public List getVariableFields(String[] tag); + public List getVariableFields(String[] tag); /** * Returns the Leader. @@ -183,7 +183,7 @@ public interface Record extends Serializable { * the regular expression * @return List - the result list */ - public List find(String pattern); + public List find(String pattern); /** * Returns a List of VariableField objects with the given tag that have a @@ -200,7 +200,7 @@ public interface Record extends Serializable { * the regular expression * @return List - the result list */ - public List find(String tag, String pattern); + public List find(String tag, String pattern); /** * Returns a List of VariableField objects with the given tags that have a @@ -217,6 +217,6 @@ public interface Record extends Serializable { * the regular expression * @return List - the result list */ - public List find(String[] tag, String pattern); + public List find(String[] tag, String pattern); } \ No newline at end of file diff --git a/src/org/marc4j/marc/VariableField.java b/src/org/marc4j/marc/VariableField.java index 5320179..3aebaf2 100644 --- a/src/org/marc4j/marc/VariableField.java +++ b/src/org/marc4j/marc/VariableField.java @@ -22,14 +22,13 @@ package org.marc4j.marc; import java.io.Serializable; -import org.marc4j.marc.impl.VariableFieldImpl; - /** * Represents a variable field in a MARC record. * * @author Bas Peters * @version $Revision: 1.10 $ */ +@SuppressWarnings("rawtypes") public interface VariableField extends Serializable, Comparable { /** diff --git a/src/org/marc4j/marc/impl/ControlFieldImpl.java b/src/org/marc4j/marc/impl/ControlFieldImpl.java index 2d0a93e..ea06d1a 100644 --- a/src/org/marc4j/marc/impl/ControlFieldImpl.java +++ b/src/org/marc4j/marc/impl/ControlFieldImpl.java @@ -33,6 +33,11 @@ import org.marc4j.marc.ControlField; */ public class ControlFieldImpl extends VariableFieldImpl implements ControlField { + /** + * + */ + private static final long serialVersionUID = 8072900114616013850L; + private Long id; private String data; diff --git a/src/org/marc4j/marc/impl/DataFieldImpl.java b/src/org/marc4j/marc/impl/DataFieldImpl.java index 6a684f5..dfed133 100644 --- a/src/org/marc4j/marc/impl/DataFieldImpl.java +++ b/src/org/marc4j/marc/impl/DataFieldImpl.java @@ -36,19 +36,24 @@ import org.marc4j.marc.Subfield; */ public class DataFieldImpl extends VariableFieldImpl implements DataField { + /** + * + */ + private static final long serialVersionUID = -1804044736102463060L; + private Long id; private char ind1; private char ind2; - private List subfields; + private List subfields; /** * Creates a new DataField. */ public DataFieldImpl() { - subfields = new ArrayList(); + subfields = new ArrayList(); } /** @@ -148,13 +153,13 @@ public class DataFieldImpl extends VariableFieldImpl implements DataField { * * @return List - the list of Subfield objects */ - public List getSubfields() { + public List getSubfields() { return subfields; } - public List getSubfields(char code) { - List retSubfields = new ArrayList(); - Iterator i = subfields.iterator(); + public List getSubfields(char code) { + List retSubfields = new ArrayList(); + Iterator i = subfields.iterator(); while (i.hasNext()) { Subfield sf = (Subfield) i.next(); if (sf.getCode() == code) @@ -164,7 +169,7 @@ public class DataFieldImpl extends VariableFieldImpl implements DataField { } public Subfield getSubfield(char code) { - Iterator i = subfields.iterator(); + Iterator i = subfields.iterator(); while (i.hasNext()) { Subfield sf = (Subfield) i.next(); if (sf.getCode() == code) @@ -174,7 +179,7 @@ public class DataFieldImpl extends VariableFieldImpl implements DataField { } public boolean find(String pattern) { - Iterator i = subfields.iterator(); + Iterator i = subfields.iterator(); while (i.hasNext()) { Subfield sf = (Subfield) i.next(); if (sf.find(pattern)) @@ -201,7 +206,7 @@ public class DataFieldImpl extends VariableFieldImpl implements DataField { sb.append(' '); sb.append(getIndicator1()); sb.append(getIndicator2()); - Iterator i = getSubfields().iterator(); + Iterator i = getSubfields().iterator(); while (i.hasNext()) { Subfield sf = (Subfield) i.next(); sb.append(sf.toString()); diff --git a/src/org/marc4j/marc/impl/LeaderImpl.java b/src/org/marc4j/marc/impl/LeaderImpl.java index 56db8cf..0534ead 100644 --- a/src/org/marc4j/marc/impl/LeaderImpl.java +++ b/src/org/marc4j/marc/impl/LeaderImpl.java @@ -33,6 +33,11 @@ import org.marc4j.marc.Leader; */ public class LeaderImpl implements Leader { + /** + * + */ + private static final long serialVersionUID = 6483942612907658766L; + private Long id; /** The logical record length (Position 0-4). */ diff --git a/src/org/marc4j/marc/impl/RecordImpl.java b/src/org/marc4j/marc/impl/RecordImpl.java index b6b8a8c..ceb6249 100644 --- a/src/org/marc4j/marc/impl/RecordImpl.java +++ b/src/org/marc4j/marc/impl/RecordImpl.java @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.List; import org.marc4j.marc.ControlField; +import org.marc4j.marc.DataField; import org.marc4j.marc.IllegalAddException; import org.marc4j.marc.Leader; import org.marc4j.marc.Record; @@ -39,13 +40,18 @@ import org.marc4j.marc.VariableField; */ public class RecordImpl implements Record { + /** + * + */ + private static final long serialVersionUID = 1906886225329068668L; + private Long id; private Leader leader; - private List controlFields; + private List controlFields; - private List dataFields; + private List dataFields; private String type; @@ -53,8 +59,8 @@ public class RecordImpl implements Record { * Creates a new Record. */ public RecordImpl() { - controlFields = new ArrayList(); - dataFields = new ArrayList(); + controlFields = new ArrayList(); + dataFields = new ArrayList(); } public void setType(String type) { @@ -87,6 +93,7 @@ public class RecordImpl implements Record { * when the parameter is not a VariableField * instance */ + @SuppressWarnings("unchecked") public void addVariableField(VariableField field) { if (!(field instanceof VariableField)) throw new IllegalAddException("Expected VariableField instance"); @@ -94,15 +101,16 @@ public class RecordImpl implements Record { String tag = field.getTag(); if (Verifier.isControlNumberField(tag)) { if (Verifier.hasControlNumberField(controlFields)) - controlFields.set(0, field); + // TODO create converter from VariableField to ControlField + controlFields.set(0, ((ControlField) field)); else - controlFields.add(0, field); + controlFields.add(0, ((ControlField) field)); Collections.sort(controlFields); } else if (Verifier.isControlField(tag)) { - controlFields.add(field); + controlFields.add(((ControlField) field)); Collections.sort(controlFields); } else { - dataFields.add(field); + dataFields.add(((DataField) field)); Collections.sort(dataFields); } @@ -129,16 +137,17 @@ public class RecordImpl implements Record { return null; } - public List getControlFields() { + public List getControlFields() { return controlFields; } - public List getDataFields() { + public List getDataFields() { return dataFields; } public VariableField getVariableField(String tag) { - Iterator i; + @SuppressWarnings("rawtypes") + Iterator i; if (Verifier.isControlField(tag)) i = controlFields.iterator(); else @@ -151,9 +160,10 @@ public class RecordImpl implements Record { return null; } - public List getVariableFields(String tag) { - List fields = new ArrayList(); - Iterator i; + public List getVariableFields(String tag) { + List fields = new ArrayList(); + @SuppressWarnings("rawtypes") + Iterator i; if (Verifier.isControlField(tag)) i = controlFields.iterator(); else @@ -166,15 +176,16 @@ public class RecordImpl implements Record { return fields; } - public List getVariableFields() { - List fields = new ArrayList(); - Iterator i; - i = controlFields.iterator(); + @SuppressWarnings("rawtypes") + public List getVariableFields() { + List fields = new ArrayList(); + Iterator i; + i = ((List) controlFields).iterator(); while (i.hasNext()) - fields.add(i.next()); + fields.add((VariableField) i.next()); i = dataFields.iterator(); while (i.hasNext()) - fields.add(i.next()); + fields.add((VariableField) i.next()); return fields; } @@ -184,7 +195,8 @@ public class RecordImpl implements Record { return(result); } - public List getVariableFields(String[] tags) { + @SuppressWarnings({ "rawtypes", "unchecked" }) + public List getVariableFields(String[] tags) { List list = new ArrayList(); for (int i = 0; i < tags.length; i++) { String tag = tags[i]; @@ -228,7 +240,8 @@ public class RecordImpl implements Record { sb.append("LEADER "); sb.append(getLeader().toString()); sb.append('\n'); - Iterator i = getVariableFields().iterator(); + @SuppressWarnings("rawtypes") + Iterator i = getVariableFields().iterator(); while (i.hasNext()) { VariableField field = (VariableField) i.next(); sb.append(field.toString()); @@ -237,9 +250,12 @@ public class RecordImpl implements Record { return sb.toString(); } - public List find(String pattern) { - List result = new ArrayList(); - Iterator i = controlFields.iterator(); + @SuppressWarnings("unchecked") + public List find(String pattern) { + @SuppressWarnings("rawtypes") + List result = new ArrayList(); + @SuppressWarnings("rawtypes") + Iterator i = controlFields.iterator(); while (i.hasNext()) { VariableField field = (VariableField) i.next(); if (field.find(pattern)) @@ -254,7 +270,8 @@ public class RecordImpl implements Record { return result; } - public List find(String tag, String pattern) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + public List find(String tag, String pattern) { List result = new ArrayList(); Iterator i = getVariableFields(tag).iterator(); while (i.hasNext()) { @@ -265,7 +282,8 @@ public class RecordImpl implements Record { return result; } - public List find(String[] tag, String pattern) { + @SuppressWarnings({ "rawtypes", "unchecked" }) + public List find(String[] tag, String pattern) { List result = new ArrayList(); Iterator i = getVariableFields(tag).iterator(); while (i.hasNext()) { diff --git a/src/org/marc4j/marc/impl/SubfieldImpl.java b/src/org/marc4j/marc/impl/SubfieldImpl.java index 4428e5b..c5db0a2 100644 --- a/src/org/marc4j/marc/impl/SubfieldImpl.java +++ b/src/org/marc4j/marc/impl/SubfieldImpl.java @@ -33,6 +33,11 @@ import org.marc4j.marc.Subfield; */ public class SubfieldImpl implements Subfield { + /** + * + */ + private static final long serialVersionUID = -5652216007819993017L; + private Long id; private char code; diff --git a/src/org/marc4j/marc/impl/VariableFieldImpl.java b/src/org/marc4j/marc/impl/VariableFieldImpl.java index b0deb05..6265166 100644 --- a/src/org/marc4j/marc/impl/VariableFieldImpl.java +++ b/src/org/marc4j/marc/impl/VariableFieldImpl.java @@ -30,6 +30,10 @@ import org.marc4j.marc.VariableField; */ public abstract class VariableFieldImpl implements VariableField { + /** + * + */ + private static final long serialVersionUID = -1946945669891526509L; private String tag; /** diff --git a/src/org/marc4j/marc/impl/Verifier.java b/src/org/marc4j/marc/impl/Verifier.java index 199a668..0f1211b 100644 --- a/src/org/marc4j/marc/impl/Verifier.java +++ b/src/org/marc4j/marc/impl/Verifier.java @@ -62,7 +62,8 @@ public class Verifier { * @param col * the collection of ControlField objects. */ - public static boolean hasControlNumberField(Collection col) { + public static boolean hasControlNumberField(@SuppressWarnings("rawtypes") Collection col) { + @SuppressWarnings("rawtypes") Iterator i = col.iterator(); while (i.hasNext()) { ControlField field = (ControlField) i.next(); diff --git a/src/org/marc4j/samples/CheckAgencyExample.java b/src/org/marc4j/samples/CheckAgencyExample.java index e8d2d7b..bfaab39 100644 --- a/src/org/marc4j/samples/CheckAgencyExample.java +++ b/src/org/marc4j/samples/CheckAgencyExample.java @@ -27,6 +27,7 @@ import org.marc4j.MarcReader; import org.marc4j.MarcStreamReader; import org.marc4j.marc.DataField; import org.marc4j.marc.Record; +import org.marc4j.marc.VariableField; /** * Demostrates the use of the find method. @@ -46,7 +47,7 @@ public class CheckAgencyExample { Record record = reader.next(); // check if the cataloging agency is DLC - List result = record.find("040", "DLC"); + List result = record.find("040", "DLC"); if (result.size() > 0) System.out.println("Agency for this record is DLC"); diff --git a/src/org/marc4j/samples/DataFieldExample.java b/src/org/marc4j/samples/DataFieldExample.java index ee518f2..713b2a0 100644 --- a/src/org/marc4j/samples/DataFieldExample.java +++ b/src/org/marc4j/samples/DataFieldExample.java @@ -29,6 +29,7 @@ import org.marc4j.MarcStreamReader; import org.marc4j.marc.DataField; import org.marc4j.marc.Record; import org.marc4j.marc.Subfield; +import org.marc4j.marc.VariableField; /** * Read data fields. @@ -52,21 +53,24 @@ public class DataFieldExample { System.out.println(dataField.toString() + '\n'); // get all occurences for a particular tag - List dataFields = record.getVariableFields("650"); - Iterator i = dataFields.iterator(); - while (i.hasNext()) { - dataField = (DataField) i.next(); - System.out.println(dataField.toString()); + List variableFields = record.getVariableFields("650"); + Iterator vi = variableFields.iterator(); + while (vi.hasNext()) { + VariableField variableField = vi.next(); + System.out.println(variableField.toString()); } System.out.print('\n'); // get all occurences for a given list of tags String[] tags = { "010", "100", "245", "250", "260", "300" }; - dataFields = record.getVariableFields(tags); - i = dataFields.iterator(); - while (i.hasNext()) { - dataField = (DataField) i.next(); - System.out.println(dataField.toString()); + variableFields = record.getVariableFields(tags); + vi = variableFields.iterator(); + while (vi.hasNext()) { + VariableField vf = (DataField) vi.next(); + if (vf instanceof DataField) + System.out.println( ((DataField) vf).toString()); + else + System.err.println("Not a Datafield: " + vf.toString()); } System.out.print('\n'); @@ -79,11 +83,11 @@ public class DataFieldExample { System.out.println("Tag: " + tag + " Indicator 1: " + ind1 + " Indicator 2: " + ind2); - List subfields = dataField.getSubfields(); - i = subfields.iterator(); + List subfields = dataField.getSubfields(); + Iterator si = subfields.iterator(); - while (i.hasNext()) { - Subfield subfield = (Subfield) i.next(); + while (si.hasNext()) { + Subfield subfield = si.next(); char code = subfield.getCode(); String data = subfield.getData(); diff --git a/src/org/marc4j/samples/PermissiveReaderExample.java b/src/org/marc4j/samples/PermissiveReaderExample.java index 57f1eb1..f986cfe 100644 --- a/src/org/marc4j/samples/PermissiveReaderExample.java +++ b/src/org/marc4j/samples/PermissiveReaderExample.java @@ -11,6 +11,7 @@ import java.util.Iterator; import java.util.List; import org.marc4j.ErrorHandler; +import org.marc4j.ErrorHandler.Error; import org.marc4j.MarcException; import org.marc4j.MarcPermissiveStreamReader; import org.marc4j.MarcReader; @@ -207,13 +208,12 @@ public class PermissiveReaderExample } - @SuppressWarnings("unchecked") public static void dumpErrors(PrintStream out, ErrorHandler errorHandler) { - List errors = errorHandler.getErrors(); + List errors = errorHandler.getErrors(); if (errors != null) { - Iterator iter = errors.iterator(); + Iterator iter = errors.iterator(); while (iter.hasNext()) { Object error = iter.next(); diff --git a/src/org/marc4j/samples/RemoveLocalFieldsExample.java b/src/org/marc4j/samples/RemoveLocalFieldsExample.java index aea44c3..6547d83 100644 --- a/src/org/marc4j/samples/RemoveLocalFieldsExample.java +++ b/src/org/marc4j/samples/RemoveLocalFieldsExample.java @@ -51,9 +51,9 @@ public class RemoveLocalFieldsExample { Pattern pattern = Pattern.compile("9\\d\\d"); - List fields = record.getDataFields(); + List fields = record.getDataFields(); - Iterator i = fields.iterator(); + Iterator i = fields.iterator(); while (i.hasNext()) { DataField field = (DataField) i.next(); Matcher matcher = pattern.matcher(field.getTag()); diff --git a/src/org/marc4j/samples/TagAnalysisExample.java b/src/org/marc4j/samples/TagAnalysisExample.java index b31a77e..2c651b8 100644 --- a/src/org/marc4j/samples/TagAnalysisExample.java +++ b/src/org/marc4j/samples/TagAnalysisExample.java @@ -26,7 +26,7 @@ public class TagAnalysisExample { InputStream input = AddLocationExample.class .getResourceAsStream("resources/chabon.mrc"); - Hashtable table = new Hashtable(); + Hashtable table = new Hashtable(); int counter = 0; @@ -36,8 +36,8 @@ public class TagAnalysisExample { Record record = reader.next(); - List fields = record.getVariableFields(); - Iterator i = fields.iterator(); + List fields = record.getVariableFields(); + Iterator i = fields.iterator(); while (i.hasNext()) { VariableField field = (VariableField) i.next(); String tag = field.getTag(); @@ -54,9 +54,9 @@ public class TagAnalysisExample { System.out.println("Analyzed " + counter + " records"); System.out.println("Tag\tCount"); - List list = new ArrayList(table.keySet()); + List list = new ArrayList(table.keySet()); Collections.sort(list); - Iterator i = list.iterator(); + Iterator i = list.iterator(); while (i.hasNext()) { String tag = (String) i.next(); Integer value = (Integer) table.get(tag); diff --git a/src/org/marc4j/samples/XercesSerializerExample.java b/src/org/marc4j/samples/XercesSerializerExample.java index a2a025c..79aee41 100644 --- a/src/org/marc4j/samples/XercesSerializerExample.java +++ b/src/org/marc4j/samples/XercesSerializerExample.java @@ -22,15 +22,8 @@ package org.marc4j.samples; import java.io.InputStream; -import javax.xml.transform.Result; -import javax.xml.transform.sax.SAXResult; - -// import org.apache.xml.serialize.OutputFormat; -// import org.apache.xml.serialize.XMLSerializer; import org.marc4j.MarcReader; import org.marc4j.MarcStreamReader; -import org.marc4j.MarcXmlWriter; -import org.marc4j.converter.impl.AnselToUnicode; import org.marc4j.marc.Record; /** @@ -58,7 +51,8 @@ public class XercesSerializerExample { // MarcXmlWriter writer = new MarcXmlWriter(result); // writer.setConverter(new AnselToUnicode()); while (reader.hasNext()) { - Record record = reader.next(); + @SuppressWarnings("unused") + Record record = reader.next(); // writer.write(record); } // writer.close(); diff --git a/src/org/marc4j/test/ControlFieldTest.java b/src/org/marc4j/test/ControlFieldTest.java index a1c9bf7..f146737 100644 --- a/src/org/marc4j/test/ControlFieldTest.java +++ b/src/org/marc4j/test/ControlFieldTest.java @@ -28,6 +28,7 @@ public class ControlFieldTest extends TestCase { assertEquals("12883376", cf.getData()); } + @SuppressWarnings("unchecked") public void testComparable() throws Exception { ControlField cf1 = factory.newControlField("008", "12345"); ControlField cf2 = factory.newControlField("008", "12345"); diff --git a/src/org/marc4j/test/DataFieldTest.java b/src/org/marc4j/test/DataFieldTest.java index 904b803..1018ed1 100644 --- a/src/org/marc4j/test/DataFieldTest.java +++ b/src/org/marc4j/test/DataFieldTest.java @@ -42,6 +42,7 @@ public class DataFieldTest extends TestCase { assertEquals('a', s.getCode()); } + @SuppressWarnings("unchecked") public void testComparable() throws Exception { DataField df1 = factory.newDataField("600", '0', '0'); DataField df2 = factory.newDataField("600", '0', '0'); diff --git a/src/org/marc4j/test/RecordTest.java b/src/org/marc4j/test/RecordTest.java index 7e44545..f78e05e 100644 --- a/src/org/marc4j/test/RecordTest.java +++ b/src/org/marc4j/test/RecordTest.java @@ -38,14 +38,14 @@ public class RecordTest extends TestCase { assertEquals("001", cf.getTag()); assertEquals("12883376", cf.getData()); - List fieldList = record.getVariableFields(); + List fieldList = record.getVariableFields(); assertEquals(15, fieldList.size()); - fieldList = record.getControlFields(); - assertEquals(3, fieldList.size()); + List controlList = record.getControlFields(); + assertEquals(3, controlList.size()); - fieldList = record.getDataFields(); - assertEquals(12, fieldList.size()); + List dataList = record.getDataFields(); + assertEquals(12, dataList.size()); VariableField field = record.getVariableField("245"); assertEquals("245", field.getTag()); @@ -58,6 +58,7 @@ public class RecordTest extends TestCase { assertEquals(3, fieldList.size()); } + @SuppressWarnings("rawtypes") public void testFind() throws Exception { VariableField field = record.getVariableField("245"); assertEquals(true, field.find("Summerland")); diff --git a/src/org/marc4j/test/RoundtripTest.java b/src/org/marc4j/test/RoundtripTest.java index b1f30f6..c53cbf5 100644 --- a/src/org/marc4j/test/RoundtripTest.java +++ b/src/org/marc4j/test/RoundtripTest.java @@ -42,7 +42,8 @@ public class RoundtripTest extends TestCase { reader = new MarcStreamReader(input); while (reader.hasNext()) { - Record record = reader.next(); + @SuppressWarnings("unused") + Record record = reader.next(); counter++; } input.close(); @@ -77,7 +78,8 @@ public class RoundtripTest extends TestCase { reader = new MarcStreamReader(input, "UTF8"); while (reader.hasNext()) { - Record record = reader.next(); + @SuppressWarnings("unused") + Record record = reader.next(); counter++; } input.close(); -- 1.7.10.4