org.linkeddatafragments.fragments.tpf.TriplePatternElementFactory Maven / Gradle / Ivy
package org.linkeddatafragments.fragments.tpf;
/**
* A factory for {@link ITriplePatternElement}s.
*
* @param
* type for representing constants in triple patterns (i.e., URIs and
* literals)
* @param
* type for representing named variables in triple patterns
* @param
* type for representing anonymous variables in triple patterns (i.e.,
* variables denoted by a blank node)
*
* @author Olaf Hartig
*/
public class TriplePatternElementFactory
{
/**
*
* @return
*/
public ITriplePatternElement createUnspecifiedVariable()
{
return new UnspecifiedVariable();
}
/**
*
* @param v
* @return
*/
public ITriplePatternElement createNamedVariable(final NVT v )
{
return new NamedVariable( v );
}
/**
*
* @param bnode
* @return
*/
public ITriplePatternElement createAnonymousVariable(
final AVT bnode )
{
return new AnonymousVariable( bnode );
}
/**
*
* @param term
* @return
*/
public ITriplePatternElement createConstantRDFTerm(
final CTT term )
{
return new ConstantRDFTerm( term );
}
/**
*
* @param
* @param
* @param
*/
static abstract public class Variable
implements ITriplePatternElement
{
@Override
public boolean isVariable() { return true; }
@Override
public CTT asConstantTerm() { throw new UnsupportedOperationException(); }
}
/**
*
* @param
* @param
* @param
*/
static public class UnspecifiedVariable
extends Variable
{
@Override
public boolean isSpecificVariable() { return false; }
@Override
public boolean isNamedVariable() { return false; }
@Override
public NVT asNamedVariable() { throw new UnsupportedOperationException(); }
@Override
public boolean isAnonymousVariable() { return false; }
@Override
public AVT asAnonymousVariable() { throw new UnsupportedOperationException(); }
@Override
public String toString() { return "UnspecifiedVariable"; }
}
/**
*
* @param
* @param
* @param
*/
static abstract public class SpecificVariable
extends Variable
{
@Override
public boolean isSpecificVariable() { return true; }
}
/**
*
* @param
* @param
* @param
*/
static public class NamedVariable
extends SpecificVariable
{
/**
*
*/
protected final NVT v;
/**
*
* @param variable
*/
public NamedVariable( final NVT variable ) { v = variable; }
@Override
public boolean isNamedVariable() { return true; }
@Override
public NVT asNamedVariable() { return v; }
@Override
public boolean isAnonymousVariable() { return false; }
@Override
public AVT asAnonymousVariable() { throw new UnsupportedOperationException(); }
@Override
public String toString() { return "NamedVariable(" + v.toString() + ")"; }
}
/**
*
* @param
* @param
* @param
*/
static public class AnonymousVariable
extends SpecificVariable
{
/**
*
*/
protected final AVT bn;
/**
*
* @param bnode
*/
public AnonymousVariable( final AVT bnode ) { bn = bnode; }
@Override
public boolean isNamedVariable() { return false; }
@Override
public NVT asNamedVariable() { throw new UnsupportedOperationException(); }
@Override
public boolean isAnonymousVariable() { return true; }
@Override
public AVT asAnonymousVariable() { return bn; }
@Override
public String toString() { return "AnonymousVariable(" + bn.toString() + ")"; }
}
/**
*
* @param
* @param
* @param
*/
static public class ConstantRDFTerm
implements ITriplePatternElement
{
/**
*
*/
protected final CTT t;
/**
*
* @param term
*/
public ConstantRDFTerm( final CTT term ) { t = term; }
@Override
public boolean isVariable() { return false; }
@Override
public boolean isSpecificVariable() { return false; }
@Override
public boolean isNamedVariable() { return false; }
@Override
public NVT asNamedVariable() { throw new UnsupportedOperationException(); }
@Override
public boolean isAnonymousVariable() { return false; }
@Override
public AVT asAnonymousVariable() { throw new UnsupportedOperationException(); }
@Override
public CTT asConstantTerm() { return t; }
@Override
public String toString() { return "ConstantRDFTerm(" + t.toString() + ")(type: " + t.getClass().getSimpleName() + ")"; }
}
}