Skip to content

Commit fa375f6

Browse files
authored
Merge pull request #101 from eclipse-researchlabs/reduceCodeDuplication
reduce code duplication
2 parents 8ea19c9 + 130c889 commit fa375f6

File tree

8 files changed

+845
-1081
lines changed

8 files changed

+845
-1081
lines changed

context-core/src/main/java/de/atb/context/common/util/SPARQLHelper.java

+33-44
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* #L%
1515
*/
1616

17-
import org.apache.jena.rdf.model.ResourceFactory;
1817
import org.apache.jena.rdf.model.Property;
18+
import org.apache.jena.rdf.model.ResourceFactory;
1919
import thewebsemantic.Namespace;
2020
import thewebsemantic.RdfType;
2121

@@ -24,57 +24,46 @@
2424
*
2525
* @author scholze
2626
* @version $LastChangedRevision: 417 $
27-
*
2827
*/
2928
public class SPARQLHelper {
30-
private SPARQLHelper() {}
29+
private SPARQLHelper() {
30+
}
3131

32-
public static String appendDefaultPrefixes(final String sparqlQuery) {
32+
public static String appendDefaultPrefixes(final String sparqlQuery) {
3333
return SPARQLPrefixMappings.getAllAsPrefixString() + sparqlQuery;
34-
}
34+
}
3535

36-
public static synchronized <T> String getRdfNamespace(
37-
final Class<T> clazz) {
38-
final Namespace namespaceAnnotation = clazz
39-
.getAnnotation(Namespace.class);
40-
if (namespaceAnnotation == null) {
41-
throw new IllegalArgumentException(
42-
"Clazz must be annotated with thewebsemantic.Namespace annotation.");
43-
}
44-
return namespaceAnnotation.value().endsWith("/") ? namespaceAnnotation
45-
.value() : namespaceAnnotation.value() + "/";
46-
}
36+
public static synchronized <T> String getRdfNamespace(final Class<T> clazz) {
37+
final Namespace namespaceAnnotation = clazz.getAnnotation(Namespace.class);
38+
if (namespaceAnnotation == null) {
39+
throw new IllegalArgumentException("Clazz must be annotated with thewebsemantic.Namespace annotation.");
40+
}
41+
return namespaceAnnotation.value().endsWith("/")
42+
? namespaceAnnotation.value()
43+
: namespaceAnnotation.value() + "/";
44+
}
4745

48-
public static synchronized <T> String getRdfType(final Class<T> clazz) {
49-
final RdfType typeAnnotation = clazz.getAnnotation(RdfType.class);
50-
if (typeAnnotation == null) {
51-
throw new IllegalArgumentException(
52-
"Clazz must be annotated with thewebsemantic.RdfType annotation.");
53-
}
54-
return typeAnnotation.value();
55-
}
46+
public static synchronized <T> String getRdfType(final Class<T> clazz) {
47+
final RdfType typeAnnotation = clazz.getAnnotation(RdfType.class);
48+
if (typeAnnotation == null) {
49+
throw new IllegalArgumentException("Clazz must be annotated with thewebsemantic.RdfType annotation.");
50+
}
51+
return typeAnnotation.value();
52+
}
5653

57-
public static synchronized <T> String getRdfPropertyQualifier(
58-
final Class<T> clazz, final String propertyName) {
59-
return String.format("<%s%s>", SPARQLHelper.getRdfNamespace(clazz),
60-
propertyName);
61-
}
54+
public static synchronized <T> String getRdfPropertyQualifier(final Class<T> clazz, final String propertyName) {
55+
return String.format("<%s%s>", SPARQLHelper.getRdfNamespace(clazz), propertyName);
56+
}
6257

63-
public static synchronized <T> Property createProperty(
64-
final Class<T> clazz, final String propertyName) {
65-
return ResourceFactory.createProperty(String.format("%s%s",
66-
SPARQLHelper.getRdfNamespace(clazz), propertyName));
67-
}
58+
public static synchronized <T> Property createProperty(final Class<T> clazz, final String propertyName) {
59+
return ResourceFactory.createProperty(String.format("%s%s", SPARQLHelper.getRdfNamespace(clazz), propertyName));
60+
}
6861

69-
public static synchronized <T> String getRdfClassQualifier(
70-
final Class<T> clazz) {
71-
return String.format("<%s%s>", SPARQLHelper.getRdfNamespace(clazz),
72-
SPARQLHelper.getRdfType(clazz));
73-
}
62+
public static synchronized <T> String getRdfClassQualifier(final Class<T> clazz) {
63+
return String.format("<%s%s>", SPARQLHelper.getRdfNamespace(clazz), SPARQLHelper.getRdfType(clazz));
64+
}
7465

75-
public static synchronized <T> String getRdfClassQualifierWithoutBraces(
76-
final Class<T> clazz) {
77-
return String.format("%s%s", SPARQLHelper.getRdfNamespace(clazz),
78-
SPARQLHelper.getRdfType(clazz));
79-
}
66+
public static synchronized <T> String getRdfClassQualifierWithoutBraces(final Class<T> clazz) {
67+
return String.format("%s%s", SPARQLHelper.getRdfNamespace(clazz), SPARQLHelper.getRdfType(clazz));
68+
}
8069
}

0 commit comments

Comments
 (0)