/** * Construct an enumerator. The <code>plus</code> function is derived from the <code>successor * </code> and <code>predecessor</code>. * * @param successor The successor function. * @param predecessor The predecessor function. * @param max The potential maximum value. * @param min The potential minimum value. * @param order The ordering for the type. * @return An enumerator with the given values. */ public static <A> Enumerator<A> enumerator( final F<A, Option<A>> successor, final F<A, Option<A>> predecessor, final Option<A> max, final Option<A> min, final Ord<A> order) { return new Enumerator<A>( successor, predecessor, max, min, order, curry( (a, l) -> { if (l == 0L) return some(a); else if (l < 0L) { A aa = a; for (long x = l; x < 0; x++) { final Option<A> s = predecessor.f(aa); if (s.isNone()) return none(); else aa = s.some(); } return some(aa); } else { A aa = a; for (long x = l; x > 0; x--) { final Option<A> s = successor.f(aa); if (s.isNone()) return none(); else aa = s.some(); } return some(aa); } })); }
private int sub() throws Exception { Array<P2<String, Option<UUID>>> parse = outvoicePaidClient.parse(outvoicePaidClient.get()); int i = 0; for (P2<String, Option<UUID>> p : parse) { RegistrationsSqlMapper.Registration registration; try (Connection c = dataSource.getConnection()) { c.setAutoCommit(false); Option<UUID> apiClientRef = p._2(); if (apiClientRef.isNone()) continue; Option<UUID> registrationId = registrationsSqlMapper.invoiceReferenceToRegistrationId(c, apiClientRef.some()); if (registrationId.isNone()) continue; registration = registrationsSqlMapper.one(c, registrationId.some()).some(); } if (registration.tuple.state != RegistrationState.INVOICING) continue; markAsPaidService.markAsPaid(registration.id); i++; } return i; }
private void onEvent(NexusDao dao, HasNexusEvent e) throws SQLException { NexusEvent event = e.event; String repositoryId = event.guid.replaceAll( "^" + quote(server.url.toASCIIString()) + "/content/repositories/([-a-zA-Z0-9]*)/.*", "$1"); if (repositoryId.length() == 0) { return; } Option<NexusRepositoryDto> r = dao.findRepository(server.uuid, repositoryId); if (r.isNone()) { return; } NexusRepositoryDto repository = r.some(); Option<ArtifactDto> a = dao.findArtifact(repository.uuid, event.artifactId); UUID uuid; if (a.isNone()) { System.out.println("New artifact: " + event.artifactId); uuid = dao.insertArtifact(repository.uuid, event.artifactId); } else { ArtifactDto artifact = a.some(); // System.out.println("Updated artifact: " + event.artifactId); uuid = artifact.uuid; } if (e instanceof NewSnapshotEvent) { NewSnapshotEvent newSnapshotEvent = (NewSnapshotEvent) e; dao.insertNewSnapshotEvent( uuid, event.guid, event.creator, event.date, newSnapshotEvent.snapshotTimestamp, newSnapshotEvent.buildNumber, newSnapshotEvent.url.toASCIIString()); } else if (e instanceof NewReleaseEvent) { NewReleaseEvent nre = (NewReleaseEvent) e; dao.insertNewReleaseEvent( uuid, event.guid, event.creator, event.date, nre.url.toASCIIString()); } else { System.out.println("Unknown event type: " + event.getClass().getName()); } }
@Path("/events/{eventName}/sessions/{sessionId}/session-interest") @POST public Response setSessionInterest( @Context final SecurityContext securityContext, @PathParam("eventName") final String eventName, @PathParam("sessionId") final String sessionId, String payload) { Option<String> userName = getUserName.f(securityContext); if (userName.isNone()) { return Response.status(Status.UNAUTHORIZED).build(); } OperationResult<User> result = incogito.setInterestLevel( userName.some(), eventName, new SessionId(sessionId), InterestLevel.valueOf(payload)); return this.<User>defaultResponsePatternMatcher() .add(OkOperationResult.class, this.<OperationResult<User>>created()) .match(result); }