in progress
[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     @Override
109     public int compareTo( final Tuplet n ) {
110         if ( ( getValue1() != Tuplet.DEFAULT ) && ( n.getValue1() != Tuplet.DEFAULT ) ) {
111             if ( getValue1() < n.getValue1() ) {
112                 return _p[ 0 ];
113             }
114             if ( getValue1() > n.getValue1() ) {
115                 return ( -_p[ 0 ] );
116             }
117         }
118         if ( ( getValue2() != Tuplet.DEFAULT ) && ( n.getValue2() != Tuplet.DEFAULT ) ) {
119             if ( getValue2() < n.getValue2() ) {
120                 return _p[ 1 ];
121             }
122             if ( getValue2() > n.getValue2() ) {
123                 return ( -_p[ 1 ] );
124             }
125         }
126         if ( ( getValue3() != Tuplet.DEFAULT ) && ( n.getValue3() != Tuplet.DEFAULT ) ) {
127             if ( getValue3() < n.getValue3() ) {
128                 return _p[ 2 ];
129             }
130             if ( getValue3() > n.getValue3() ) {
131                 return ( -_p[ 2 ] );
132             }
133         }
134         if ( ( getValue4() != Tuplet.DEFAULT ) && ( n.getValue4() != Tuplet.DEFAULT ) ) {
135             if ( getValue4() < n.getValue4() ) {
136                 return _p[ 3 ];
137             }
138             if ( getValue4() > n.getValue4() ) {
139                 return ( -_p[ 3 ] );
140             }
141         }
142         return ( getKey().compareTo( n.getKey() ) );
143     }
144
145     String getKey() {
146         return _key;
147     }
148
149     double getValue1() {
150         return _value1;
151     }
152
153     double getValue2() {
154         return _value2;
155     }
156
157     double getValue3() {
158         return _value3;
159     }
160
161     double getValue4() {
162         return _value4;
163     }
164
165     private void setSigns() {
166         _p = new int[ 4 ];
167         _p[ 0 ] = _p[ 1 ] = _p[ 2 ] = _p[ 3 ] = +1;
168     }
169 }