JAL-1953 JAL-2852 added public "paintFile" method
[jalview.git] / forester / java / src / org / forester / surfacing / ProteinCountsBasedPairwiseDomainSimilarityCalculator.java
index fbcedb6..8c42787 100644 (file)
@@ -23,7 +23,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 //
 // Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
 
 package org.forester.surfacing;
 
@@ -35,8 +35,13 @@ public class ProteinCountsBasedPairwiseDomainSimilarityCalculator implements Pai
         if ( !domains_1.getKeyDomain().equals( domains_2.getKeyDomain() ) ) {
             throw new IllegalArgumentException( "attempt to calculate similarity between domain collection with different keys" );
         }
-        final int pc1 = domains_1.getKeyDomainProteinsCount();
-        final int pc2 = domains_2.getKeyDomainProteinsCount();
-        return new CountsBasedPairwiseDomainSimilarity( pc1 - pc2, pc1 + pc2 );
+        if ( ( domains_1.getKeyDomainProteinsCount() > Short.MAX_VALUE )
+                || ( domains_2.getKeyDomainProteinsCount() > Short.MAX_VALUE )
+                || ( ( domains_1.getKeyDomainProteinsCount() + domains_2.getKeyDomainCount() ) > Short.MAX_VALUE ) ) {
+            throw new IllegalArgumentException( "too large for short!" );
+        }
+        final short pc1 = ( short ) domains_1.getKeyDomainProteinsCount();
+        final short pc2 = ( short ) domains_2.getKeyDomainProteinsCount();
+        return new CountsBasedPairwiseDomainSimilarity( ( short ) ( pc1 - pc2 ), ( short ) ( pc1 + pc2 ) );
     }
 }