From b8390005722dd1cdb24d762797ef3f98ebc37755 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Jul 2024 17:46:17 -0700 Subject: Update instanceof expressions --- src/main/java/org/traccar/api/BaseObjectResource.java | 9 +++------ src/main/java/org/traccar/api/ResourceErrorHandler.java | 3 +-- src/main/java/org/traccar/api/security/PermissionsService.java | 9 +++------ 3 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src/main/java/org/traccar/api') diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java index 3c97dd1f8..e35850e1f 100644 --- a/src/main/java/org/traccar/api/BaseObjectResource.java +++ b/src/main/java/org/traccar/api/BaseObjectResource.java @@ -89,15 +89,13 @@ public abstract class BaseObjectResource extends BaseResour permissionsService.checkPermission(baseClass, getUserId(), entity.getId()); boolean skipReadonly = false; - if (entity instanceof User) { - User after = (User) entity; + if (entity instanceof User after) { User before = storage.getObject(User.class, new Request( new Columns.All(), new Condition.Equals("id", entity.getId()))); permissionsService.checkUserUpdate(getUserId(), before, (User) entity); skipReadonly = permissionsService.getUser(getUserId()) .compare(after, "notificationTokens", "termsAccepted"); - } else if (entity instanceof Group) { - Group group = (Group) entity; + } else if (entity instanceof Group group) { if (group.getId() == group.getGroupId()) { throw new IllegalArgumentException("Cycle in group hierarchy"); } @@ -108,8 +106,7 @@ public abstract class BaseObjectResource extends BaseResour storage.updateObject(entity, new Request( new Columns.Exclude("id"), new Condition.Equals("id", entity.getId()))); - if (entity instanceof User) { - User user = (User) entity; + if (entity instanceof User user) { if (user.getHashedPassword() != null) { storage.updateObject(entity, new Request( new Columns.Include("hashedPassword", "salt"), diff --git a/src/main/java/org/traccar/api/ResourceErrorHandler.java b/src/main/java/org/traccar/api/ResourceErrorHandler.java index 387f3db6a..5f5e70632 100644 --- a/src/main/java/org/traccar/api/ResourceErrorHandler.java +++ b/src/main/java/org/traccar/api/ResourceErrorHandler.java @@ -25,8 +25,7 @@ public class ResourceErrorHandler implements ExceptionMapper { @Override public Response toResponse(Exception e) { - if (e instanceof WebApplicationException) { - WebApplicationException webException = (WebApplicationException) e; + if (e instanceof WebApplicationException webException) { return Response.fromResponse(webException.getResponse()).entity(Log.exceptionStack(webException)).build(); } else { return Response.status(Response.Status.BAD_REQUEST).entity(Log.exceptionStack(e)).build(); diff --git a/src/main/java/org/traccar/api/security/PermissionsService.java b/src/main/java/org/traccar/api/security/PermissionsService.java index d4a6fba1a..721793c2f 100644 --- a/src/main/java/org/traccar/api/security/PermissionsService.java +++ b/src/main/java/org/traccar/api/security/PermissionsService.java @@ -128,8 +128,7 @@ public class PermissionsService { throws StorageException, SecurityException { if (!getUser(userId).getAdministrator()) { checkEdit(userId, object.getClass(), addition, skipReadonly); - if (object instanceof GroupedModel) { - GroupedModel after = ((GroupedModel) object); + if (object instanceof GroupedModel after) { if (after.getGroupId() > 0) { GroupedModel before = null; if (!addition) { @@ -141,8 +140,7 @@ public class PermissionsService { } } } - if (object instanceof Schedulable) { - Schedulable after = ((Schedulable) object); + if (object instanceof Schedulable after) { if (after.getCalendarId() > 0) { Schedulable before = null; if (!addition) { @@ -154,8 +152,7 @@ public class PermissionsService { } } } - if (object instanceof Notification) { - Notification after = ((Notification) object); + if (object instanceof Notification after) { if (after.getCommandId() > 0) { Notification before = null; if (!addition) { -- cgit v1.2.3