1515import java .util .Objects ;
1616import java .util .Optional ;
1717import java .util .Set ;
18- import java .util .stream . Stream ;
18+ import java .util .function . Supplier ;
1919
2020import org .eclipse .rdf4j .model .BNode ;
2121import 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