Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DoubleValuedPathAlgebra |
|
| 0.0;0 |
1 | /* | |
2 | This file is part of Combean. | |
3 | ||
4 | Combean is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation; either version 2 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | Combean is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with Combean; if not, write to the Free Software | |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | /* | |
19 | * Created on 10.04.2005 | |
20 | * | |
21 | */ | |
22 | package net.sourceforge.combean.graph.alg.spath; | |
23 | ||
24 | import net.sourceforge.combean.interfaces.graph.alg.spath.PathAlgebra; | |
25 | ||
26 | /** | |
27 | * A path algebra which works with subclasses of java.lang.Number and | |
28 | * uses double values for the arithmetic | |
29 | * | |
30 | * @author schickin | |
31 | * | |
32 | */ | |
33 | 333 | public class DoubleValuedPathAlgebra implements PathAlgebra<Double> { |
34 | ||
35 | /** | |
36 | * constructor | |
37 | */ | |
38 | public DoubleValuedPathAlgebra() { | |
39 | 21 | super(); |
40 | 21 | } |
41 | ||
42 | /* (non-Javadoc) | |
43 | * @see net.sourceforge.combean.interfaces.graph.alg.spath.PathAlgebra#add(java.lang.Double, java.lang.Double) | |
44 | */ | |
45 | public Double add(Double pathLenOne, Double pathLenTwo) { | |
46 | 291 | return new Double(doubleValue(pathLenOne) + doubleValue(pathLenTwo)); |
47 | } | |
48 | ||
49 | /* (non-Javadoc) | |
50 | * @see net.sourceforge.combean.interfaces.graph.alg.spath.PathAlgebra#min(java.lang.Double, java.lang.Double) | |
51 | */ | |
52 | public Double min(Double pathLenOne, Double pathLenTwo) { | |
53 | 0 | return new Double( |
54 | Math.min(doubleValue(pathLenOne), doubleValue(pathLenTwo))); | |
55 | } | |
56 | ||
57 | /* (non-Javadoc) | |
58 | * @see net.sourceforge.combean.interfaces.graph.alg.spath.PathAlgebra#infinitePathLen() | |
59 | */ | |
60 | public Double infinitePathLen() { | |
61 | 21 | return new Double(Double.POSITIVE_INFINITY); |
62 | } | |
63 | ||
64 | /* (non-Javadoc) | |
65 | * @see net.sourceforge.combean.interfaces.graph.alg.spath.PathAlgebra#emptyPathLen() | |
66 | */ | |
67 | public Double emptyPathLen() { | |
68 | 21 | return new Double(0.0); |
69 | } | |
70 | ||
71 | ||
72 | /** | |
73 | * Convenience method which converts a Double (which is casted to | |
74 | * Number) to a double value. | |
75 | * | |
76 | * @param num the Number to be converted. | |
77 | * @return the double value of num | |
78 | */ | |
79 | private double doubleValue(Double num) { | |
80 | 582 | return ((Number) num).doubleValue(); |
81 | } | |
82 | } |