X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fsurfacing%2FProteinCountsBasedPairwiseDomainSimilarityCalculator.java;h=8c42787c106dcf59cca739dd24cf1e36744c9a0a;hb=b528989f688291ba7615867e5322090ec42096d8;hp=d61252c9490ace32f2ad9aa36d0031e932836112;hpb=48f7a89be9d34f1930a1f863e608235cc27184c5;p=jalview.git diff --git a/forester/java/src/org/forester/surfacing/ProteinCountsBasedPairwiseDomainSimilarityCalculator.java b/forester/java/src/org/forester/surfacing/ProteinCountsBasedPairwiseDomainSimilarityCalculator.java index d61252c..8c42787 100644 --- a/forester/java/src/org/forester/surfacing/ProteinCountsBasedPairwiseDomainSimilarityCalculator.java +++ b/forester/java/src/org/forester/surfacing/ProteinCountsBasedPairwiseDomainSimilarityCalculator.java @@ -7,7 +7,7 @@ // Copyright (C) 2008-2009 Christian M. Zmasek // Copyright (C) 2008-2009 Burnham Institute for Medical Research // All rights reserved -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -17,25 +17,31 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // 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; public class ProteinCountsBasedPairwiseDomainSimilarityCalculator implements PairwiseDomainSimilarityCalculator { + @Override public PairwiseDomainSimilarity calculateSimilarity( final CombinableDomains domains_1, final CombinableDomains domains_2 ) { 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 ) ); } }