public void testStringConverter_reverse() { Converter<String, Integer> converter = Ints.stringConverter(); assertEquals("1", converter.reverse().convert(1)); assertEquals("0", converter.reverse().convert(0)); assertEquals("-1", converter.reverse().convert(-1)); assertEquals("255", converter.reverse().convert(0xff)); assertEquals("255", converter.reverse().convert(0xFF)); assertEquals("-255", converter.reverse().convert(-0xFF)); assertEquals("438", converter.reverse().convert(0666)); }
@Override @Nullable A correctedDoBackward(@Nullable C c) { return first.correctedDoBackward(second.correctedDoBackward(c)); }
public void testIdentityConverter() { Converter<String, String> stringIdentityConverter = Converter.identity(); assertSame(stringIdentityConverter, stringIdentityConverter.reverse()); assertSame(STR_TO_LONG, stringIdentityConverter.andThen(STR_TO_LONG)); assertSame(STR_VAL, stringIdentityConverter.convert(STR_VAL)); assertSame(STR_VAL, stringIdentityConverter.reverse().convert(STR_VAL)); assertEquals("Converter.identity()", stringIdentityConverter.toString()); assertSame(Converter.identity(), Converter.identity()); }
public void testConverter() { assertEquals(LONG_VAL, STR_TO_LONG.convert(STR_VAL)); assertEquals(STR_VAL, STR_TO_LONG.reverse().convert(LONG_VAL)); Iterable<Long> convertedValues = STR_TO_LONG.convertAll(STRINGS); assertEquals(LONGS, ImmutableList.copyOf(convertedValues)); }
@Override @Nullable C correctedDoForward(@Nullable A a) { return second.correctedDoForward(first.correctedDoForward(a)); }
@Override @Nullable A correctedDoBackward(@Nullable C c) { return first.correctedDoBackward(second.correctedDoBackward(c)); }
/** * Get the membership resource relation asserted by the container * @param parent resource with relations * @return Node of member * @throws RepositoryException on error */ private Node getMemberResource(final FedoraResource parent) throws RepositoryException { final Node membershipResource; if (parent.hasProperty(LDP_MEMBER_RESOURCE)) { final Property memberResource = getJcrNode(parent).getProperty(LDP_MEMBER_RESOURCE); if (REFERENCE_TYPES.contains(memberResource.getType())) { membershipResource = nodeConverter().convert(memberResource.getNode()).asNode(); } else { membershipResource = createURI(memberResource.getString()); } } else { membershipResource = uriFor(parent); } return membershipResource; } }
/** * This is a helper method for using the idTranslator to convert this resource into an associated Jena Node. * * @param resource to be converted into a Jena Node * @return the Jena node */ protected Node asNode(final FedoraResource resource) { return translator().reverse().convert(resource).asNode(); }
private static void addContentStatements(final IdentifierConverter<Resource,FedoraResource> idTranslator, final FedoraBinary resource, final Model model) { // fcr:fixity final Resource subject = idTranslator.reverse().convert(resource); model.add(subject, HAS_FIXITY_SERVICE, createResource(subject.getURI() + "/fcr:fixity")); }
@Override public RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> idTranslator, final Set<? extends TripleCategory> contexts) { final FedoraResource described = getOriginalResource().getDescribedResource(); final org.apache.jena.graph.Node describedNode = idTranslator.reverse().convert(described).asNode(); final String resourceUri = idTranslator.reverse().convert(this).getURI(); Stream<Triple> triples = contexts.stream() .filter(contextMap::containsKey) .map(x -> contextMap.get(x).apply(this).apply(idTranslator).apply(contexts.contains(MINIMAL))) .reduce(empty(), Stream::concat) .map(t -> mapSubject(t, resourceUri, describedNode)); // if a memento, convert subjects to original resource and object references from referential integrity // ignoring internal URL back the original external URL. if (isMemento()) { final IdentifierConverter<Resource, FedoraResource> internalIdTranslator = new InternalIdentifierTranslator(getSession()); triples = triples.map(convertMementoReferences(idTranslator, internalIdTranslator)); } return new DefaultRdfStream(idTranslator.reverse().convert(described).asNode(), triples); }
/** * @deprecated Provided to satisfy the {@code Function} interface; use {@link #convert} instead. */ @Deprecated @Override @CanIgnoreReturnValue public final @Nullable B apply(@Nullable A a) { return convert(a); }
@Override protected void addResourceHttpHeaders(final FedoraResource resource) { super.addResourceHttpHeaders(resource); if (session.isBatchSession()) { final String canonical = translator().reverse() .convert(resource) .toString() .replaceFirst("/tx:[^/]+", ""); servletResponse.addHeader(LINK, "<" + canonical + ">;rel=\"canonical\""); } addExternalContentHeaders(resource); }
public void testSerialization_andThen() { Converter<String, Long> converterA = Longs.stringConverter(); Converter<Long, String> reverseConverter = Longs.stringConverter().reverse(); Converter<String, String> composedConverter = converterA.andThen(reverseConverter); SerializableTester.reserializeAndAssert(composedConverter); }
@Override @Nullable C correctedDoForward(@Nullable A a) { return second.correctedDoForward(first.correctedDoForward(a)); }
@Override @Nullable C correctedDoForward(@Nullable A a) { return second.correctedDoForward(first.correctedDoForward(a)); }