Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Dec 20, 2023
1 parent f9049c4 commit 62ef732
Show file tree
Hide file tree
Showing 73 changed files with 129 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void testVariableNameHandling() throws Exception {
assertTrue(tqr.hasNext());

List<BindingSet> result = QueryResults.asList(tqr);
assertTrue(result.size() > 0);
assertTrue(!result.isEmpty());
for (BindingSet bs : result) {
assertTrue(bs.hasBinding("val"));
assertTrue(bs.hasBinding("s"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public String toASCIIString() {
appendAscii(sb, userInfo);
sb.append('@');
}
if (host.length() > 0) {
if (!host.isEmpty()) {
sb.append(IDN.toASCII(host, IDN.ALLOW_UNASSIGNED));
}
if (port >= 0) {
Expand Down Expand Up @@ -516,7 +516,7 @@ public ParsedIRI normalize() {
boolean localhost = isScheme("file") && userInfo == null && -1 == port
&& ("".equals(host) || "localhost".equals(host));
String _host = localhost ? null
: host == null || host.length() == 0 ? host
: host == null || host.isEmpty() ? host
: IDN.toUnicode(pctEncodingNormalization(toLowerCase(host)),
IDN.USE_STD3_ASCII_RULES | IDN.ALLOW_UNASSIGNED);
String _path = _scheme != null && path == null ? "" : normalizePath(path);
Expand Down Expand Up @@ -581,14 +581,14 @@ public ParsedIRI resolve(ParsedIRI relative) {
// relURI._scheme == null

// RFC, step 2:
if (relative.getHost() == null && relative.getQuery() == null && relative.getPath().length() == 0) {
if (relative.getHost() == null && relative.getQuery() == null && relative.getPath().isEmpty()) {

// Inherit any fragment identifier from relURI
String fragment = relative.getFragment();

return new ParsedIRI(this.getScheme(), this.getUserInfo(), this.getHost(), this.getPort(), this.getPath(),
this.getQuery(), fragment);
} else if (relative.getHost() == null && relative.getPath().length() == 0) {
} else if (relative.getHost() == null && relative.getPath().isEmpty()) {

// Inherit any query or fragment from relURI
String query = relative.getQuery();
Expand Down Expand Up @@ -636,7 +636,7 @@ public ParsedIRI resolve(ParsedIRI relative) {
path = path.substring(0, lastSlashIdx + 1);
}

if (path.length() == 0) {
if (path.isEmpty()) {
// No path means: start at root.
path = "/";
}
Expand Down Expand Up @@ -782,7 +782,7 @@ private void parse() throws URISyntaxException {
if (':' == peek()) {
advance(1);
String p = parseMember(DIGIT, '/');
if (p.length() > 0) {
if (!p.isEmpty()) {
port = Integer.parseInt(p);
} else {
port = -1;
Expand Down Expand Up @@ -1101,7 +1101,7 @@ && isMember(ALPHA, path.codePointAt(1))) {
}

private String pctEncodingNormalization(String path) {
if (path == null || path.length() == 0 || path.indexOf('%') < 0) {
if (path == null || path.isEmpty() || path.indexOf('%') < 0) {
return path; // no pct encodings
}
String[] encodings = listPctEncodings(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ protected void upload(HttpEntity reqEntity, String baseURI, boolean overwrite, b
for (String encodedContext : Protocol.encodeContexts(contexts)) {
url.addParameter(Protocol.CONTEXT_PARAM_NAME, encodedContext);
}
if (baseURI != null && baseURI.trim().length() != 0) {
if (baseURI != null && !baseURI.trim().isEmpty()) {
String encodedBaseURI = Protocol.encodeValue(SimpleValueFactory.getInstance().createIRI(baseURI));
url.setParameter(Protocol.BASEURI_PARAM_NAME, encodedBaseURI);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ protected List<NameValuePair> getUpdateMethodParameters(QueryLanguage ql, String
}

if (dataset != null) {
if (dataset.getDefaultRemoveGraphs().size() > 0) {
if (!dataset.getDefaultRemoveGraphs().isEmpty()) {
if (!(dataset.getDefaultRemoveGraphs().equals(dataset.getDefaultGraphs()))) {
logger.warn(
"ambiguous dataset spec for SPARQL endpoint: default graphs and default remove graphs both defined but not equal");
Expand Down Expand Up @@ -1091,7 +1091,7 @@ protected HttpResponse execute(HttpUriRequest method) throws IOException, RDF4JE
throw new RepositoryException(new RemoteShaclValidationException(
new StringReader(errInfo.toString()), "", format));

} else if (errInfo.toString().length() > 0) {
} else if (!errInfo.toString().isEmpty()) {
throw new RepositoryException(errInfo.toString());
} else {
throw new RepositoryException(response.getStatusLine().getReasonPhrase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected AbstractHTTPQuery(SPARQLProtocolSession httpClient, QueryLanguage quer
// for legacy reasons we should support the empty string for baseURI
// this is used in the SPARQL repository in several places, e.g. in
// getStatements
this.baseURI = baseURI != null && baseURI.length() > 0 ? baseURI : null;
this.baseURI = baseURI != null && !baseURI.isEmpty() ? baseURI : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ public static Duration parseDuration(String s) {
* plus signs cannot be parsed by methods such as {@link Integer#parseInt(String)}.
*/
private static String trimPlusSign(String s) {
if (s.length() > 0 && s.charAt(0) == '+') {
if (!s.isEmpty() && s.charAt(0) == '+') {
return s.substring(1);
} else {
return s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public IRI createIRI(String namespace, String localName) {

@Override
public BNode createBNode(String nodeID) {
if (nodeID.length() < 1) {
if (nodeID.isEmpty()) {
throw new IllegalArgumentException("Blank node ID cannot be empty");
}
if (!isMember(PN_CHARS_U, nodeID.codePointAt(0))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public static boolean isValidLanguageTag(String languageTag) {
public static boolean langMatches(String langTag, String langRange) {
boolean result = false;
if (langRange.equals("*")) {
result = langTag.length() > 0;
result = !langTag.isEmpty();
} else if (langTag.length() == langRange.length()) {
result = langTag.equalsIgnoreCase(langRange);
} else if (langTag.length() > langRange.length()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static boolean isCorrectURISplit(String namespace, String localName) {
assert namespace != null : "namespace must not be null";
assert localName != null : "localName must not be null";

if (namespace.length() == 0) {
if (namespace.isEmpty()) {
return false;
}

Expand Down Expand Up @@ -213,7 +213,7 @@ private static boolean isUnreserved(char c) {
*/
public static boolean isValidLocalName(String name) {
// Empty names are legal
if (name.length() == 0) {
if (name.isEmpty()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public int size() {
@Override
public boolean equals(Object o) {
if (o instanceof BindingSet) {
return ((BindingSet) o).size() == 0;
return ((BindingSet) o).isEmpty();
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,21 @@ class Minimal implements QueryEvaluationContext {
// this field is volatile, as a precaution in case we call it directly.
private volatile Literal now;
private final Dataset dataset;
private final ValueFactory vf;
private final ValueFactory valueFactory;
private final Comparator<Value> comparator;

/**
* Set the shared now value to a preexisting object
*
* @param now that is shared.
* @param dataset that a query should use to evaluate
* @param now that is shared.
* @param dataset that a query should use to evaluate
* @param comparator to use for ordering
*/
public Minimal(Literal now, Dataset dataset, Comparator<Value> comparator) {
super();
this.now = now;
this.dataset = dataset;
this.vf = SimpleValueFactory.getInstance();
this.valueFactory = SimpleValueFactory.getInstance();
this.comparator = comparator;
}

Expand All @@ -85,47 +86,42 @@ public Minimal(Literal now, Dataset dataset, Comparator<Value> comparator) {
* @param dataset that a query should use to evaluate
*/
public Minimal(Literal now, Dataset dataset) {
super();
this.now = now;
this.dataset = dataset;
this.vf = SimpleValueFactory.getInstance();
this.comparator = null;
this(now, dataset, null);
}

/**
* @param dataset that a query should use to evaluate
*/
public Minimal(Dataset dataset) {
this.dataset = dataset;
this.vf = SimpleValueFactory.getInstance();
this.comparator = null;
this(null, dataset);
}

/**
* @param dataset that a query should use to evaluate
* @param dataset that a query should use to evaluate
* @param comparator to use for ordering
*/
public Minimal(Dataset dataset, Comparator<Value> comparator) {
this.dataset = dataset;
this.vf = SimpleValueFactory.getInstance();
this.comparator = comparator;
this(null, dataset, comparator);
}

/**
* @param dataset that a query should use to the evaluate
* @param dataset that a query should use to the evaluate
* @param valueFactory that a query should use to the evaluate
* @param comparator to use for ordering
*
*/
public Minimal(Dataset dataset, ValueFactory vf, Comparator<Value> comparator) {
public Minimal(Dataset dataset, ValueFactory valueFactory, Comparator<Value> comparator) {
this.dataset = dataset;
this.vf = vf;
this.valueFactory = valueFactory;
this.comparator = comparator;
}

/**
* @param dataset that a query should use to the evaluate
* @param dataset that a query should use to the evaluate
* @param valueFactory that a query should use to the evaluate
*/
public Minimal(Dataset dataset, ValueFactory vf) {
this.dataset = dataset;
this.vf = vf;
this.comparator = null;
public Minimal(Dataset dataset, ValueFactory valueFactory) {
this(dataset, valueFactory, null);
}

@Override
Expand All @@ -140,7 +136,7 @@ public Literal getNow() {
// creating a new date is expensive because it uses the XMLGregorianCalendar implementation which is very
// complex.
if (now == null) {
now = vf.createLiteral(new Date());
now = valueFactory.createLiteral(new Date());
boolean success = NOW.compareAndSet(this, null, now);
if (!success) {
now = (Literal) NOW.getAcquire(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BindingSetAssignmentQueryEvaluationStep(BindingSetAssignment node, QueryE
@Override
public CloseableIteration<BindingSet> evaluate(BindingSet bindings) {
final Iterator<BindingSet> assignments = node.getBindingSets().iterator();
if (bindings.size() == 0) {
if (bindings.isEmpty()) {
// we can just return the assignments directly without checking existing bindings
return new CloseableIteratorIteration<>(assignments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BindingAssignerOptimizer implements QueryOptimizer {

@Override
public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
if (bindings.size() > 0) {
if (!bindings.isEmpty()) {
tupleExpr.visit(new VarVisitor(bindings));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static boolean getEffectiveBooleanValue(Value value) throws ValueExprEval
CoreDatatype.XSD datatype = literal.getCoreDatatype().asXSDDatatypeOrNull();

if (datatype == CoreDatatype.XSD.STRING) {
return label.length() > 0;
return !label.isEmpty();
} else if (datatype == CoreDatatype.XSD.BOOLEAN) {
// also false for illegal values
return "true".equals(label) || "1".equals(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Result getEffectiveBooleanValue(Value value) {
CoreDatatype.XSD datatype = literal.getCoreDatatype().asXSDDatatypeOrNull();

if (datatype == CoreDatatype.XSD.STRING) {
return Result.fromBoolean(label.length() > 0);
return Result.fromBoolean(!label.isEmpty());
} else if (datatype == CoreDatatype.XSD.BOOLEAN) {
// also false for illegal values
return Result.fromBoolean("true".equals(label) || "1".equals(label));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.rdf4j.common.annotation.Experimental;

/**
* A natural join between two tuple expressions.
*/
Expand Down Expand Up @@ -72,14 +74,17 @@ public Join clone() {
return (Join) super.clone();
}

@Experimental
public boolean isMergeJoin() {
return mergeJoin;
}

@Experimental
public void setMergeJoin(boolean mergeJoin) {
this.mergeJoin = mergeJoin;
}

@Experimental
public void setCacheable(boolean cacheable) {
this.cacheable = cacheable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Set<String> getBindingNames() {
public Set<String> getAssuredBindingNames() {
Set<String> bindingNames = new HashSet<>();

if (projections.size() >= 1) {
if (!projections.isEmpty()) {
Set<String> assuredSourceNames = getArg().getAssuredBindingNames();

bindingNames.addAll(projections.get(0).getProjectedNamesFor(assuredSourceNames));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ protected Dataset getMergedDataset(Dataset sparqlDefinedDataset) {

// if there are default graphs in the SPARQL update but it's not a WITH
// clause, it's a USING clause
final boolean hasUsingClause = !hasWithClause && sparqlDefaultGraphs != null ? sparqlDefaultGraphs.size() > 0
final boolean hasUsingClause = !hasWithClause && sparqlDefaultGraphs != null ? !sparqlDefaultGraphs.isEmpty()
: false;

final Set<IRI> sparqlNamedGraphs = sparqlDefinedDataset.getNamedGraphs();
final boolean hasUsingNamedClause = sparqlNamedGraphs != null ? sparqlNamedGraphs.size() > 0 : false;
final boolean hasUsingNamedClause = sparqlNamedGraphs != null ? !sparqlNamedGraphs.isEmpty() : false;

if (hasUsingClause) {
// one or more USING-clauses in the update itself, we need to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ protected Dataset getMergedDataset(Dataset sparqlDefinedDataset) {

// if there are default graphs in the SPARQL update but it's not a WITH
// clause, it's a USING clause
final boolean hasUsingClause = !hasWithClause && sparqlDefaultGraphs != null ? sparqlDefaultGraphs.size() > 0
final boolean hasUsingClause = !hasWithClause && sparqlDefaultGraphs != null ? !sparqlDefaultGraphs.isEmpty()
: false;

final Set<IRI> sparqlNamedGraphs = sparqlDefinedDataset.getNamedGraphs();
final boolean hasUsingNamedClause = sparqlNamedGraphs != null ? sparqlNamedGraphs.size() > 0 : false;
final boolean hasUsingNamedClause = sparqlNamedGraphs != null ? !sparqlNamedGraphs.isEmpty() : false;

if (hasUsingClause) {
// one or more USING-clauses in the update itself, we need to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static void main(String[] args) throws java.io.IOException {

int emptyLineCount = 0;
while ((line = in.readLine()) != null) {
if (line.length() > 0) {
if (!line.isEmpty()) {
emptyLineCount = 0;
buf.append(' ').append(line).append('\n');
} else {
Expand All @@ -269,7 +269,7 @@ public static void main(String[] args) throws java.io.IOException {
if (emptyLineCount == 2) {
emptyLineCount = 0;
String queryStr = buf.toString().trim();
if (queryStr.length() > 0) {
if (!queryStr.isEmpty()) {
try {
long start = System.currentTimeMillis();
ParsedOperation parsedQuery = QueryParserUtil.parseOperation(QueryLanguage.SPARQL, queryStr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public TupleExpr visit(ASTSelect node, Object data) throws VisitorException {
AggregateCollector collector = new AggregateCollector();
valueExpr.visit(collector);

if (collector.getOperators().size() > 0) {
if (!collector.getOperators().isEmpty()) {
elem.setAggregateOperatorInExpression(true);
for (AggregateOperator operator : collector.getOperators()) {
// Apply implicit grouping if necessary
Expand Down Expand Up @@ -1150,7 +1150,7 @@ public String visit(ASTGroupCondition node, Object data) throws VisitorException
extension.addElement(elem);
}

if (extension.getElements().size() > 0 && !(arg instanceof Extension)) {
if (!extension.getElements().isEmpty() && !(arg instanceof Extension)) {
extension.setArg(arg);
group.setArg(extension);
}
Expand Down
Loading

0 comments on commit 62ef732

Please sign in to comment.