Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,41 @@ public static List<String> multiValueURI(Resource r, Property p) {
return values;
}

/** @deprecated */
@Deprecated(forRemoval=true)
public static boolean exactlyOneProperty(Resource r, Property p) {
StmtIterator sIter = r.listProperties(p);
try {
if ( !sIter.hasNext() )
return false;
sIter.next();
if ( sIter.hasNext() )
return false;
}
finally {
sIter.close();
}
return true;
}

/** Returns for exactly one object of a subject-property, else return false. */
public static boolean checkExactlyOneProperty(Resource r, Property p) {
StmtIterator sIter = r.listProperties(p);
try {
if ( !sIter.hasNext() )
return false;
sIter.next();
if ( sIter.hasNext() )
return false;
}
finally {
sIter.close();
}
return true;
}

/** Check for exactly one object of a subject-property. Throw an exception is this condition is not correct. */
public static void exactlyOnePropertyEx(Resource r, Property p) {
StmtIterator sIter = r.listProperties(p);
try {
if ( !sIter.hasNext() )
Expand All @@ -154,9 +188,10 @@ public static boolean exactlyOneProperty(Resource r, Property p) {
finally {
sIter.close();
}
return true;
}

/** @deprecated Use {@link #atMostOneProperty} which always returns a boolean and does not throw exceptions. */
@Deprecated(forRemoval = true)
public static boolean atmostOneProperty(Resource r, Property p) {
StmtIterator sIter = r.listProperties(p);
try {
Expand All @@ -172,8 +207,24 @@ public static boolean atmostOneProperty(Resource r, Property p) {
return true;
}

/** Check whether the resource-property pair has zero or one values. Return true or false. */
public static boolean atMostOneProperty(Resource r, Property p) {
StmtIterator sIter = r.listProperties(p);
try {
if ( !sIter.hasNext() )
return true;
sIter.next();
if ( sIter.hasNext() )
return false;
}
finally {
sIter.close();
}
return true;
}

public static boolean getBooleanValue(Resource r, Property p) {
if ( !GraphUtils.atmostOneProperty(r, p) )
if ( !GraphUtils.atMostOneProperty(r, p) )
throw new NotUniqueException(r, p);
Statement s = r.getProperty(p);
if ( s == null )
Expand Down Expand Up @@ -249,7 +300,7 @@ private static String asFilename(Resource r) {
}

public static RDFNode getAsRDFNode(Resource r, Property p) {
if ( !atmostOneProperty(r, p) )
if ( !atMostOneProperty(r, p) )
throw new NotUniqueException(r, p);
Statement s = r.getProperty(p);
if ( s == null )
Expand All @@ -258,7 +309,7 @@ public static RDFNode getAsRDFNode(Resource r, Property p) {
}

public static Resource getResourceValue(Resource r, Property p) {
if ( !atmostOneProperty(r, p) )
if ( !atMostOneProperty(r, p) )
throw new NotUniqueException(r, p);
Statement s = r.getProperty(p);
if ( s == null )
Expand Down Expand Up @@ -319,7 +370,7 @@ public static Iterator<Node> allNodes(Graph graph) {
return distinctIterator;
}

static class IterSO extends NiceIterator<Node> {
private static class IterSO extends NiceIterator<Node> {
private ExtendedIterator<Triple> it;
private boolean tripleConsumed;
private Triple triple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class AssemblerAccessDataset extends AssemblerBase {
*/
@Override
public Dataset open(Assembler a, Resource root, Mode mode) {
if ( ! GraphUtils.exactlyOneProperty(root, VocabSecurity.pSecurityRegistry) )
if ( ! GraphUtils.checkExactlyOneProperty(root, VocabSecurity.pSecurityRegistry) )
throw new AssemblerException(root, "Expected exactly one access:registry property");
if ( ! GraphUtils.exactlyOneProperty(root, VocabSecurity.pDataset) )
if ( ! GraphUtils.checkExactlyOneProperty(root, VocabSecurity.pDataset) )
throw new AssemblerException(root, "Expected exactly one access:dataset property");

RDFNode rnRegistry = root.getProperty(VocabSecurity.pSecurityRegistry).getObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ private void parseList(MultiValuedMap<String, Node> map, Resource root, GNode en

/** Format:: access:entry [ :user "user2"; :graphs (<http://host/graphname3> ) ] */
private void parseStruct(MultiValuedMap<String, Node> map, Resource root, Resource r) {
if ( ! GraphUtils.exactlyOneProperty(r, VocabSecurity.pUser) )
if ( ! GraphUtils.checkExactlyOneProperty(r, VocabSecurity.pUser) )
throw new AssemblerException(root, "Expected exactly one access:user property for "+r);
if ( ! GraphUtils.exactlyOneProperty(r, VocabSecurity.pGraphs) )
if ( ! GraphUtils.checkExactlyOneProperty(r, VocabSecurity.pGraphs) )
throw new AssemblerException(root, "Expected exactly one access:graphs property for "+r);

String user = GraphUtils.getStringValue(r, VocabSecurity.pUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package org.apache.jena.rdfpatch.filelog;

import static org.apache.jena.sparql.util.graph.GraphUtils.exactlyOneProperty;
import static org.apache.jena.sparql.util.graph.GraphUtils.checkExactlyOneProperty;

import java.util.List;

Expand Down Expand Up @@ -69,7 +69,7 @@ public AssemblerFileLog() {}

@Override
public Object open(Assembler a, Resource root, Mode mode) {
if ( !exactlyOneProperty(root, VocabPatch.pDataset) )
if ( !checkExactlyOneProperty(root, VocabPatch.pDataset) )
throw new AssemblerException(root, "No dataset to be logged");
if ( !root.hasProperty(VocabPatch.pLogFile) )
throw new AssemblerException(root, "No log file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package org.apache.jena.tdb2.assembler;

import static org.apache.jena.sparql.util.graph.GraphUtils.exactlyOneProperty;
import static org.apache.jena.sparql.util.graph.GraphUtils.checkExactlyOneProperty;
import static org.apache.jena.sparql.util.graph.GraphUtils.getAsFilename;
import static org.apache.jena.tdb2.assembler.VocabTDB2.pLocation;
import static org.apache.jena.tdb2.assembler.VocabTDB2.pUnionDefaultGraph;
Expand Down Expand Up @@ -54,7 +54,7 @@ public DatasetGraph createDataset(Assembler a, Resource root) {
}

public static DatasetGraph make(Assembler a, Resource root) {
if ( !exactlyOneProperty(root, pLocation) )
if ( !checkExactlyOneProperty(root, pLocation) )
throw new AssemblerException(root, "No location given");

String dir = getAsFilename(root, pLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
import org.apache.jena.rdf.model.RDFNode ;
import org.apache.jena.rdf.model.Resource ;
import org.apache.jena.rdf.model.Statement ;
import org.apache.jena.sparql.util.graph.GraphUtils ;
import org.apache.lucene.analysis.Analyzer ;
import org.apache.lucene.store.*;

import static org.apache.jena.query.text.assembler.TextVocab.*;
import static org.apache.jena.sparql.util.graph.GraphUtils.checkExactlyOneProperty;
import static org.apache.jena.sparql.util.graph.GraphUtils.getResourceValue;

public class TextIndexLuceneAssembler extends AssemblerBase {
/*
Expand All @@ -53,7 +54,7 @@ public class TextIndexLuceneAssembler extends AssemblerBase {
@Override
public TextIndex open(Assembler a, Resource root, Mode mode) {
try {
if ( !GraphUtils.exactlyOneProperty(root, pDirectory) )
if ( !checkExactlyOneProperty(root, pDirectory) )
throw new TextIndexException("No 'text:directory' property on " + root) ;

Directory directory ;
Expand Down Expand Up @@ -200,7 +201,7 @@ public TextIndex open(Assembler a, Resource root, Mode mode) {
cacheQueries = cqNode.asLiteral().getBoolean();
}

Resource r = GraphUtils.getResourceValue(root, pEntityMap) ;
Resource r = getResourceValue(root, pEntityMap) ;
EntityDefinition docDef = (EntityDefinition)a.open(r) ;
TextIndexConfig config = new TextIndexConfig(docDef);
config.setAnalyzer(analyzer);
Expand Down