Example usage for java.util.stream IntStream rangeClosed

List of usage examples for java.util.stream IntStream rangeClosed

Introduction

In this page you can find the example usage for java.util.stream IntStream rangeClosed.

Prototype

public static IntStream rangeClosed(int startInclusive, int endInclusive) 

Source Link

Document

Returns a sequential ordered IntStream from startInclusive (inclusive) to endInclusive (inclusive) by an incremental step of 1 .

Usage

From source file:org.sonar.server.qualityprofile.RuleActivatorTest.java

@Test
public void bulk_deactivation() {
    int bulkSize = SearchOptions.MAX_LIMIT + 10 + new Random().nextInt(100);
    String language = randomAlphanumeric(10);
    String repositoryKey = randomAlphanumeric(10);
    QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(),
            p -> p.setLanguage(language));

    List<RuleDto> rules = new ArrayList<>();
    IntStream.rangeClosed(1, bulkSize).forEach(i -> rules
            .add(db.rules().insertRule(r -> r.setLanguage(language).setRepositoryKey(repositoryKey))));

    verifyNoActiveRules();/*from   www  . j a  v  a  2s .co  m*/
    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());

    RuleQuery ruleQuery = new RuleQuery().setRepositories(singletonList(repositoryKey));

    BulkChangeResult bulkChangeResult = underTest.bulkActivateAndCommit(db.getSession(), ruleQuery, profile,
            MINOR);

    assertThat(bulkChangeResult.countFailed()).isEqualTo(0);
    assertThat(bulkChangeResult.countSucceeded()).isEqualTo(bulkSize);
    assertThat(bulkChangeResult.getChanges()).hasSize(bulkSize);
    assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).hasSize(bulkSize);

    // Now deactivate all rules
    bulkChangeResult = underTest.bulkDeactivateAndCommit(db.getSession(), ruleQuery, profile);

    assertThat(bulkChangeResult.countFailed()).isEqualTo(0);
    assertThat(bulkChangeResult.countSucceeded()).isEqualTo(bulkSize);
    assertThat(bulkChangeResult.getChanges()).hasSize(bulkSize);
    assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).hasSize(0);
    rules.stream().forEach(r -> assertThatRuleIsNotPresent(profile, r.getDefinition()));
}

From source file:org.sonar.server.setting.ws.SetAction.java

private String doHandlePropertySet(DbSession dbSession, SetRequest request,
        @Nullable PropertyDefinition definition, Optional<ComponentDto> component) {
    validatePropertySet(request, definition);

    int[] fieldIds = IntStream.rangeClosed(1, request.getFieldValues().size()).toArray();
    String inlinedFieldKeys = IntStream.of(fieldIds).mapToObj(String::valueOf).collect(COMMA_JOINER);
    String key = persistedKey(request);
    Long componentId = component.isPresent() ? component.get().getId() : null;

    deleteSettings(dbSession, component, key);
    dbClient.propertiesDao().saveProperty(dbSession,
            new PropertyDto().setKey(key).setValue(inlinedFieldKeys).setResourceId(componentId));

    List<String> fieldValues = request.getFieldValues();
    IntStream.of(fieldIds).boxed()
            .flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream()
                    .map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue())))
            .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession,
                    toFieldProperty(keyValue, componentId)));

    return inlinedFieldKeys;
}

From source file:org.specvis.logic.Functions.java

/**
 * Create arange vector.//www.j  a  v  a2 s . com
 * @param start
 * @param end
 * @param step
 * @return Arange vector.
 */
public double[] arange(double start, double end, double step) {
    return IntStream.rangeClosed(0, (int) ((end - start) / step)).mapToDouble(x -> x * step + start).toArray();
}

From source file:picard.sam.markduplicates.UmiGraph.java

public UmiGraph(DuplicateSet set, String umiTag, String assignedUmiTag, boolean allowMissingUmis) {
    this.umiTag = umiTag;
    this.assignedUmiTag = assignedUmiTag;
    this.allowMissingUmis = allowMissingUmis;
    records = set.getRecords();/*w  ww  .  j av  a2 s. c  o  m*/

    // First ensure that all the reads have a UMI, if any reads are missing a UMI throw an exception unless allowMissingUmis is true
    for (SAMRecord rec : records) {
        if (UmiUtil.getSanitizedUMI(rec, umiTag) == null) {
            if (allowMissingUmis) {
                rec.setAttribute(umiTag, "");
            } else {
                throw new PicardException("Read " + rec.getReadName() + " does not contain a UMI with the "
                        + umiTag + " attribute.");
            }
        }
    }

    // Count the number of times each UMI occurs
    umiCounts = records.stream()
            .collect(Collectors.groupingBy(p -> UmiUtil.getSanitizedUMI(p, umiTag), counting()));

    // At first we consider every UMI as if it were its own duplicate set
    numUmis = umiCounts.size();
    umi = new String[numUmis];
    duplicateSetID = IntStream.rangeClosed(0, numUmis - 1).toArray();

    int i = 0;
    for (String key : umiCounts.keySet()) {
        umi[i] = key;
        i++;
    }
}