List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:org.apache.hyracks.storage.am.lsm.common.impls.MemoryComponentMetadata.java
public void copy(IMetadataPageManager mdpManager) throws HyracksDataException { ITreeIndexMetadataFrame frame = mdpManager.createMetadataFrame(); for (Pair<IValueReference, ArrayBackedValueStorage> pair : store) { mdpManager.put(frame, pair.getKey(), pair.getValue()); }/*from w ww . j av a 2s . c om*/ }
From source file:org.apache.james.jmap.mailet.VacationMailet.java
private void manageVacation(MailAddress recipient, Mail processedMail, ZonedDateTime processingDate) { AccountId accountId = AccountId.fromString(recipient.toString()); Mono<Vacation> vacation = Mono.fromCompletionStage(vacationRepository.retrieveVacation(accountId)); Mono<Boolean> alreadySent = Mono .fromCompletionStage(notificationRegistry.isRegistered(AccountId.fromString(recipient.toString()), RecipientId.fromMailAddress(processedMail.getMaybeSender().get()))); Pair<Vacation, Boolean> pair = Flux.combineLatest(vacation, alreadySent, Pair::of).blockFirst(); sendNotificationIfRequired(recipient, processedMail, processingDate, pair.getKey(), pair.getValue()); }
From source file:org.apache.james.webadmin.service.ReprocessingService.java
public void reprocess(MailRepositoryPath path, MailKey key, Optional<String> targetProcessor, String targetQueue) throws MailRepositoryStore.MailRepositoryStoreException, MessagingException { Reprocessor reprocessor = new Reprocessor(getMailQueue(targetQueue), targetProcessor); Pair<MailRepository, Mail> mailPair = mailRepositoryStoreService.getRepositories(path) .map(Throwing/*w ww .j ava 2 s.c o m*/ .function(repository -> Pair.of(repository, Optional.ofNullable(repository.retrieve(key))))) .filter(pair -> pair.getRight().isPresent()) .map(pair -> Pair.of(pair.getLeft(), pair.getRight().get())).findFirst() .orElseThrow(() -> new MissingKeyException(key)); reprocessor.reprocess(mailPair.getKey(), mailPair.getValue()); }
From source file:org.apache.metron.common.stellar.evaluators.ArithmeticEvaluator.java
public Token<? extends Number> evaluate(BiFunction<Number, Number, Token<? extends Number>> function, Pair<Token<? extends Number>, Token<? extends Number>> p) { if (p == null || p.getKey() == null || p.getValue() == null) { throw new IllegalArgumentException(); }//from w ww . j a v a 2s . com final Number l = p.getKey().getValue(); final Number r = p.getValue().getValue(); return function.apply(l == null ? 0 : l, r == null ? 0 : r); }
From source file:org.apache.olingo.fit.AbstractServices.java
@POST @Path("/{entitySetName}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM }) public Response postNewEntity(@Context final UriInfo uriInfo, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer, @PathParam("entitySetName") final String entitySetName, final String entity) { try {/* w w w.j a v a 2s . c om*/ final Accept acceptType = Accept.parse(accept, version); if (acceptType == Accept.XML || acceptType == Accept.TEXT) { throw new UnsupportedMediaTypeException("Unsupported media type"); } final ResWrap<Entity> container; final org.apache.olingo.fit.metadata.EntitySet entitySet = metadata.getEntitySet(entitySetName); final Entity entry; final String entityKey; if (xml.isMediaContent(entitySetName)) { entry = new EntityImpl(); entry.setMediaContentType(ContentType.APPLICATION_OCTET_STREAM.toContentTypeString()); entry.setType(entitySet.getType()); entityKey = xml.getDefaultEntryKey(entitySetName, entry); xml.addMediaEntityValue(entitySetName, entityKey, IOUtils.toInputStream(entity, Constants.ENCODING)); final Pair<String, EdmPrimitiveTypeKind> id = Commons.getMediaContent().get(entitySetName); if (id != null) { final Property prop = new PropertyImpl(); prop.setName(id.getKey()); prop.setType(id.getValue().toString()); prop.setValue(ValueType.PRIMITIVE, id.getValue() == EdmPrimitiveTypeKind.Int32 ? Integer.parseInt(entityKey) : id.getValue() == EdmPrimitiveTypeKind.Guid ? UUID.fromString(entityKey) : entityKey); entry.getProperties().add(prop); } final Link editLink = new LinkImpl(); editLink.setHref(Commons.getEntityURI(entitySetName, entityKey)); editLink.setRel("edit"); editLink.setTitle(entitySetName); entry.setEditLink(editLink); entry.setMediaContentSource(URI.create(editLink.getHref() + "/$value")); container = new ResWrap<Entity>((URI) null, null, entry); } else { final Accept contentTypeValue = Accept.parse(contentType, version); if (Accept.ATOM == contentTypeValue) { container = atomDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING)); } else { container = jsonDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING)); } entry = container.getPayload(); updateInlineEntities(entry); entityKey = xml.getDefaultEntryKey(entitySetName, entry); } normalizeAtomEntry(entry, entitySetName, entityKey); final ByteArrayOutputStream content = new ByteArrayOutputStream(); final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); atomSerializer.write(writer, container); writer.flush(); writer.close(); final InputStream serialization = xml.addOrReplaceEntity(entityKey, entitySetName, new ByteArrayInputStream(content.toByteArray()), entry); ResWrap<Entity> result = atomDeserializer.toEntity(serialization); result = new ResWrap<Entity>( URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)), null, result.getPayload()); final String path = Commons.getEntityBasePath(entitySetName, entityKey); FSManager.instance(version).putInMemory(result, path + Constants.get(version, ConstantKey.ENTITY)); final String location; if ((this instanceof V3KeyAsSegment) || (this instanceof V4KeyAsSegment)) { location = uriInfo.getRequestUri().toASCIIString() + "/" + entityKey; final Link editLink = new LinkImpl(); editLink.setRel("edit"); editLink.setTitle(entitySetName); editLink.setHref(location); result.getPayload().setEditLink(editLink); } else { location = uriInfo.getRequestUri().toASCIIString() + "(" + entityKey + ")"; } final Response response; if ("return-no-content".equalsIgnoreCase(prefer)) { response = xml.createResponse(location, null, null, acceptType, Response.Status.NO_CONTENT); } else { response = xml.createResponse(location, xml.writeEntity(acceptType, result), null, acceptType, Response.Status.CREATED); } if (StringUtils.isNotBlank(prefer)) { response.getHeaders().put("Preference-Applied", Collections.<Object>singletonList(prefer)); } return response; } catch (Exception e) { LOG.error("While creating new entity", e); return xml.createFaultResponse(accept, e); } }
From source file:org.apache.olingo.fit.Services.java
@POST @Path("/{entitySetName}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM }) public Response postNewEntity(@Context final UriInfo uriInfo, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer, @PathParam("entitySetName") final String entitySetName, final String entity) { try {/*from w w w .j av a 2s . c o m*/ final Accept acceptType = Accept.parse(accept); if (acceptType == Accept.XML || acceptType == Accept.TEXT) { throw new UnsupportedMediaTypeException("Unsupported media type"); } final ResWrap<Entity> container; final org.apache.olingo.fit.metadata.EntitySet entitySet = metadata.getEntitySet(entitySetName); final Entity entry; final String entityKey; if (xml.isMediaContent(entitySetName)) { entry = new Entity(); entry.setMediaContentType(ContentType.APPLICATION_OCTET_STREAM.toContentTypeString()); entry.setType(entitySet.getType()); entityKey = xml.getDefaultEntryKey(entitySetName, entry); xml.addMediaEntityValue(entitySetName, entityKey, IOUtils.toInputStream(entity, Constants.ENCODING)); final Pair<String, EdmPrimitiveTypeKind> id = Commons.getMediaContent().get(entitySetName); if (id != null) { final Property prop = new Property(); prop.setName(id.getKey()); prop.setType(id.getValue().toString()); prop.setValue(ValueType.PRIMITIVE, id.getValue() == EdmPrimitiveTypeKind.Int32 ? Integer.parseInt(entityKey) : id.getValue() == EdmPrimitiveTypeKind.Guid ? UUID.fromString(entityKey) : entityKey); entry.getProperties().add(prop); } final Link editLink = new Link(); editLink.setHref(Commons.getEntityURI(entitySetName, entityKey)); editLink.setRel("edit"); editLink.setTitle(entitySetName); entry.setEditLink(editLink); entry.setMediaContentSource(URI.create(editLink.getHref() + "/$value")); container = new ResWrap<Entity>((URI) null, null, entry); } else { final Accept contentTypeValue = Accept.parse(contentType); if (Accept.ATOM == contentTypeValue) { container = atomDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING)); } else { container = jsonDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING)); } entry = container.getPayload(); updateInlineEntities(entry); entityKey = xml.getDefaultEntryKey(entitySetName, entry); } normalizeAtomEntry(entry, entitySetName, entityKey); final ByteArrayOutputStream content = new ByteArrayOutputStream(); final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); atomSerializer.write(writer, container); writer.flush(); writer.close(); final InputStream serialization = xml.addOrReplaceEntity(entityKey, entitySetName, new ByteArrayInputStream(content.toByteArray()), entry); ResWrap<Entity> result = atomDeserializer.toEntity(serialization); result = new ResWrap<Entity>(URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + entitySetName + Constants.get(ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)), null, result.getPayload()); final String path = Commons.getEntityBasePath(entitySetName, entityKey); FSManager.instance().putInMemory(result, path + Constants.get(ConstantKey.ENTITY)); final String location; if ((this instanceof KeyAsSegment)) { location = uriInfo.getRequestUri().toASCIIString() + "/" + entityKey; final Link editLink = new Link(); editLink.setRel("edit"); editLink.setTitle(entitySetName); editLink.setHref(location); result.getPayload().setEditLink(editLink); } else { location = uriInfo.getRequestUri().toASCIIString() + "(" + entityKey + ")"; } final Response response; if ("return-no-content".equalsIgnoreCase(prefer)) { response = xml.createResponse(location, null, null, acceptType, Response.Status.NO_CONTENT); } else { response = xml.createResponse(location, xml.writeEntity(acceptType, result), null, acceptType, Response.Status.CREATED); } if (StringUtils.isNotBlank(prefer)) { response.getHeaders().put("Preference-Applied", Collections.<Object>singletonList(prefer)); } return response; } catch (Exception e) { LOG.error("While creating new entity", e); return xml.createFaultResponse(accept, e); } }
From source file:org.apache.openejb.server.hessian.TomcatHessianRegistry.java
@Override public String deploy(final ClassLoader loader, final HessianServer listener, final String hostname, final String app, final String authMethod, final String transportGuarantee, final String realmName, final String name) throws URISyntaxException { Container host = engine.findChild(hostname); if (host == null) { host = engine.findChild(engine.getDefaultHost()); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + engine.getDefaultHost() + "'. Do you have a matchiing Host entry in the server.xml?"); }//w w w .j ava2 s.co m } final String contextRoot = contextName(app); Context context = Context.class.cast(host.findChild(contextRoot)); if (context == null) { Pair<Context, Integer> fakeContext = fakeContexts.get(contextRoot); if (fakeContext != null) { context = fakeContext.getLeft(); fakeContext.setValue(fakeContext.getValue() + 1); } else { context = Context.class.cast(host.findChild(contextRoot)); if (context == null) { fakeContext = fakeContexts.get(contextRoot); if (fakeContext == null) { context = createNewContext(loader, authMethod, transportGuarantee, realmName, app); fakeContext = new MutablePair<>(context, 1); fakeContexts.put(contextRoot, fakeContext); } else { context = fakeContext.getLeft(); fakeContext.setValue(fakeContext.getValue() + 1); } } } } final String servletMapping = generateServletPath(name); Wrapper wrapper = Wrapper.class.cast(context.findChild(servletMapping)); if (wrapper != null) { throw new IllegalArgumentException("Servlet " + servletMapping + " in web application context " + context.getName() + " already exists"); } wrapper = context.createWrapper(); wrapper.setName(HESSIAN.replace("/", "") + "_" + name); wrapper.setServlet(new OpenEJBHessianServlet(listener)); context.addChild(wrapper); context.addServletMapping(servletMapping, wrapper.getName()); if ("BASIC".equals(authMethod) && StandardContext.class.isInstance(context)) { final StandardContext standardContext = StandardContext.class.cast(context); boolean found = false; for (final Valve v : standardContext.getPipeline().getValves()) { if (LimitedBasicValve.class.isInstance(v) || BasicAuthenticator.class.isInstance(v)) { found = true; break; } } if (!found) { standardContext.addValve(new LimitedBasicValve()); } } final List<String> addresses = new ArrayList<>(); for (final Connector connector : connectors) { for (final String mapping : wrapper.findMappings()) { final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), contextRoot + mapping, null, null); addresses.add(address.toString()); } } return HttpUtil.selectSingleAddress(addresses); }
From source file:org.apache.openejb.server.hessian.TomcatHessianRegistry.java
@Override public void undeploy(final String hostname, final String app, final String name) { Container host = engine.findChild(hostname); if (host == null) { host = engine.findChild(engine.getDefaultHost()); if (host == null) { throw new IllegalArgumentException("Invalid virtual host '" + engine.getDefaultHost() + "'. Do you have a matchiing Host entry in the server.xml?"); }//ww w . ja va 2s . c o m } final String contextRoot = contextName(app); final Pair<Context, Integer> fakeContext = fakeContexts.get(contextRoot); if (fakeContext != null) { fakeContext.setValue(fakeContext.getValue() - 1); if (fakeContext.getValue() == 0) { fakeContexts.remove(contextRoot); host.removeChild(fakeContext.getKey()); } } }
From source file:org.apache.samza.operators.impl.InputOperatorImpl.java
@Override public Collection<M> handleMessage(Pair<K, V> pair, MessageCollector collector, TaskCoordinator coordinator) { // TODO: SAMZA-1148 - Cast to appropriate input (key, msg) types based on the serde before applying the msgBuilder. M message = this.inputOpSpec.getMsgBuilder().apply(pair.getKey(), pair.getValue()); return Collections.singletonList(message); }
From source file:org.apache.samza.sql.serializers.TestSamzaSqlRelMessageSerde.java
@Test public void testNestedRecordConversion() { Map<String, String> props = new HashMap<>(); SystemStream ss1 = new SystemStream("test", "nestedRecord"); props.put(String.format(ConfigBasedAvroRelSchemaProviderFactory.CFG_SOURCE_SCHEMA, ss1.getSystem(), ss1.getStream()), Profile.SCHEMA$.toString()); ConfigBasedAvroRelSchemaProviderFactory factory = new ConfigBasedAvroRelSchemaProviderFactory(); AvroRelSchemaProvider nestedRecordSchemaProvider = (AvroRelSchemaProvider) factory.create(ss1, new MapConfig(props)); AvroRelConverter nestedRecordAvroRelConverter = new AvroRelConverter(ss1, nestedRecordSchemaProvider, new MapConfig()); Pair<SamzaSqlRelMessage, GenericData.Record> messageRecordPair = createNestedSamzaSqlRelMessage( nestedRecordAvroRelConverter); SamzaSqlRelMessageSerde serde = (SamzaSqlRelMessageSerde) new SamzaSqlRelMessageSerdeFactory() .getSerde(null, null);/* w ww. j av a 2s .c o m*/ SamzaSqlRelMessage resultMsg = serde.fromBytes(serde.toBytes(messageRecordPair.getKey())); KV<Object, Object> samzaMessage = nestedRecordAvroRelConverter.convertToSamzaMessage(resultMsg); GenericRecord recordPostConversion = (GenericRecord) samzaMessage.getValue(); for (Schema.Field field : Profile.SCHEMA$.getFields()) { // equals() on GenericRecord does the nested record equality check as well. Assert.assertEquals(messageRecordPair.getValue().get(field.name()), recordPostConversion.get(field.name())); } }