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 */ 021package org.biojava.bio.taxa; 022 023import java.lang.ref.WeakReference; 024import java.util.Collections; 025import java.util.Set; 026 027/** 028 * <p>An implementation of Taxon that keeps only weak references to 029 * children, but full references to parents.</p> 030 * 031 * <p>This may be suitable for deriving memory-savy implementations 032 * of TaxonFactory.</p> 033 * 034 * <p>To manipulate the children set, use the getChildrenRaw and 035 * setChildrenRaw methods. These 'box' the actual weak reference, but 036 * recognize null to mean that there are no children currently 037 * known. A code-fragment may wish to do something like this:</p> 038 * 039 * <pre><code> 040 * Set children = weakTaxon.getChildrenRaw(); 041 * if(children == null) { 042 * children = new HashSet(); 043 * weakTaxon.setChildrenRaw(children); 044 * } 045 * // do stuff to update child set e.g. add children 046 * </code></pre> 047 * </p> 048 * 049 * @author Matthew Pocock 050 * @deprecated replaced by classes in {@link org.biojavax.bio.taxa org.biojavax.bio.taxa} 051 */ 052public class WeakTaxon extends AbstractTaxon { 053 protected Taxon parent; 054 private WeakReference /*Set*/ children; 055 056 public WeakTaxon() { 057 super(); 058 } 059 060 public WeakTaxon(String scientificName, String commonName) { 061 super(scientificName, commonName); 062 } 063 064 public Taxon getParent() { 065 return parent; 066 } 067 068 void setParent(Taxon parent) { 069 this.parent = parent; 070 } 071 072 public Set getChildren() { 073 Set c = getChildrenRaw(); 074 if(c != null) { 075 return c; 076 } else { 077 return Collections.EMPTY_SET; 078 } 079 } 080 081 public Set getChildrenRaw() { 082 if(children != null) { 083 Set c = (Set) children.get(); 084 if(c != null) { 085 return c; 086 } 087 } 088 089 return null; 090 } 091 092 public void setChildrenRaw(Set children) { 093 this.children = new WeakReference(children); 094 } 095}