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; 025 026import org.biojava.utils.SmallMap; 027 028/** 029 * <p> 030 * <code>TagMapper</code> maps arbitrary object keys to new keys. 031 * </p> 032 * 033 * <p> 034 * If there is no explicit mapping from old to new keys, then the old key will 035 * be used. 036 * </p> 037 * 038 * @since 1.2 039 * @author Matthew Pocock 040 * @author Keith James (docs). 041 */ 042public class TagMapper implements PropertyChanger { 043 private Map tags; 044 045 /** 046 * Creates a new, empty <code>TagMapper</code>. 047 */ 048 public TagMapper() { 049 this.tags = new SmallMap(); 050 } 051 052 /** 053 * <code>setNewTag</code>. 054 * 055 * @param oldTag an <code>Object</code> tag to be substituted. 056 * @param newTag an <code>Object</code> tag to substitue for the 057 * old value. 058 */ 059 public void setNewTag(Object oldTag, Object newTag) { 060 tags.put(oldTag, newTag); 061 } 062 063 public Object getNewTag(Object oldTag) { 064 Object newTag = tags.get(oldTag); 065 if(newTag == null) { 066 newTag = oldTag; 067 } 068 return newTag; 069 } 070} 071