X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fprotein%2FBasicDomain.java;h=b1328987768593d50f4bffb584ec4b288ea29a32;hb=8aadbec1b0627ebd71e57e60e06621d4038bb79a;hp=171b0d07d2f44c3ce68830b3366e838d92115981;hpb=87d34f343d0262cd0c009c6f1da058a5a217bc64;p=jalview.git diff --git a/forester/java/src/org/forester/protein/BasicDomain.java b/forester/java/src/org/forester/protein/BasicDomain.java index 171b0d0..b132898 100644 --- a/forester/java/src/org/forester/protein/BasicDomain.java +++ b/forester/java/src/org/forester/protein/BasicDomain.java @@ -26,31 +26,33 @@ package org.forester.protein; +import java.util.HashMap; +import java.util.Map; + import org.forester.util.ForesterUtil; public class BasicDomain implements Domain { - final private String _id; - final private int _from; - final private int _to; - final private short _number; - final private short _total_count; - final private double _per_sequence_evalue; - final private double _per_sequence_score; - final private double _per_domain_evalue; - final private double _per_domain_score; + private static short COUNT = 0; + private final static Map ID_TO_STRING = new HashMap(); + private final static Map STRING_TO_ID = new HashMap(); + final private int _from; + final private short _id; + final private short _number; + final private double _per_domain_evalue; + final private double _per_domain_score; + final private int _to; + final private short _total_count; public BasicDomain( final String id ) { if ( ForesterUtil.isEmpty( id ) ) { throw new IllegalArgumentException( "attempt to create protein domain with null or empty id" ); } - _id = id; + _id = obtainIdAsShort( id ); _from = -1; _to = -1; _number = -1; _total_count = -1; - _per_sequence_evalue = -1; - _per_sequence_score = -1; _per_domain_evalue = -1; _per_domain_score = -1; } @@ -60,18 +62,6 @@ public class BasicDomain implements Domain { final int to, final short number, final short total_count, - final double per_sequence_evalue, - final double per_sequence_score ) { - this( id, from, to, number, total_count, per_sequence_evalue, per_sequence_score, 0, 0 ); - } - - public BasicDomain( final String id, - final int from, - final int to, - final short number, - final short total_count, - final double per_sequence_evalue, - final double per_sequence_score, final double per_domain_evalue, final double per_domain_score ) { if ( ( from >= to ) || ( from < 0 ) ) { @@ -84,28 +74,22 @@ public class BasicDomain implements Domain { throw new IllegalArgumentException( "attempt to create protein domain number " + number + " out of " + total_count ); } - if ( ( per_sequence_evalue < 0.0 ) || ( per_domain_evalue < 0.0 ) ) { + if ( per_domain_evalue < 0.0 ) { throw new IllegalArgumentException( "attempt to create protein domain with negative E-value" ); } - _id = id; + _id = obtainIdAsShort( id ); _from = from; _to = to; _number = number; _total_count = total_count; - _per_sequence_evalue = per_sequence_evalue; - _per_sequence_score = per_sequence_score; _per_domain_evalue = per_domain_evalue; _per_domain_score = per_domain_score; } - // ^^ @Override - // ^^ public void addGoId( final GoId go_id ) { - // ^^ getDomainId().getGoIds().add( go_id ); - // ^^ } /** * Basic domains are compared/sorted based upon their identifiers (case * insensitive) and their numbers. - * + * */ @Override public int compareTo( final Domain domain ) { @@ -122,7 +106,7 @@ public class BasicDomain implements Domain { /** * Basic domains are considered equal if they have the same identifier (case * sensitive). - * + * */ @Override public boolean equals( final Object o ) { @@ -143,7 +127,7 @@ public class BasicDomain implements Domain { @Override public String getDomainId() { - return _id; + return obtainIdFromShort( _id ); } @Override @@ -151,19 +135,16 @@ public class BasicDomain implements Domain { return _from; } - // ^^ @Override - // ^^ public GoId getGoId( final int i ) { - // ^^ return getDomainId().getGoIds().get( i ); - // ^^ } + @Override + public int getLength() { + return ( 1 + getTo() ) - getFrom(); + } + @Override public short getNumber() { return _number; } - // ^^ @Override - // ^^ public int getNumberOfGoIds() { - // ^^ return getDomainId().getGoIds().size(); - // ^^ } @Override public double getPerDomainEvalue() { return _per_domain_evalue; @@ -175,16 +156,6 @@ public class BasicDomain implements Domain { } @Override - public double getPerSequenceEvalue() { - return _per_sequence_evalue; - } - - @Override - public double getPerSequenceScore() { - return _per_sequence_score; - } - - @Override public int getTo() { return _to; } @@ -208,8 +179,19 @@ public class BasicDomain implements Domain { return new StringBuffer( getDomainId() ); } - @Override - public int getLength() { - return ( 1 + getTo() ) - getFrom(); + public final static short obtainIdAsShort( final String id ) { + if ( !STRING_TO_ID.containsKey( id ) ) { + if ( COUNT >= ( Short.MAX_VALUE - 2 ) ) { + throw new RuntimeException( "too many domain ids!" ); + } + ID_TO_STRING.put( COUNT, id ); + STRING_TO_ID.put( id, COUNT ); + ++COUNT; + } + return STRING_TO_ID.get( id ); + } + + public final static String obtainIdFromShort( final short id ) { + return ID_TO_STRING.get( id ); } }