Example usage for com.google.common.collect Iterables cycle

List of usage examples for com.google.common.collect Iterables cycle

Introduction

In this page you can find the example usage for com.google.common.collect Iterables cycle.

Prototype

public static <T> Iterable<T> cycle(T... elements) 

Source Link

Document

Returns an iterable whose iterators cycle indefinitely over the provided elements.

Usage

From source file:com.facebook.buck.ocaml.OcamlLinkStep.java

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> cmd = ImmutableList.<String>builder().addAll(ocamlCompilerCommandPrefix)
            .addAll(OcamlCompilables.DEFAULT_OCAML_FLAGS);

    if (stdlib.isPresent()) {
        cmd.add("-nostdlib", OcamlCompilables.OCAML_INCLUDE_FLAG, stdlib.get());
    }//w  w  w.j  ava 2s .  c  o  m

    return cmd.add("-cc", cxxCompiler.get(0))
            .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-ccopt"),
                    cxxCompiler.subList(1, cxxCompiler.size())))
            .addAll(OptionalCompat.asSet(isLibrary ? Optional.of("-a") : Optional.empty()))
            .addAll(OptionalCompat.asSet(!isLibrary && isBytecode ? Optional.of("-custom") : Optional.empty()))
            .add("-o", output.toString()).addAll(flags).addAll(ocamlInput)
            .addAll(input.stream().map(Object::toString).iterator())
            .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-cclib"),
                    FluentIterable.from(cDepInput).transformAndConcat(Arg::stringifyList)))
            .build();
}

From source file:com.palantir.common.collect.IterableView.java

public IterableView<T> cycle() {
    return of(Iterables.cycle(delegate()));
}

From source file:com.facebook.buck.haskell.HaskellLinkRule.java

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(getOutput());
    return ImmutableList.of(
            new MakeCleanDirectoryStep(getProjectFilesystem(),
                    getOutputDir(getBuildTarget(), getProjectFilesystem())),
            new ShellStep(getProjectFilesystem().getRootPath()) {

                @Override//  w w  w  .  j  a  v a 2s . c om
                public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
                    return ImmutableMap.<String, String>builder().putAll(super.getEnvironmentVariables(context))
                            .putAll(linker.getEnvironment()).build();
                }

                @Override
                protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
                    return ImmutableList.<String>builder().addAll(linker.getCommandPrefix(getResolver()))
                            .add("-o", getProjectFilesystem().resolve(getOutput()).toString())
                            .addAll(Arg.stringify(args)).addAll(MoreIterables
                                    .zipAndConcat(Iterables.cycle("-optl"), Arg.stringify(linkerArgs)))
                            .build();
                }

                @Override
                public String getShortName() {
                    return "haskell-link";
                }

            });
}

From source file:r.lang.ListExp.java

public static SEXP ofLength(int length) {
    return ListExp.fromIterable(Iterables.limit(Iterables.cycle(NilExp.INSTANCE), length));
}

From source file:org.obiba.opal.core.identifiers.IdentifiersMaps.java

@Override
public Iterator<IdentifiersMap> iterator() {
    return new Iterator<IdentifiersMap>() {

        private final Iterator<VariableEntity> systemEntities;

        private final Iterator<Value> privateIdentifiers;

        {//from  ww  w  .  j a v  a 2 s.  c om
            NavigableSet<VariableEntity> entities = new TreeSet<>(identifiersTable.getVariableEntities());

            privateIdentifiers = identifiersTable.hasVariable(idMapping)
                    ? identifiersTable.getVariableValueSource(idMapping).asVectorSource().getValues(entities)
                            .iterator()
                    : Iterables.cycle(TextType.get().nullValue()).iterator();
            systemEntities = entities.iterator();
        }

        @Override
        public boolean hasNext() {
            return systemEntities.hasNext();
        }

        @Override
        public IdentifiersMap next() {
            Value value = privateIdentifiers.next();
            return new IdentifiersMap(systemEntities.next().getIdentifier(),
                    value.isNull() ? null : (String) value.getValue());
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };
}

From source file:com.facebook.buck.features.ocaml.OcamlLinkStep.java

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> cmd = ImmutableList.<String>builder().addAll(ocamlCompilerCommandPrefix)
            .addAll(OcamlCompilables.DEFAULT_OCAML_FLAGS);

    if (stdlib.isPresent()) {
        cmd.add("-nostdlib", OcamlCompilables.OCAML_INCLUDE_FLAG, stdlib.get());
    }/*from w ww  .  j  a  v  a 2s .co  m*/

    cmd.add("-cc", cxxCompiler.get(0));
    cmd.addAll(
            MoreIterables.zipAndConcat(Iterables.cycle("-ccopt"), cxxCompiler.subList(1, cxxCompiler.size())));
    if (isLibrary) {
        cmd.add("-a");
    } else if (isBytecode) {
        cmd.add("-custom");
    }
    return cmd.add("-o", output.toString()).addAll(flags).addAll(ocamlInput)
            .addAll(input.stream().map(Object::toString).iterator())
            .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-cclib"), cDepInput)).build();
}

From source file:com.facebook.buck.features.haskell.HaskellLinkRule.java

@Override
public ImmutableList<Step> getBuildSteps(BuildContext buildContext, BuildableContext buildableContext) {
    buildableContext.recordArtifact(getOutput());
    return new ImmutableList.Builder<Step>()
            .add(MkdirStep.of(BuildCellRelativePath.fromCellRelativePath(buildContext.getBuildCellRootPath(),
                    getProjectFilesystem(), getOutputDir())))
            .add(/* ww  w. j  ava2s . co m*/
                    // The output path might be a folder, so delete it all
                    RmStep.of(BuildCellRelativePath.fromCellRelativePath(buildContext.getBuildCellRootPath(),
                            getProjectFilesystem(), getOutput())).withRecursive(true))
            .add(new ShellStep(getProjectFilesystem().getRootPath()) {

                @Override
                public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
                    return ImmutableMap.<String, String>builder().putAll(super.getEnvironmentVariables(context))
                            .putAll(linker.getEnvironment(buildContext.getSourcePathResolver())).build();
                }

                @Override
                protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
                    return ImmutableList.<String>builder()
                            .addAll(linker.getCommandPrefix(buildContext.getSourcePathResolver()))
                            .add("-o", getProjectFilesystem().resolve(getOutput()).toString())
                            .addAll(Arg.stringify(args, buildContext.getSourcePathResolver()))
                            .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-optl"),
                                    Arg.stringify(linkerArgs, buildContext.getSourcePathResolver())))
                            .build();
                }

                @Override
                protected boolean shouldPrintStderr(Verbosity verbosity) {
                    return !verbosity.isSilent();
                }

                @Override
                public String getShortName() {
                    return "haskell-link";
                }
            }).build();
}

From source file:com.facebook.buck.features.ocaml.OcamlMLCompileStep.java

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> cmd = ImmutableList.<String>builder()
            .addAll(args.ocamlCompiler.getCommandPrefix(resolver)).addAll(OcamlCompilables.DEFAULT_OCAML_FLAGS);

    if (args.stdlib.isPresent()) {
        cmd.add("-nostdlib", OcamlCompilables.OCAML_INCLUDE_FLAG, args.stdlib.get());
    }/*  ww w .  java2 s  . c om*/

    String ext = Files.getFileExtension(args.input.toString());
    String dotExt = "." + ext;
    boolean isImplementation = dotExt.equals(OcamlCompilables.OCAML_ML)
            || dotExt.equals(OcamlCompilables.OCAML_RE);
    boolean isReason = dotExt.equals(OcamlCompilables.OCAML_RE) || dotExt.equals(OcamlCompilables.OCAML_REI);

    cmd.add("-cc", args.cCompiler.get(0))
            .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-ccopt"),
                    args.cCompiler.subList(1, args.cCompiler.size())))
            .add("-c").add("-annot").add("-bin-annot").add("-o", args.output.toString())
            .addAll(Arg.stringify(args.flags, resolver));

    if (isReason && isImplementation) {
        cmd.add("-pp").add("refmt").add("-intf-suffix").add("rei").add("-impl");
    }
    if (isReason && !isImplementation) {
        cmd.add("-pp").add("refmt").add("-intf");
    }

    cmd.add(args.input.toString());
    return cmd.build();
}

From source file:com.facebook.buck.ocaml.OcamlMLCompileStep.java

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> cmd = ImmutableList.<String>builder()
            .addAll(args.ocamlCompiler.getCommandPrefix(resolver)).addAll(OcamlCompilables.DEFAULT_OCAML_FLAGS);

    if (args.stdlib.isPresent()) {
        cmd.add("-nostdlib", OcamlCompilables.OCAML_INCLUDE_FLAG, args.stdlib.get());
    }/*www  . j  av  a2 s  . c om*/

    String ext = Files.getFileExtension(args.input.toString());
    String dotExt = "." + ext;
    boolean isImplementation = dotExt.equals(OcamlCompilables.OCAML_ML)
            || dotExt.equals(OcamlCompilables.OCAML_RE);
    boolean isReason = dotExt.equals(OcamlCompilables.OCAML_RE) || dotExt.equals(OcamlCompilables.OCAML_REI);

    cmd.add("-cc", args.cCompiler.get(0))
            .addAll(MoreIterables.zipAndConcat(Iterables.cycle("-ccopt"),
                    args.cCompiler.subList(1, args.cCompiler.size())))
            .add("-c").add("-annot").add("-bin-annot").add("-o", args.output.toString()).addAll(args.flags);

    if (isReason && isImplementation) {
        cmd.add("-pp").add("refmt").add("-intf-suffix").add("rei").add("-impl");
    }
    if (isReason && !isImplementation) {
        cmd.add("-pp").add("refmt").add("-intf");
    }

    cmd.add(args.input.toString());
    return cmd.build();
}

From source file:org.onosproject.flowperf.FlowPerfApp.java

private void runTest() {
    pendingBatchCount = new AtomicInteger(totalFlows / batchSize);
    installationLatch = new CountDownLatch(totalFlows);
    List<Device> deviceList = Lists.newArrayList();
    deviceService.getAvailableDevices().forEach(deviceList::add);
    devices = Iterables.cycle(deviceList).iterator();
    log.info("Starting installation. Total flows: {}, Total threads: {}, " + "Batch Size: {}", totalFlows,
            totalThreads, batchSize);//w  ww . j a va2 s  . c  o  m

    macIndex = new AtomicLong(0);
    FlowRuleListener addMonitor = event -> {
        if (event.type() == FlowRuleEvent.Type.RULE_ADDED) {
            installationLatch.countDown();
        }
    };

    flowRuleService.addListener(addMonitor);
    long addStartTime = System.currentTimeMillis();
    for (int i = 0; i < totalThreads; ++i) {
        installer.submit(() -> {
            while (pendingBatchCount.getAndDecrement() > 0) {
                List<FlowRule> batch = nextBatch(batchSize);
                addedRules.addAll(batch);
                flowRuleService.applyFlowRules(batch.toArray(new FlowRule[] {}));
            }
        });
    }

    // Wait till all the flows are in ADDED state.
    try {
        installationLatch.await();
    } catch (InterruptedException e) {
        Thread.interrupted();
    }
    log.info("Time to install {} flows: {} ms", totalFlows, System.currentTimeMillis() - addStartTime);
    flowRuleService.removeListener(addMonitor);

    uninstallationLatch = new CountDownLatch(totalFlows);
    FlowRuleListener removeListener = event -> {
        if (event.type() == FlowRuleEvent.Type.RULE_REMOVED) {
            uninstallationLatch.countDown();
        }
    };
    AtomicInteger currentIndex = new AtomicInteger(0);
    long removeStartTime = System.currentTimeMillis();
    flowRuleService.addListener(removeListener);
    // Uninstallation runs on a single thread.
    installer.submit(() -> {
        while (currentIndex.get() < addedRules.size()) {
            List<FlowRule> removeBatch = addedRules.subList(currentIndex.get(),
                    Math.min(currentIndex.get() + batchSize, addedRules.size()));
            currentIndex.addAndGet(removeBatch.size());
            flowRuleService.removeFlowRules(removeBatch.toArray(new FlowRule[] {}));
        }
    });
    try {
        uninstallationLatch.await();
    } catch (InterruptedException e) {
        Thread.interrupted();
    }
    log.info("Time to uninstall {} flows: {} ms", totalFlows, System.currentTimeMillis() - removeStartTime);
    flowRuleService.removeListener(removeListener);
}