java的list集合操作List<T>转化List<Long>

java的list集合操作List<T>转化List<Long>

package com.google.common.collect;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;

@GwtCompatible(
emulated = true
)
public abstract class FluentIterable<E> implements Iterable<E> {
。。。。。
}
如下
List<SysDepartBook> departBooks = departBookManager.findByDepartId(sysDepart1.getDepartId());
List<Long> departSeeIds = FluentIterable.from(departBooks).transform(new Function<SysDepartBook, Long>() {
@Override
public Long apply(SysDepartBook p) {
return p.getDepartIdSee();
}
}).toList();

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

List<String> areaId = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(employeeReportForm.getAreaId());

package com.google.common.base;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.CheckReturnValue;

@GwtCompatible(
emulated = true
)
public final class Splitter {
。。。。。
}

==========================================
String fileIds = innerEntity.getFileIds();
List<String> fileIdStrList = StringUtil.splitString(fileIds);
// List<Long> list = JSONArray.parseArray(fileIds, Long.class);
List<Long> list = FluentIterable.from(fileIdStrList).transform(new Function<String, Long>() {
@Override
public Long apply(String p) {
return Long.parseLong(p);
}
}).toList();

List<Long> fids = new ArrayList<Long>();
HashSet hs1 = new HashSet(list);
HashSet hs2 = new HashSet(idList);
hs1.removeAll(hs2);
fids.addAll(hs1);

String ids = Joiner.on(",").join(fids);
innerEntity.setFileIds(ids);
archiveInnerMapper.updateByPrimaryKeySelective(innerEntity);






posted on 2017-11-30 11:00  小甜瓜安东泥  阅读(5543)  评论(0编辑  收藏  举报