List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:com.aimluck.eip.modules.actions.project.util.ProjectTestUtil.java
public static <T> List<List<T>> devide(List<T> origin, int size) { if (origin == null || origin.isEmpty() || size <= 0) { return Collections.emptyList(); }// w w w .java2 s . co m int block = origin.size() / size + (origin.size() % size > 0 ? 1 : 0); List<List<T>> devidedList = new ArrayList<List<T>>(block); for (int i = 0; i < block; i++) { int start = i * size; int end = Math.min(start + size, origin.size()); devidedList.add(new ArrayList<T>(origin.subList(start, end))); } return devidedList; }
From source file:com.civprod.writerstoolbox.testarea.UnsupervisedDiscourseSegmentation.java
public static List<List<String>> splitIntoFixLengthLists(List<String> inList, int length) { int sizeOfRList = ((inList.size() - 1) / length) + 1; List<List<String>> rList = new ArrayList<>(sizeOfRList); for (int i = 0; i < sizeOfRList; i++) { int startIndex = i * length; int endIndex = startIndex + length; if (endIndex > inList.size()) { endIndex = inList.size();//from w w w .ja va2 s . co m } rList.add(inList.subList(startIndex, endIndex)); } return rList; }
From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.utility.TextareaStringListUtility.java
/** * Returns a list of string parsed from a input of textarea. * /*w w w .ja va2s .c o m*/ * @param choiceListText the input of a textarea * @return a list of string. */ public static List<String> stringListFromTextarea(String choiceListText) { List<String> stringList = (choiceListText != null) ? Arrays.asList(choiceListText.split("\\r?\\n", -1)) : new ArrayList<String>(0); if (!stringList.isEmpty() && StringUtils.isEmpty(stringList.get(stringList.size() - 1))) { // The last empty line will be ignored. // The list object returned from asList() does not support remove, // so use subList(). stringList = stringList.subList(0, stringList.size() - 1); } return stringList; }
From source file:com.spotify.heroic.HeroicShell.java
static void standalone(List<String> arguments, Builder builder) throws Exception { final String taskName = arguments.iterator().next(); final List<String> rest = arguments.subList(1, arguments.size()); log.info("Running standalone task {}", taskName); final HeroicCore core = builder.build(); log.info("Starting Heroic..."); final HeroicCoreInstance instance = core.newInstance(); instance.start().get();//w w w . j a v a 2 s . c o m final ShellTask task = instance.inject(c -> c.tasks().resolve(taskName)); final TaskParameters params = task.params(); final CmdLineParser parser = setupParser(params); try { parser.parseArgument(rest); } catch (CmdLineException e) { log.error("Error parsing arguments", e); System.exit(1); return; } if (params.help()) { parser.printUsage(System.err); HeroicModules.printAllUsage(System.err, "-P"); System.exit(0); return; } try { final PrintWriter o = standaloneOutput(params, System.out); final ShellIO io = new DirectShellIO(o); try { task.run(io, params).get(); } catch (Exception e) { log.error("Failed to run task", e); } finally { o.flush(); } } finally { instance.shutdown().get(); } }
From source file:Main.java
/** * Performs a safe limit on a given list. checks wether offset and amount are within bounds. If the offset is out of bounds, limit will automatically adapt by * substracting amount from the lists size. If amount is larger than initial's size, initia will be returned in its entirity. * * * @param <T>// ww w . j a v a 2s . co m * @param initial * @param offset * @param amount * @return a safely limited version of initial. */ public static <T> List<T> limit(List<T> initial, int offset, int amount) { if (isNullOrEmpty(initial)) { return new ArrayList<T>(); } else if (amount > initial.size()) { return initial; } int lower = (int) ((offset < initial.size()) ? offset : (((initial.size() - offset) < 0) ? 0 : (initial.size() - offset))); int upper = amount + lower; List<T> resultSet = new ArrayList<T>( initial.subList((lower > initial.size()) ? (initial.size() - amount) : lower, (upper > initial.size()) ? initial.size() : upper)); return resultSet; }
From source file:Main.java
private static <T> List<List<T>> getChunkList(List<T> unpartitionedList, int splitCount) { int totalProblemSize = unpartitionedList.size(); int chunkSize = (int) Math.ceil((double) totalProblemSize / splitCount); List<List<T>> chunkList = new ArrayList<List<T>>(splitCount); int offset = 0; int limit = 0; for (int x = 0; x < splitCount; x++) { limit = offset + chunkSize;/* ww w. j av a2 s . c o m*/ if (limit > totalProblemSize) limit = totalProblemSize; List<T> subList = unpartitionedList.subList(offset, limit); chunkList.add(subList); offset = limit; } return chunkList; }
From source file:Main.java
/** * @param list/*from w w w.j av a2 s . c o m*/ * @param splitSize * @return splited collection */ public static <T> List<List<T>> split(List<T> list, int splitSize) { if (list == null || list.isEmpty() || splitSize <= 0) { return Collections.emptyList(); } List<List<T>> result = new ArrayList<List<T>>(); if (list.size() > splitSize) { int fromIndex = 0; while (true) { int toIndex = fromIndex + splitSize; if (toIndex > list.size()) { toIndex = list.size(); } result.add(list.subList(fromIndex, toIndex)); fromIndex += splitSize; if (fromIndex >= list.size()) { break; } } } else { result.add(list); } return result; }
From source file:org.jboss.aerogear.io.netty.handler.codec.sockjs.protocol.MessageFrame.java
private static ByteBuf generateContent(final List<String> messages) { final JsonStringEncoder jsonEndocder = new JsonStringEncoder(); final ByteBuf content = Unpooled.buffer(); content.writeByte('a').writeByte('['); final int size = messages.size(); for (int i = 0; i < size; i++) { content.writeByte('"'); final String element = messages.get(i); if (element == null) { messages.subList(i, size).clear(); break; }//from w w w .jav a2 s . co m final String escaped = escapeCharacters(jsonEndocder.quoteAsString(element)); final ByteBuf escapedBuf = Unpooled.copiedBuffer(escaped, CharsetUtil.UTF_8); content.writeBytes(escapedBuf).writeByte('"'); escapedBuf.release(); if (i < size - 1) { content.writeByte(','); } } return content.writeByte(']'); }
From source file:com.civprod.writerstoolbox.testarea.UnsupervisedDiscourseSegmentation.java
public static List<List<String>> segment(Document<?> inDocument, SentenceDetector inSentenceDetector, StringTokenizer inStringTokenizer) { List<String> concatenateTokens = concatenateTokens(inDocument, inSentenceDetector, inStringTokenizer); List<String> stemmAndFilterList = TokenUtil.stemmAndFilterList(concatenateTokens); List<List<String>> splitIntoFixLengthLists = splitIntoFixLengthLists(stemmAndFilterList, 20); List<Counter<String>> counters = splitIntoFixLengthLists.parallelStream() .map((List<String> curSentence) -> CounterUtils.count(curSentence)).collect(Collectors.toList()); List<Double> cosineSimilarity = new ArrayList<>(counters.size() - 20); for (int i = 0; i < (counters.size() - 20); i++) { cosineSimilarity.add(cosineSimilarityStemmedAndFiltered(Counter.join(counters.subList(i, i + 10)), Counter.join(counters.subList(i + 11, i + 20)))); }//w w w . j a v a2s. c o m List<Double> valleys = new ArrayList<>(cosineSimilarity.size() - 2); for (int i = 0; i < valleys.size(); i++) { double ya1 = cosineSimilarity.get(i); double ya2 = cosineSimilarity.get(i + 1); double ya3 = cosineSimilarity.get(i + 2); valleys.add((ya1 - ya2) + (ya3 - ya2)); } SummaryStatistics valleyStatistics = valleys.parallelStream().collect(SummaryStatisticCollector.instance); double cutoffThreshold = valleyStatistics.getMean() - valleyStatistics.getStandardDeviation(); int lastLocation = 0; List<Span> spans = new ArrayList<>(1); for (int i = 0; i < valleys.size(); i++) { double curValley = valleys.get(i); if (curValley < cutoffThreshold) { int curLocation = (i + 11) * 20; spans.add(new Span(lastLocation, curLocation)); lastLocation = curLocation; } } spans.add(new Span(lastLocation, concatenateTokens.size())); return spans.parallelStream() .map((Span curSpan) -> concatenateTokens.subList(curSpan.getStart(), curSpan.getEnd())) .collect(Collectors.toList()); }
From source file:com.github.feribg.audiogetter.helpers.Utils.java
/** * Break a list of strings into multiple lists of given max size partitionSize * * @param originalList the original list * @param partitionSize max number of elements per list * @return a list of paritioned lists/*from w ww. jav a2 s .co m*/ */ public static List<List> partition(List originalList, int partitionSize) { List<List> partitions = new LinkedList<List>(); for (int i = 0; i < originalList.size(); i += partitionSize) { partitions.add(originalList.subList(i, i + Math.min(partitionSize, originalList.size() - i))); } return partitions; }