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.seq.db; 023 024import java.util.Collections; 025import java.util.HashMap; 026import java.util.Iterator; 027import java.util.Map; 028import java.util.Set; 029 030import org.biojava.bio.BioException; 031import org.biojava.bio.seq.Sequence; 032import org.biojava.bio.seq.SequenceIterator; 033import org.biojava.bio.seq.impl.DummySequence; 034import org.biojava.utils.ChangeListener; 035import org.biojava.utils.ChangeVetoException; 036 037/** 038 * <code>DummySequenceDB</code> is an implementation which contains 039 * only a <code>DummySequence</code>. It will return the same 040 * <code>DummySequence</code> instance regardless of the sequence id 041 * used to retrieve a sequence. 042 * 043 * @author <a href="mailto:kdj@sanger.ac.uk">Keith James</a> 044 * @since 1.2 045 */ 046public class DummySequenceDB extends AbstractSequenceDB 047 implements SequenceDB 048{ 049 private String name; 050 private Map seqs; 051 052 public DummySequenceDB(String name) 053 { 054 this.name = name; 055 seqs = new HashMap(); 056 seqs.put("dummy", new DummySequence("dummy", "dummy")); 057 058 // Lock to prevent sequences being added or removed 059 this.addChangeListener(ChangeListener.ALWAYS_VETO); 060 } 061 062 public Set ids() 063 { 064 return Collections.unmodifiableSet(seqs.keySet()); 065 } 066 067 public SequenceIterator sequenceIterator() 068 { 069 return new SequenceIterator() 070 { 071 Iterator i = seqs.values().iterator(); 072 073 public boolean hasNext() 074 { 075 return i.hasNext(); 076 } 077 078 public Sequence nextSequence() 079 { 080 return (Sequence) i.next(); 081 } 082 }; 083 } 084 085 public String getName() 086 { 087 return name; 088 } 089 090 public Sequence getSequence(String id) 091 throws IllegalIDException, BioException 092 { 093 return (Sequence) seqs.get("dummy"); 094 } 095 096 public void addSequence(Sequence seq) 097 throws IllegalIDException, BioException, ChangeVetoException { } 098 099 public void removeSequence(String id) 100 throws IllegalIDException, BioException, ChangeVetoException { } 101}