Example usage for java.util.stream IntStream range

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

Introduction

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

Prototype

public static IntStream range(int startInclusive, int endExclusive) 

Source Link

Document

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

Usage

From source file:enmasse.broker.prestop.QueueDrainerTest.java

private static void sendMessages(TestBroker broker, String prefix, int numMessages)
        throws IOException, InterruptedException {
    List<String> messages = IntStream.range(0, numMessages).mapToObj(i -> prefix + i)
            .collect(Collectors.toList());
    broker.sendMessages(messages);/*from w  w  w .  ja v  a 2s. co  m*/
}

From source file:nova.minecraft.wrapper.mc.forge.v17.wrapper.redstone.backward.BWRedstone.java

@Override
public int getOutputStrongPower() {
    return IntStream.range(0, 6).map(side -> block().mcBlock.isProvidingStrongPower(mcWorld(), block().x(),
            block().y(), block().z(), side)).max().orElse(0);
}

From source file:Fasta.java

/**Splits the fasta sequence into a set of every possible
//sequence of a certain size which can be found in the sequence
including the reverse strand*///w ww .  ja v a2  s . c om
public static Set<CharSequence> splitFasta(String[] seq, int length) {

    Set<CharSequence> collect = IntStream.range(0, length).mapToObj(start -> {
        List<CharSequence> primers = new ArrayList<>();
        for (int i = start; i < seq[0].length() - length; i += length) {
            CharSequence s = seq[0].substring(i, i + length);
            primers.add(s);
        }
        return primers;
    }).flatMap((i) -> i.stream()).collect(Collectors.toSet());
    Set<CharSequence> collect2 = IntStream.range(0, length).mapToObj(start -> {
        List<CharSequence> primers = new ArrayList<>();
        for (int i = start; i < seq[1].length() - length; i += length) {
            CharSequence s = seq[1].substring(i, i + length);
            primers.add(s);
        }
        return primers;
    }).flatMap((i) -> i.stream()).collect(Collectors.toSet());
    collect.addAll(collect2);
    return collect;
}

From source file:com.simiacryptus.mindseye.labs.encoding.FindPCAFeatures.java

/**
 * Find band bias double [ ].//w  w w.  j a  v  a 2  s .co m
 *
 * @return the double [ ]
 */
protected double[] findBandBias() {
    final int outputBands = getFeatures().findAny().get()[1].getDimensions()[2];
    return IntStream.range(0, outputBands).parallel().mapToDouble(b -> {
        return getFeatures().mapToDouble(tensor -> {
            return tensor[1].coordStream(false).filter((c) -> c.getCoords()[2] == b)
                    .mapToDouble((c) -> tensor[1].get(c)).average().getAsDouble();
        }).average().getAsDouble();
    }).toArray();
}

From source file:com.yahoo.bullet.parsing.SpecificationTest.java

public static Stream<BulletRecord> makeStream(int count) {
    return IntStream.range(0, count).mapToObj(x -> RecordBox.get().getRecord());
}

From source file:nova.minecraft.wrapper.mc.forge.v18.wrapper.redstone.backward.BWRedstone.java

@Override
public int getOutputStrongPower() {
    BlockPos pos = new BlockPos(block().x(), block().y(), block().z());
    return IntStream.range(0, 6).map(side -> block().mcBlock.isProvidingStrongPower(mcWorld(), pos,
            mcWorld().getBlockState(pos), EnumFacing.values()[side])).max().orElse(0);
}

From source file:ru.xxlabaza.test.batch.job.RangePartitioner.java

@Override
public Map<String, ExecutionContext> partition(int gridSize) {
    long totalItems = personRepository.count();
    System.out.println("\nTotal items: " + totalItems);

    int range = (int) totalItems / gridSize;
    if (range < chunkSize) {
        throw new IllegalArgumentException();
    }/*  ww w  .  ja  v  a  2 s . c  om*/

    return IntStream.range(0, gridSize).boxed().map(index -> {
        ExecutionContext context = new ExecutionContext();
        context.putString("name", "partition-" + index);
        context.putInt("from", index * range);
        int nextIndex = index + 1;
        int to = nextIndex * range - 1;
        if (nextIndex == gridSize) {
            to += totalItems % gridSize;
        }
        context.putInt("to", to);
        return context;
    }).map(context -> {
        System.out.format("\nCREATED PARTITION: '%s', RANGE FROM %d, TO %d\n", context.getString("name"),
                context.getInt("from"), context.getInt("to"));
        return context;
    }).collect(toMap(context -> context.getString("name"), Function.identity()));
}

From source file:com.github.robozonky.common.remote.InterceptingInputStreamTest.java

@Test
void tooLong() throws IOException {
    final int maxLength = 1024;
    final int uuidLength = UUID.randomUUID().toString().length();
    final String contents = IntStream.range(0, (maxLength / uuidLength) + 2)
            .mapToObj(i -> UUID.randomUUID().toString()).collect(Collectors.joining());
    final InputStream s = new ByteArrayInputStream(contents.getBytes());
    try (final InterceptingInputStream s2 = new InterceptingInputStream(s)) {
        assertThat(s2.getContents()).endsWith("...more...");
    }//from   w w  w.  jav  a  2  s.  c o  m
}

From source file:org.apache.james.blob.cassandra.utils.DataChunker.java

public Stream<Pair<Integer, ByteBuffer>> chunk(byte[] data, int chunkSize) {
    Preconditions.checkNotNull(data);/*from  ww  w. ja  v a 2 s  . com*/
    Preconditions.checkArgument(chunkSize > 0, "ChunkSize can not be negative");

    int size = data.length;
    int fullChunkCount = size / chunkSize;

    return Stream.concat(
            IntStream.range(0, fullChunkCount)
                    .mapToObj(i -> Pair.of(i, ByteBuffer.wrap(data, i * chunkSize, chunkSize))),
            lastChunk(data, chunkSize * fullChunkCount, fullChunkCount));
}

From source file:com.ludgerpeters.acl.UserAclManagerImp.java

public boolean checkUserPermissions(String userId, String permissions[]) {
    HashSet<String> permissionSet = new HashSet<>();
    Arrays.asList(permissions).forEach(s -> {
        permissionSet.add(s);//from   www .  j  a v  a2s. co  m
        String[] split = s.split("\\.");
        IntStream.range(0, split.length).forEach(i -> {
            String join = "";
            for (int j = 0; j < i; j++) {
                join += split[j] + ".";
            }
            join += "*";
            permissionSet.add(join);

        });
    });
    Set<String> userPermissions = userRepository.getPermissions(userId);
    return permissionSet.stream().anyMatch(userPermissions::contains);
}