Skip to content

Package: Rational

Rational

nameinstructionbranchcomplexitylinemethod
Rational(int, int)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
byteValue()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
canEqual(Object)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
divide(double)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
doubleValue()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 35 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
floatValue()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDenominator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNumerator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getReciprocal()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
intValue()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isInteger()
M: 23 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
longValue()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
of(double)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
of(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
of(int, int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
shortValue()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.image;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.concurrent.Immutable;
31: import lombok.EqualsAndHashCode;
32: import lombok.Getter;
33: import lombok.RequiredArgsConstructor;
34:
35: /***********************************************************************************************************************
36: *
37: * @author Fabrizio Giudici
38: *
39: **********************************************************************************************************************/
40:•@Immutable @RequiredArgsConstructor(staticName = "of") @EqualsAndHashCode(callSuper = false)
41: public final class Rational extends Number
42: {
43: @Getter
44: private final int numerator;
45:
46: @Getter
47: private final int denominator;
48:
49: /*******************************************************************************************************************
50: *
51: * @param i
52: *
53: ******************************************************************************************************************/
54: @Nonnull
55: public static Rational of (final int i)
56: {
57: return of(i, 1);
58: }
59:
60: /*******************************************************************************************************************
61: *
62: * @param d
63: *
64: ******************************************************************************************************************/
65: @Nonnull
66: public static Rational of (final double d)
67: {
68: var denominator = 100000;
69: var numerator = (int)Math.round(d * denominator);
70: // TODO: normalize
71: return of(numerator, denominator);
72: }
73:
74: /*******************************************************************************************************************
75: *
76: * {@inheritDoc}
77: *
78: ******************************************************************************************************************/
79: @Override
80: public double doubleValue()
81: {
82: return (double)numerator / (double)denominator;
83: }
84:
85: /*******************************************************************************************************************
86: *
87: * {@inheritDoc}
88: *
89: ******************************************************************************************************************/
90: @Override
91: public float floatValue()
92: {
93: return (float)numerator / (float)denominator;
94: }
95:
96: /*******************************************************************************************************************
97: *
98: * {@inheritDoc}
99: *
100: ******************************************************************************************************************/
101: @Override
102: public byte byteValue()
103: {
104: return (byte)doubleValue();
105: }
106:
107: /*******************************************************************************************************************
108: *
109: * {@inheritDoc}
110: *
111: ******************************************************************************************************************/
112: @Override
113: public int intValue()
114: {
115: return (int)doubleValue();
116: }
117:
118: /*******************************************************************************************************************
119: *
120: * {@inheritDoc}
121: *
122: ******************************************************************************************************************/
123: @Override
124: public long longValue()
125: {
126: return (long)doubleValue();
127: }
128:
129: /*******************************************************************************************************************
130: *
131: * {@inheritDoc}
132: *
133: ******************************************************************************************************************/
134: @Override
135: public short shortValue()
136: {
137: return (short)doubleValue();
138: }
139:
140: /*******************************************************************************************************************
141: *
142: *
143: * @param det
144: * @return
145: *
146: ******************************************************************************************************************/
147: @Nonnull
148: public Rational divide (final double det)
149: {
150: return Rational.of(numerator, (int)Math.round(denominator * det));
151: }
152:
153: /*******************************************************************************************************************
154: *
155: *
156: *
157: ******************************************************************************************************************/
158: @Nonnull
159: public Rational getReciprocal()
160: {
161: return Rational.of(denominator, numerator);
162: }
163:
164: /*******************************************************************************************************************
165: *
166: *
167: *
168: ******************************************************************************************************************/
169: public boolean isInteger()
170: {
171:• return (denominator == 1) || ((denominator != 0) && ((numerator % denominator) == 0))
172: || ((denominator == 0) && (numerator == 0));
173: }
174:
175: /*******************************************************************************************************************
176: *
177: * {@inheritDoc}
178: *
179: ******************************************************************************************************************/
180: @Override @Nonnull
181: public String toString()
182: {
183: return numerator + "/" + denominator;
184: }
185: }