private TripleConsumerAdapter(final Property property, final Individual<?, ?> individual, final DataSetHelperImpl.TripleConsumer consumer) { this.predicate = property.predicate(); this.individual = individual; this.consumer = consumer; }
@Override public URI predicate() { return this.property.predicate(); }
private TripleGenerator(Resource<?> resource, Property property) { this.subject = resource; this.predicate = property.predicate(); }
private void dump(StringBuilder builder, Map<Property, Value> map, String prefix, String infix) { for(Iterator<Entry<Property,Value>> it=map.entrySet().iterator();it.hasNext();) { Entry<Property, Value> entry = it.next(); builder.append(prefix+" value '"+FormatUtils.formatValue(entry.getValue())+"' "+infix+" property '"+entry.getKey().predicate()+"'"); if(it.hasNext()) { builder.append(", "); } } } }
@Override public void visitIndividual(Individual<?, ?> value) { if(value==this.src) { this.individual.removeValue(this.property.predicate(), value); } } }
private void cleanIndividual(Individual<?,?> individual) { for(Property property:individual) { URI propertyId = property.predicate(); for(Value value:property) { individual.removeValue(propertyId,value); } } }
private static void formatIndividual(StringBuilder builder, Individual<?, ?> individual) { PropertyValueFormatter formatter=new PropertyValueFormatter(builder); builder.append(TAB).append("- Individual(").append(FormatUtils.formatId(individual)).append(BLOCK_START).append(NL); for(Property property:individual) { builder.append(TAB).append(TAB).append("+ Property(").append(property.predicate()).append(BLOCK_START).append(NL); for(Value value:property) { value.accept(formatter); } builder.append(TAB).append(TAB).append(BLOCK_END).append(NL); } builder.append(TAB).append(BLOCK_END).append(NL); }
private final boolean mustBeAnalyzed(Property property) { return this.predicate.equals(property.predicate()) && (this.individualId==null || this.individualId.equals(property.individual().id())); }
private void mergeIndividuals(Individual<?, ?> source, Individual<?, ?> target) { for(Property property:source.properties()) { for(Value value:property) { target.addValue(property.predicate(), value); } } }
private <T> String format(T item) { String result=item.toString(); if(item instanceof DataSet) { result="DataSet {"+FormatUtils.formatName(((DataSet)item).name())+"}"; } else if(item instanceof Individual<?,?>) { result="Individual {"+FormatUtils.formatId((Individual<?,?>)item)+"}"; } else if(item instanceof Property) { result="Property {"+((Property)item).predicate()+"}"; } return result; }
public static void remove(Individual<?,?> source, final Individual<?,?> target) { for(Property property:source.properties()) { final URI propertyId=property.predicate(); ValueVisitor visitor = new ValueVisitor(){ @Override public void visitLiteral(Literal<?> value) { target.removeValue(propertyId, value); } @Override public void visitIndividual(Individual<?,?> value) { Individual<?, ?> cValue = target.dataSet().individualOfId(value.id()); if(cValue!=null) { target.removeValue(propertyId, cValue); } } }; for(Value value:property) { value.accept(visitor); } } }
public static ValidationConstraint<Property> mandatoryPropertyValues(Property property) { checkNotNull(property,INDIVIDUAL_IDENTIFIER_CANNOT_BE_NULL); return new MandatoryPropertyValuesValidationConstraint(property.individual().id(), property.predicate(), property.values()); }
public static ValidationConstraint<Property> readOnlyProperty(Property property) { checkNotNull(property,PROPERTY_CANNOT_BE_NULL); return new ReadOnlyPropertyValidationConstraint(property.individual().id(), property.predicate(), property.values()); }
public static void merge(Individual<?,?> source, Individual<?,?> target) { ValueReplicator replicator=new ValueReplicator(target.dataSet()); for(Property property:source.properties()) { for(Value value:property) { target.addValue(property.predicate(),replicator.replicate(value)); } } }
private void contains(DataSet dataSet, DataSet original) { for(Individual<?,?> individual:dataSet) { Individual<?, ?> originalInd = original.individualOfId(individual.id()); assertThat(originalInd,notNullValue()); for(Property property:individual) { assertThat(originalInd.hasProperty(property.predicate()),equalTo(true)); final Property originalProp = originalInd.property(property.predicate()); for(Value value:property) { value.accept( new ValueVisitor() { @Override public void visitLiteral(Literal<?> value) { assertThat(originalProp.hasLiteralValue(value),equalTo(true)); } @Override public void visitIndividual(Individual<?, ?> value) { assertThat(originalProp.hasIdentifiedIndividual(value.id()),equalTo(true)); } }); } } } }