解释这段代码public Object getAreaHotChart(){ List<List> areaHotData = new ArrayList(); List<House> houseList = houseMapper.selectList(new QueryWrapper<House>().eq("status",2)); for(House house : houseList){ Double longitude = house.getLongitude(); Double latitude = house.getLatitude(); int has = 0; for(int i = 0; i < areaHotData.size(); i++){ (double)latitude){ List oneData = areaHotData.get(i); if((double)oneData.get(0) == (double)longitude && (double)oneData.get(1) == Integer count = (Integer)oneData.get(2); List newData = new ArrayList(); newData.add(longitude); newData.add(latitude); newData.add(count+1); areaHotData.set(i,newData); has = 1; }} if(has == 0){ List newData = new ArrayList(); newData.add(longitude); newData.add(latitude); newData.add(1); areaHotData.add(newData); } } return areaHotData; }
时间: 2023-06-05 11:07:04 浏览: 48
){
int count = (int)oneData.get(2);
oneData.set(2,count+1);
has = 1;
}
}
if(has == 0){
List newData = new ArrayList();
newData.add(longitude);
newData.add(latitude);
newData.add(1);
areaHotData.add(newData);
}
}
return ResultFactory.buildSuccessResult(areaHotData);
}
这段代码是一个获取房屋热度图的方法,首先从数据库中查询出状态为2的房屋列表,然后逐一计算每个房屋的经纬度并且根据经纬度判断该房屋是否已经在热度图列表中出现过。如果已经出现过,则将该房屋的数量加1;如果没有出现过,则将该房屋加入热度图列表中并且指定数量为1。最终返回一个热度图数据列表。
相关问题
List<List<Integer>> ans = new ArrayList<>();是什么,怎么用
引用[1]中的代码`List<Integer> list = new ArrayList<Integer>()`表示创建了一个名为`list`的列表,该列表只能存储`Integer`类型的元素。`List`是Java中的接口,`ArrayList`是`List`接口的实现类。通过`ArrayList`类,我们可以使用`List`接口中定义的方法,如`add()`和`get()`等。
引用中的代码`List<Integer> list = new ArrayList<Integer>()`与引用中的代码相同,都是创建了一个只能存储`Integer`类型元素的列表。`<>`表示了列表中存储的对象类型,即`Integer`类型。
现在回答你的问题,`List<List<Integer>> ans = new ArrayList<>();`表示创建了一个名为`ans`的列表,该列表的元素是`List<Integer>`类型的列表。换句话说,`ans`是一个二维列表,每个元素都是一个列表,而这些列表中的元素都是`Integer`类型的。
你可以使用`ans`来存储多个`List<Integer>`类型的列表,每个列表可以包含不同数量的`Integer`元素。例如,你可以将不同长度的整数列表存储在`ans`中,如`[[1, 2, 3], [4, 5], [6, 7, 8, 9]]`。
以下是一个示例代码,演示了如何使用`List<List<Integer>>`类型的变量`ans`:
```java
List<List<Integer>> ans = new ArrayList<>();
List<Integer> list1 = new ArrayList<>();
list1.add(1);
list1.add(2);
list1.add(3);
List<Integer> list2 = new ArrayList<>();
list2.add(4);
list2.add(5);
ans.add(list1);
ans.add(list2);
System.out.println(ans); // 输出:[[1, 2, 3], [4, 5]]
```
List<CustomerInfo> customerInfoList = new ArrayList<>(); List<PostLoanOrder> orderList = new ArrayList<>(); List<PostControllerLegalInfo> plistInfo = new ArrayList<>(); List<PostLoanReceipt> receipts = new ArrayList<>(); List<PostRepaymentPlan> plans = new ArrayList<>(); List<AuthBatchAndSendDto> authBatchAndSendDtoList = new ArrayList<>(); 改进代码
可以使用 diamond operator 来简化代码,还可以使用 var 关键字来更清晰地表达变量类型:
```java
var customerInfoList = new ArrayList<CustomerInfo>();
var orderList = new ArrayList<PostLoanOrder>();
var plistInfo = new ArrayList<PostControllerLegalInfo>();
var receipts = new ArrayList<PostLoanReceipt>();
var plans = new ArrayList<PostRepaymentPlan>();
var authBatchAndSendDtoList = new ArrayList<AuthBatchAndSendDto>();
```
此外,如果这些变量都是在同一个类中使用的,可以将它们作为类的成员变量,这样代码会更加简洁。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)