jsonnnnnn's recent timeline updates
jsonnnnnn

jsonnnnnn

V2EX member #455877, joined on 2019-11-27 15:51:19 +08:00
jsonnnnnn's recent replies
Apr 30, 2020
Replied to a topic by NoKey 程序员 那天看到一个名词, java6 程序员
看了下,果然大部分都是 j8 程序员。。
分母+1
Apr 8, 2020
Replied to a topic by jsonnnnnn 问与答 求助大佬!多字段排序问题。。
@popvlovs 我研究了下,已经搞定了。。谢谢
Apr 8, 2020
Replied to a topic by jsonnnnnn 问与答 求助大佬!多字段排序问题。。
研究了一下,,自定义了一个 comparator 搞定了。。

public class GoogleReportComparator implements Comparator<CampaignVO> {

private ArrayList<String> fieldList;

public GoogleReportComparator(ArrayList<String> fieldList) {
this.fieldList = fieldList;
}

@Override
public int compare(CampaignVO obj1, CampaignVO obj2) {

int compare = 0;
for (int i = 0; i < fieldList.size(); i++) {
compare = getCompare(obj1, obj2, i);

if (compare != 0) {
return compare;
}
}
return compare;
}

private int getCompare(CampaignVO obj1, CampaignVO obj2, int i) {
String filedValue1 = getCurrnetFiledValue(obj1, fieldList.get(i));
String filedValue2 = getCurrnetFiledValue(obj2, fieldList.get(i));
return filedValue1.compareTo(filedValue2);
}


private String getCurrnetFiledValue(CampaignVO campaignVO, String fieldName) {
StringBuffer sb = new StringBuffer();
sb.append("get");
sb.append(fieldName.substring(0, 1).toUpperCase());
sb.append(fieldName.substring(1));

try {
Method method = campaignVO.getClass().getMethod(sb.toString());

Object obj = method.invoke(campaignVO);
if (null == obj) {
return StringUtils.EMPTY;
} else {
return obj.toString();
}

} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
log.error("invoke method error::", e);
}
return StringUtils.EMPTY;
}
}
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2401 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 19ms · UTC 10:16 · PVG 18:16 · LAX 03:16 · JFK 06:16
♥ Do have faith in what you're doing.