From: <rv...@us...> - 2012-02-03 22:41:25
|
Revision: 1046 http://treebase.svn.sourceforge.net/treebase/?rev=1046&view=rev Author: rvos Date: 2012-02-03 22:41:19 +0000 (Fri, 03 Feb 2012) Log Message: ----------- Added caching of taxon and taxa block lookups using hash maps Modified Paths: -------------- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java Modified: trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java =================================================================== --- trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java 2012-02-03 22:38:37 UTC (rev 1045) +++ trunk/treebase-core/src/main/java/org/cipres/treebase/domain/nexus/nexml/NexmlObjectConverter.java 2012-02-03 22:41:19 UTC (rev 1046) @@ -3,6 +3,8 @@ import java.net.URI; import java.text.CharacterIterator; import java.text.StringCharacterIterator; +import java.util.HashMap; +import java.util.Map; import org.apache.log4j.Logger; import org.cipres.treebase.Constants; @@ -26,6 +28,8 @@ protected static URI mStudyBaseURI = URI.create(Constants.BaseURI.toString() + "study/TB2:"); public static String TreeBASE2Prefix = "TreeBASE2"; private Document mDocument; + private Map<Long,OTU> otuById = new HashMap<Long,OTU>(); + private Map<Long,OTUs> otusById = new HashMap<Long,OTUs>(); /** * @@ -44,6 +48,12 @@ setDocument(document); } + /** + * + * @param study + * @param taxonLabelHome + * @param document + */ public NexmlObjectConverter(Study study, TaxonLabelHome taxonLabelHome, Document document) { this(study,taxonLabelHome,document,mStudyBaseURI.toString()); } @@ -51,16 +61,6 @@ /** * - * @param tbPersistable - * @return - */ -// private String makeNamespacedID (TBPersistable tbPersistable,Class<?> persistableClass) { -// TreebaseIDString tbIDString = new TreebaseIDString(persistableClass,tbPersistable.getId()); -// return tbIDString.getNamespacedGUID().toString(); -// } - - /** - * * @param annotatable * @param tbPersistable */ @@ -91,8 +91,6 @@ * @return */ protected Long readTreeBaseID(Annotatable annotatable) { - // we no longer need to read owl:sameAs annotations because we - // use the TreebaseIDString objects as xml IDs try { TreebaseIDString treebaseIDString = new TreebaseIDString(annotatable.getId()); return treebaseIDString.getId(); @@ -102,36 +100,68 @@ return null; } + /** + * + * @param taxonLabelSetId + * @return + */ protected OTUs getOTUsById(Long taxonLabelSetId) { logger.debug("Going to look for taxa block "+taxonLabelSetId); + if ( otusById.containsKey(taxonLabelSetId) ) { + return otusById.get(taxonLabelSetId); + } for ( OTUs otus : getDocument().getOTUsList() ) { Long annotatedID = readTreeBaseID(otus); logger.debug("Seen taxa block "+annotatedID); if ( taxonLabelSetId.equals(annotatedID) ) { + otusById.put(taxonLabelSetId, otus); return otus; } } return null; } + /** + * + * @param otus + * @param taxonLabelId + * @return + */ protected OTU getOTUById(OTUs otus,Long taxonLabelId) { + if ( otuById.containsKey(taxonLabelId) ) { + return otuById.get(taxonLabelId); + } for ( OTU otu : otus.getAllOTUs() ) { Long annotatedID = readTreeBaseID(otu); if ( taxonLabelId.equals(annotatedID) ) { + otuById.put(taxonLabelId, otu); return otu; } } return null; } + /** + * + * @return + */ public Document getDocument() { return mDocument; } + /** + * + * @param document + */ public void setDocument(Document document) { mDocument = document; } + /** + * Encodes some common x(ht)ml entities + * @param aText + * @return + */ public static String forXML(String aText){ final StringBuilder result = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(aText); @@ -157,10 +187,18 @@ return result.toString(); } + /** + * + * @return + */ public URI getBaseURI() { return mBaseURI; } + /** + * + * @param baseURI + */ public void setBaseURI(URI baseURI) { mBaseURI = baseURI; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |