@SuppressWarnings("unchecked") private static GroupOperation makeOperation(Object object) { try { Map<String, String> data = (Map<String, String>) object; String type = data.get(OPERATION_TYPE); Optional<GroupOperationType> operation = SUPPORTED_GROUP_OPERATIONS.stream().filter(t -> t.isMe(type)).findFirst(); // May or may not be present String field = data.get(OPERATION_FIELD); // May or may not be present String newName = data.get(OPERATION_NEW_NAME); // Unknown GroupOperations are ignored. return operation.isPresent() ? new GroupOperation(operation.get(), field, newName) : null; } catch (ClassCastException | NullPointerException e) { return null; } } }