求高手帮我重构下这段代码

 

private boolean isAllWhiteNameListShop(List<CqShopReportInfoDO> shopReportInfoList) {
        for (int i = 0; i < shopReportInfoList.size(); i++) {
            CqShopReportInfoDO obj = shopReportInfoList.get(i);
            if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {
                return false; 
            }
        }
        return true;
    }

    private boolean isAllWhiteNameListAuction(List<CqAuctionReportInfoDO> auctionReportInfoList) {
        for (int i = 0; i < auctionReportInfoList.size(); i++) {
            CqAuctionReportInfoDO obj = auctionReportInfoList.get(i);
            if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {
                return false;
            }
        }
        return true;
    }
想把上面两个方法 重构成一个方法 ,本人水平有限,求高手帮我重构下,谢谢

格式化一下。。。

CqAuctionReportInfoDO 和 CqShopReportInfoDO 继承ReportInfoDO(status、dealerId、dealerNick…… 共性属性)

[code="java"]private boolean isAllWhiteNameListShop(List<? extends ReportInfoDO> reportInfoList) {
for (ReportInfoDO obj : reportInfoList) {
if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {
return false;
}
}
return true;
} [/code]

CqAuctionReportInfoDO 和 CqShopReportInfoDO 继承ReportInfoDO(status、dealerId、dealerNick…… 共性属性)

private boolean isAllWhiteNameListShop(List<? extends ReportInfoDO> reportInfoList) {
    for (ReportInfoDO obj : reportInfoList) {
        if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {
            return false; 
        }
    }
    return true;
}

//仅供参考
[code="java"]
public boolean demo(List shopReportInfoList ,boolean handType)
{
boolean result=fasle;
if(handType)//原来的 isAllWhiteNameListShop 方法
{
for (int i = 0; i < shopReportInfoList.size(); i++) {

CqShopReportInfoDO obj = shopReportInfoList.get(i);

if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {

result= false;

}

}

}else// isAllWhiteNameListAuction 方法
{
for (int i = 0; i < auctionReportInfoList.size(); i++) {

CqAuctionReportInfoDO obj = auctionReportInfoList.get(i);

if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {

result= false;

}

}

}

return result;
}
[/code]

[code="java"]
private boolean isAllWhiteNameList(List itemList) {
for (int i = 0; i < itemList.size(); i++) {
if (itemList.get(i) instanceof CqShopReportInfoDO) {
CqShopReportInfoDO obj = (CqShopReportInfoDO)itemList.get(i);
if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick()))
return false;
}
else if (itemList.get(i) instanceof CqAuctionReportInfoDO) {
CqAuctionReportInfoDO obj = (CqAuctionReportInfoDO)itemList.get(i);
if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick()))
return false;
}
}
return true;
}
[/code]

刚那个错了,没看类型
[code="java"]
public boolean demo(List shopReportInfoList ,List auctionReportInfoList boolean handType)
{
boolean result=fasle;
if(handType)//原来的 isAllWhiteNameListShop 方法
{
for (int i = 0; i < shopReportInfoList.size(); i++) {

CqShopReportInfoDO obj = shopReportInfoList.get(i);

if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {

result= false;

}

}

}else// isAllWhiteNameListAuction 方法
{
for (int i = 0; i < auctionReportInfoList.size(); i++) {

CqAuctionReportInfoDO obj = auctionReportInfoList.get(i);

if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {

result= false;

}

}

}

return result;
}
[/code]

1.把 CqShopReportInfoDO ,CqAuctionReportInfoDO 抽象一个父类 这样能确保 传入一个list
2.要么就和我下面做的用 instanceof 判断类型做强制转换
[code="java"]

private boolean isAllWhiteNameListShop(List list)
{
boolean result=true;
Object obj1=list.get(0);
if (obj1 instanceof CqShopReportInfoDO) {//调用之前 isAllWhiteNameListShop 方法
for (int i = 0; i < list.size(); i++) {
CqShopReportInfoDO obj = (CqShopReportInfoDO)list.get(i);
if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {
result= false;
}
}

}else
{
for (int i = 0; i < list.size(); i++) {
CqAuctionReportInfoDO obj =(CqAuctionReportInfoDO) list.get(i);
if (!isWhiteNameList(obj.getStatus(), obj.getDealerId(), obj.getDealerNick())) {
result= false;
}
}

}
return result;
}
[/code]