List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:com.streamsets.pipeline.stage.processor.hbase.HBaseStore.java
public List<Optional<String>> get(List<Pair<String, HBaseColumn>> keys) throws Exception { ArrayList<Optional<String>> values = new ArrayList<>(); List<Get> gets = new ArrayList<>(); for (Pair<String, HBaseColumn> key : keys) { Get g = new Get(Bytes.toBytes(key.getKey())); HBaseColumn hBaseColumn = key.getValue(); if (hBaseColumn.getCf() != null && hBaseColumn.getQualifier() != null) { g.addColumn(hBaseColumn.getCf(), hBaseColumn.getQualifier()); }//from w w w . j ava 2 s.c o m if (hBaseColumn.getTimestamp() > 0) { g.setTimeStamp(hBaseColumn.getTimestamp()); } gets.add(g); } Result[] results = hTable.get(gets); int index = 0; for (Pair<String, HBaseColumn> key : keys) { Result result = results[index]; HBaseColumn hBaseColumn = key.getValue(); String value = getValue(hBaseColumn, result); values.add(Optional.fromNullable(value)); index++; } return values; }
From source file:com.nesscomputing.jackson.datatype.CommonsLang3SerializerTest.java
@Test public void testEntryCrossover() throws IOException { Entry<String, Boolean> pair = Maps.immutableEntry("foo", true); Pair<String, Boolean> newPair = mapper.readValue(mapper.writeValueAsBytes(pair), new TypeReference<Pair<String, Boolean>>() { });/*from w w w . java 2 s . com*/ assertEquals(pair.getKey(), newPair.getKey()); assertEquals(pair.getValue(), newPair.getValue()); pair = mapper.readValue(mapper.writeValueAsBytes(newPair), new TypeReference<Entry<String, Boolean>>() { }); assertEquals(newPair.getKey(), pair.getKey()); assertEquals(newPair.getValue(), pair.getValue()); }
From source file:com.evolveum.midpoint.prism.path.CanonicalItemPath.java
private String extractExplicitReplacements(String uri) { for (Pair<String, String> mapping : EXPLICIT_REPLACEMENTS) { if (uri.startsWith(mapping.getKey())) { return SHORTCUT_MARKER_START + mapping.getValue() + SHORTCUT_MARKER_END + uri.substring(mapping.getKey().length()); }// w ww .ja v a 2 s . com } return uri; }
From source file:blusunrize.immersiveengineering.client.render.ItemRendererIEOBJ.java
private void renderQuadsForGroups(String[] groups, IOBJModelCallback<ItemStack> callback, IESmartObjModel model, List<Pair<BakedQuad, ShaderLayer>> quadsForGroup, ItemStack stack, ShaderCase sCase, ItemStack shader, BufferBuilder bb, Tessellator tes, Map<String, Boolean> visible, float partialTicks) { quadsForGroup.clear();/* w ww . jav a2 s . c o m*/ for (String g : groups) { if (visible.getOrDefault(g, Boolean.FALSE) && callback.shouldRenderGroup(stack, g)) quadsForGroup.addAll(model.addQuadsForGroup(callback, stack, g, sCase, shader).stream() .filter(Objects::nonNull).collect(Collectors.toList())); visible.remove(g); } if (!callback.areGroupsFullbright(stack, groups)) bb.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM); else bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); VertexBufferConsumer vbc = new VertexBufferConsumer(bb); ShaderLayer lastShaderLayer = null; for (Pair<BakedQuad, ShaderLayer> pair : quadsForGroup) { BakedQuad bq = pair.getKey(); ShaderLayer layer = pair.getValue(); //Switch to or between dynamic layers boolean switchDynamic = layer != lastShaderLayer; if (switchDynamic) { //interrupt batch tes.draw(); if (lastShaderLayer != null)//finish dynamic call on last layer lastShaderLayer.modifyRender(false, partialTicks); //set new layer lastShaderLayer = layer; if (lastShaderLayer != null)//start dynamic call on layer lastShaderLayer.modifyRender(true, partialTicks); //start new batch if (!callback.areGroupsFullbright(stack, groups)) bb.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM); else bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); } bq.pipe(vbc); } tes.draw(); if (lastShaderLayer != null)//finish dynamic call on final layer lastShaderLayer.modifyRender(false, partialTicks); }
From source file:com.trenako.web.tags.ActivityTags.java
@Override protected int writeTagContent(JspWriter jspWriter, String contextPath) throws JspException { StringBuilder sb = new StringBuilder(); Account user = users().findBySlug(activity().getActor()); String slug = user == null ? activity().getActor() : user.getSlug(); String displayName = user == null ? activity().getActor() : user.getDisplayName(); sb.append("\n<a href=\"").append(contextPath).append("/users/").append(slug).append("\">") .append(displayName).append("</a>"); LocalizedEnum<ActivityVerb> verb = LocalizedEnum.parseString(activity().getVerb(), messageSource(), ActivityVerb.class); sb.append(" ").append(verb.getLabel()).append(" "); String objectName = activity().getObject().getDisplayName(); String objectUrl = activity().getObject().getUrl(); sb.append("\n<a href=\"").append(contextPath).append(objectUrl).append("\">").append(objectName) .append("</a>"); if (activity().getContext() != null) { String contextMsg = "activitycontext." + activity().getContext().getContextType() + ".label"; String contextLabel = messageSource().getMessage(contextMsg, null, contextMsg, getRequestContext().getLocale()); sb.append(" ").append(contextLabel); }/*from w w w.j av a2s. c om*/ Pair<String, Integer> p = periodUntilNow(activity().getRecorded()); String periodText = messageSource().getMessage(p.getKey(), new Object[] { p.getValue() }, p.getKey(), getRequestContext().getLocale()); sb.append("\n<br/><strong>").append(periodText).append("</strong>"); try { jspWriter.append(sb.toString()); } catch (IOException e) { throw new JspException(e); } return SKIP_BODY; }
From source file:gobblin.cluster.ScheduledJobConfigurationManager.java
/*** * TODO: Change cluster code to handle Spec. Right now all job properties are needed to be in config and template is not honored * TODO: Materialized JobSpec and make use of ResolvedJobSpec * @throws ExecutionException/*from ww w .j a v a2s. com*/ * @throws InterruptedException */ private void fetchJobSpecs() throws ExecutionException, InterruptedException { List<Pair<SpecExecutorInstance.Verb, Spec>> changesSpecs = (List<Pair<SpecExecutorInstance.Verb, Spec>>) this.specExecutorInstanceConsumer .changedSpecs().get(); for (Pair<SpecExecutorInstance.Verb, Spec> entry : changesSpecs) { SpecExecutorInstance.Verb verb = entry.getKey(); if (verb.equals(SpecExecutorInstance.Verb.ADD)) { // Handle addition JobSpec jobSpec = (JobSpec) entry.getValue(); postNewJobConfigArrival(jobSpec.getUri().toString(), jobSpec.getConfigAsProperties()); jobSpecs.put(entry.getValue().getUri(), (JobSpec) entry.getValue()); } else if (verb.equals(SpecExecutorInstanceConsumer.Verb.UPDATE)) { // Handle update JobSpec jobSpec = (JobSpec) entry.getValue(); postUpdateJobConfigArrival(jobSpec.getUri().toString(), jobSpec.getConfigAsProperties()); jobSpecs.put(entry.getValue().getUri(), (JobSpec) entry.getValue()); } else if (verb.equals(SpecExecutorInstanceConsumer.Verb.DELETE)) { // Handle delete Spec anonymousSpec = (Spec) entry.getValue(); postDeleteJobConfigArrival(anonymousSpec.getUri().toString(), new Properties()); jobSpecs.remove(entry.getValue().getUri()); } } }
From source file:com.acmutv.ontoqa.benchmark.basic.QuestionB01Test.java
/** * Tests the question-answering with parsing. * @throws QuestionException when the question is malformed. * @throws OntoqaFatalException when the question cannot be processed due to some fatal errors. *//*from www .j av a 2 s .c om*/ @Test public void test_nlp() throws Exception { final Grammar grammar = Common.getGrammar(); final Ontology ontology = Common.getOntology(); final Pair<Query, Answer> result = CoreController.process(QUESTION, grammar, ontology); final Query query = result.getKey(); final Answer answer = result.getValue(); LOGGER.info("Query: {}", query); LOGGER.info("Answer: {}", answer); Assert.assertEquals(QUERY_1, query.toString()); Assert.assertEquals(ANSWER, answer); }
From source file:com.acmutv.ontoqa.benchmark.basic.QuestionB01Test.java
/** * Tests the question-answering with parsing. * @throws QuestionException when the question is malformed. * @throws OntoqaFatalException when the question cannot be processed due to some fatal errors. *///from w w w . ja v a2 s. c o m @Test public void test_nlp_wired() throws Exception { final Grammar grammar = CommonGrammar.build_completeGrammar(); final Ontology ontology = Common.getOntology(); final Pair<Query, Answer> result = CoreController.process(QUESTION, grammar, ontology); final Query query = result.getKey(); final Answer answer = result.getValue(); LOGGER.info("Query: {}", query); LOGGER.info("Answer: {}", answer); Assert.assertEquals(QUERY_2, query.toString()); Assert.assertEquals(ANSWER, answer); }
From source file:gobblin.cluster.StreamingJobConfigurationManager.java
private void fetchJobSpecs() throws ExecutionException, InterruptedException { List<Pair<SpecExecutorInstance.Verb, Spec>> changesSpecs = (List<Pair<SpecExecutorInstance.Verb, Spec>>) this.specExecutorInstanceConsumer .changedSpecs().get();//w w w . ja va 2 s . com // propagate thread interruption so that caller will exit from loop if (Thread.interrupted()) { throw new InterruptedException(); } for (Pair<SpecExecutorInstance.Verb, Spec> entry : changesSpecs) { SpecExecutorInstance.Verb verb = entry.getKey(); if (verb.equals(SpecExecutorInstance.Verb.ADD)) { // Handle addition JobSpec jobSpec = (JobSpec) entry.getValue(); postNewJobConfigArrival(jobSpec.getUri().toString(), jobSpec.getConfigAsProperties()); } else if (verb.equals(SpecExecutorInstanceConsumer.Verb.UPDATE)) { // Handle update JobSpec jobSpec = (JobSpec) entry.getValue(); postUpdateJobConfigArrival(jobSpec.getUri().toString(), jobSpec.getConfigAsProperties()); } else if (verb.equals(SpecExecutorInstanceConsumer.Verb.DELETE)) { // Handle delete Spec anonymousSpec = (Spec) entry.getValue(); postDeleteJobConfigArrival(anonymousSpec.getUri().toString(), new Properties()); } } }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForOneDay() { int numberOfDays = 1; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusDays(numberOfDays); Pair<String, Integer> dayPair = PeriodUtils.period(start, end); assertEquals(DAY_LABEL, dayPair.getKey()); assertEquals(numberOfDays, (int) dayPair.getValue()); }