Skip to content

Commit ad5d02e

Browse files
committed
issue #834 : Add NamespaceAware to abstract Model getNamespaces
Abstracts out the Model getNamespace methods to a new NamespaceAware interface that can be reused to make other code more generic Signed-off-by: Peter Ansell <p_ansell@yahoo.com>
1 parent f42cee6 commit ad5d02e

2 files changed

Lines changed: 43 additions & 20 deletions

File tree

core/model/src/main/java/org/eclipse/rdf4j/model/Model.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @see org.eclipse.rdf4j.model.util.Models the Models utility class
2929
*/
3030
@SuppressWarnings("deprecation")
31-
public interface Model extends Graph, Set<Statement>, Serializable {
31+
public interface Model extends Graph, Set<Statement>, Serializable, NamespaceAware {
3232

3333
/**
3434
* Returns an unmodifiable view of this model. This method provides "read-only" access to this model.
@@ -40,25 +40,6 @@ public interface Model extends Graph, Set<Statement>, Serializable {
4040
*/
4141
public Model unmodifiable();
4242

43-
/**
44-
* Gets the map that contains the assigned namespaces.
45-
*
46-
* @return Map of prefix to namespace
47-
*/
48-
public Set<Namespace> getNamespaces();
49-
50-
/**
51-
* Gets the namespace that is associated with the specified prefix, if any.
52-
*
53-
* @param prefix
54-
* A namespace prefix.
55-
* @return The namespace name that is associated with the specified prefix, or {@link Optional#empty()} if
56-
* there is no such namespace.
57-
*/
58-
public default Optional<Namespace> getNamespace(String prefix) {
59-
return getNamespaces().stream().filter(t -> t.getPrefix().equals(prefix)).findAny();
60-
}
61-
6243
/**
6344
* Sets the prefix for a namespace. This will replace any existing namespace associated to the prefix.
6445
*
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Eclipse RDF4J contributors 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;
9+
10+
import java.util.Optional;
11+
import java.util.Set;
12+
13+
/**
14+
* An interface that is used to signify that something is able to provide {@link Namespace} information, in
15+
* addition to {@link Statement}s.
16+
*
17+
* @author Peter Ansell
18+
*/
19+
@FunctionalInterface
20+
public interface NamespaceAware {
21+
22+
/**
23+
* Gets the set that contains the assigned namespaces.
24+
*
25+
* @return A {@link Set} containing the {@link Namespace} objects that are available.
26+
*/
27+
public Set<Namespace> getNamespaces();
28+
29+
/**
30+
* Gets the namespace that is associated with the specified prefix, if any. If multiple namespaces match
31+
* the given prefix, the result may not be consistent over successive calls to this method.
32+
*
33+
* @param prefix
34+
* A namespace prefix.
35+
* @return The namespace name that is associated with the specified prefix, or {@link Optional#empty()} if
36+
* there is no such namespace.
37+
*/
38+
public default Optional<Namespace> getNamespace(String prefix) {
39+
return getNamespaces().stream().filter(t -> t.getPrefix().equals(prefix)).findAny();
40+
}
41+
42+
}

0 commit comments

Comments
 (0)