本文整理匯總了Java中java.util.List.subList方法的典型用法代碼示例。如果您正苦於以下問題:Java List.subList方法的具體用法?Java List.subList怎麽用?Java List.subList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.List
的用法示例。
在下文中一共展示了List.subList方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadGraphFeatures
import java.util.List; //導入方法依賴的package包/類
private Map<Integer, Map<String, Double>> loadGraphFeatures(int topic) {
// concept -> feature_name -> value
Map<Integer, Map<String, Double>> data = new HashMap<Integer, Map<String, Double>>();
String fileName = this.baseFolder + "/" + topic + "/" + this.graphFile;
try {
List<String> lines = FileUtils.readLines(new File(fileName), Charsets.UTF_8);
String[] header = lines.get(0).split("\t");
for (String line : lines.subList(1, lines.size())) {
String[] cols = line.split("\t");
int id = Integer.parseInt(cols[0]);
Map<String, Double> features = new HashMap<String, Double>();
for (int i = 1; i < cols.length; i++)
features.put(header[i], Double.parseDouble(cols[i]));
data.put(id, features);
}
} catch (IOException e) {
e.printStackTrace();
}
return data;
}
示例2: parseStructure
import java.util.List; //導入方法依賴的package包/類
/**
* Identifies main parts of the parsed element and sets them in the
* parser's fields.
*
* @param linesToParse
*/
protected void parseStructure(List<String> linesToParse) {
Matcher startMatcher = getStartPattern().matcher(linesToParse.get(0));
// locate capture groups
startMatcher.find();
idString = startMatcher.group(1);
title = startMatcher.group(2);
String bodyInFirstLine = startMatcher.group(3);
if (bodyInFirstLine.trim().isEmpty()) {
bodyLines = linesToParse.subList(1, linesToParse.size());
} else {
// pass leftover text to children parsers
linesToParse.set(0, bodyInFirstLine);
bodyLines = linesToParse;
}
}
示例3: jreCreate
import java.util.List; //導入方法依賴的package包/類
private static int jreCreate(@NonNull final List<String> cmdLine) {
ExternalProcessBuilder pb = new ExternalProcessBuilder(cmdLine.get(0));
pb = pb.addEnvironmentVariable(
ENV_JAVA_HOME,
FileUtil.toFile(JavaPlatform.getDefault().getInstallFolders().iterator().next()).getAbsolutePath());
for (String arg : cmdLine.subList(1, cmdLine.size())) {
pb = pb.addArgument(arg);
}
int res;
try {
final Process process = pb.call();
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = in.readLine())!= null) {
System.out.println(line);
}
}
process.waitFor();
res = process.exitValue();
} catch (IOException | InterruptedException e) {
res = -1;
}
return res;
}
示例4: unresizable
import java.util.List; //導入方法依賴的package包/類
/**
* Lists that don't allow resizing, but allow setting values
*/
@DataProvider
public static Object[][] unresizable() {
final List<Integer> c1 = Arrays.asList(42);
final List<Integer> c9 = Arrays.asList(40, 41, 42, 43, 44, 45, -1,
Integer.MIN_VALUE, 1000500);
Object[][] l1 = unsettable();
Object[][] l2 = {
{c1, 0, 1},
{c1.subList(0, 1), 0, 1},
{Collections.checkedList(c1, Integer.class), 0, 1},
{Collections.synchronizedList(c1), 0, 1},
{c9, 0, 4},
{c9, 4, 6},
{c9.subList(1, 8), 1, 4},
{c9.subList(1, 8), 0, 7},
{Collections.checkedList(c9, Integer.class), 3, 6},
{Collections.synchronizedList(c9), 3, 5},
};
Object[][] res = Arrays.copyOf(l1, l1.length + l2.length);
System.arraycopy(l2, 0, res, l1.length, l2.length);
return res;
}
示例5: findPasswords
import java.util.List; //導入方法依賴的package包/類
/**
* Find passwords end point
* @param request Find password query
* @param responseObserver Response observer
*/
@Override
public void findPasswords(FindPasswordsQuery request, StreamObserver<FindPasswordsResponse> responseObserver) {
String prefix = request.getQuery();
List<String> results = reader.getDict().findPrefixes(prefix);
int totalMatches = results.size();
if(totalMatches > maxResults) {
results = results.subList(0, maxResults);
}
responseObserver.onNext(FindPasswordsResponse.newBuilder()
.addAllMatches(results)
.setNumOfMatches(totalMatches)
.build());
responseObserver.onCompleted();
}
示例6: getLastStatus
import java.util.List; //導入方法依賴的package包/類
public static GetLastStatusResp getLastStatus(GetLastStatusReq req) throws Exception {
IgniteStatus currentStatus = ComponentManager.getStatus(IgniteStatus.class);
GetLastStatusResp resp = new GetLastStatusResp();
List<String> msgs = currentStatus.getMessages();
if(msgs.size()>=req.msgIndex) {
currentStatus.refresh();
resp.status = currentStatus.getStatus();
resp.currentPluginIndex = currentStatus.getCurrentPluginIndex();
if(req.msgIndex<msgs.size()-1) {
resp.messages = msgs.subList(req.msgIndex, msgs.size() - 1);
}
resp.cost = currentStatus.getCost();
}
return resp;
}
示例7: getFieldsConfig
import java.util.List; //導入方法依賴的package包/類
/**
* Load configuration from a CSV file defining ARCLib XML.
*
* @return Set with config object for each index field.
* @throws IOException
*/
default Set<IndexFieldConfig> getFieldsConfig() throws IOException {
List<String> fieldsDefinitions = Files.readAllLines(Paths.get("src/main/resources/index/fieldDefinitions.csv"));
Set<IndexFieldConfig> fieldConfigs = new HashSet<>();
for (String line :
fieldsDefinitions.subList(1, fieldsDefinitions.size())) {
String arr[] = line.split(",");
if (arr.length != 8)
throw new IllegalArgumentException(String.format("fieldDefinitions.csv can't contain row with empty column: %s", line));
if (!arr[5].equals("fulltext") && !arr[5].equals("atribut"))
fieldConfigs.add(new IndexFieldConfig(arr[5], arr[6], arr[7], "N" .equals(arr[2])));
}
return fieldConfigs;
}
示例8: partitionImpl
import java.util.List; //導入方法依賴的package包/類
private static <T> UnmodifiableIterator<List<T>> partitionImpl(
final Iterator<T> iterator, final int size, final boolean pad) {
checkNotNull(iterator);
checkArgument(size > 0);
return new UnmodifiableIterator<List<T>>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public List<T> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Object[] array = new Object[size];
int count = 0;
for (; count < size && iterator.hasNext(); count++) {
array[count] = iterator.next();
}
for (int i = count; i < size; i++) {
array[i] = null; // for GWT
}
@SuppressWarnings("unchecked") // we only put Ts in it
List<T> list = Collections.unmodifiableList(
(List<T>) Arrays.asList(array));
return (pad || count == size) ? list : list.subList(0, count);
}
};
}
示例9: testModListIteratorNext
import java.util.List; //導入方法依賴的package包/類
@Test(dataProvider = "modifiable",
expectedExceptions = ConcurrentModificationException.class)
public void testModListIteratorNext(List<Integer> list, int from, int to) {
List<Integer> subList = list.subList(from, to);
ListIterator<Integer> it = subList.listIterator();
list.add(42);
it.next();
}
示例10: getAllStations
import java.util.List; //導入方法依賴的package包/類
/**
* Get favorite and recent stations, and apply user preferences (order, count)
*
* @return Sorted array with favorite and recent station names
*/
public List<Suggestion<StationSuggestion>> getAllStations() {
int recentLimit = Integer.valueOf(sharedPreferences.getString("stations_history_count", "3"));
int order = Integer.valueOf(sharedPreferences.getString("stations_order", "0"));
// 0 || 2: recents before favorites
// 1 || 3: favorites before recents
List<Suggestion<StationSuggestion>> favorites = getStations(FAVORITE);
if (recentLimit == 0) {
return favorites;
}
// Keep some margin to ensure that we will always show the number of recents set by the user
List<Suggestion<StationSuggestion>> recents = getStations(HISTORY, recentLimit + favorites.size());
recents = (List<Suggestion<StationSuggestion>>) removeFromCollection(recents, favorites);
if (recents.size() > recentLimit) {
recents = recents.subList(0, recentLimit);
}
if (order == 0 || order == 2) {
recents.addAll(favorites);
return recents;
} else {
favorites.addAll(recents);
return favorites;
}
}
示例11: discoverFile
import java.util.List; //導入方法依賴的package包/類
/**
*
* Discover the CSV format of a CSV file.
*
* @param fileName
* @param charset
* @return CSV Format
* @throws IOException
*/
public CSVFormat discoverFile(String fileName, Charset charset) throws IOException {
LOG.info("Detecting CSV parser configuration for file " + fileName);
InputStream is = openFile(fileName);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
List<String> lines = reader.lines().limit(1000L).collect(Collectors.toList());
if(lines.size() <= 0) {
throw new QuartetRuntimeException("Cannot process empty file: " + fileName);
}
String separator = detectSeparator(lines);
LOG.info("Detected separator: " + separator);
// Extract column names from header
List<String> headers = Arrays.asList(CSVSplitter.split(lines.get(0), separator));
LOG.info("Column names: " + headers);
// Remove header and detect column types
List<String> content = lines.subList(1, lines.size());
List<List<String>> columns = toColumns(content, separator);
List<String> types = new ArrayList<>(columns.size());
for(List<String> column : columns) {
String type = detectType(column);
types.add(type);
}
LOG.info("Detected types: " + types);
return new CSVFormat(separator, headers, types);
}
}
示例12: removeDuplicate
import java.util.List; //導入方法依賴的package包/類
private List<PostsItem> removeDuplicate(List<PostsItem> postsItems) {
int i = 0;
for (; i < postsItems.size(); i++) {
if (lastTimestamp > postsItems.get(i).getTimestamp()) {
break;
}
}
if (i > 0 && i < postsItems.size()) {
postsItems = postsItems.subList(i, postsItems.size());
// } else if (i >= postsItems.size()) {
// postsItems.clear();
//this case is complicated, don't clear, just show them.
}
return postsItems;
}
示例13: doExecute
import java.util.List; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractEbeanQuery query, Object[] values) {
ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Pageable pageable = accessor.getPageable();
Object createQuery = query.createQuery(values);
List<Object> resultList = null;
int pageSize = pageable.getPageSize();
if (createQuery instanceof Query) {
Query ormQuery = (Query) createQuery;
ormQuery.setMaxRows(pageSize + 1);
ormQuery.findList();
} else if (createQuery instanceof SqlQuery) {
SqlQuery sqlQuery = (SqlQuery) createQuery;
sqlQuery.setMaxRows(pageSize + 1);
sqlQuery.findList();
} else {
throw new InvalidEbeanQueryMethodException("query must be Query or SqlQuery");
}
boolean hasNext = resultList != null && resultList.size() > pageSize;
return new SliceImpl<Object>(hasNext ? resultList.subList(0, pageSize) : resultList, pageable, hasNext);
}
示例14: getSmaph
import java.util.List; //導入方法依賴的package包/類
public static SmaphAnnotator getSmaph(SmaphVersion v, WikipediaInterface wikiApi, WikipediaToFreebase wikiToFreeb,
WAT2Annotator auxAnnotator, EntityToAnchors e2a, boolean includeS2, Websearch ws, SmaphConfig c, int greedyStepLimit)
throws FileNotFoundException, ClassNotFoundException, IOException {
URL model = getDefaultModel(v, ws, true, includeS2, true, -1);
URL zscore = getDefaultZscoreNormalizer(v, ws, true, includeS2, true, -1);
SmaphAnnotator a = null;
switch (v) {
case ANNOTATION_REGRESSOR: {
AnnotationRegressor ar = getCachedAnnotationRegressor(model);
FeatureNormalizer fn = getCachedFeatureNormalizer(zscore, new GreedyFeaturePack());
a = getDefaultSmaphParam(wikiApi, wikiToFreeb, auxAnnotator, e2a, new NoEntityFilter(), null,
new IndividualLinkback(ar, fn, wikiApi, wikiToFreeb, e2a, DEFAULT_ANCHOR_MENTION_ED), true, includeS2,
true, ws, c);
}
break;
case ENTITY_FILTER: {
EntityFilter ef = getCachedSvmEntityFilter(model);
FeatureNormalizer norm = getCachedFeatureNormalizer(zscore, new EntityFeaturePack());
a = getDefaultSmaphParam(wikiApi, wikiToFreeb, auxAnnotator, e2a, ef, norm, new DummyLinkBack(), true, includeS2,
true, ws, c);
}
break;
case COLLECTIVE: {
BindingRegressor bindingRegressor = getCachedBindingRegressor(model);
CollectiveLinkBack lb = new CollectiveLinkBack(wikiApi, wikiToFreeb, e2a, new DefaultBindingGenerator(),
bindingRegressor, new NoFeatureNormalizer());
a = getDefaultSmaphParam(wikiApi, wikiToFreeb, auxAnnotator, e2a, new NoEntityFilter(), null, lb, true, includeS2,
true, ws, c);
}
break;
case GREEDY: {
Pair<List<AnnotationRegressor>,List<FeatureNormalizer> > regressorsAndNormalizers = getGreedyRegressors(ws, true, includeS2, true);
List<AnnotationRegressor> regressors = regressorsAndNormalizers.getFirst();
List<FeatureNormalizer> normalizers = regressorsAndNormalizers.getSecond();
if (regressors.isEmpty())
throw new IllegalArgumentException("Could not find models.");
if (greedyStepLimit >= 0){
regressors = regressors.subList(0, greedyStepLimit);
normalizers = normalizers.subList(0, greedyStepLimit);
}
GreedyLinkback lbGreedy = new GreedyLinkback(regressors, normalizers, wikiApi, wikiToFreeb, e2a, DEFAULT_ANCHOR_MENTION_ED);
a = getDefaultSmaphParam(wikiApi, wikiToFreeb, auxAnnotator, e2a, new NoEntityFilter(), null, lbGreedy, true,
includeS2, true, ws, c);
}
break;
default:
throw new NotImplementedException();
}
a.appendName(String.format(" - %s, %s%s", v, ws, includeS2 ? "" : ", excl. S2"));
return a;
}
示例15: asSubList
import java.util.List; //導入方法依賴的package包/類
private static <T> List<T> asSubList(List<T> list) {
return list.subList(0, list.size());
}