org.jbibtex.BibTeXDatabase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbibtex Show documentation
Show all versions of jbibtex Show documentation
Java BibTeX parser and formatter
/*
* Copyright (c) 2012 University of Tartu
*/
package org.jbibtex;
import java.util.*;
public class BibTeXDatabase {
private List objects = new ArrayList();
private List includes = new ArrayList();
private KeyMap strings = new KeyMap();
private KeyMap entries = new KeyMap();
public void addObject(BibTeXObject object){
this.objects.add(object);
if(object instanceof BibTeXInclude){
BibTeXInclude include = (BibTeXInclude)object;
this.includes.add(include);
} else
if(object instanceof BibTeXString){
BibTeXString string = (BibTeXString)object;
this.strings.put(string.getKey(), string);
} else
if(object instanceof BibTeXEntry){
BibTeXEntry entry = (BibTeXEntry)object;
this.entries.put(entry.getKey(), entry);
}
}
public void removeObject(BibTeXObject object){
this.objects.remove(object);
if(object instanceof BibTeXInclude){
BibTeXInclude include = (BibTeXInclude)object;
this.includes.remove(include);
} else
if(object instanceof BibTeXString){
BibTeXString string = (BibTeXString)object;
this.strings.remove(string.getKey());
} else
if(object instanceof BibTeXEntry){
BibTeXEntry entry = (BibTeXEntry)object;
this.entries.remove(entry.getKey());
}
}
public List getObjects(){
return Collections.unmodifiableList(this.objects);
}
public BibTeXString resolveString(Key key){
BibTeXString string = this.strings.get(key);
if(string == null){
for(BibTeXInclude include : this.includes){
BibTeXDatabase database = include.getDatabase();
string = database.resolveString(key);
if(string != null){
return string;
}
}
}
return string;
}
public Map getStrings(){
return Collections.unmodifiableMap(this.strings);
}
public BibTeXEntry resolveEntry(Key key){
BibTeXEntry entry = this.entries.get(key);
if(entry == null){
for(BibTeXInclude include : this.includes){
BibTeXDatabase database = include.getDatabase();
entry = database.resolveEntry(key);
if(entry != null){
return entry;
}
}
}
return entry;
}
public Map getEntries(){
return Collections.unmodifiableMap(this.entries);
}
}