|
| 1 | +package org.linkeddatafragments.fragments.tpf; |
| 2 | + |
| 3 | +/** |
| 4 | + * A factory for {@link TriplePatternElement}s. |
| 5 | + * |
| 6 | + * @param <TermType> type for representing RDF terms in triple patterns |
| 7 | + * @param <VarType> type for representing specific variables in triple patterns |
| 8 | + * |
| 9 | + * @author <a href="http://olafhartig.de">Olaf Hartig</a> |
| 10 | + */ |
| 11 | +public class TriplePatternElementFactory<TermType,VarType> |
| 12 | +{ |
| 13 | + public TriplePatternElement<TermType,VarType> createUnspecifiedVariable() { |
| 14 | + return new UnspecifiedVariable<TermType,VarType>(); |
| 15 | + } |
| 16 | + |
| 17 | + public TriplePatternElement<TermType,VarType> createSpecificVariable( |
| 18 | + final VarType variable ) { |
| 19 | + return new SpecificVariable<TermType,VarType>( variable ); |
| 20 | + } |
| 21 | + public TriplePatternElement<TermType,VarType> createRDFTerm( |
| 22 | + final TermType term ) { |
| 23 | + return new RDFTerm<TermType,VarType>( term ); |
| 24 | + } |
| 25 | + |
| 26 | + static abstract public class Variable<TermType,VarType> |
| 27 | + implements TriplePatternElement<TermType,VarType> |
| 28 | + { |
| 29 | + public boolean isVariable() { return true; } |
| 30 | + public TermType asTerm() { throw new UnsupportedOperationException(); } |
| 31 | + } |
| 32 | + |
| 33 | + static public class UnspecifiedVariable<TermType,VarType> |
| 34 | + extends Variable<TermType,VarType> |
| 35 | + { |
| 36 | + public boolean isSpecificVariable() { return false; } |
| 37 | + public VarType asVariable() { throw new UnsupportedOperationException(); } |
| 38 | + public String toString() { return "UnspecifiedVariable"; } |
| 39 | + } |
| 40 | + |
| 41 | + static public class SpecificVariable<TermType,VarType> |
| 42 | + extends Variable<TermType,VarType> |
| 43 | + { |
| 44 | + protected final VarType v; |
| 45 | + public SpecificVariable( final VarType variable ) { v = variable; } |
| 46 | + public boolean isSpecificVariable() { return true; } |
| 47 | + public VarType asVariable() { return v; } |
| 48 | + public String toString() { return "SpecificVariable(" + v.toString() + ")"; } |
| 49 | + } |
| 50 | + |
| 51 | + static public class RDFTerm<TermType,VarType> |
| 52 | + implements TriplePatternElement<TermType,VarType> |
| 53 | + { |
| 54 | + protected final TermType t; |
| 55 | + public RDFTerm( final TermType term ) { t = term; } |
| 56 | + public boolean isVariable() { return false; } |
| 57 | + public boolean isSpecificVariable() { return false; } |
| 58 | + public VarType asVariable() { throw new UnsupportedOperationException(); } |
| 59 | + public TermType asTerm() { return t; } |
| 60 | + public String toString() { return "RDFTerm(" + t.toString() + ")(type: " + t.getClass().getSimpleName() + ")"; } |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments