X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsurfacing%2FAdjactantDirectedBinaryDomainCombination.java;h=fabf40033fd54ad2f1ad56e81acb99137fd59213;hb=5ea47511ea9c077b4b4709bed68ac31d6eee0477;hp=7ec6cb427eec0a9a9fe73e54fdd9168628d31436;hpb=40c926ee11c43ef8f7e42607f3c4fdef3555b8be;p=jalview.git diff --git a/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java b/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java index 7ec6cb4..fabf400 100644 --- a/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java +++ b/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java @@ -26,23 +26,26 @@ package org.forester.surfacing; +import java.util.HashMap; +import java.util.Map; + +import org.forester.protein.BasicDomain; import org.forester.protein.BinaryDomainCombination; public class AdjactantDirectedBinaryDomainCombination extends BasicBinaryDomainCombination { - public AdjactantDirectedBinaryDomainCombination( final String n_terminal, final String c_terminal ) { + final private static Map ADDC_POOL = new HashMap(); + + private AdjactantDirectedBinaryDomainCombination( final String n_terminal, final String c_terminal ) { super(); if ( ( n_terminal == null ) || ( c_terminal == null ) ) { throw new IllegalArgumentException( "attempt to create binary domain combination using null" ); } - // _id0 = n_terminal; - // _id1 = c_terminal; - // _data = n_terminal + SEPARATOR + c_terminal; - _id0 = getId( n_terminal ); - _id1 = getId( c_terminal ); + _id0 = BasicDomain.obtainIdAsShort( n_terminal ); + _id1 = BasicDomain.obtainIdAsShort( c_terminal ); } - public static AdjactantDirectedBinaryDomainCombination createInstance( final String ids ) { + public final static AdjactantDirectedBinaryDomainCombination obtainInstance( final String ids ) { if ( ids.indexOf( BinaryDomainCombination.SEPARATOR ) < 1 ) { throw new IllegalArgumentException( "Unexpected format for binary domain combination [" + ids + "]" ); } @@ -50,6 +53,23 @@ public class AdjactantDirectedBinaryDomainCombination extends BasicBinaryDomainC if ( ids_ary.length != 2 ) { throw new IllegalArgumentException( "Unexpected format for binary domain combination [" + ids + "]" ); } - return new AdjactantDirectedBinaryDomainCombination( ids_ary[ 0 ], ids_ary[ 1 ] ); + return AdjactantDirectedBinaryDomainCombination.obtainInstance( ids_ary[ 0 ], ids_ary[ 1 ] ); + } + + public final static AdjactantDirectedBinaryDomainCombination obtainInstance( final String n_terminal, + final String c_terminal ) { + final int code = calcCode( BasicDomain.obtainIdAsShort( n_terminal ), BasicDomain.obtainIdAsShort( c_terminal ) ); + if ( ADDC_POOL.containsKey( code ) ) { + return ADDC_POOL.get( code ); + } + else { + final AdjactantDirectedBinaryDomainCombination dc = new AdjactantDirectedBinaryDomainCombination( n_terminal, + c_terminal ); + ADDC_POOL.put( code, dc ); + if ( VERBOSE && ( ADDC_POOL.size() % 100 == 0 ) ) { + System.out.println( " addc pool size: " + ADDC_POOL.size() ); + } + return dc; + } } }