Example usage for org.apache.commons.lang3.tuple Pair getRight

List of usage examples for org.apache.commons.lang3.tuple Pair getRight

Introduction

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

Prototype

public abstract R getRight();

Source Link

Document

Gets the right element from this pair.

When treated as a key-value pair, this is the value.

Usage

From source file:alfio.manager.location.DefaultLocationManager.java

@Override
@Cacheable/*  w  w  w .j a  va2  s .c o  m*/
public TimeZone getTimezone(Pair<String, String> location) {
    return getTimezone(location.getLeft(), location.getRight());
}

From source file:com.samsung.sjs.Compiler.java

public static void compile(CompilerOptions opts, boolean typecheckonly, boolean checkTypes)
        throws IOException, SolverException {

    Path p = Paths.get(opts.getInputFileName());
    AstRoot sourcetree = null;//from   www.  j a v a2s .  co  m
    Map<AstNode, Type> types;

    JSEnvironment env = opts.getRuntimeEnvironment();
    switch (opts.getTargetPlatform()) {
    case Web:
        // Fall-through
    case Native:
        // This may be the most hideous line of code I've ever written
        InputStream jsenv = Compiler.class.getClass().getResourceAsStream("/environment.json");
        assert (jsenv != null);
        env.includeFile(jsenv);
    }
    for (Path fname : opts.getExtraDeclarationFiles()) {
        env.includeFile(fname);
    }

    ModuleSystem modsys = new ModuleSystem(opts);

    assert (opts.useConstraints());

    FFILinkage ffi = new FFILinkage();
    InputStream stdlib_linkage = Compiler.class.getClass().getResourceAsStream("/linkage.json");
    ffi.includeFile(stdlib_linkage);
    for (Path fname : opts.getExtraLinkageFiles()) {
        ffi.includeFile(fname);
    }

    String script = IOUtils.toString(p.toUri(), Charset.defaultCharset());
    org.mozilla.javascript.Parser parser = new org.mozilla.javascript.Parser();
    sourcetree = parser.parse(script, "", 1);
    ConstraintFactory factory = new ConstraintFactory();
    ConstraintGenerator generator = new ConstraintGenerator(factory, env, modsys);
    generator.generateConstraints(sourcetree);
    Set<ITypeConstraint> constraints = generator.getTypeConstraints();
    if (opts.shouldDumpConstraints()) {
        System.err.println("Constraints:");
        System.err.println(generator.stringRepresentationWithTermLineNumbers(constraints));
    }
    if (!opts.oldExplanations()) {
        SatSolver satSolver = new Sat4J();
        SJSTypeTheory theorySolver = new SJSTypeTheory(env, modsys, sourcetree);
        List<ITypeConstraint> initConstraints = theorySolver.getConstraints();
        ConstraintGenerator g = theorySolver.hackyGenerator();
        List<Integer> hardConstraints = new ArrayList<>(initConstraints.size());
        List<Integer> softConstraints = new ArrayList<>(initConstraints.size());
        for (int i = 0; i < initConstraints.size(); ++i) {
            boolean isSoft = g.hasExplanation(initConstraints.get(i));
            (isSoft ? softConstraints : hardConstraints).add(i);
        }

        FixingSetFinder<Integer> finder = FixingSetFinder.getStrategy(opts.explanationStrategy());
        Pair<TypeAssignment, Collection<Integer>> result = TheorySolver.solve(theorySolver, finder,
                hardConstraints, softConstraints);
        if (!finder.isOptimal() && !result.getRight().isEmpty()) {
            result = TheorySolver.minimizeFixingSet(theorySolver, hardConstraints, softConstraints,
                    result.getLeft(), result.getRight());
        }
        if (!result.getRight().isEmpty()) {
            System.out.println("Found " + result.getRight().size() + " type errors");
            g = theorySolver.hackyGenerator();
            int i = 0;
            for (ITypeConstraint c : theorySolver.hackyConstraintAccess()) {
                if (result.getRight().contains(i++)) {
                    System.out.println();
                    g.explainFailure(c, result.getLeft()).prettyprint(System.out);
                }
            }
            System.exit(1);
        }
        types = result.getLeft().nodeTypes();
        if (opts.shouldDumpConstraintSolution()) {
            System.err.println("Solved Constraints:");
            System.err.println(result.getLeft().debugString());
        }
    } else {
        DirectionalConstraintSolver solver = new DirectionalConstraintSolver(constraints, factory, generator);
        TypeAssignment solution = null;
        try {
            solution = solver.solve();
        } catch (SolverException e) {
            System.out.println("type inference failed");
            String explanation = e.explanation();
            System.out.println(explanation);
            System.exit(1);
        }
        if (opts.shouldDumpConstraintSolution()) {
            System.err.println("Solved Constraints:");
            System.err.println(solution.debugString());
        }
        types = solution.nodeTypes();
    }

    if (typecheckonly) {
        return;
    }

    if (checkTypes) {
        new RhinoTypeValidator(sourcetree, types).check();
    }

    // Translate Rhino IR to SJS IR.
    RhinoToIR rti = new RhinoToIR(opts, sourcetree, types);
    com.samsung.sjs.backend.asts.ir.Script ir = rti.convert();

    // Collect the set of explicit property / slot names
    IRFieldCollector fc = new IRFieldCollector(env, modsys);
    ir.accept(fc);
    IRFieldCollector.FieldMapping m = fc.getResults();
    if (opts.debug()) {
        System.out.println(m.toString());
    }

    boolean iterate_constant_inlining = true;
    if (opts.debug()) {
        System.err.println("**********************************************");
        System.err.println("* Pre-constant inlining:                     *");
        System.err.println("**********************************************");
        System.err.println(ir.toSource(0));
    }
    while (iterate_constant_inlining) {
        ConstantInliningPass cip = new ConstantInliningPass(opts, ir);
        ir = cip.visitScript(ir);
        // Replacing may make more things constant (vars aren't const) so repeat
        iterate_constant_inlining = cip.didSomething();
        if (opts.debug()) {
            System.err.println("**********************************************");
            System.err.println("* Post-constant inlining:                    *");
            System.err.println("**********************************************");
            System.err.println(ir.toSource(0));
        }
    }

    IREnvironmentLayoutPass envlayout = new IREnvironmentLayoutPass(ir, opts.debug());
    ir.accept(envlayout);
    if (opts.debug()) {
        System.err.println("**********************************************");
        System.err.println("* IR Env Layout Result:                      *");
        System.err.println("**********************************************");
        System.err.println(ir.toSource(0));
    }

    SwitchDesugaringPass sdp = new SwitchDesugaringPass(opts, ir);
    com.samsung.sjs.backend.asts.ir.Script post_switch_desugar = sdp.convert();

    IntrinsicsInliningPass iip = new IntrinsicsInliningPass(post_switch_desugar, opts, ffi);
    com.samsung.sjs.backend.asts.ir.Script post_intrinsics = iip.convert();
    if (opts.debug()) {
        System.err.println("**********************************************");
        System.err.println("* IR Intrinsics Inlining Result:              *");
        System.err.println("**********************************************");
        System.err.println(post_intrinsics.toSource(0));
    }

    IRClosureConversionPass ccp = new IRClosureConversionPass(post_intrinsics, envlayout.getMainCaptures(),
            opts.debug(), opts.isGuestRuntime() ? "__sjs_main" : "main");
    com.samsung.sjs.backend.asts.ir.Script post_cc = ccp.convert();
    if (opts.debug()) {
        System.err.println("**********************************************");
        System.err.println("* IR Closure Conversion Result:              *");
        System.err.println("**********************************************");
        System.err.println(post_cc.toSource(0));
    }

    post_cc = new ThreeAddressConversion(post_cc).visitScript(post_cc);
    if (logger.isDebugEnabled()) {
        System.err.println("**********************************************");
        System.err.println("* Three-Address Conversion Result:           *");
        System.err.println("**********************************************");
        System.err.println(post_cc.toSource(0));
    }

    // Gather constraints for optimizing object layouts
    PhysicalLayoutConstraintGathering plcg = new PhysicalLayoutConstraintGathering(opts, m, ffi);
    post_cc.accept(plcg);
    // TODO: Eventually feed this to the IRVTablePass as a source of layout information

    // Decorate SJS IR with vtables.
    IRVTablePass irvt = new IRVTablePass(opts, m, ffi);
    post_cc.accept(irvt);
    if (opts.fieldOptimizations()) {
        System.err.println("WARNING: Running experimental field access optimizations!");
        post_cc = (com.samsung.sjs.backend.asts.ir.Script) (new FieldAccessOptimizer(post_cc, opts, m,
                irvt.getVtablesByFieldMap()).visitScript(post_cc));
        if (opts.debug()) {
            System.err.println("**********************************************");
            System.err.println("* Field Access Optimization Result:          *");
            System.err.println("**********************************************");
            System.err.println(post_cc.toSource(0));
        }
    }

    IRCBackend ir2c = new IRCBackend(post_cc, opts, m, ffi, env, modsys);
    CompilationUnit c_via_ir = ir2c.compile();
    if (opts.debug()) {
        System.err.println("**********************************************");
        System.err.println("* C via IR Result:                           *");
        System.err.println("**********************************************");
        for (com.samsung.sjs.backend.asts.c.Statement s : c_via_ir) {
            System.err.println(s.toSource(0));
        }
    }

    c_via_ir.writeToDisk(opts.getOutputCName());
}

From source file:io.knotx.mocks.knot.MockKnotHandler.java

private JsonObject mergeResponseValues(JsonObject result, Pair<String, Optional<Object>> value) {
    return new JsonObject().put(value.getLeft(), value.getRight().orElse(StringUtils.EMPTY));
}

From source file:hu.ppke.itk.nlpg.purepos.common.lemma.AbstractLemmaTransformation.java

@Override
public IToken convert(String word, IVocabulary<String, Integer> vocab) {
    Pair<String, Integer> anal = this.analyze(word);
    String tag = vocab.getWord(anal.getRight());
    return token(word, anal.getLeft(), tag);
}

From source file:com.teambrmodding.neotech.registries.recipes.SolidifierRecipe.java

/**
 * Is the input valid for an output/*from www.  j  a  va 2s  . c  om*/
 *
 * @param input The input object
 * @return True if there is an output
 */
@Override
public boolean isValidInput(Pair<SolidifierMode, FluidStack> input) {
    return input.getLeft() == requiredMode && !(input == null || input.getRight().getFluid() == null)
            && getFluidStackFromString(inputFluidStack).getFluid().getName()
                    .equalsIgnoreCase(input.getRight().getFluid().getName())
            && input.getRight().amount >= getFluidStackFromString(inputFluidStack).amount;
}

From source file:flens.input.SocketInput.java

@Override
public void readAndProcess(Pair<String, DataInputStream> inx) throws IOException {
    DataInputStream in = inx.getRight();
    String host = inx.getLeft();/*from   w w w .  j a v a 2 s  .c  om*/
    int line = in.readInt();

    byte[] block = new byte[line];

    IOUtils.readFully(in, block);

    Map<String, Object> values = new HashMap<String, Object>();

    values.put(Constants.BODY, block);
    Record r = Record.createWithTimeHostAndValues(System.currentTimeMillis(), host, values);
    dispatch(r);

}

From source file:com.newlandframework.avatarmq.core.SendMessageCache.java

public void parallelDispatch(LinkedList<MessageDispatchTask> list) {
    List<Callable<Void>> tasks = new ArrayList<Callable<Void>>();
    int startPosition = 0;
    Pair<Integer, Integer> pair = calculateBlocks(list.size(), list.size());
    int numberOfThreads = pair.getRight();
    int blocks = pair.getLeft();

    for (int i = 0; i < numberOfThreads; i++) {
        MessageDispatchTask[] task = new MessageDispatchTask[blocks];
        phaser.register();/*from ww w  .  j  a v a2 s .  c o  m*/
        System.arraycopy(list.toArray(), startPosition, task, 0, blocks);
        tasks.add(new SendMessageTask(phaser, task));
        startPosition += blocks;
    }

    ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
    for (Callable<Void> element : tasks) {
        executor.submit(element);
    }
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.fineGrainedLogicForOptimization.ReactorConsumer.java

public void accept(Event<ContainerGivenHandN> ev) {
    SolutionPerJob spj = ev.getData().getSpj();
    ContainerLogicGivenH containerLogic = ev.getData().getHandler();
    logger.info("|Q-STATUS| received spjWrapper" + spj.getId() + "." + spj.getNumberUsers() + " on channel" + id
            + "\n");
    Pair<Boolean, Long> solverResult = runSolver(spj);
    long exeTime = solverResult.getRight();
    if (solverResult.getLeft()) {
        containerLogic.registerCorrectSolutionPerJob(spj, exeTime);
    } else {//from www .  j a va2 s  .  co  m
        containerLogic.registerFailedSolutionPerJob(spj, exeTime);
    }
    dispatcher.notifyReadyChannel(this);
}

From source file:com.git.ifly6.nsapi.builders.NSNationQueryBuilder.java

/** Returns the relevant NS API <code>String</code> that can be used to create the relevant URL which can then call
 * the document desired.//from w w w  . j  av a  2 s  .c om
 * @see java.lang.Object#toString() */
@Override
public String toString() {

    for (NSNationShard shard : queryShards) {
        builder.append(shard.toString() + "+");
    }

    if (censusShards.size() > 0) {

        List<Integer> cScores = new ArrayList<>(censusShards.size());
        for (Pair<NSNationShard, Integer> pair : censusShards) {
            cScores.add(pair.getRight());
        }

        builder.append("census;mode=score;scale=");

        for (Integer cScore : cScores) {
            builder.append(cScore.toString() + "+");
        }

    }

    String output = builder.toString();
    return output.endsWith("+") ? output.substring(0, output.length() - 1) : output;

}

From source file:fi.jgke.miniplc.unit.VariableTest.java

@Test
public void typeSanity() {
    List<Pair<VariableType, Object>> types = new ArrayList<>();
    types.add(new ImmutablePair<>(VariableType.BOOL, "str"));
    types.add(new ImmutablePair<>(VariableType.BOOL, 5));
    types.add(new ImmutablePair<>(VariableType.BOOL, null));
    types.add(new ImmutablePair<>(VariableType.STRING, true));
    types.add(new ImmutablePair<>(VariableType.STRING, 5));
    types.add(new ImmutablePair<>(VariableType.STRING, null));
    types.add(new ImmutablePair<>(VariableType.INT, true));
    types.add(new ImmutablePair<>(VariableType.INT, "str"));
    types.add(new ImmutablePair<>(VariableType.INT, null));
    for (Pair<VariableType, Object> p : types) {
        try {//from   w ww  . ja  va 2  s. c o  m
            createVariable(p.getLeft(), p.getRight());
            assertTrue(false);
        } catch (TypeException e) {
            assertNotNull(p.getRight());
        } catch (IllegalStateException e) {
            assertNull(p.getRight());
        }
    }
}