if (!string.IsNullOrWhiteSpace(SaveView.ModelFamily)) { string filter = $"&$filter=startswith(modelfamily,'{SaveView.ModelFamily.ToUpper()}')"; cimModels = await LoadCimModel(filter); }
时间: 2024-04-18 10:34:04 浏览: 6
这段代码是用来加载CIM模型的。首先,它会检查SaveView.ModelFamily是否为空或者只包含空格。如果SaveView.ModelFamily不为空,那么它会构建一个$filter参数,用于筛选模型族(ModelFamily),以便只加载模型族以SaveView.ModelFamily开头的CIM模型。最后,它调用LoadCimModel方法,传递$filter参数来加载符合条件的CIM模型。
相关问题
List<String> list = stringList.stream().filter(e->e.startsWith(spec+style)).collect(Collectors.toList());进行非空判断
当使用 `List` 的 `stream` 方法进行过滤操作时,可能会出现结果为 `null` 的情况。为了避免这种情况,可以在 `collect` 方法后添加一个 `Optional` 对象来进行非空判断。
下面是一个示例代码:
```java
List<String> list = stringList.stream()
.filter(e -> e != null && e.startsWith(spec + style))
.collect(Collectors.collectingAndThen(Collectors.toList(), optionalList -> optionalList.isEmpty() ? null : optionalList));
```
在这个示例中,首先使用 `filter` 方法进行过滤操作,同时添加了非空判断。然后使用 `collect` 方法将过滤后的结果转换为 `List` 对象。在 `collect` 方法后,使用 `collectingAndThen` 方法将结果包装在一个 `Optional` 对象中,并进行了非空判断。如果结果为空,则返回 `null`,否则返回过滤后的结果。
这样就可以避免出现结果为 `null` 的情况。需要注意的是,使用 `Optional` 对象进行非空判断时,需要进行额外的处理,以确保代码的正确性。
@Override public void onRFDData(TagData[] tagData) { requireActivity().runOnUiThread(new Runnable() { @Override public void run() { if (tagData != null && tagData.length > 0) { for (TagData tag : tagData) { String rfidNO = tag.getTagID(); if (rfidNO.startsWith("40") && !tags.contains(rfidNO)) { tags.add(rfidNO); String hex = rfidNO.replaceAll("40", ""); if (!hex.isEmpty()) { try { String code = RSAEncryptProvider.hexToAscii(hex); if (code.length() > 10) { String sn = code.substring(code.length() - 7); // 7位序列号 String style = code.substring(code.length() - 10, code.length() - 7); // 3位款式 String spec = code.substring(0, code.length() - 10); // 型号 ExcelImportViewModel m = iv.inventoryList.stream().filter(t -> t.spec.equalsIgnoreCase(spec) && t.style.equalsIgnoreCase(style)).findFirst().orElse(null); if (m != null) { m.check_inventory += 1; if (m.check_inventory == m.real_inventory) { m.status = 1; // } else if (m.check_inventory > m.real_inventory) { m.status = 2; } } } } catch (Exception ex) { } } } } updateView(); } } }); }什么意思
这段代码是在 Android 应用中用于处理 RFID 标签数据的方法。当有新的标签数据传入时,它会遍历标签数据数组,将标签 ID 转换成字符串并去掉前缀 "40",再将字符串转换成特定编码的文本,然后根据文本中的序列号、款式、型号等信息在一个 Excel 表格中查找对应的记录,并更新记录的相关信息,例如增加已盘点数量、更新状态等。最后,它会调用 `updateView()` 方法,更新界面显示。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)