All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jbibtex.BibTeXDatabase Maven / Gradle / Ivy

There is a newer version: 1.0.20
Show newest version
/*
 * 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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy