Skip to content

Commit dcd5562

Browse files
committed
refactor: fix THRUSTMASTER typo, make Axis final, and improve downcall error message
- Add VENDOR_THRUSTMASTER (0x044F) and deprecate typo VENDOR_THURSTMASTER - Mark Axis class as final per project style guidelines - Remove unused Locale import from ControllerType - Correct javadoc in InputDevices.init describing failure behavior - Provide descriptive UnsatisfiedLinkError in captureCallState overload of downcallHandle - Add tests for Thrustmaster lookup and deprecated constant compatibility
1 parent 52f7475 commit dcd5562

6 files changed

Lines changed: 31 additions & 9 deletions

File tree

‎src/main/java/de/gurkenlabs/input4j/ControllerDatabase.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ public final class ControllerDatabase {
3535
public static final int VENDOR_LOGITECH = 0x046D;
3636

3737
/** Known vendor ID for Thrustmaster. */
38-
public static final int VENDOR_THURSTMASTER = 0x044F;
38+
public static final int VENDOR_THRUSTMASTER = 0x044F;
39+
40+
/**
41+
* Known vendor ID for Thrustmaster.
42+
*
43+
* @deprecated Typo in constant name, use {@link #VENDOR_THRUSTMASTER} instead.
44+
*/
45+
@Deprecated
46+
public static final int VENDOR_THURSTMASTER = VENDOR_THRUSTMASTER;
3947

4048
/** Known vendor ID for Mad Catz. */
4149
public static final int VENDOR_MAD_CATZ = 0x0738;

‎src/main/java/de/gurkenlabs/input4j/ControllerType.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package de.gurkenlabs.input4j;
22

3-
import java.util.Locale;
4-
53
/**
64
* Represents the type of game controller.
75
* This enum is used to identify the category of a controller based on its vendor and product IDs.

‎src/main/java/de/gurkenlabs/input4j/InputDevices.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static InputDevicePlugin init(Frame owner, InputLibrary library) {
9292
* The plugin class must be a fully qualified class name of a class that implements the {@link InputDevicePlugin} interface.
9393
* <p>
9494
* This can be used to explicitly select a custom input library implementation.
95-
* If the class is not found or cannot be instantiated, an {@link IOException} is thrown.
95+
* If the class is not found or cannot be instantiated, null is returned and the error is logged.
9696
* The class must have a public no-argument constructor.
9797
* </p>
9898
* @return The initialized input device provider or null if the initialization fails.

‎src/main/java/de/gurkenlabs/input4j/components/Axis.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Predefined axis component identifiers for standard gamepad controllers.
88
*/
9-
public class Axis {
9+
public final class Axis {
1010
private Axis() {}
1111

1212
/** Maximum default axis ID value. */

‎src/main/java/de/gurkenlabs/input4j/foreign/NativeHelper.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ public static MethodHandle downcallHandle(MemorySegment address, FunctionDescrip
2121
return Linker.nativeLinker().downcallHandle(address, fdesc);
2222
}
2323

24-
public static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc, String captureCallState){
24+
public static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc, String captureCallState) {
2525
Linker.Option ccs = Linker.Option.captureCallState(captureCallState);
2626
return Linker.nativeLinker().downcallHandle(
27-
SymbolLookup.loaderLookup().find(name).or(() -> Linker.nativeLinker().defaultLookup().find(name)).orElseThrow(),
28-
fdesc,
29-
ccs);
27+
SymbolLookup.loaderLookup().find(name)
28+
.or(() -> Linker.nativeLinker().defaultLookup().find(name))
29+
.orElseThrow(() -> new UnsatisfiedLinkError(
30+
"Native symbol not found: " + name + " with descriptor " + fdesc)),
31+
fdesc,
32+
ccs);
3033
}
3134
}

‎src/test/java/de/gurkenlabs/input4j/ControllerDatabaseTests.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ void testLookupKnownController_8BitDo() {
5050
assertEquals(ControllerType.EIGHTBITDO, result.get().type());
5151
}
5252

53+
@Test
54+
void testLookupKnownController_Thrustmaster() {
55+
var result = ControllerDatabase.lookup(ControllerDatabase.VENDOR_THRUSTMASTER, 0x0F00);
56+
assertTrue(result.isPresent());
57+
assertEquals("Thrustmaster Wheel Xbox", result.get().displayName());
58+
}
59+
60+
@Test
61+
@SuppressWarnings("deprecation")
62+
void testDeprecatedThrustmasterConstantEqualsCorrectConstant() {
63+
assertEquals(ControllerDatabase.VENDOR_THRUSTMASTER, ControllerDatabase.VENDOR_THURSTMASTER);
64+
}
65+
5366
@Test
5467
void testLookupUnknownReturnsEmpty() {
5568
var result = ControllerDatabase.lookup(0x1234, 0x5678);

0 commit comments

Comments
 (0)