renamed
[jalview.git] / forester / java / src / org / forester / sdi / Tuplet.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
9 // All rights reserved
10 // 
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 // 
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 //
25 // Contact: phylosoft @ gmail . com
26 // WWW: www.phylosoft.org/forester
27
28 package org.forester.sdi;
29
30 class Tuplet implements Comparable<Tuplet> {
31
32     public static final int DEFAULT = -999;
33     private final String    _key;
34     private final double    _value1;
35     private final double    _value2;
36     private final double    _value3;
37     private final double    _value4;
38     private int[]           _p;            // Since
39
40     Tuplet() {
41         setSigns();
42         _key = "";
43         _value1 = Tuplet.DEFAULT;
44         _value2 = Tuplet.DEFAULT;
45         _value3 = Tuplet.DEFAULT;
46         _value4 = Tuplet.DEFAULT;
47     }
48
49     // distance
50     // needs to be
51     // sorted in
52     // different
53     // direction than other values, and it is not
54     // known which value will be the distance.
55     Tuplet( final String name,
56             final double value1,
57             final double value2,
58             final double value3,
59             final double value4,
60             final int c ) {
61         setSigns();
62         _key = name;
63         _value1 = value1;
64         _value2 = value2;
65         _value3 = value3;
66         _value4 = value4;
67         if ( ( c >= 0 ) && ( c <= 3 ) ) {
68             _p[ c ] = -1;
69         }
70     }
71
72     Tuplet( final String name, final double value1, final double value2, final double value3, final int c ) {
73         setSigns();
74         _key = name;
75         _value1 = value1;
76         _value2 = value2;
77         _value3 = value3;
78         _value4 = Tuplet.DEFAULT;
79         if ( ( c >= 0 ) && ( c <= 2 ) ) {
80             _p[ c ] = -1;
81         }
82     }
83
84     Tuplet( final String name, final double value1, final double value2, final int c ) {
85         setSigns();
86         _key = name;
87         _value1 = value1;
88         _value2 = value2;
89         _value3 = Tuplet.DEFAULT;
90         _value4 = Tuplet.DEFAULT;
91         if ( ( c >= 0 ) && ( c <= 1 ) ) {
92             _p[ c ] = -1;
93         }
94     }
95
96     Tuplet( final String name, final double value1, final int c ) {
97         setSigns();
98         _key = name;
99         _value1 = value1;
100         _value2 = Tuplet.DEFAULT;
101         _value3 = Tuplet.DEFAULT;
102         _value4 = Tuplet.DEFAULT;
103         if ( c == 0 ) {
104             _p[ 0 ] = -1;
105         }
106     }
107
108     public int compareTo( final Tuplet n ) {
109         if ( ( getValue1() != Tuplet.DEFAULT ) && ( n.getValue1() != Tuplet.DEFAULT ) ) {
110             if ( getValue1() < n.getValue1() ) {
111                 return _p[ 0 ];
112             }
113             if ( getValue1() > n.getValue1() ) {
114                 return ( -_p[ 0 ] );
115             }
116         }
117         if ( ( getValue2() != Tuplet.DEFAULT ) && ( n.getValue2() != Tuplet.DEFAULT ) ) {
118             if ( getValue2() < n.getValue2() ) {
119                 return _p[ 1 ];
120             }
121             if ( getValue2() > n.getValue2() ) {
122                 return ( -_p[ 1 ] );
123             }
124         }
125         if ( ( getValue3() != Tuplet.DEFAULT ) && ( n.getValue3() != Tuplet.DEFAULT ) ) {
126             if ( getValue3() < n.getValue3() ) {
127                 return _p[ 2 ];
128             }
129             if ( getValue3() > n.getValue3() ) {
130                 return ( -_p[ 2 ] );
131             }
132         }
133         if ( ( getValue4() != Tuplet.DEFAULT ) && ( n.getValue4() != Tuplet.DEFAULT ) ) {
134             if ( getValue4() < n.getValue4() ) {
135                 return _p[ 3 ];
136             }
137             if ( getValue4() > n.getValue4() ) {
138                 return ( -_p[ 3 ] );
139             }
140         }
141         return ( getKey().compareTo( n.getKey() ) );
142     }
143
144     String getKey() {
145         return _key;
146     }
147
148     double getValue1() {
149         return _value1;
150     }
151
152     double getValue2() {
153         return _value2;
154     }
155
156     double getValue3() {
157         return _value3;
158     }
159
160     double getValue4() {
161         return _value4;
162     }
163
164     private void setSigns() {
165         _p = new int[ 4 ];
166         _p[ 0 ] = _p[ 1 ] = _p[ 2 ] = _p[ 3 ] = +1;
167     }
168 }