Java Code Examples for com.google.common.collect.Iterables#partition()
The following examples show how to use
com.google.common.collect.Iterables#partition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClinicalEvidenceDAO.java From hmftools with GNU General Public License v3.0 | 6 votes |
void writeClinicalEvidence(@NotNull String sample, @NotNull List<EvidenceItem> evidenceItem) { deleteClinicalEvidenceForSample(sample); Timestamp timestamp = new Timestamp(new Date().getTime()); for (List<EvidenceItem> items : Iterables.partition(evidenceItem, DB_BATCH_INSERT_SIZE)) { InsertValuesStep11 inserter = context.insertInto(CLINICALEVIDENCE, CLINICALEVIDENCE.SAMPLEID, CLINICALEVIDENCE.MODIFIED, CLINICALEVIDENCE.EVENT, CLINICALEVIDENCE.EVENTMATCH, CLINICALEVIDENCE.NAME, CLINICALEVIDENCE.TYPE, CLINICALEVIDENCE.RESPONSE, CLINICALEVIDENCE.LEVEL, CLINICALEVIDENCE.SOURCE, CLINICALEVIDENCE.CANCERTYPE, CLINICALEVIDENCE.ISONLABEL); items.forEach(trial -> addValues(sample, trial, inserter, timestamp)); inserter.execute(); } }
Example 2
Source File: StructuralVariantClusterDAO.java From hmftools with GNU General Public License v3.0 | 6 votes |
void writeDrivers(@NotNull String sample, @NotNull List<LinxDriver> drivers) { Timestamp timestamp = new Timestamp(new Date().getTime()); context.delete(SVDRIVER).where(SVDRIVER.SAMPLEID.eq(sample)).execute(); for (List<LinxDriver> batch : Iterables.partition(drivers, DB_BATCH_INSERT_SIZE)) { InsertValuesStep5 inserter = context.insertInto(SVDRIVER, SVDRIVER.SAMPLEID, SVDRIVER.MODIFIED, SVDRIVER.CLUSTERID, SVDRIVER.GENE, SVDRIVER.EVENTTYPE); batch.forEach(entry -> addRecord(timestamp, inserter, sample, entry)); inserter.execute(); } }
Example 3
Source File: ClinicalEvidenceDAOProtect.java From hmftools with GNU General Public License v3.0 | 6 votes |
public void writeClinicalEvidence(@NotNull String sample, @NotNull List<EvidenceItem> evidenceItem) { deleteClinicalEvidenceForSample(sample); Timestamp timestamp = new Timestamp(new Date().getTime()); for (List<EvidenceItem> items : Iterables.partition(evidenceItem, DB_BATCH_INSERT_SIZE)) { InsertValuesStep10 inserter = context.insertInto(CLINICALEVIDENCEPROTECT, CLINICALEVIDENCEPROTECT.SAMPLEID, CLINICALEVIDENCEPROTECT.MODIFIED, CLINICALEVIDENCEPROTECT.EVENT, CLINICALEVIDENCEPROTECT.NAME, CLINICALEVIDENCEPROTECT.TYPE, CLINICALEVIDENCEPROTECT.RESPONSE, CLINICALEVIDENCEPROTECT.LEVEL, CLINICALEVIDENCEPROTECT.SOURCE, CLINICALEVIDENCEPROTECT.CANCERTYPE, CLINICALEVIDENCEPROTECT.ISONLABEL); items.forEach(trial -> addValues(sample, trial, inserter, timestamp)); inserter.execute(); } }
Example 4
Source File: UserSyncService.java From cloudbreak with Apache License 2.0 | 6 votes |
@VisibleForTesting void removeUsersFromGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("removing users {} from group {}", users, group); try { RPCResponse<Group> groupRemoveMembersResponse = freeIpaClient.groupRemoveMembers(group, users); List<String> members = Optional.ofNullable(groupRemoveMembersResponse.getResult().getMemberUser()).orElse(List.of()); if (Collections.disjoint(members, users)) { LOGGER.debug("Successfully removed users {} from {}", users, groupRemoveMembersResponse.getResult()); } else { // TODO specialize RPCResponse completed/failed objects LOGGER.error("Failed to remove {} from group '{}': {}", users, group, groupRemoveMembersResponse.getFailed()); warnings.accept(group, String.format("Failed to remove users from group: %s", groupRemoveMembersResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to remove {} from group '{}'", users, group, e); warnings.accept(group, String.format("Failed to remove users %s from group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } }
Example 5
Source File: StructuralVariantClusterDAO.java From hmftools with GNU General Public License v3.0 | 6 votes |
void writeClusters(@NotNull String sample, @NotNull List<LinxCluster> clusters) { Timestamp timestamp = new Timestamp(new Date().getTime()); context.delete(SVCLUSTER).where(SVCLUSTER.SAMPLEID.eq(sample)).execute(); for (List<LinxCluster> batch : Iterables.partition(clusters, DB_BATCH_INSERT_SIZE)) { InsertValuesStep9 inserter = context.insertInto(SVCLUSTER, SVCLUSTER.SAMPLEID, SVCLUSTER.MODIFIED, SVCLUSTER.CLUSTERID, SVCLUSTER.RESOLVEDTYPE, SVCLUSTER.SYNTHETIC, SVCLUSTER.SUBCLONAL, SVCLUSTER.SUBTYPE, SVCLUSTER.CLUSTERCOUNT, SVCLUSTER.CLUSTERDESC); batch.forEach(entry -> addRecord(timestamp, inserter, sample, entry)); inserter.execute(); } }
Example 6
Source File: UserSyncService.java From cloudbreak with Apache License 2.0 | 6 votes |
@VisibleForTesting void addUsersToGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { LOGGER.debug("adding users to groups: [{}]", groupMapping); for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("adding users [{}] to group [{}]", users, group); try { RPCResponse<Group> groupAddMemberResponse = freeIpaClient.groupAddMembers(group, users); List<String> members = Optional.ofNullable(groupAddMemberResponse.getResult().getMemberUser()).orElse(List.of()); if (members.containsAll(users)) { LOGGER.debug("Successfully added users {} to {}", users, groupAddMemberResponse.getResult()); } else { // TODO specialize RPCResponse completed/failed objects LOGGER.error("Failed to add {} to group '{}': {}", users, group, groupAddMemberResponse.getFailed()); warnings.accept(group, String.format("Failed to add users to group: %s", groupAddMemberResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to add {} to group '{}'", users, group, e); warnings.accept(group, String.format("Failed to add users %s to group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } }
Example 7
Source File: GeneCopyNumberDAO.java From hmftools with GNU General Public License v3.0 | 5 votes |
void writeCopyNumber(@NotNull String sample, @NotNull List<GeneCopyNumber> copyNumbers) { Timestamp timestamp = new Timestamp(new Date().getTime()); deleteGeneCopyNumberForSample(sample); for (List<GeneCopyNumber> splitCopyNumbers : Iterables.partition(copyNumbers, DB_BATCH_INSERT_SIZE)) { InsertValuesStep21 inserter = context.insertInto(GENECOPYNUMBER, GENECOPYNUMBER.SAMPLEID, GENECOPYNUMBER.CHROMOSOME, GENECOPYNUMBER.START, GENECOPYNUMBER.END, GENECOPYNUMBER.GENE, GENECOPYNUMBER.MINCOPYNUMBER, GENECOPYNUMBER.MAXCOPYNUMBER, GENECOPYNUMBER.SOMATICREGIONS, GENECOPYNUMBER.GERMLINEHOMDELETIONREGIONS, GENECOPYNUMBER.GERMLINEHETTOHOMDELETIONREGIONS, GENECOPYNUMBER.TRANSCRIPTID, GENECOPYNUMBER.TRANSCRIPTVERSION, GENECOPYNUMBER.CHROMOSOMEBAND, GENECOPYNUMBER.MINREGIONS, GENECOPYNUMBER.MINREGIONSTART, GENECOPYNUMBER.MINREGIONEND, GENECOPYNUMBER.MINREGIONSTARTSUPPORT, GENECOPYNUMBER.MINREGIONENDSUPPORT, GENECOPYNUMBER.MINREGIONMETHOD, GENECOPYNUMBER.MINMINORALLELECOPYNUMBER, COPYNUMBER.MODIFIED); splitCopyNumbers.forEach(x -> addCopynumberRecord(timestamp, inserter, sample, x)); inserter.execute(); } }
Example 8
Source File: CollectionGuavaPartitionUnitTest.java From tutorials with MIT License | 5 votes |
@Test public final void givenCollection_whenParitioningIntoNSublists_thenCorrect() { final Collection<Integer> intCollection = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8); final Iterable<List<Integer>> subSets = Iterables.partition(intCollection, 3); // When final List<Integer> firstPartition = subSets.iterator().next(); final List<Integer> expectedLastPartition = Lists.<Integer> newArrayList(1, 2, 3); assertThat(firstPartition, equalTo(expectedLastPartition)); }
Example 9
Source File: SomaticVariantDAO.java From hmftools with GNU General Public License v3.0 | 5 votes |
void write(@NotNull String sample, @NotNull List<SomaticVariant> variants) { Timestamp timestamp = new Timestamp(new Date().getTime()); deleteSomaticVariantForSample(sample); for (List<SomaticVariant> splitRegions : Iterables.partition(variants, DB_BATCH_INSERT_SIZE)) { writeAll(timestamp, sample, splitRegions); } }
Example 10
Source File: Word2VecTest.java From Word2VecJava with MIT License | 5 votes |
/** @return raw test dataset. The tokens are separated by newlines. */ @VisibleForTesting public static Iterable<List<String>> testData() throws IOException { List<String> lines = Common.readResource(Word2VecTest.class, "word2vec.short.txt"); Iterable<List<String>> partitioned = Iterables.partition(lines, 1000); return partitioned; }
Example 11
Source File: StructuralVariantClusterDAO.java From hmftools with GNU General Public License v3.0 | 5 votes |
void writeSvData(@NotNull String sample, @NotNull List<LinxSvData> svData) { Timestamp timestamp = new Timestamp(new Date().getTime()); context.delete(SVANNOTATION).where(SVANNOTATION.SAMPLEID.eq(sample)).execute(); for (List<LinxSvData> batch : Iterables.partition(svData, DB_BATCH_INSERT_SIZE)) { InsertValuesStep22 inserter = context.insertInto(SVANNOTATION, SVANNOTATION.SAMPLEID, SVANNOTATION.MODIFIED, SVANNOTATION.SVID, SVANNOTATION.CLUSTERID, SVANNOTATION.CLUSTERREASON, SVANNOTATION.FRAGILESITESTART, SVANNOTATION.FRAGILESITEEND, SVANNOTATION.ISFOLDBACK, SVANNOTATION.LINETYPESTART, SVANNOTATION.LINETYPEEND, SVANNOTATION.JUNCTIONCOPYNUMBERMIN, SVANNOTATION.JUNCTIONCOPYNUMBERMAX, SVANNOTATION.GENESTART, SVANNOTATION.GENEEND, SVANNOTATION.REPLICATIONTIMINGSTART, SVANNOTATION.REPLICATIONTIMINGEND, SVANNOTATION.LOCALTOPOLOGYIDSTART, SVANNOTATION.LOCALTOPOLOGYIDEND, SVANNOTATION.LOCALTOPOLOGYSTART, SVANNOTATION.LOCALTOPOLOGYEND, SVANNOTATION.LOCALTICOUNTSTART, SVANNOTATION.LOCALTICOUNTEND); batch.forEach(entry -> addRecord(timestamp, inserter, sample, entry)); inserter.execute(); } }
Example 12
Source File: HttpRepositoryService.java From SquirrelID with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ImmutableList<Profile> findAllByName(Iterable<String> names) throws IOException, InterruptedException { Builder<Profile> builder = ImmutableList.builder(); for (List<String> partition : Iterables.partition(names, MAX_NAMES_PER_REQUEST)) { builder.addAll(query(partition)); } return builder.build(); }
Example 13
Source File: QuerydslUtils.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * Return IN expression for {@code entityPath.fieldName}. * <p/> * Expr: <br/> * entityPath.fieldName IN ( values ) <br/> * <br/> * If values.size() > 500 its generates: <br/> * Expr: <br/> * (entityPath.fieldName IN ( values[0-500] ) OR [entityPath.fieldName IN ( * values[501-100]... ])) <br/> * <br/> * * @param entityPath Full path to entity and associations. For example: * {@code Pet} , {@code Pet.owner} * @param fieldName Property name in the given entity path. For example: * {@code name} in {@code Pet} entity, {@code firstName} in * {@code Pet.owner} entity. * @param values the Set of values to find the given field name, may be null * @return BooleanExpression */ public static <T, E> BooleanExpression createCollectionExpression( PathBuilder<T> entityPath, String fieldName, Collection<E> values) { if (StringUtils.isEmpty(fieldName) || values.isEmpty()) { return null; } if (values.size() > 500) { BooleanExpression expression = null; Iterable<List<E>> collectionParts = Iterables .partition(values, 500); for (List<E> part : collectionParts) { if (expression == null) { expression = doCreateCollectionExpression(entityPath, fieldName, part); } else { expression = expression.or(doCreateCollectionExpression( entityPath, fieldName, part)); } } return expression; } else { return doCreateCollectionExpression(entityPath, fieldName, values); } }
Example 14
Source File: ReactiveTfvcClientHost.java From azure-devops-intellij with MIT License | 5 votes |
public CompletionStage<Void> getLocalItemsInfoAsync( ServerIdentification serverIdentification, Stream<Path> localPaths, Consumer<ItemInfo> onItemReceived) { // Pack the paths into partitions of predefined size to avoid overloading the protocol. Iterable<List<Path>> partitions = Iterables.partition(localPaths::iterator, INFO_PARTITION_COUNT); return getReadyCollectionAsync(serverIdentification) .thenCompose(collection -> getLocalItemsInfoAsyncChunk(collection, partitions.iterator(), onItemReceived)); }
Example 15
Source File: ReactiveTfvcClientHost.java From azure-devops-intellij with MIT License | 5 votes |
public CompletionStage<Void> getExtendedItemsInfoAsync( ServerIdentification serverIdentification, Stream<Path> localPaths, Consumer<ExtendedItemInfo> onItemReceived) { // Pack the paths into partitions of predefined size to avoid overloading the protocol. Iterable<List<Path>> partitions = Iterables.partition(localPaths::iterator, INFO_PARTITION_COUNT); return getReadyCollectionAsync(serverIdentification) .thenCompose(collection -> getExtendedItemsInfoAsyncChunk( collection, partitions.iterator(), onItemReceived)); }
Example 16
Source File: ExecutionQueueRepositoryImpl.java From score with Apache License 2.0 | 4 votes |
@Override public Set<Long> getExecutionIdsForExecutionStateIds(Set<Long> execStateIds) { Set<Long> result = new HashSet<>(); for (List<Long> part: Iterables.partition(execStateIds, PARTITION_SIZE)) { String qMarks = StringUtils.repeat("?", ",", part.size()); String sqlStat = FIND_EXEC_IDS.replace(":IDS", qMarks); List<Long> execIds = findExecIDsJdbcTemplate.query(sqlStat, part.toArray(), (rs, rowNum) -> rs.getLong("MSG_ID") ); result.addAll(execIds); } return result; }
Example 17
Source File: CodeGenerator_new.java From sailfish-core with Apache License 2.0 | 4 votes |
private void testCode(List<AMLTestCase> testCases) throws WorkspaceSecurityException, AMLException, FileNotFoundException, IOException { progressChanged(60); List<SetterInfo> setters = new ArrayList<>(); for(AMLTestCase testCase : testCases) { for(AMLAction action : testCase.getActions()) { for(Pair<String, String> setter : action.getSetters()) { String column = setter.getFirst(); String code = setter.getSecond(); Value element = action.getParameters().get(column); String value = element.getValue(); String reference = ObjectUtils.defaultIfNull(action.getReference(), action.getReferenceToFilter()); StringUtils.removeStart(value, BoolExp.NotEqualsUnary.getName()); value = new String(Base64.encodeBase64(value.getBytes())); SetterInfo info = new SetterInfo(column, code, value, element.getLineNumber(), action.getUID(), reference); setters.add(info); } } } int count = 0; for(List<SetterInfo> subList : Iterables.partition(setters, MAX_SETTERS_PER_CLASS)) { String className = "TestClass" + count++; File javaFile = workspaceDispatcher.createFile(FolderType.REPORT, true, amlSettings.getBaseDir(), className + ".java"); File classFile = workspaceDispatcher.createFile(FolderType.REPORT, true, amlSettings.getBaseDir(), className + ".class"); try(TextOutputStream stream = new TextOutputStream(new FileOutputStream(javaFile))) { tcCodeBuilder.writeTestClass(stream, className, subList); String error = compileTest(javaFile, classFile); if(error == null) { continue; } parseErrors(error); } } progressChanged(70); }
Example 18
Source File: SaveToCassandraActionExecutionFunction.java From Decision with Apache License 2.0 | 4 votes |
@Override public void process(Iterable<StratioStreamingMessage> messages) throws Exception { Integer partitionSize = maxBatchSize; if (partitionSize <= 0){ partitionSize = Iterables.size(messages); } Iterable<List<StratioStreamingMessage>> partitionIterables = Iterables.partition(messages, partitionSize); try { getCassandraTableOperationsService().checkKeyspace(); for (List<StratioStreamingMessage> messageList : partitionIterables) { BatchStatement batch = new BatchStatement(batchType); for (StratioStreamingMessage stratioStreamingMessage : messageList) { Set<String> columns = getColumnSet(stratioStreamingMessage.getColumns()); if (getCassandraTableOperationsService().getTableNames().get(stratioStreamingMessage.getStreamName()) == null) { getCassandraTableOperationsService().createTable(stratioStreamingMessage.getStreamName(), stratioStreamingMessage.getColumns(), TIMESTAMP_FIELD); getCassandraTableOperationsService().refreshTablenames(); } if (getCassandraTableOperationsService().getTableNames().get(stratioStreamingMessage.getStreamName()) != columns.hashCode()) { getCassandraTableOperationsService() .alterTable(stratioStreamingMessage.getStreamName(), columns, stratioStreamingMessage.getColumns()); getCassandraTableOperationsService().refreshTablenames(); } batch.add(getCassandraTableOperationsService().createInsertStatement( stratioStreamingMessage.getStreamName(), stratioStreamingMessage.getColumns(), TIMESTAMP_FIELD)); } getCassandraTableOperationsService().getSession().execute(batch); } }catch(Exception e){ log.error("Error in Cassandra for batch size {}: {}", Iterables.size(partitionIterables), e.getMessage()); } }
Example 19
Source File: DataTables.java From JGiven with Apache License 2.0 | 3 votes |
/** * Creates a table, i.e. a list of lists, with {@code numberOfColumns} columns from the given {@code data} including the header. * <p> * Example: * <pre>{@code * table(2, * "name", "age", // header * "Peter", 20, // first row of data * "Susan", 35); // second row of data * }</pre> * * @param numberOfColumns the number of columns the resulting table should have * @param data the data of the table represented as a one-dimensional list, * the number of entries must be a multiple of {@code numberOfColumns}. * The first {@code numberOfColumns} elements are taken as the header of the table, * the remaining values as data * @return a list of list that contains the same data as {@code data}, but in a two-dimensional form * @throws java.lang.IllegalArgumentException if {@code data.length % numberOfColumns != 0} */ public static Iterable<? extends Iterable<?>> table( int numberOfColumns, Object... data ) { if( data.length % numberOfColumns != 0 ) { throw new IllegalArgumentException( "The provided number of data elements '" + data.length + "' is not a multiple of " + numberOfColumns ); } return Iterables.partition( Arrays.asList( data ), numberOfColumns ); }