Skip to content

Commit 119467e

Browse files
committed
merge latest updates from master branch
1 parent 6a4648c commit 119467e

10 files changed

Lines changed: 816 additions & 33 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Distribution License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/org/documents/edl-v10.php.
7+
*******************************************************************************/
8+
package org.eclipse.rdf4j.model.util;
9+
10+
import java.util.Optional;
11+
12+
import org.eclipse.rdf4j.model.IRI;
13+
import org.eclipse.rdf4j.model.Resource;
14+
import org.eclipse.rdf4j.model.Statement;
15+
import org.eclipse.rdf4j.model.Value;
16+
17+
/**
18+
* Either supplies a statement matching the given pattern, or
19+
* {@link Optional#empty()} otherwise.
20+
*
21+
* @author Peter Ansell
22+
*/
23+
@FunctionalInterface
24+
public interface GetStatementOptional {
25+
26+
/**
27+
* Either supplies a statement matching the given pattern, or
28+
* {@link Optional#empty()} otherwise.
29+
*
30+
* @param subject
31+
* A {@link Resource} to be used to match to statements.
32+
* @param predicate
33+
* An {@link IRI} to be used to match to statements.
34+
* @param object
35+
* A {@link Value} to be used to match to statements.
36+
* @param contexts
37+
* An array of context {@link Resource} objects, or left out (not
38+
* null) to select from all contexts.
39+
* @return An {@link Optional} either containing a single statement matching
40+
* the pattern or {@link Optional#empty()} otherwise.
41+
*/
42+
Optional<Statement> get(Resource subject, IRI predicate, Value object, Resource... contexts);
43+
44+
}

core/model/src/main/java/org/eclipse/rdf4j/model/util/ModelException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*******************************************************************************/
88
package org.eclipse.rdf4j.model.util;
99

10-
import org.eclipse.rdf4j.model.Model;
10+
import org.eclipse.rdf4j.OpenRDFException;
1111
import org.eclipse.rdf4j.model.Value;
1212

1313
/**
@@ -16,7 +16,7 @@
1616
*
1717
* @author Arjohn Kampman
1818
*/
19-
public class ModelException extends RuntimeException {
19+
public class ModelException extends OpenRDFException {
2020

2121
private static final long serialVersionUID = 3886967415616842867L;
2222

core/model/src/main/java/org/eclipse/rdf4j/model/util/Models.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Objects;
1616
import java.util.Optional;
1717
import java.util.Set;
18-
import java.util.stream.Stream;
18+
import java.util.function.Supplier;
1919

2020
import org.eclipse.rdf4j.model.BNode;
2121
import org.eclipse.rdf4j.model.IRI;
@@ -79,7 +79,8 @@ public static Value anyObject(Model m) {
7979
* @since 4.0
8080
*/
8181
public static Optional<Literal> objectLiteral(Model m) {
82-
return m.stream().map(st -> st.getObject()).filter(o -> o instanceof Literal).map(l -> (Literal)l).findAny();
82+
return m.stream().map(st -> st.getObject()).filter(o -> o instanceof Literal).map(
83+
l -> (Literal)l).findAny();
8384
}
8485

8586
/**
@@ -103,7 +104,8 @@ public static Literal anyObjectLiteral(Model m) {
103104
* @since 4.0
104105
*/
105106
public static Optional<Resource> objectResource(Model m) {
106-
return m.stream().map(st -> st.getObject()).filter(o -> o instanceof Resource).map(r -> (Resource)r).findAny();
107+
return m.stream().map(st -> st.getObject()).filter(o -> o instanceof Resource).map(
108+
r -> (Resource)r).findAny();
107109
}
108110

109111
/**
@@ -128,16 +130,17 @@ public static Resource anyObjectResource(Model m) {
128130
public static Optional<IRI> objectIRI(Model m) {
129131
return m.stream().map(st -> st.getObject()).filter(o -> o instanceof IRI).map(r -> (IRI)r).findAny();
130132
}
131-
133+
132134
/**
133135
* Retrieves an object value as a String from the statements in the given
134-
* model. If more than one possible object value exists, any one value is picked
135-
* and returned.
136+
* model. If more than one possible object value exists, any one value is
137+
* picked and returned.
136138
*
137139
* @param m
138140
* the model from which to retrieve an object String value.
139-
* @return an {@link Optional} object String value from the given model, which
140-
* will be {@link Optional#empty() empty} if no such value exists.
141+
* @return an {@link Optional} object String value from the given model,
142+
* which will be {@link Optional#empty() empty} if no such value
143+
* exists.
141144
* @since 4.0
142145
*/
143146
public static Optional<String> objectString(Model m) {
@@ -210,7 +213,8 @@ public static URI anySubjectURI(Model m) {
210213
* @since 4.0
211214
*/
212215
public static Optional<BNode> subjectBNode(Model m) {
213-
return m.stream().map(st -> st.getSubject()).filter(s -> s instanceof BNode).map(s -> (BNode)s).findAny();
216+
return m.stream().map(st -> st.getSubject()).filter(s -> s instanceof BNode).map(
217+
s -> (BNode)s).findAny();
214218
}
215219

216220
/**
@@ -573,4 +577,18 @@ private static <S extends Statement> Set<S> toSet(Iterable<S> iterable) {
573577
}
574578
return set;
575579
}
580+
581+
/**
582+
* Creates a {@link Supplier} of {@link ModelException} objects that be
583+
* passed to {@link Optional#orElseThrow(Supplier)} to generate exceptions as
584+
* necessary.
585+
*
586+
* @param message
587+
* The message to be used for the exception
588+
* @return A {@link Supplier} that will create {@link ModelException} objects
589+
* with the given message.
590+
*/
591+
public static Supplier<ModelException> modelException(String message) {
592+
return () -> new ModelException(message);
593+
}
576594
}

0 commit comments

Comments
 (0)