Skip to content

Commit 692e8f9

Browse files
committed
code smell fixes
1 parent 6133772 commit 692e8f9

7 files changed

Lines changed: 71 additions & 30 deletions

File tree

src/main/java/tech/fastj/graphics/textures/Textures.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import java.nio.file.Path;
77

88
public class Textures {
9+
10+
private Textures() {
11+
throw new IllegalStateException();
12+
}
13+
914
public static TexturePaint create(Path texturePath, Rectangle2D textureLocation) {
1015
return TextureBuilder.builder(texturePath, textureLocation).build();
1116
}

src/main/java/tech/fastj/input/mouse/Mouse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static void init() {
185185
*/
186186
public static boolean interactsWith(Drawable button, MouseAction recentMouseAction) {
187187
PathIterator buttonPathIterator = button.getCollisionPath().getPathIterator(null);
188-
return Path2D.Float.intersects(buttonPathIterator, mouseLocation.x, mouseLocation.y, 1, 1) && recentMouseAction.recentAction;
188+
return Path2D.intersects(buttonPathIterator, mouseLocation.x, mouseLocation.y, 1, 1) && recentMouseAction.recentAction;
189189
}
190190

191191
/**

src/main/java/tech/fastj/math/Point.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313
*/
1414
public class Point {
1515

16-
/** {@code Point} representing the origin as an {@code int}: {@code (0, 0)}. */
16+
/**
17+
* {@code Point} representing the origin as an {@code int}: {@code (0, 0)}.
18+
*
19+
* @deprecated As an object, users are likely to accidentally modify this value. Furthermore, Java will likely not
20+
* receive <a href="https://openjdk.java.net/jeps/401" target="_blank">primitive objects</a> any time soon, so this
21+
* value will be removed very soon. Use {@link Point#origin()} instead.
22+
*/
23+
@Deprecated
1724
public static final Point Origin = new Point();
1825

1926
/** The x value of the {@link Point}. */
@@ -81,54 +88,61 @@ public Point(int xVal, int yVal) {
8188
}
8289

8390
/**
84-
* {@code Point} representing a 2D graph's origin as a pair of {@code integer}s: {@code (0, 0)}.
91+
* {@code Point} representing a 2D graph's origin as a pair of {@code integer}s: {@code (0, 0)}. Each returned
92+
* instance is a newly created object.
8593
*
86-
* @return The {@code origin} instance.
94+
* @return An {@code origin} instance.
95+
* @since 1.6.0
8796
*/
8897
public static Point origin() {
8998
return new Point();
9099
}
91100

92101
/**
93-
* {@code Point} representing a unit vector in a 2D graph as a pair of {@code integer}s: {@code (0, 0)}.
102+
* {@code Point} representing a unit vector in a 2D graph as a pair of {@code integer}s: {@code (0, 0)}. Each
103+
* returned instance is a newly created object.
94104
*
95-
* @return The {@code unit} vector instance.
105+
* @return A {@code unit} vector instance.
96106
*/
97107
public static Point unit() {
98108
return new Point(1);
99109
}
100110

101111
/**
102-
* {@code Point} representing an up vector in a 2D graph as a pair of {@code integer}s: {@code (0, -1)}.
112+
* {@code Point} representing an up vector in a 2D graph as a pair of {@code integer}s: {@code (0, -1)}. Each
113+
* returned instance is a newly created object.
103114
*
104-
* @return The {@code up} vector instance.
115+
* @return An {@code up} vector instance.
105116
*/
106117
public static Point up() {
107118
return new Point(0, -1);
108119
}
109120

110121
/**
111-
* {@code Point} representing a down vector in a 2D graph as a pair of {@code integer}s: {@code (0, 1)}.
122+
* {@code Point} representing a down vector in a 2D graph as a pair of {@code integer}s: {@code (0, 1)}. Each
123+
* returned instance is a newly created object.
112124
*
113-
* @return The {@code down} vector instance.
125+
* @return A {@code down} vector instance.
114126
*/
115127
public static Point down() {
116128
return new Point(0, 1);
117129
}
118130

119131
/**
120-
* {@code Point} representing a left vector in a 2D graph as a pair of {@code integer}s: {@code (-1, 0)}.
132+
* {@code Point} representing a left vector in a 2D graph as a pair of {@code integer}s: {@code (-1, 0)}. Each
133+
* returned instance is a newly created object.
121134
*
122-
* @return The {@code left} vector instance.
135+
* @return A {@code left} vector instance.
123136
*/
124137
public static Point left() {
125138
return new Point(-1, 0);
126139
}
127140

128141
/**
129-
* {@code Point} representing a right vector in a 2D graph as a pair of {@code integer}s: {@code (1, 0)}.
142+
* {@code Point} representing a right vector in a 2D graph as a pair of {@code integer}s: {@code (1, 0)}. Each
143+
* returned instance is a newly created object.
130144
*
131-
* @return The {@code right} vector instance.
145+
* @return A {@code right} vector instance.
132146
*/
133147
public static Point right() {
134148
return new Point(1, 0);
@@ -317,8 +331,8 @@ public static int cross(Point p, Point p1) {
317331
* @return The calculated distance.
318332
*/
319333
public static float distance(Point p, Point p1) {
320-
float differenceX = p1.x - p.x;
321-
float differenceY = p1.y - p.y;
334+
float differenceX = (float) p1.x - p.x;
335+
float differenceY = (float) p1.y - p.y;
322336
return (float) Math.sqrt(differenceX * differenceX + differenceY * differenceY);
323337
}
324338

src/main/java/tech/fastj/math/Pointf.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
*/
1313
public class Pointf {
1414

15-
/** {@code Pointf} representing the origin as a {@code float}: {@code (0f, 0f)}. */
15+
/**
16+
* {@code Pointf} representing the origin as a {@code float}: {@code (0f, 0f)}.
17+
*
18+
* @deprecated As an object, users are likely to accidentally modify this value. Furthermore, Java will likely not
19+
* receive <a href="https://openjdk.java.net/jeps/401" target="_blank">primitive objects</a> any time soon, so this
20+
* value will be removed very soon. Use {@link Pointf#origin()} instead.
21+
*/
22+
@Deprecated
1623
public static final Pointf Origin = new Pointf();
1724

1825
/** The x value of the {@link Pointf}. */
@@ -68,54 +75,61 @@ public Pointf(float xVal, float yVal) {
6875
}
6976

7077
/**
71-
* {@code Pointf} representing a 2D graph's origin as a pair of {@code float}s: {@code (0f, 0f)}.
78+
* A new {@code Pointf} representing a 2D graph's origin as a pair of {@code float}s: {@code (0f, 0f)}. Each
79+
* returned instance is a newly created object.
7280
*
73-
* @return The {@code origin} instance.
81+
* @return An {@code origin} instance.
82+
* @since 1.6.0
7483
*/
7584
public static Pointf origin() {
7685
return new Pointf();
7786
}
7887

7988
/**
80-
* {@code Pointf} representing a unit vector in a 2D graph as a pair of {@code float}s: {@code (0f, 0f)}.
89+
* {@code Pointf} representing a unit vector in a 2D graph as a pair of {@code float}s: {@code (0f, 0f)}. Each
90+
* returned instance is a newly created object.
8191
*
82-
* @return The {@code unit} vector instance.
92+
* @return A {@code unit} vector instance.
8393
*/
8494
public static Pointf unit() {
8595
return new Pointf(1f);
8696
}
8797

8898
/**
89-
* {@code Pointf} representing an up vector in a 2D graph as a pair of {@code float}s: {@code (0f, -1f)}.
99+
* {@code Pointf} representing an up vector in a 2D graph as a pair of {@code float}s: {@code (0f, -1f)}. Each
100+
* returned instance is a newly created object.
90101
*
91-
* @return The {@code up} vector instance.
102+
* @return An {@code up} vector instance.
92103
*/
93104
public static Pointf up() {
94105
return new Pointf(0f, -1f);
95106
}
96107

97108
/**
98-
* {@code Pointf} representing a down vector in a 2D graph as a pair of {@code float}s: {@code (0f, 1f)}.
109+
* {@code Pointf} representing a down vector in a 2D graph as a pair of {@code float}s: {@code (0f, 1f)}. Each
110+
* returned instance is a newly created object.
99111
*
100-
* @return The {@code down} vector instance.
112+
* @return A {@code down} vector instance.
101113
*/
102114
public static Pointf down() {
103115
return new Pointf(0f, 1f);
104116
}
105117

106118
/**
107-
* {@code Pointf} representing a left vector in a 2D graph as a pair of {@code float}s: {@code (-1f, 0f)}.
119+
* {@code Pointf} representing a left vector in a 2D graph as a pair of {@code float}s: {@code (-1f, 0f)}. Each
120+
* returned instance is a newly created object.
108121
*
109-
* @return The {@code left} vector instance.
122+
* @return A {@code left} vector instance.
110123
*/
111124
public static Pointf left() {
112125
return new Pointf(-1f, 0f);
113126
}
114127

115128
/**
116-
* {@code Pointf} representing a right vector in a 2D graph as a pair of {@code float}s: {@code (1f, 0f)}.
129+
* {@code Pointf} representing a right vector in a 2D graph as a pair of {@code float}s: {@code (1f, 0f)}. Each
130+
* returned instance is a newly created object.
117131
*
118-
* @return The {@code right} vector instance.
132+
* @return A {@code right} vector instance.
119133
*/
120134
public static Pointf right() {
121135
return new Pointf(1f, 0f);

src/main/java/tech/fastj/resources/ResourceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public abstract class ResourceManager<T extends Resource<V>, V> {
1515
protected final Map<Path, UUID> pathToUUIDMap;
1616
protected final Map<String, Path> idToPathMap;
1717

18-
public ResourceManager() {
18+
protected ResourceManager() {
1919
resourceStorage = new ConcurrentHashMap<>();
2020
pathToUUIDMap = new ConcurrentHashMap<>();
2121
idToPathMap = new ConcurrentHashMap<>();

src/main/java/tech/fastj/resources/files/FileUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
*/
1616
public class FileUtil {
1717

18+
private FileUtil() {
19+
throw new IllegalStateException();
20+
}
21+
1822
/**
1923
* Gets the file extension of the specified path.
2024
* <p>

src/main/java/tech/fastj/resources/images/ImageUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
public class ImageUtil {
2222

23+
private ImageUtil() {
24+
throw new IllegalStateException();
25+
}
26+
2327
public static VolatileImage createVolatileImage(int width, int height) {
2428
try {
2529
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleVolatileImage(

0 commit comments

Comments
 (0)