@Test public void map_withPassedAndOwnGraphs_removesDuplicatesFromConcatenatedContext() throws Exception { SimpleValueFactory f = SimpleValueFactory.getInstance(); IRI subjectIRI = f.createIRI("http: PredicateMapper childMapper = mock(PredicateMapper.class); Model model = new ModelBuilder().build(); EvaluateExpression evaluator = null; IRI subjectGraphIri = f.createIRI("http: IRI ownGraphIri = f.createIRI("http: Set<IRI> subjectContext = ImmutableSet.of(subjectGraphIri, ownGraphIri, ownGraphIri, subjectGraphIri); Set<IRI> ownContext = ImmutableSet.of(ownGraphIri, subjectGraphIri, subjectGraphIri, ownGraphIri); IRI[] expectedContext = new IRI[] { subjectGraphIri, ownGraphIri }; Set<TermGenerator<IRI>> ownGraphGenerators = ownContext.stream() .map(graphIri -> { @SuppressWarnings("unchecked") TermGenerator<IRI> generator = (TermGenerator<IRI>) mock(TermGenerator.class); when(generator.apply(evaluator)).thenReturn(ImmutableList.of(graphIri)).getMock(); return generator; }) .collect(ImmutableCollectors.toImmutableSet()); PredicateObjectMapper testSubject = new PredicateObjectMapper(ownGraphGenerators, ImmutableSet.of(childMapper)); testSubject.map(model, evaluator, subjectIRI, subjectContext); verify(childMapper).map(model, evaluator, subjectIRI, expectedContext); }
void map(Model model, EvaluateExpression evaluate, Resource subject, Set<IRI> subjectGraphs) { Resource[] contexts = Stream .concat( subjectGraphs.stream(), graphGenerators.stream() .map(g -> g.apply(evaluate)) .filter(l -> !l.isEmpty()) .map(l -> l.get(0)) ) .distinct() .filter(g -> !g.equals(Rr.defaultGraph)) .toArray(Resource[]::new); predicateMappers.forEach(p -> p.map(model, evaluate, subject, contexts)); }
PredicateObjectMapper { void map(Model model, EvaluateExpression evaluate, Resource subject, Set<IRI> subjectGraphs) { Resource[] contexts = Stream .concat( subjectGraphs.stream(), graphGenerators.stream() .map(g -> g.apply(evaluate)) .filter(l -> !l.isEmpty()) .map(l -> l.get(0)) ) .distinct() .filter(g -> !g.equals(Rr.defaultGraph)) .toArray(Resource[]::new); predicateMappers.forEach(p -> p.map(model, evaluate, subject, contexts)); } }
PredicateObjectMapper { void map(Model model, EvaluateExpression evaluate, Resource subject, Set<IRI> subjectGraphs) { Resource[] contexts = Stream .concat( subjectGraphs.stream(), graphGenerators.stream() .map(g -> g.apply(evaluate)) .filter(l -> !l.isEmpty()) .map(l -> l.get(0)) ) .distinct() .filter(g -> !g.equals(Rr.defaultGraph)) .toArray(Resource[]::new); predicateMappers.forEach(p -> p.map(model, evaluate, subject, contexts)); } PredicateObjectMapper(
		Set<TermGenerator<IRI>> graphGenerators,
		Set<PredicateMapper> predicateMappers
	); }
PredicateObjectMapper { void map(Model model, EvaluateExpression evaluate, Resource subject, Set<IRI> subjectGraphs) { Resource[] contexts = Stream .concat( subjectGraphs.stream(), graphGenerators.stream() .map(g -> g.apply(evaluate)) .filter(l -> !l.isEmpty()) .map(l -> l.get(0)) ) .distinct() .filter(g -> !g.equals(Rr.defaultGraph)) .toArray(Resource[]::new); predicateMappers.forEach(p -> p.map(model, evaluate, subject, contexts)); } PredicateObjectMapper(
		Set<TermGenerator<IRI>> graphGenerators,
		Set<PredicateMapper> predicateMappers
	);  }
PredicateObjectMapper { void map(Model model, EvaluateExpression evaluate, Resource subject, Set<IRI> subjectGraphs) { Resource[] contexts = Stream .concat( subjectGraphs.stream(), graphGenerators.stream() .map(g -> g.apply(evaluate)) .filter(l -> !l.isEmpty()) .map(l -> l.get(0)) ) .distinct() .filter(g -> !g.equals(Rr.defaultGraph)) .toArray(Resource[]::new); predicateMappers.forEach(p -> p.map(model, evaluate, subject, contexts)); } PredicateObjectMapper(
		Set<TermGenerator<IRI>> graphGenerators,
		Set<PredicateMapper> predicateMappers
	);   }