Use instanceof pattern matching for call ID extraction

Replace explicit null check and Number cast with instanceof pattern
matching in AcceptCallCommand, HangupCallCommand, and
RejectCallCommand.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Shaheen Gandhi 2026-03-17 16:24:14 -07:00
parent ad8d692a13
commit cb7725482a
3 changed files with 6 additions and 9 deletions

View File

@ -35,11 +35,10 @@ public class AcceptCallCommand implements JsonRpcLocalCommand {
final Manager m,
final OutputWriter outputWriter
) throws CommandException {
final var callIdNumber = ns.get("call-id");
if (callIdNumber == null) {
if (!(ns.get("call-id") instanceof Number callIdNumber)) {
throw new UserErrorException("No call ID given");
}
final long callId = ((Number) callIdNumber).longValue();
final long callId = callIdNumber.longValue();
try {
var callInfo = m.acceptCall(callId);

View File

@ -33,11 +33,10 @@ public class HangupCallCommand implements JsonRpcLocalCommand {
final Manager m,
final OutputWriter outputWriter
) throws CommandException {
final var callIdNumber = ns.get("call-id");
if (callIdNumber == null) {
if (!(ns.get("call-id") instanceof Number callIdNumber)) {
throw new UserErrorException("No call ID given");
}
final long callId = ((Number) callIdNumber).longValue();
final long callId = callIdNumber.longValue();
try {
m.hangupCall(callId);

View File

@ -33,11 +33,10 @@ public class RejectCallCommand implements JsonRpcLocalCommand {
final Manager m,
final OutputWriter outputWriter
) throws CommandException {
final var callIdNumber = ns.get("call-id");
if (callIdNumber == null) {
if (!(ns.get("call-id") instanceof Number callIdNumber)) {
throw new UserErrorException("No call ID given");
}
final long callId = ((Number) callIdNumber).longValue();
final long callId = callIdNumber.longValue();
try {
m.rejectCall(callId);