inprogress
[jalview.git] / forester / java / src / org / forester / msa_compactor / GapContribution.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.msa_compactor;
26
27 import org.forester.util.ForesterUtil;
28
29 public final class GapContribution implements Comparable<GapContribution> {
30
31     private final String _id;
32     private double       _value;
33
34     GapContribution( final String id ) {
35         if ( ForesterUtil.isEmpty( id ) ) {
36             throw new IllegalArgumentException( "id is empty or null" );
37         }
38         _id = id;
39         _value = 0;
40     }
41
42     final String getId() {
43         return _id;
44     }
45
46     final double getValue() {
47         return _value;
48     }
49
50     final void addToValue( final double v ) {
51         if ( v < 0 ) {
52             throw new IllegalArgumentException( "cannot add negative value" );
53         }
54         _value += v;
55     }
56
57     final void divideValue( final double d ) {
58         if ( d <= 0 ) {
59             throw new IllegalArgumentException( "attempt to divide by non-positive value" );
60         }
61         _value /= d;
62     }
63
64     @Override
65     public int compareTo( final GapContribution o ) {
66         if ( getValue() < o.getValue() ) {
67             return 1;
68         }
69         else if ( getValue() > o.getValue() ) {
70             return -1;
71         }
72         return 0;
73     }
74 }