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;
023
024import java.util.LinkedHashMap;
025import java.util.Map;
026
027/**
028 * <p>A no-frills implementation of Annotation that is just a wrapper
029 * around a <code>LinkedHashMap</code>.</p>
030 * 
031 * <p>It will allow you to set any property, but will throw exceptions
032 * if you try to retrieve a property that is not set. Because of the use of
033 * a <code>LinkedHashMap</code> properties are iterated in the order they 
034 * are entered.</p>
035 * When you need to make a new Annotation instance and will want to populate
036 * it with properties, use this class.
037 * 
038 * @author Matthew Pocock
039 * @author Greg Cox
040 * @author Mark Schreiber
041 * @since 1.0
042 * 
043 * @see org.biojavax.SimpleRichAnnotation
044 */
045public class SimpleAnnotation extends AbstractAnnotation {
046  /**
047   * The properties map. This may be null if no property values have
048   * yet been set.
049   */
050  private Map properties;
051
052  /**
053   * Get the property value pairs in this annotation
054   * @return a <code>LinkedHashMap</code> of properties and values
055   */
056  protected final Map getProperties() {
057    if(!propertiesAllocated()) {
058      properties = new LinkedHashMap();
059    }
060    return properties;
061  }
062
063  /**
064   * Test to see if any properties have been allocated
065   * @return true if any have (even if they have since been removed),
066   * false otherwise
067   */
068  protected final boolean propertiesAllocated() {
069    return properties != null;
070  }
071
072  /**
073   * Create a new, empty SimpleAnnotation instance.
074   */
075  public SimpleAnnotation() {
076    super();
077  }
078  
079  /**
080   * Create a new SimpleAnnotation by copying the properties from another
081   * one. The new Annotation instance will be independant of the original.
082   * 
083   * @param ann the Annotation to copy
084   */
085  public SimpleAnnotation(Annotation ann) {
086    super(ann);
087  }
088  
089  /**
090   * Create a new SimpleAnnotation using the values in a Map.
091   *
092   * @param map  the Map to copy properties out of
093   */
094  public SimpleAnnotation(Map map) {
095    super(map);
096  }
097}