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.nbio.ontology.utils; 023 024import java.util.Map; 025 026 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 @Override 051 protected final Map getProperties() { 052 if(!propertiesAllocated()) { 053 properties = new SmallMap(); 054 } 055 return properties; 056 } 057 058 @Override 059 protected final boolean propertiesAllocated() { 060 return properties != null; 061 } 062 063 /** 064 * Return a new SmallAnnotation optimised for small sets of properties. 065 */ 066 public SmallAnnotation() { 067 super(); 068 } 069 070 /** 071 * Return a new SmallAnnotation that copies all values from another annoation. 072 * 073 * @param ann the Annoation to copy all values from 074 * @throws NullPointerException if ann is null 075 */ 076 public SmallAnnotation(Annotation ann) { 077 super(ann); 078 } 079 080 /** 081 * Return a new SmallAnnotation that copies all values from a Map. 082 * 083 * @param map the Map to copy values from 084 */ 085 public SmallAnnotation(Map map) { 086 super(map); 087 } 088} 089