001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021 022package org.biojava.bio.program.tagvalue; 023 024import java.util.Map; 025import java.util.Set; 026 027import org.biojava.utils.SmallMap; 028 029public class Index2Model { 030 private final Map keys; 031 private String primaryKeyName; 032 033 public Index2Model() { 034 keys = new SmallMap(); 035 } 036 037 /** 038 * <p> 039 * Set the tag to use as a primary key in the index. 040 * </p> 041 * 042 * <p> 043 * Whenever a value for the primary key tag is seen, this is passed to the 044 * indexer as the primary key for indexing. 045 * </p> 046 * 047 * <p> 048 * Primary keys must be unique between entries, and each entry must provide 049 * exactly one primary key value. 050 * </p> 051 * 052 * @param primaryKeyName the tag to use as primary key 053 */ 054 public void setPrimaryKeyName(String primaryKeyName) { 055 this.primaryKeyName = primaryKeyName; 056 } 057 058 /** 059 * Retrieve the tag currently used as primary key. 060 * 061 * @return a String representing the primary key name 062 */ 063 public String getPrimaryKeyName() { 064 return primaryKeyName; 065 } 066 067 /** 068 * <p> 069 * Add a key and a path to that key in the tag-value hierachy. 070 * </p> 071 * 072 * <p> 073 * Secondary keys are potentialy non-unique properties of the entries being 074 * indexed. Multiple records can use the same secondary key values, and a 075 * single record can have multiple values for a secondary key. However, the 076 * primary key must be unique. 077 * </p> 078 * 079 * @param keyName the name of the secondary key to add 080 * @param path the names of each tag to follow to reach the value of the key 081 */ 082 public void addKeyPath(String keyName, Object[] path) { 083 keys.put(keyName, path); 084 } 085 086 /** 087 * Remove a key. 088 * 089 * @param keyName the name of the key to remove 090 */ 091 public void removeKeyPath(String keyName) { 092 keys.remove(keyName); 093 } 094 095 public Object[] getKeyPath(String keyName) { 096 return (Object []) keys.get(keyName); 097 } 098 099 public Set getKeys() { 100 return keys.keySet(); 101 } 102}