Debian Codegraph @

src/main/java/org/jfree/pdf/util/RadialGradientPaintKey.java

raw
1 /* =====================================================================
2 * JFreePDF : a fast, light-weight PDF library for the Java(tm) platform
3 * =====================================================================
4 *
5 * (C)opyright 2013-2022, by David Gilbert. All rights reserved.
6 *
7 * https://github.com/jfree/orsonpdf
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program 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
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
23 * Other names may be trademarks of their respective owners.]
24 *
25 * If you do not wish to be bound by the terms of the GPL, an alternative
26 * runtime license is available to JFree sponsors:
27 *
28 * https://github.com/sponsors/jfree
29 *
30 */
31
32 package org.jfree.pdf.util;
33
34 import java.awt.RadialGradientPaint;
35 import java.util.Arrays;
36
37 /**
38 * A wrapper for a {@code RadialGradientPaint} that can be used as the key
39 * for a {@code HashMap}. This class is used internally by
40 * {@code PDFGraphics2D} to track and re-use gradient definitions.
41 * {@code RadialGradientPaint} itself does not implement the {@code equals()}
42 * and {@code hashCode()} methods, so it doesn't make a good key for a
43 * {@code Map}.
44 */
45 public class RadialGradientPaintKey {
46
47 private RadialGradientPaint paint;
48
49 float f = 0.0f;
50
51 /**
52 * Creates a new key instance.
53 *
54 * @param rgp the radial gradient paint ({@code null} not permitted).
55 */
56 public RadialGradientPaintKey(RadialGradientPaint rgp) {
57 Args.nullNotPermitted(rgp, "rgp");
58 this.paint = rgp;
59 }
60
61 /**
62 * Returns the {@code RadialGradientPaint} that was supplied to the
63 * constructor.
64 *
65 * @return The {@code RadialGradientPaint} (never {@code null}).
66 */
67 public RadialGradientPaint getPaint() {
68 return this.paint;
69 }
70
71 /**
72 * Tests this instance for equality with an arbitrary object.
73 *
74 * @param obj the object to test ({@code null} permitted).
75 *
76 * @return A boolean.
77 */
78 @Override
79 public boolean equals(Object obj) {
80 if (obj == this) {
81 return true;
82 }
83 if (! (obj instanceof RadialGradientPaint)) {
84 return false;
85 }
86 RadialGradientPaint that = (RadialGradientPaint) obj;
87 if (!this.paint.getCenterPoint().equals(that.getCenterPoint())) {
88 return false;
89 }
90 if (!this.paint.getFocusPoint().equals(that.getCenterPoint())) {
91 return false;
92 }
93 if (!Arrays.equals(this.paint.getColors(), that.getColors())) {
94 return false;
95 }
96 if (!Arrays.equals(this.paint.getFractions(), that.getFractions())) {
97 return false;
98 }
99 return true;
100 }
101
102 /**
103 * Returns a hash code for this instance.
104 *
105 * @return A hash code.
106 */
107 @Override
108 public int hashCode() {
109 int hash = 5;
110 hash = 47 * hash + this.paint.getCenterPoint().hashCode();
111 hash = 47 * hash + this.paint.getFocusPoint().hashCode();
112 hash = 47 * hash + Float.floatToIntBits(this.paint.getRadius());
113 hash = 47 * hash + Arrays.hashCode(this.paint.getColors());
114 hash = 47 * hash + Arrays.hashCode(this.paint.getFractions());
115 return hash;
116 }
117
118 }