in progress
[jalview.git] / forester / java / src / org / forester / msa_compactor / GapContribution.java
1
2 package org.forester.msa_compactor;
3
4 import org.forester.util.ForesterUtil;
5
6 public final class GapContribution implements Comparable<GapContribution> {
7
8     private final String _id;
9     private double       _value;
10
11     GapContribution( final String id ) {
12         if ( ForesterUtil.isEmpty( id ) ) {
13             throw new IllegalArgumentException( "id is empty or null" );
14         }
15         _id = id;
16         _value = 0;
17     }
18
19     final String getId() {
20         return _id;
21     }
22
23     final double getValue() {
24         return _value;
25     }
26
27     final void addToValue( final double v ) {
28         if ( v < 0 ) {
29             throw new IllegalArgumentException( "cannot add negative value" );
30         }
31         _value += v;
32     }
33
34     final void divideValue( final double d ) {
35         if ( d <= 0 ) {
36             throw new IllegalArgumentException( "attempt to divide by non-positive value" );
37         }
38         _value /= d;
39     }
40
41     @Override
42     public int compareTo( final GapContribution o ) {
43         if ( getValue() < o.getValue() ) {
44             return 1;
45         }
46         else if ( getValue() > o.getValue() ) {
47             return -1;
48         }
49         return 0;
50     }
51 }