refactor: 使用 getFirst 优化首元素访问

This commit is contained in:
疯狂的狮子Li
2026-06-11 13:57:43 +08:00
parent d8f8d5493d
commit 0d72999366
14 changed files with 22 additions and 22 deletions
@@ -93,7 +93,7 @@ public class SysLoginService {
remoteSocialService.insertByBo(bo);
} else {
// 更新用户信息
bo.setId(list.get(0).getId());
bo.setId(list.getFirst().getId());
remoteSocialService.updateByBo(bo);
// 如果要绑定的平台账号已经被绑定过了 是否抛异常自行决断
// throw new ServiceException("此平台账号已经被绑定!");
@@ -65,7 +65,7 @@ public class SocialAuthStrategy implements IAuthStrategy {
if (CollUtil.isEmpty(list)) {
throw new ServiceException("你还没有绑定第三方账号,绑定后才可以登录!");
}
RemoteSocialVo socialVo = list.get(0);
RemoteSocialVo socialVo = list.getFirst();
LoginUser loginUser = remoteUserService.getUserInfo(socialVo.getUserId());
loginUser.setClientKey(client.getClientKey());
@@ -62,7 +62,7 @@ public class TreeBuildUtils extends TreeUtil {
if (CollUtil.isEmpty(list)) {
return CollUtil.newArrayList();
}
K k = ReflectUtils.invokeGetter(list.get(0), "parentId");
K k = ReflectUtils.invokeGetter(list.getFirst(), "parentId");
return TreeUtil.build(list, k, DEFAULT_CONFIG, nodeParser);
}
@@ -196,8 +196,8 @@ public class OpenApiHandler extends OpenAPIService {
// 自定义部分 修改使用java注释当tag名
List<String> list = IoUtil.readLines(new StringReader(description), new ArrayList<>());
// tag.setName(tagAutoName);
tag.setName(list.get(0));
operation.addTagsItem(list.get(0));
tag.setName(list.getFirst());
operation.addTagsItem(list.getFirst());
tag.setDescription(description);
if (openAPI.getTags() == null || !openAPI.getTags().contains(tag)) {
@@ -49,7 +49,7 @@ public class CellMergeHandler {
}
// 获取有合并注解的字段
Map<Field, FieldColumnIndex> mergeFields = getFieldColumnIndexMap(rows.get(0).getClass());
Map<Field, FieldColumnIndex> mergeFields = getFieldColumnIndexMap(rows.getFirst().getClass());
// 如果没有需要合并的字段则返回空集
if (CollUtil.isEmpty(mergeFields)) {
return Collections.emptyList();
@@ -154,7 +154,7 @@ public class DropDownOptions {
sonList.forEach(everySon -> {
if (parentGroupByIdMap.containsKey(sonHowToGetParentIdFunction.apply(everySon))) {
// 找到对应的上级
T parentObj = parentGroupByIdMap.get(sonHowToGetParentIdFunction.apply(everySon)).get(0);
T parentObj = parentGroupByIdMap.get(sonHowToGetParentIdFunction.apply(everySon)).getFirst();
// 提取名称和ID作为Key
String key = howToBuildEveryOption.apply(parentObj);
// Key对应的Value
@@ -276,10 +276,10 @@ public class ExcelDownHandler implements SheetWriteHandler {
continue;
}
// 取第一个
String str = data.get(0);
String str = data.getFirst();
rowData.add(str);
// 通过移除的方式避免重复
data.remove(0);
data.removeFirst();
// 设置可以继续
flag = true;
}
@@ -59,7 +59,7 @@ public class SnailJobConfig {
if (StringUtils.isNotBlank(serverName)) {
List<ServiceInstance> instances = discoveryClient.getInstances(serverName);
if (CollUtil.isNotEmpty(instances)) {
ServiceInstance instance = instances.get(0);
ServiceInstance instance = instances.getFirst();
System.setProperty("snail-job.server.host", instance.getHost());
System.setProperty("snail-job.server.port", properties.getPort());
}
@@ -108,7 +108,7 @@ public class PlusDataPermissionHandler {
}
Object defaultValue = "-1";
NullSafeStandardEvaluationContext context = new NullSafeStandardEvaluationContext(defaultValue);
context.addPropertyAccessor(new NullSafePropertyAccessor(context.getPropertyAccessors().get(0), defaultValue));
context.addPropertyAccessor(new NullSafePropertyAccessor(context.getPropertyAccessors().getFirst(), defaultValue));
context.setBeanResolver(beanResolver);
DataPermissionHelper.getContext().forEach(context::setVariable);
Set<String> conditions = new HashSet<>();
@@ -112,7 +112,7 @@ public class ExportExcelServiceImpl implements IExportExcelService {
Map<Integer, List<DemoCityData>> groupByIdMap =
cityDataList.stream().collect(Collectors.groupingBy(DemoCityData::getId));
if (groupByIdMap.containsKey(id)) {
DemoCityData demoCityData = groupByIdMap.get(id).get(0);
DemoCityData demoCityData = groupByIdMap.get(id).getFirst();
return DropDownOptions.createOptionValue(demoCityData.getName(), demoCityData.getId());
} else {
return StrUtil.EMPTY;
@@ -206,7 +206,7 @@ public class ExportExcelServiceImpl implements IExportExcelService {
sonList.forEach(everySon -> {
if (parentGroupByIdMap.containsKey(everySon.getPid())) {
everySon.setPData(parentGroupByIdMap.get(everySon.getPid()).get(0));
everySon.setPData(parentGroupByIdMap.get(everySon.getPid()).getFirst());
}
});
}
@@ -593,7 +593,7 @@ public class GenTableServiceImpl implements IGenTableService {
}
}
if (ObjectUtil.isNull(table.getPkColumn())) {
table.setPkColumn(table.getColumns().get(0));
table.setPkColumn(table.getColumns().getFirst());
}
}
@@ -211,7 +211,7 @@ public class WorkflowGlobalListener implements GlobalListener {
}
if (!BusinessStatusEnum.initialState(instance.getFlowStatus())) {
if (task != null && CollUtil.isNotEmpty(nextTasks) && nextTasks.size() == 1
&& flwCommonService.applyNodeCode(definition.getId()).equals(nextTasks.get(0).getNodeCode())) {
&& flwCommonService.applyNodeCode(definition.getId()).equals(nextTasks.getFirst().getNodeCode())) {
// 如果为画线指定驳回 线条指定为驳回 驳回得节点为申请人节点 则修改流程状态为退回
flowProcessEventHandler.processHandler(definition.getFlowCode(), instance, BusinessStatusEnum.BACK.getStatus(), params, false);
notifyInitiatorIfNeeded(definition, instance, BusinessStatusEnum.BACK.getStatus(), variable);
@@ -266,7 +266,7 @@ public class WorkflowGlobalListener implements GlobalListener {
return true;
}
String applyNodeCode = flwCommonService.applyNodeCode(definition.getId());
return !StringUtils.equals(applyNodeCode, nextTasks.get(0).getNodeCode());
return !StringUtils.equals(applyNodeCode, nextTasks.getFirst().getNodeCode());
}
private void notifyInitiatorIfNeeded(Definition definition, Instance instance, String status, Map<String, Object> variable) {
@@ -165,7 +165,7 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
if (CollUtil.isEmpty(firstBetweenNode)) {
throw new ServiceException("流程定义缺少申请人节点,请检查流程定义配置");
}
return firstBetweenNode.get(0).getNodeCode();
return firstBetweenNode.getFirst().getNodeCode();
}
}
@@ -136,8 +136,8 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
taskService.mergeVariable(flowInstance, variables);
insService.updateById(flowInstance);
RemoteStartProcessReturn dto = new RemoteStartProcessReturn();
dto.setProcessInstanceId(taskList.get(0).getInstanceId());
dto.setTaskId(taskList.get(0).getId());
dto.setProcessInstanceId(taskList.getFirst().getInstanceId());
dto.setTaskId(taskList.getFirst().getId());
// 保存流程实例业务信息
this.buildFlowInstanceBizExt(flowInstance, bizExt);
return dto;
@@ -170,7 +170,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
}
RemoteStartProcessReturn dto = new RemoteStartProcessReturn();
dto.setProcessInstanceId(instance.getId());
dto.setTaskId(taskList.get(0).getId());
dto.setTaskId(taskList.getFirst().getId());
return dto;
}
@@ -346,7 +346,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
if (CollUtil.isEmpty(flowHisTasks)) {
throw new ServiceException("流程历史任务不存在,无法添加抄送记录");
}
FlowHisTask flowHisTask = flowHisTasks.get(0);
FlowHisTask flowHisTask = flowHisTasks.getFirst();
FlowNode flowNode = new FlowNode();
flowNode.setNodeCode(flowHisTask.getTargetNodeCode());
flowNode.setNodeName(flowHisTask.getTargetNodeName());
@@ -531,7 +531,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
return nodeCodes;
}
//判断是否配置了固定驳回节点
Node node = nodeCodes.get(0);
Node node = nodeCodes.getFirst();
if (StringUtils.isNotBlank(node.getAnyNodeSkip())) {
return nodeService.getByNodeCodes(Collections.singletonList(node.getAnyNodeSkip()), task.getDefinitionId());
}