mac
2024-03-07 0a13476751c01ae346c30a4c4dd266bad700d2c3
app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java
@@ -28,6 +28,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -89,6 +90,48 @@
        this.houseIdList = houseIdList;
    }
    /**
     * 删除电站
     *
     * @param houseId 电站id
     */
    public void delHouseId(String houseId) {
        if (TextUtils.isEmpty(houseId)) {
            return;
        }
        for (int i = 0; i < houseIdList.size(); i++) {
            if (houseIdList.get(i).getHomeId().equals(houseId)) {
                houseIdList.remove(i);
                break;
            }
        }
    }
    /**
     * 移动电站位置
     *
     * @param houseId 电站id
     */
    public void moveHouseId(String houseId) {
        if (TextUtils.isEmpty(houseId)) {
            return;
        }
        int index = -1;
        for (int i = 0; i < houseIdList.size(); i++) {
            if (houseIdList.get(i).getHomeId().equals(houseId)) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return;
        }
        //index==0表示只有一个元素或者在首位,不需要移动位置
        if (index > 0) {
            Collections.swap(houseIdList, index - 1, index);
        }
    }
    //住宅ID列表
    private List<HouseIdBean> houseIdList = new ArrayList<>();
    //住宅详情列表