Example usage for org.apache.commons.lang3.tuple ImmutablePair of

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair of

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple ImmutablePair of.

Prototype

public static <L, R> ImmutablePair<L, R> of(final L left, final R right) 

Source Link

Document

Obtains an immutable pair of from two objects inferring the generic types.

This factory allows the pair to be created using inference to obtain the generic types.

Usage

From source file:com.yahoo.bullet.storm.testing.CustomBoltDeclarer.java

@Override
public BoltDeclarer shuffleGrouping(String componentId) {
    shuffleGroupings.add(ImmutablePair.of(componentId, Utils.DEFAULT_STREAM_ID));
    return this;
}

From source file:com.wrmsr.wava.driver.StandardFunctionProcessor.java

@Override
public Function processFunction(Function function) {
    Node body = function.getBody();

    body = Transforms.mangleCallNames(body, callMangler::mangleName);
    body = Transforms.mangleLabelNames(body, labelMangler::mangleName);
    body = Transforms.squishBlocks(body);
    body = Transforms.uniquifyLabels(body, new NameGenerator(Analyses.getNames(body), "_dupe$"));

    Analyses.checkLocalTypes(body, function.getLocals().getList().stream()
            .map(l -> ImmutablePair.of(l.getIndex(), l.getType())).collect(toImmutableMap()));

    body = Transforms.ensureTerminal(body, function.getSignature().getResult());
    body = Transforms.eliminateUnreferencedLabels(body, Analyses.getReferencedNames(body));
    body = Transforms.squishBlocks(body);

    TempManager tm = new TempManager(new NameGenerator(
            function.getLocals().getList().stream().map(Local::getName).collect(toImmutableSet()), "_temp$"),
            Index.of(function.getLocals().getList().size()), false);
    body = new StatementizerTransform(ControlTransferAnalysis.analyze(body),
            ValueTypeAnalysis.analyze(body, false), tm).transformFunctionBody(body);

    body = Transforms.insertExplicitLoopBreaks(body, ControlTransferAnalysis.analyze(body));
    body = Transforms.eliminateUnreferencedLabels(body, Analyses.getReferencedNames(body));
    body = Transforms.squishBlocks(body);

    body = Transforms.eliminateUnreachable(body, ControlTransferAnalysis.analyze(body), true);
    body = Transforms.squishBlocks(body);

    Locals locals = new Locals(Stream
            .concat(function.getLocals().getList().stream()
                    .map(l -> new Local(localMangler.mangleName(l.getName()), l.getIndex(), l.getType())),
                    tm.getTempList().stream().map(t -> new Local(t.getName(), t.getIndex(), t.getType())))
            .collect(toImmutableList()));

    return new Function(callMangler.mangleName(function.getName()), function.getResult(),
            function.getArgCount(), locals, body);
}

From source file:com.yahoo.bullet.storm.testing.CustomBoltDeclarer.java

@Override
public BoltDeclarer shuffleGrouping(String componentId, String streamId) {
    shuffleGroupings.add(ImmutablePair.of(componentId, streamId));
    return this;
}

From source file:com.foudroyantfactotum.mod.fousarchive.midi.generation.MidiImageGeneration.java

public ImmutablePair<String, BufferedImage> buildImage() throws InterruptedException, ExecutionException {
    final Future<String> name = pool.submit(new LineProcessor(imgX));
    final BufferedImage mdbf = new BufferedImage(imgX, imgY, BufferedImage.TYPE_BYTE_GRAY);
    final Graphics g = mdbf.getGraphics();

    g.setColor(Color.BLACK);/* w  w  w .  j  a v a2s .c o m*/
    g.fillRect(0, 0, imgX, imgY);
    g.setColor(Color.WHITE);

    for (Line l = lines.take(); l != TERMINATE; l = lines.take()) {
        g.drawLine(l.note, (int) Math.round(l.tickStart * imgY), l.note, (int) Math.round(l.tickEnd * imgY));
    }

    pool.shutdown();

    g.dispose();

    return ImmutablePair.of(name.get(), mdbf);
}

From source file:com.wrmsr.wava.transform.TestStatementizer.java

@Test
public void testStatementizer() throws Throwable {
    Node pre = new Return(new Label(Name.of("label$0"),
            new Label(Name.of("label$1"), new Break(Name.of("label$0"), new Const(Literal.of(1))))));

    StatementizerTransform st = new StatementizerTransform(ControlTransferAnalysis.analyze(pre),
            ValueTypeAnalysis.analyze(pre, false), new TempManager(new NameGenerator(), Index.of(0), false));

    Node post = st.transformFunctionBody(pre);

    assertEquals(post, new Block(ImmutableList.of(
            new Label(Name.of("label$0"), new Label(Name.of("label$1"),
                    new Block(ImmutableList.of(new SetLocal(Index.of(0), Type.I32, new Const(Literal.of(1))),
                            new Break(Name.of("label$0"), new Nop()))))),
            new Return(new GetLocal(Index.of(0), Type.I32)))));

    Locals locals = new Locals(st.getTempManager().getTempList().stream()
            .map(t -> new Local(t.getName(), t.getIndex(), t.getType())).collect(toImmutableList()));
    assertEquals(locals, Locals.of(ImmutableList.of(ImmutablePair.of(Name.of("__anon$0"), Type.I32))));
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesEventHandler.java

@Override
public void addRelationships(Map<KubernetesKind, List<KubernetesManifest>> allResources,
        Map<KubernetesManifest, List<KubernetesManifest>> relationshipMap) {
    relationshipMap.putAll(allResources.getOrDefault(EVENT, new ArrayList<>()).stream()
            .map(m -> ImmutablePair.of(m, KubernetesCacheDataConverter.getResource(m, V1Event.class)))
            .collect(Collectors.toMap(ImmutablePair::getLeft,
                    p -> Collections.singletonList(involvedManifest(p.getRight())))));
}

From source file:com.wrmsr.wava.basic.BasicLoopInfo.java

public static SetMultimap<Name, Name> findBasicBackEdges(Iterable<Basic> basics, Set<Name> loops,
        BasicDominatorInfo di) {//  w w w  .j a v  a2  s . c om
    return StreamSupport.stream(basics.spliterator(), false).flatMap(brk -> {
        Set<Name> bdf = di.getDominanceFrontiers().get(brk.getName());
        return brk.getAllTargets().stream()
                .filter(loop -> loops.contains(loop) && bdf.contains(loop)
                        && (loop.equals(brk.getName()) || di.getDominated(loop).contains(brk.getName())))
                .map(loop -> ImmutablePair.of(loop, brk.getName()));
    }).collect(toHashMultimap());
}

From source file:com.wrmsr.wava.yen.translation.UnitTranslation.java

public static Module translateModule(Name name, YModule module) {
    YMemory ymemory = module.getMemory();
    Memory memory = new Memory(ymemory.getInitial(),
            ymemory.getMax() >= 0 ? OptionalInt.of(ymemory.getMax()) : OptionalInt.empty(), ymemory
                    .getSegments().stream().map(
                            s -> new Segment(s.getOffset(),
                                    s.getData().length == s.getSize() ? s.getData()
                                            : Arrays.copyOf(s.getData(), s.getSize())))
                    .collect(toImmutableList()));
    Table table = new Table(module.getTable().getNames());
    Map<Name, Signature> functionSignatures = ImmutableMap.<Name, Signature>builder()
            .putAll(module.getFunctions().stream()
                    .map(f -> ImmutablePair.of(f.getName().get(), new Signature(f.getResult(), f.getParams())))
                    .collect(toImmutableList()))
            .putAll(module.getImports().stream()
                    .map(i -> ImmutablePair.of(i.getName().get(),
                            new Signature(i.getType().getResult(), i.getType().getParams())))
                    .collect(toImmutableList()))
            .build();//w w  w. j  a v  a  2 s .  c  om
    Map<Name, Import> imports = module.getImports().stream()
            .map(i -> ImmutablePair.of(i.getName().get(),
                    new Import(i.getName().get(), i.getModule(), i.getBase(),
                            new Signature(i.getType().getResult(), i.getType().getParams()))))
            .collect(toImmutableMap());
    Map<Name, Export> exports = module.getExports().stream()
            .map(e -> ImmutablePair.of(e.getName().get(), new Export(e.getName().get(), e.getValue())))
            .collect(toImmutableMap());
    Map<Name, Function> functions = module.getFunctions().stream().parallel() // FIXME boo this man
            .map(f -> ImmutablePair.of(f.getName().get(), translateFunction(f, functionSignatures)))
            .sequential().collect(toImmutableMap());
    Set<Signature> declaredSignatures = module.getNamedFunctionTypes().stream()
            .map(i -> new Signature(i.getResult(), i.getParams())).collect(Collectors.toSet());
    return new Module(name, memory, table, declaredSignatures, imports, exports, functions);
}

From source file:cc.kave.commons.pointsto.evaluation.ProjectTrainValidateEvaluation.java

public void export(Path dir, ResultExporter exporter) throws IOException {
    exporter.export(dir.resolve("TrainValidate.txt"), getResults().entrySet().stream()
            .flatMap(e -> e.getValue().stream().map(er -> ImmutablePair.of(e.getKey(), er))).map(p -> {
                return new String[] { CoReNames.vm2srcQualifiedType(p.left), p.right.training,
                        p.right.validation, String.format(Locale.US, "%.3f", p.right.score),
                        Integer.toString(p.right.numTrainingUsages),
                        Integer.toString(p.right.numValidationUsages) };
            }));/*from www  . j  a  v  a  2  s .c o m*/
}

From source file:io.github.carlomicieli.footballdb.starter.pages.TableTests.java

@Test
public void shouldReturnsTheTableSize() {
    Table emptyTable = new TableBuilder().toTable();
    Table table3x3 = newTable3x3();//  w  w w. jav  a  2  s . co m

    assertThat(emptyTable.size()).isEqualTo(ImmutablePair.of(0, 0));
    assertThat(table3x3.size()).isEqualTo(ImmutablePair.of(3, 3));
}