Skip to content

Commit f411906

Browse files
committed
Added initial VocabUtil code
Signed-off-by:Bart Hanssens <bart.hanssens@fedict.be>
1 parent d5e7815 commit f411906

1 file changed

Lines changed: 44 additions & 0 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) 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.util;
9+
10+
import java.lang.reflect.Field;
11+
import java.lang.reflect.Modifier;
12+
import java.util.HashSet;
13+
import java.util.Set;
14+
15+
import org.eclipse.rdf4j.model.IRI;
16+
17+
/**
18+
* Utility functions for working with vocabularies.
19+
*
20+
* @author Bart Hanssens
21+
*/
22+
public class VocabUtil {
23+
24+
/**
25+
* Get all the {@link IRI IRIs} of the classes and properties of a vocabulary.
26+
*
27+
* @param vocabulary RDF vocabulary
28+
* @return set of IRIs
29+
*/
30+
public static Set<IRI> getVocabularyIRIs(Class vocabulary) {
31+
Set<IRI> iris = new HashSet<>();
32+
33+
for(Field f : vocabulary.getFields ()) {
34+
if (f.getType().equals(IRI.class) && Modifier.isPublic(f.getModifiers())) {
35+
try {
36+
iris.add((IRI) f.get(f));
37+
} catch (IllegalArgumentException|IllegalAccessException ex) {
38+
// should not happen
39+
}
40+
}
41+
}
42+
return iris;
43+
}
44+
}

0 commit comments

Comments
 (0)