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.Map;
025
026import org.biojava.utils.SmallMap;
027
028/**
029 * Annotation that is optimized for memory usage.  Access time
030 * is linear, so SmallAnnotations are not recommended when
031 * the number of entries is large.  However, they are fine for
032 * small numbers of keys.
033 *
034 * @author Thomas Down
035 * @author Matthew Pocock
036 * @since 1.2
037 *
038 * 
039 * A minimal-memory alternative to SimpleAnnotation
040 *
041 * 
042 * When creating a large number of small Annotation instances, it is worth
043 * instantiating SmallAnnotation. Small is anything up to at least 30 properties
044 * but will vary with the JavaVM and underlying platform.
045 */
046
047public class SmallAnnotation extends AbstractAnnotation {
048  private Map properties;
049  
050  protected final Map getProperties() {
051    if(!propertiesAllocated()) {
052      properties = new SmallMap();
053    }
054    return properties;
055  }
056  
057  protected final boolean propertiesAllocated() {
058    return properties != null;
059  }
060
061  /**
062   * Return a new SmallAnnotation optimised for small sets of properties.
063   */
064  public SmallAnnotation() {
065    super();
066  }
067
068  /**
069   * Return a new SmallAnnotation that copies all values from another annoation.
070   *
071   * @param ann  the Annoation to copy all values from
072   * @throws NullPointerException if ann is null
073   */
074  public SmallAnnotation(Annotation ann) {
075    super(ann);
076  }
077
078  /**
079   * Return a new SmallAnnotation that copies all values from a Map.
080   *
081   * @param map  the Map to copy values from
082   */
083  public SmallAnnotation(Map map) {
084    super(map);
085  }
086}
087