List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:edu.cmu.cs.lti.ark.fn.identification.FrameIdentificationRelease.java
public static Pair<IdFeatureExtractor, TObjectDoubleHashMap<String>> parseParamFile(String paramsFile) throws IOException { final List<String> lines = Files.readLines(new File(paramsFile), Charsets.UTF_8); final IdFeatureExtractor featureExtractor = IdFeatureExtractor.fromName(lines.get(0)); final TObjectDoubleHashMap<String> model = readModel(lines.subList(1, lines.size())); return Pair.of(featureExtractor, model); }
From source file:Main.java
/** * This API creates a list of list from a given list. This uses the * maxSplitSize to make sublist from the given list and add the list to the * output list.//from ww w . j ava 2s . c om * * @param <T> * The type of the Object the list can contain * @param fromList * The input list which needs to split and create new List of * list * @param maxSplitSize * maximum size of each split * @return List of List<code><T></code> * @author sabuj.das */ public static <T> List<List<T>> split(List<T> fromList, int maxSplitSize) { int n = fromList.size(); // total size of the list List<List<T>> toList = new ArrayList<List<T>>(); // split the list by the maxSplitSize for (int i = 0; i < n; i += maxSplitSize) { if ((i + maxSplitSize) > n) { toList.add(fromList.subList(i, n)); } else { toList.add(fromList.subList(i, (i + maxSplitSize))); } } return toList; }
From source file:com.adguard.commons.collections.Lists.java
/** * Partitions list into smaller lists of the specified size * * @param input Input collection//from www. j a va 2 s . co m * @param size Partition size * @return List of smaller size */ public static <E> List<List<E>> split(Collection<E> input, int size) { List<List<E>> master = new ArrayList<>(); if (input != null && input.size() > 0) { List<E> col = new ArrayList<>(input); boolean done = false; int startIndex = 0; int endIndex = col.size() > size ? size : col.size(); while (!done) { master.add(col.subList(startIndex, endIndex)); if (endIndex == col.size()) { done = true; } else { startIndex = endIndex; endIndex = col.size() > (endIndex + size) ? (endIndex + size) : col.size(); } } } return master; }
From source file:Main.java
public static <T> List<T> circleSubList(List<T> srcList, int position, int count) { if (srcList == null || srcList.size() == 0) { return Collections.emptyList(); }/* ww w . j a va 2 s. c om*/ position = position < 0 ? 0 : position; count = count > srcList.size() ? srcList.size() : count; if (position > srcList.size() - 1) { return srcList.subList(0, count); } if (position + count <= srcList.size()) { return srcList.subList(position, (position + count)); } List<T> fList = srcList.subList(position, srcList.size()); List<T> eList = srcList.subList(0, count - srcList.size() + position); fList.addAll(eList); return fList; }
From source file:Main.java
public static <T> Stream<List<T>> batches(List<T> source, int length) { if (length <= 0) throw new IllegalArgumentException("length = " + length); int size = source.size(); if (size <= 0) return Stream.empty(); int fullChunks = (size - 1) / length; return IntStream.range(0, fullChunks + 1) .mapToObj(n -> source.subList(n * length, n == fullChunks ? size : (n + 1) * length)); }
From source file:at.bestsolution.persistence.java.Util.java
public static void trimToSize(List<?> listToTrim, int size) { listToTrim.subList(size, listToTrim.size()).clear(); }
From source file:com.reprezen.swagedit.validation.ValidationUtil.java
private static Node findNode(MappingNode root, List<String> paths) { if (paths.isEmpty()) return root; String path = paths.get(0);// w ww .jav a2s. c o m if (path.startsWith("/")) { path = path.substring(1, path.length()); } final List<String> next = paths.subList(1, paths.size()); // ~1 is use to escape / if (path.contains("~1")) { path = path.replaceAll("~1", "/"); } for (NodeTuple child : root.getValue()) { if (child.getKeyNode() instanceof ScalarNode) { ScalarNode scalar = (ScalarNode) child.getKeyNode(); if (scalar.getValue().equals(path)) { return findNode(child, next); } } } return root; }
From source file:Main.java
public static List<List<String>> slice(List<String> stringList, int subListSize) { List<List<String>> listOfSubLists = new ArrayList<>(); if (stringList != null) { int leftBoundary = 0; int rightBoundary = subListSize < stringList.size() ? subListSize : stringList.size(); do {/* ww w . ja v a2 s.com*/ listOfSubLists.add(stringList.subList(leftBoundary, rightBoundary)); leftBoundary = rightBoundary; rightBoundary = rightBoundary + subListSize < stringList.size() ? rightBoundary + subListSize : stringList.size(); } while (leftBoundary != rightBoundary); return listOfSubLists; } return listOfSubLists; }
From source file:Main.java
/** * Shift object in the list/*ww w .j a v a 2 s. c o m*/ * * @param list list * @param index object index * @param offset offset value can be positive or negative. * @return new index of the object */ public static int shiftItem(List<?> list, int index, int offset) { if (offset == 0 || index < 0) { return 0; } if (offset > 0) { int end = index + offset + 1; if (end > list.size()) { end = list.size(); } Collections.rotate(list.subList(index, end), -1); return end - 1; } else { int start = index + offset; if (start < 0) { start = 0; } Collections.rotate(list.subList(start, index + 1), 1); return start; } }
From source file:com.insightml.utils.Collections.java
public static <T> List<T> subList(final List<T> sentences, final int max) { if (sentences.size() < max) { return sentences; }/*from w w w .jav a2 s . co m*/ return sentences.subList(0, max); }