List of usage examples for org.apache.commons.lang3.tuple Pair getLeft
public abstract L getLeft();
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
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;/*w w w. jav a 2s .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:hu.ppke.itk.nlpg.purepos.model.internal.NGramModelTest.java
@Test public void testMaxFinder() { model = new NGramModel<Integer>(3); Integer f = 0;//from ww w . j av a 2 s . co m IntTrieNode<Integer> n0 = new IntTrieNode<Integer>(-1, 0); IntTrieNode<Integer> n1 = new IntTrieNode<Integer>(-1, 0); n1.addWord(0); IntTrieNode<Integer> n2 = new IntTrieNode<Integer>(-1, 0); n2.addWord(5); n2.addWord(0); ArrayList<TrieNode<Integer, Integer, Integer>> l = new ArrayList<TrieNode<Integer, Integer, Integer>>(); // MutablePair<ArrayList<IntTrieNode<Integer>>, Integer> arg = new // MutablePair<ArrayList<IntTrieNode<Integer>>, Integer>( // l, f); Pair<Integer, Double> ret = model.findMax(l, f); Assert.assertEquals(ret.getLeft(), null); Assert.assertEquals(ret.getRight(), null); l.add(n0); ret = model.findMax(l, f); Assert.assertEquals((Integer) (-1), ret.getLeft()); Assert.assertEquals(0.0, ret.getRight()); l.add(n2); ret = model.findMax(l, f); Assert.assertEquals((Integer) 1, ret.getLeft()); Assert.assertEquals(0.5, ret.getRight()); l.add(n1); ret = model.findMax(l, f); Assert.assertEquals((Integer) 2, ret.getLeft()); Assert.assertEquals(1.0, ret.getRight()); }
From source file:cherry.sqlman.tool.statement.SqlStatementIdControllerImpl.java
@Override public ModelAndView execute(int id, SqlStatementForm form, BindingResult binding, Authentication auth, Locale locale, SitePreference sitePref, NativeWebRequest request) { if (hasErrors(form, binding)) { return withViewname(viewnameOfStart).build(); }//from w ww. j a v a 2 s. c om try { initializeForm(form, id, auth, false); Pair<PageSet, ResultSet> pair = search(form); return withViewname(viewnameOfStart).addObject(pair.getLeft()).addObject(pair.getRight()).build(); } catch (BadSqlGrammarException ex) { LogicalErrorUtil.reject(binding, LogicError.BadSqlGrammer, Util.getRootCause(ex).getMessage()); return withViewname(viewnameOfStart).build(); } }
From source file:alfio.util.TemplateResourceTest.java
@Test public void buildModelForTicketEmail() throws Exception { Pair<ZonedDateTime, ZonedDateTime> dates = getDates(); Map<String, Object> model = TemplateResource.buildModelForTicketEmail(organization, event, ticketReservation, "Https://test", ticket, ticketCategory); assertEquals(dates.getLeft(), model.get("validityStart")); assertEquals(dates.getRight(), model.get("validityEnd")); }
From source file:cherry.sqlman.tool.clause.SqlClauseIdControllerImpl.java
@Override public ModelAndView execute(int id, SqlClauseForm form, BindingResult binding, Authentication auth, Locale locale, SitePreference sitePref, NativeWebRequest request) { if (hasErrors(form, binding)) { return withViewname(viewnameOfStart).build(); }/*from ww w. ja v a 2 s.c o m*/ try { initializeForm(form, id, auth, false); Pair<PageSet, ResultSet> pair = search(form); return withViewname(viewnameOfStart).addObject(pair.getLeft()).addObject(pair.getRight()).build(); } catch (BadSqlGrammarException ex) { LogicalErrorUtil.reject(binding, LogicError.BadSqlGrammer, Util.getRootCause(ex).getMessage()); return withViewname(viewnameOfStart).build(); } }
From source file:com.qwazr.utils.json.DirectoryJsonManager.java
private T getNoLock(File file, String name, AtomicBoolean mustBeEvaluated) throws IOException { Pair<Long, T> item = instancesCache.get(name); long lastModified = file.lastModified(); if (file.exists()) { if (item != null && item.getLeft() == lastModified) return item.getRight(); if (mustBeEvaluated == null) { item = loadItem(name, file, lastModified); buildCache();//from www. java 2 s. c om return item.getRight(); } } else { if (item == null) return null; if (mustBeEvaluated == null) { instancesMap.remove(name); buildCache(); return null; } } mustBeEvaluated.set(true); return null; }
From source file:com.spotify.heroic.cluster.ClusterManagerModule.java
@Provides @ClusterScope//from w ww. j a va 2s .com public Map<String, RpcProtocol> protocols(List<Pair<String, RpcProtocolComponent>> protocols) { final Map<String, RpcProtocol> map = new HashMap<>(); for (final Pair<String, RpcProtocolComponent> m : protocols) { map.put(m.getLeft(), m.getRight().rpcProtocol()); } return map; }
From source file:com.formkiq.core.service.generator.WorkflowOutputGenerator.java
/** * Generate Document from uploaded document. * * @param archive {@link ArchiveDTO}/*from ww w. j a v a 2s . c o m*/ * @param filename {@link String} * @param data byte[] * @throws IOException IOException */ default void generate(final ArchiveDTO archive, final String filename, final byte[] data) throws IOException { Pair<FormJSON, List<WorkflowOutputFormField>> p = getOutputFormFields(filename, data); FormJSON form = p.getLeft(); WorkflowOutputDocument wo = createOrMergeWorkflowOutputDocument(archive, form, p.getRight()); String ext = wo.getInputDocumentType().getExtension(); if (ext.equals("pdf")) { archive.addPDF(wo.getName() + "." + ext, data); } else { archive.addObject(wo.getName() + "." + ext, data); } postGenerateCallback(archive, form); }
From source file:edu.uci.ics.hyracks.api.job.ActivityCluster.java
public ActivityId getProducerActivity(ConnectorDescriptorId cdId) { Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>> connEdge = connectorActivityMap.get(cdId); return connEdge.getLeft().getLeft().getActivityId(); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.core.DataProcessor.java
private long calculateMetric(@NonNull List<SolutionPerJob> spjList, BiConsumer<SolutionPerJob, Double> resultSaver, Consumer<SolutionPerJob> ifEmpty) { //to support also parallel stream. AtomicLong executionTime = new AtomicLong(); spjList.forEach(spj -> {/*from w w w. j a v a 2 s . co m*/ Pair<Optional<Double>, Long> result = simulateClass(spj); executionTime.addAndGet(result.getRight()); Optional<Double> optionalValue = result.getLeft(); if (optionalValue.isPresent()) resultSaver.accept(spj, optionalValue.get()); else ifEmpty.accept(spj); }); return executionTime.get(); }