private Stream<Record> select(final Map<URI, Record> table, final Stream<? extends URI> stream) { return stream.transform(new Function<URI, Record>() { @Override public Record apply(final URI id) { return table.get(id); } }, 0); }
private static Stream<Record> upload(final Session session, final Criteria criteria, final Stream<Record> axioms) { return axioms.transform(null, new Function<Handler<Record>, Handler<Record>>() { @Override public Handler<Record> apply(final Handler<Record> handler) { return new UploadHandler(session, criteria, handler); } }); }
private Stream<Record> project(final Stream<Record> stream, @Nullable final Iterable<? extends URI> properties) { final URI[] array = properties == null ? null : Iterables.toArray(properties, URI.class); return stream.transform(new Function<Record, Record>() { @Override public final Record apply(final Record input) { final Record result = Record.create(input, true); if (array != null) { result.retain(array); } return result; } }, 0); }
@Override public Stream<String> list() throws IOException { return super.list().transform(new Function<String, String>() { @Override public String apply(final String filename) { return toExternalFilename(filename); } }, 0); }
tx.lookup(KS.MENTION, (Set) restrictions.get(KS.HAS_MENTION), ImmutableSet.of(KS.MENTION_OF)) .transform(URI.class, true, KS.MENTION_OF).toCollection(ids); tx.lookup(KS.RESOURCE, (Set) restrictions.get(KS.MENTION_OF), ImmutableSet.of(KS.HAS_MENTION)) .transform(URI.class, true, KS.HAS_MENTION).toCollection(ids);
@Override public Stream<Record> lookup(final URI type, final Set<? extends URI> ids, final Set<? extends URI> properties) throws IOException, IllegalArgumentException, IllegalStateException { return Stream.concat(Stream.create(ids).chunk(64) .transform(new Function<List<? extends URI>, Stream<Record>>() { @Override public Stream<Record> apply(final List<? extends URI> input) { final StringBuilder builder = new StringBuilder(); builder.append(" VALUES ?s {"); for (final URI id : input) { builder.append(" <").append(id.toString()).append(">"); } builder.append(" }"); try { return query(builder.toString(), type, properties, null); } catch (final IOException ex) { throw Throwables.propagate(ex); } } }, 1)); }
stream = stream.transform(new Function<Record, Record>() {
private static Stream<Record> download(final Session session, final boolean dumpResources, final boolean dumpMentions, @Nullable final String id) throws Throwable { final List<URI> types = Lists.newArrayList(); if (dumpResources) { types.add(KS.RESOURCE); } if (dumpMentions) { types.add(KS.MENTION); } return Stream.concat(Stream.create(types) .transform( (final URI type) -> { LOGGER.info("Downloading {} data", type.getLocalName().toLowerCase()); try { final Retrieve retrieve = session.retrieve(type) .limit((long) Integer.MAX_VALUE) .timeout(7 * 24 * 60 * 60 * 1000L); // 1 week if (id != null) { retrieve.ids(new URIImpl(id)); } return retrieve.exec(); // return session.retrieve(type).limit((long) Integer.MAX_VALUE) // .timeout(24 * 60 * 60 * 1000L).exec(); } catch (final Throwable ex) { throw Throwables.propagate(ex); } }, 1)); }