List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:eu.trentorise.smartcampus.commons.test.TestSemanticHelper.java
private static void testReadingSharedContent(long ownerId, int pos, int size, String type) throws Exception { System.err.println(new Date(1348752590483L)); User u = client.readUser(ownerId);/*from w w w.j a v a 2s . co m*/ EntityBase eb = client.readEntityBase(u.getEntityBaseId()); LiveTopic filter = new LiveTopic(); filter.setActorId(ownerId); LiveTopicSource filterSource = new LiveTopicSource(); filterSource.setUserIds(Collections.singleton(ownerId)); filter.setSource(filterSource); LiveTopicContentType contentType = new LiveTopicContentType(); if (type != null && getTypesIds().containsKey(type)) { contentType.setEntityTypeIds(Collections.singleton(getTypesIds().get(type))); } else { contentType.setEntityTypeIds(new HashSet<Long>(getTypesIds().values())); } filter.setType(contentType); // <-- mandatory filter.setStatus(LiveTopicStatus.ACTIVE); // <-- mandatory LiveTopicSubject lts = new LiveTopicSubject(); lts.setAllSubjects(true); Set<LiveTopicSubject> subjects = new HashSet<LiveTopicSubject>(); subjects.add(lts); filter.setSubjects(subjects); List<Long> sharedIds = client.computeEntitiesForLiveTopic(filter, null, null); Collections.sort(sharedIds, new Comparator<Long>() { public int compare(Long o1, Long o2) { return o2 > o1 ? 1 : o2 == o1 ? 0 : -1; } }); if (pos < sharedIds.size()) { sharedIds = sharedIds.subList(pos, Math.min(pos + size, sharedIds.size())); } else { // TODO return Collections.emptyList(); } if (!sharedIds.isEmpty()) { List<Entity> results = client.readEntities(sharedIds, null); for (Entity e : results) { System.err.println(e.getId()); } } else { // TODO return Collections.emptyList(); } }
From source file:io.crate.PartitionName.java
/** * split a given partition nameor template name into its parts <code>tableName</code> * and <code>valuesString</code>. * @param partitionOrTemplateName name of a partition or template * @return a {@linkplain org.elasticsearch.common.collect.Tuple} * whose first element is the <code>tableName</code> * and whose second element is the <code>valuesString</code> * @throws java.lang.IllegalArgumentException if <code>partitionName</code> is no invalid *//*from ww w. j a v a 2s . co m*/ public static Tuple<String, String> split(String partitionOrTemplateName) { List<String> splitted = Splitter.on(".").splitToList(partitionOrTemplateName); if (!indexNamePartsPredicate.apply(splitted)) { throw new IllegalArgumentException("Invalid partition name"); } return new Tuple<>(splitted.get(2), Joiner.on(".").join(splitted.subList(3, splitted.size()))); }
From source file:Main.java
/** * Split a list into numFolds (roughly) equally sized folds. The earlier folds * may have one more item in them than later folds. */// w ww .j av a2 s . c o m public static <T> List<Collection<T>> partitionIntoFolds(List<T> values, int numFolds) { List<Collection<T>> folds = new ArrayList<Collection<T>>(); int numValues = values.size(); int foldSize = numValues / numFolds; int remainder = numValues % numFolds; int start = 0; int end = foldSize; for (int foldNum = 0; foldNum < numFolds; foldNum++) { // if we're in the first 'remainder' folds, we get an extra item if (foldNum < remainder) { end++; } folds.add(values.subList(start, end)); start = end; end += foldSize; } return folds; }
From source file:Main.java
public static <ELEMENT extends Object> List<List<ELEMENT>> splitByLimit(List<ELEMENT> elementList, int limit) { final List<List<ELEMENT>> valueList = newArrayList(); final int valueSize = elementList.size(); int index = 0; int remainderSize = valueSize; do {/*from w w w. j a va2 s .co m*/ final int beginIndex = limit * index; final int endPoint = beginIndex + limit; final int endIndex = limit <= remainderSize ? endPoint : valueSize; final List<ELEMENT> splitList = newArrayList(); splitList.addAll(elementList.subList(beginIndex, endIndex)); valueList.add(splitList); remainderSize = valueSize - endIndex; ++index; } while (remainderSize > 0); return valueList; }
From source file:Main.java
public static <T> List<List<T>> splitList(List<T> srcList, int maxSize) { List<List<T>> splitList = new ArrayList<List<T>>(); if (srcList == null || srcList.size() == 0) { return splitList; }/*from ww w . j av a 2 s. c o m*/ int listSize = srcList.size(); int splitListSize = (listSize / maxSize) + (listSize % maxSize > 0 ? 1 : 0); for (int i = 0; i < splitListSize; i++) { int beginIndex = i * maxSize; int endIndex = (i + 1) * maxSize; endIndex = endIndex > listSize ? listSize : endIndex; splitList.add(srcList.subList(beginIndex, endIndex)); } return splitList; }
From source file:com.google.android.apps.paco.FeedbackActivity.java
public static String convertLastEventToJsonString(final Feedback feedback, final Experiment experiment) { List<Event> events = experiment.getEvents(); if (events.isEmpty()) { return "[]"; }/*from w ww . j av a2s . c o m*/ return convertEventsToJsonString(feedback, experiment, events.subList(0, 1)); }
From source file:org.jboss.aerogear.unifiedpush.utils.installation.InstallationUtils.java
private static Set<String> getRandomCategories(List<String> categories, int categoriesPerInstallation) { Set<String> picked = new HashSet<String>(); Collections.shuffle(categories); picked.addAll(categories.subList(0, categoriesPerInstallation)); return picked; }
From source file:Main.java
public static <T> List<T> sub(List<T> list, int start, int end) { if (list == null || list.isEmpty()) { return null; }//from w ww. j a va2s. c o m if (start < 0) { start = 0; } if (end < 0) { end = 0; } if (start > end) { int tmp = start; start = end; end = tmp; } final int size = list.size(); if (end > size) { if (start >= size) { return null; } end = size; } return list.subList(start, end); }
From source file:Main.java
/** * Reorder a list of elements by another list. Trying to keep absolute order of initial list in alphabetical order * but reorder regarding to provided relative order list. * E.g. initial was [1, 2, 3, 4, 5] - calling reorder with list [2, 5, 4] will generate list * [1, 2, 3, 5, 4]// w w w .j a va 2s .c o m * @param elements - initial list * @param order - list describing relative order * @param <T> - Class of comparable object * @return - new reordered list */ public static <T extends Comparable> List<T> mergeReorder(List<T> elements, List<T> order) { if (order.size() == 0) { return elements; } if (elements.size() == 0) { return order; } Set<T> merged = new LinkedHashSet<>(); Set<T> elementsSet = new HashSet<>(elements); int i = 0; int j = 0; T currElement = elements.get(i); T currOrder = order.get(j); while (i < elements.size() || j < order.size()) { if (j >= order.size()) { merged.addAll(elements.subList(i, elements.size())); break; } currElement = i < elements.size() ? elements.get(i) : currElement; currOrder = j < order.size() ? order.get(j) : currOrder; if (currElement.compareTo(currOrder) < 0) { merged.add(currElement); i++; } if (currOrder.compareTo(currElement) < 0 || i >= elements.size()) { if (merged.contains(currOrder)) { merged.remove(currOrder); } if (elementsSet.contains(currOrder)) { merged.add(currOrder); } j++; } if (currElement.compareTo(currOrder) == 0) { merged.add(currElement); i++; j++; } } return new ArrayList<>(merged); }
From source file:org.eclipse.sw360.datahandler.common.SW360Utils.java
/** * Filter BU to first three blocks//from ww w.jav a2s . c o m */ public static String getBUFromOrganisation(String organisation) { if (Strings.isNullOrEmpty(organisation)) return ""; List<String> parts = Arrays.asList(organisation.toUpperCase().split("\\s")); int maxIndex = Math.min(parts.size(), 3); return spaceJoiner.join(parts.subList(0, maxIndex)).toUpperCase(); }