This was my first attempt at creating a data class to hold data from both MARC and EAD files.
/**
*
*/
package crrasolrindexer;
import java.io.*;
/**
* @author slittle2
*
* *** NOTE: This is older than CRRA_Datum. It is recommended ***
* *** that you use CRRA_Datum instead for non-MARC records. ***
* ***
*
* The IndexDatum class holds the kinds of data that are to be extracted
* from an indexed field, whether MARC or EAD (or anything else). All fields
* are private; only a protected method allows setting them, and a public
* method allows retrieving their contents. (The setField() method is
* protected so that one has to change the data through the appropriate
* class that indexes the data.
*
* This class is designed to be easily extensible for use with other kinds
* of data.
*
*/
public class IndexDatum {
private String key = "";
private String author = "";
private String title = "";
private String date = "";
private String note = "";
private String subject = "";
private String text = "";
private String type = "";
public String returnField(String fieldName) throws IOException {
if(fieldName.equalsIgnoreCase("author")) return author;
else if(fieldName.equalsIgnoreCase("key")) return key;
else if(fieldName.equalsIgnoreCase("title")) return title;
else if(fieldName.equalsIgnoreCase("date")) return date;
else if(fieldName.equalsIgnoreCase("note")) return note;
else if(fieldName.equalsIgnoreCase("subject")) return subject;
else if(fieldName.equalsIgnoreCase("text")) return text;
else if(fieldName.equalsIgnoreCase("type")) return type;
else throw new IOException();
}
protected void setField(String fieldName, String data) throws IOException {
if(fieldName.equalsIgnoreCase("author")) author = data;
else if(fieldName.equalsIgnoreCase("key")) key = data;
else if(fieldName.equalsIgnoreCase("title")) title = data;
else if(fieldName.equalsIgnoreCase("date")) date = data;
else if(fieldName.equalsIgnoreCase("note")) note = data;
else if(fieldName.equalsIgnoreCase("subject")) subject = data;
else if(fieldName.equalsIgnoreCase("text")) text = data;
else if(fieldName.equalsIgnoreCase("type")) type = data;
else throw new IOException();
}
protected void concatenateField(String fieldName, String data) throws IOException {
if(fieldName.equalsIgnoreCase("author")) author += data;
else if(fieldName.equalsIgnoreCase("key")) key += data;
else if(fieldName.equalsIgnoreCase("title")) title += data;
else if(fieldName.equalsIgnoreCase("date")) date += data;
else if(fieldName.equalsIgnoreCase("note")) note += data;
else if(fieldName.equalsIgnoreCase("subject")) subject += data;
else if(fieldName.equalsIgnoreCase("text")) text += data;
else if(fieldName.equalsIgnoreCase("type")) type += data;
else throw new IOException();
}
public String toString(){
String contents = "";
contents = "\n Key:\t" + key +
"\n Author:\t" + author +
"\n Title:\t" + title +
"\n Date:\t" + date +
"\n Note:\t" + note +
"\n Subject:\t" + subject +
"\n Text:\t" + text +
"\n Type:\t" + type;
return contents;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment