3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.surfacing;
29 import java.util.HashMap;
32 import org.forester.protein.BasicDomain;
33 import org.forester.protein.BinaryDomainCombination;
35 public class AdjactantDirectedBinaryDomainCombination extends BasicBinaryDomainCombination {
37 final private static Map<Integer, AdjactantDirectedBinaryDomainCombination> ADDC_POOL = new HashMap<Integer, AdjactantDirectedBinaryDomainCombination>();
39 private AdjactantDirectedBinaryDomainCombination( final String n_terminal, final String c_terminal ) {
41 if ( ( n_terminal == null ) || ( c_terminal == null ) ) {
42 throw new IllegalArgumentException( "attempt to create binary domain combination using null" );
44 _id0 = BasicDomain.obtainIdAsShort( n_terminal );
45 _id1 = BasicDomain.obtainIdAsShort( c_terminal );
48 public final static AdjactantDirectedBinaryDomainCombination obtainInstance( final String ids ) {
49 if ( ids.indexOf( BinaryDomainCombination.SEPARATOR ) < 1 ) {
50 throw new IllegalArgumentException( "Unexpected format for binary domain combination [" + ids + "]" );
52 final String[] ids_ary = ids.split( BinaryDomainCombination.SEPARATOR );
53 if ( ids_ary.length != 2 ) {
54 throw new IllegalArgumentException( "Unexpected format for binary domain combination [" + ids + "]" );
56 return AdjactantDirectedBinaryDomainCombination.obtainInstance( ids_ary[ 0 ], ids_ary[ 1 ] );
59 public final static AdjactantDirectedBinaryDomainCombination obtainInstance( final String n_terminal,
60 final String c_terminal ) {
61 final int code = calcCode( BasicDomain.obtainIdAsShort( n_terminal ), BasicDomain.obtainIdAsShort( c_terminal ) );
62 if ( ADDC_POOL.containsKey( code ) ) {
63 return ADDC_POOL.get( code );
66 final AdjactantDirectedBinaryDomainCombination dc = new AdjactantDirectedBinaryDomainCombination( n_terminal,
68 ADDC_POOL.put( code, dc );
69 if ( VERBOSE && ( ( ADDC_POOL.size() % 100 ) == 0 ) ) {
70 System.out.println( " addc pool size: " + ADDC_POOL.size() );