package bibtex.dom;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@author
public class BibtexEntry extends BibtexAbstractEntry {
protected BibtexEntry(BibtexFile file,String entryType, String entryKey){
super(file);
this.entryKey=entryKey;
this.entryType=entryType.toLowerCase().intern();
}
private String entryType;
private String entryKey;
private HashMap fields = new HashMap();
@return
public String getEntryKey() {
return entryKey;
}
public BibtexAbstractValue getFieldValue(String name){
return (BibtexAbstractValue) fields.get(name);
}
@return
public String getEntryType() {
return entryType;
}
@return
public Map getFields() {
return Collections.unmodifiableMap((Map)fields.clone());
}
public void setField(String fieldName, BibtexAbstractValue fieldValue){
fields.put(fieldName.toLowerCase().intern(),fieldValue);
}
@param
public void setEntryKey(String entryKey) {
this.entryKey = entryKey.toLowerCase();
}
@param
public void setEntryType(String entryType) {
this.entryType = entryType.toLowerCase().intern();
}
public void printBibtex(PrintWriter writer) {
writer.print('@');
writer.print(this.entryType);
writer.print('{');
writer.print(this.entryKey);
writer.println(',');
String keys [] = new String[fields.keySet().size()];
fields.keySet().toArray(keys);
Arrays.sort(keys);
for(int i=0;i<keys.length;i++){
String key = keys[i];
BibtexNode value = (BibtexNode) this.fields.get(key);
writer.print('\t');
writer.print(key);
writer.print('=');
value.printBibtex(writer);
writer.println(',');
}
writer.println('}');
}
@param
public void undefineField(String fieldName) {
this.fields.remove(fieldName);
}
}