public final class MergedRestriction extends Intersection
Helper class to handle multiple PropertyRestriction
s of the same
property.
There is often more than one restriction for a specific property, e.g. a
minimum cardinality restriction and a maximum cardinality restriction. All
these restrictions must be specified separately by an instance of
PropertyRestriction
. This class helps to manage multiple restrictions
for the same property.
NOTE: If you add this class to another Resource with
setProperty(String, Object)
, it will behave like an
Intersection
of the restrictions contained in this MergedRestriction.
Modifier and Type | Field and Description |
---|---|
static int |
allValuesFromID
ID of the
AllValuesFromRestriction . |
static int |
exactCardinalityID
ID of the
ExactCardinalityRestriction . |
static int |
hasValueID
ID of the
HasValueRestriction . |
static int |
MAX_UNDEFINED
The value of maximum cardinality if not defined.
|
static int |
maxCardinalityID
ID of the
MaxCardinalityRestriction . |
static int |
MIN_UNDEFINED
The value of minimum cardinality if not defined.
|
static int |
minCardinalityID
ID of the
MinCardinalityRestriction . |
static String |
MY_URI
URI for this class.
|
static int |
someValuesFromID
ID of the
SomeValuesFromRestriction . |
PROP_OWL_INTERSECTION_OF, types
EXCEPTION_TTL, OWL_CLASS, OWL_NAMESPACE, PROP_RDFS_SUB_CLASS_OF, RDFS_DATATYPE, TYPE_OWL_THING
ANON_URI_PREFIX, blockAddingTypes, isXMLLiteral, NAMESPACE_PREFIX, ns_delim_index, PROP_INVOLVED_HUMAN_USER, PROP_RDF_FIRST, PROP_RDF_REST, PROP_RDF_TYPE, PROP_RDFS_COMMENT, PROP_RDFS_LABEL, PROP_SERIALIZATION_FULL, PROP_SERIALIZATION_OPTIONAL, PROP_SERIALIZATION_REDUCED, PROP_SERIALIZATION_UNDEFINED, props, RDF_EMPTY_LIST, RDF_NAMESPACE, RDFS_NAMESPACE, SERVICE_NAMESPACE, TYPE_RDF_LIST, TYPE_RDFS_CLASS, uri, VOCABULARY_NAMESPACE
Constructor and Description |
---|
MergedRestriction()
Constructor for deserializers.
|
MergedRestriction(String onProperty)
Constructor for an empty set of restrictions.
|
MergedRestriction(String onProperty,
ArrayList<PropertyRestriction> restrictions)
Constructor with a given initial set of restrictions.
|
Modifier and Type | Method and Description |
---|---|
MergedRestriction |
addRestriction(MergedRestriction r)
Add all restrictions of the given
MergedRestriction , performing a
sanity check. |
MergedRestriction |
addRestriction(PropertyRestriction res)
Add a new Restriction, performing a sanity check.
|
boolean |
addRestrictionCheck(PropertyRestriction res)
Add a new Restriction, performing a sanity check.
|
MergedRestriction |
appendTo(MergedRestriction root,
String[] path)
Appends this restriction to the given root restriction on the given
property path.
|
TypeExpression |
copy()
Create a copy of this object, i.e.
|
MergedRestriction |
copyOnNewProperty(String onProp)
Create a new
MergedRestriction with modified onProperty value. |
MergedRestriction |
copyWithNewCardinality(int min,
int max)
Create a new
MergedRestriction with modified cardinality
restrictions. |
static MergedRestriction |
getAllValuesRestriction(String propURI,
String typeURI)
Create a new restriction to state that for all individuals of a certain
class the value of the given property is of type
typeURI . |
static MergedRestriction |
getAllValuesRestriction(String propURI,
TypeExpression expr)
Create a new restriction to state that for all individuals of a certain
class the value of the given property is of type
expr . |
static MergedRestriction |
getAllValuesRestrictionWithCardinality(String propURI,
String typeURI,
int min,
int max)
Create a new restriction to state that for all individuals of a certain
class the cardinality of the given property is at least
min
and at most max and the value of the given property is of
type typeURI . |
static MergedRestriction |
getAllValuesRestrictionWithCardinality(String propURI,
TypeExpression expr,
int min,
int max)
Create a new restriction to state that for all individuals of a certain
class the cardinality of the given property is at least
min
and at most max and the value of the given property is of
type expr . |
static MergedRestriction |
getCardinalityRestriction(String propURI,
int min,
int max)
Create a new restriction to state that for all individuals of a certain
class the cardinality of the given property is at least
min
and at most max . |
Object |
getConstraint(int id)
Get the constraint of a specific restriction, e.g.
|
Object[] |
getEnumeratedValues()
Get the set of instances.
|
static MergedRestriction |
getFixedValueRestriction(String propURI,
Object value)
Create a new restriction to state that all individuals of a certain class
must have the given value for the given property.
|
static ArrayList<MergedRestriction> |
getFromList(List<?> o)
Get a list of
MergedRestriction s from the specified list which
may contain restrictions for different properties. |
int |
getMaxCardinality()
Get the maximum cardinality, if this object specifies one.
|
int |
getMinCardinality()
Get the minimum cardinality, if this object specifies one.
|
String |
getOnProperty()
Get the property for which this restriction is defined.
|
static MergedRestriction |
getPropertyBanningRestriction(String propURI)
Create a new restriction to state that no individual of a certain class
has the given property, i.e.
|
String |
getPropTypeURI()
If this MergedRestriction restricts the values of a property to be
individuals of a specific class (i.e.
|
PropertyRestriction |
getRestriction(int id)
Get a specific
PropertyRestriction . |
MergedRestriction |
getRestrictionOnPath(String[] path)
Get a
MergedRestriction of a property path previously set by
appendTo(MergedRestriction, String[]) |
List<TypeExpression> |
getRestrictions()
Get all
PropertyRestriction s. |
boolean |
hasMemberIgnoreCardinality(Object o)
Returns true if the given object is a member of the class represented by
this class expression, otherwise false; cardinality restrictions are
ignored.
|
boolean |
isWellFormed()
Returns true, if the state of the resource is valid, otherwise
false.
|
MergedRestriction |
merge(MergedRestriction other)
Create a new
MergedRestriction that is a combination of this
restriction and the given restriction. |
boolean |
setProperty(String propURI,
Object value)
Adds a statement with this resource as the subject, the given
propURI as the predicate and the given value as the object. |
Iterator<TypeExpression> |
types()
Get an iterator for the added child class expressions.
|
addType, elements, getNamedSuperclasses, getUpperEnumeration, hasMember, isDisjointWith, matches, size
checkTTL, collectTypesMinimized, getDefaultMatchmakingTTL, hasMember, hasMember, isDisjointWith, isDisjointWith, matches, matches, synchronize
addMultiLangProp, addType, asList, asList, asRDFList, changeProperty, copy, deepCopy, equals, generateAnonURI, getDefaultLang, getFilename, getLocalName, getMultiLangProp, getNamespace, getOrConstructLabel, getOrConstructLabel, getProperty, getPropertyURIs, getPropSerializationType, getResource, getResourceComment, getResourceLabel, getResourceLabel, getStaticFieldValue, getType, getTypes, getURI, hashCode, hasProperty, hasQualifiedName, isAnon, isAnon, isBlockingAddingTypes, isClosedCollection, isQualifiedName, literal, numberOfProperties, representsQualifiedURI, serializesAsXMLLiteral, setPropertyPath, setPropertyPath, setPropertyPathFromOffset, setResourceComment, setResourceLabel, toString, toStringRecursive, toStringRecursive, unliteral
public static final String MY_URI
public static final int MIN_UNDEFINED
public static final int MAX_UNDEFINED
public static final int allValuesFromID
AllValuesFromRestriction
. Only used in the context of
this class.public static final int someValuesFromID
SomeValuesFromRestriction
. Only used in the context of
this class.public static final int hasValueID
HasValueRestriction
. Only used in the context of this
class.public static final int minCardinalityID
MinCardinalityRestriction
. Only used in the context of
this class.public static final int maxCardinalityID
MaxCardinalityRestriction
. Only used in the context of
this class.public static final int exactCardinalityID
ExactCardinalityRestriction
. Only used in the context
of this class.public MergedRestriction()
public MergedRestriction(String onProperty)
addRestriction(PropertyRestriction)
or
addRestriction(MergedRestriction)
.onProperty
- The property for which this restriction is defined.public MergedRestriction(String onProperty, ArrayList<PropertyRestriction> restrictions)
onProperty
- The property for which this restriction is defined.restrictions
- The initial set of restrictions. The array must contain only
instances of PropertyRestriction
.public static MergedRestriction getPropertyBanningRestriction(String propURI)
The new MergedRestriction
contains
MaxCardinalityRestriction
with value 0
.
propURI
- The property for which this restriction is defined.null
if the parameters are
invalid.public static MergedRestriction getFixedValueRestriction(String propURI, Object value)
The new MergedRestriction
contains
HasValueRestriction
with value value
.
public static MergedRestriction getCardinalityRestriction(String propURI, int min, int max)
min
and at most max
.
The new MergedRestriction
contains
MinCardinalityRestriction
if min
is valid and
min != max
.
MaxCardinalityRestriction
if max
is valid and
min != max
.
ExactCardinalityRestriction
if min
and
max
are valid and min == max
.
propURI
- The property for which this restriction is defined.min
- The minimum cardinality, or 0
if undefined.max
- The maximum cardinality, or -1
if undefined.null
if the parameters are
invalid.public static MergedRestriction getAllValuesRestrictionWithCardinality(String propURI, String typeURI, int min, int max)
min
and at most max
and the value of the given property is of
type typeURI
.
The new MergedRestriction
contains
AllValuesFromRestriction
MinCardinalityRestriction
if min
is valid and
min != max
.
MaxCardinalityRestriction
if max
is valid and
min != max
.
ExactCardinalityRestriction
if min
and
max
are valid and min == max
.
propURI
- The property for which this restriction is defined.min
- The minimum cardinality, or 0
if undefined.max
- The maximum cardinality, or -1
if undefined.typeURI
- URI of the type of values for this property.null
if the parameters are
invalid.public static MergedRestriction getAllValuesRestrictionWithCardinality(String propURI, TypeExpression expr, int min, int max)
min
and at most max
and the value of the given property is of
type expr
.
The new MergedRestriction
contains
AllValuesFromRestriction
MinCardinalityRestriction
if min
is valid and
min != max
.
MaxCardinalityRestriction
if max
is valid and
min != max
.
ExactCardinalityRestriction
if min
and
max
are valid and min == max
.
propURI
- The property for which this restriction is defined.min
- The minimum cardinality, or 0
if undefined.max
- The maximum cardinality, or -1
if undefined.expr
- The type of values for this property.null
if the parameters are
invalid.public static MergedRestriction getAllValuesRestriction(String propURI, String typeURI)
typeURI
.
The new MergedRestriction
contains
propURI
- The property for which this restriction is defined.typeURI
- The type of values of the property.null
if the parameters are
invalid.public static MergedRestriction getAllValuesRestriction(String propURI, TypeExpression expr)
expr
.
The new MergedRestriction
contains
propURI
- The property for which this restriction is defined.expr
- The type of values of the property.null
if the parameters are
invalid.public static ArrayList<MergedRestriction> getFromList(List<?> o)
MergedRestriction
s from the specified list which
may contain restrictions for different properties. For each
property, there exists exactly one MergedRestriction
in the
returned list.o
- The list of PropertyRestriction
s. Elements of this
list that are not instances of PropertyRestriction
are
ignored. Restrictions can be defined for different properties.MergedRestriction
s.public int getMinCardinality()
MinCardinalityRestriction
or an
ExactCardinalityRestriction
.0
if no minimum
cardinality is specified.public int getMaxCardinality()
MaxCardinalityRestriction
or an
ExactCardinalityRestriction
.-1
if no maximum
cardinality is specified.public Object getConstraint(int id)
MinCardinalityRestriction
. This method calls
PropertyRestriction.getConstraint()
; the return value depends on
the individual restriction.id
- ID of the restriction.public List<TypeExpression> getRestrictions()
PropertyRestriction
s. The list is backed by the
MergedRestriction
, so changes to the MergedRestriction
are reflected in the list.public PropertyRestriction getRestriction(int id)
PropertyRestriction
.id
- ID of the property restriction.public MergedRestriction addRestriction(PropertyRestriction res)
MinCardinalityRestriction
and a
MaxCardinalityRestriction
with the same value is added, then the
MinCardinalityRestriction
is removed and an
ExactCardinalityRestriction
is added instead.res
- The Restriction to add.IllegalArgumentException
- If the given restriction is defined for a different property
than this merged restriction.public boolean addRestrictionCheck(PropertyRestriction res)
MinCardinalityRestriction
and a
MaxCardinalityRestriction
with the same value is added, then the
MinCardinalityRestriction
is removed and an
ExactCardinalityRestriction
is added instead.res
- The Restriction to add.IllegalArgumentException
- If the given restriction is defined for a different property
than this merged restriction.public MergedRestriction addRestriction(MergedRestriction r)
MergedRestriction
, performing a
sanity check. It is not guaranteed that the given restriction will really
be added, e.g. when this MergedRestriction
already has a
MinCardinalityRestriction
and a MaxCardinalityRestriction
with the same value is added, then the MinCardinalityRestriction
is removed and an ExactCardinalityRestriction
is added instead.r
- The restriction to add.public TypeExpression copy()
TypeExpression
copy
in class Intersection
public MergedRestriction copyWithNewCardinality(int min, int max)
MergedRestriction
with modified cardinality
restrictions.min
- The new value for MinCardinalityRestriction
.max
- The new value for MaxCardinalityRestriction
.MergedRestriction
.public MergedRestriction copyOnNewProperty(String onProp)
MergedRestriction
with modified onProperty value.onProp
- The new URI of the property this restriction is defined for.MergedRestriction
which contains all simple
restrictions of this class, but is defined for a different
property.public boolean isWellFormed()
TypeExpression
isWellFormed
in class Intersection
Resource.isWellFormed()
public boolean setProperty(String propURI, Object value)
Resource
propURI
as the predicate and the given value as the object.
Subclasses must override this in order to decide if the statement to be
added fits the general class constraints. If not, the call of this method
should be ignored. For each property only one single call may be made to
this method, unless subsequent calls to this method for setting the value
of the same property are treated as an update for an update-able
property. Multi-valued properties must be set using an instance of
List
. The differentiation, if a such list should be
treated as an rdf:List, can be made with the help of
Resource.isClosedCollection(String)
. The default implementation here
accepts all property-value pairs blindly except for rdf:type which is
handled if the value is a type URI, a Resource or a java.util.List of
them.
Note: The setting of the property rdf:type is being handled by this class
via the final methods Resource.addType(String, boolean)
,
Resource.getType()
, and Resource.getTypes()
. Although these methods give
the view of handling type URIs as strings, but in reality the types are
stored as direct instances of this class. So, the subclasses should
ignore calls for setting rdf:type; if not, then the subclass must pay
attention that the value should be a List
of direct instances of
this class so that (1) the Resource.toString()
method returns just the
URI and (2) the serializers get no problems with the value. Also,
settings via subclasses may be overwritten by this class if a subsequent
call to Resource.addType(String, boolean)
is made.
setProperty
in class Intersection
public Iterator<TypeExpression> types()
types
in class Intersection
public String getPropTypeURI()
AllValuesFromRestriction
of a either a TypeURI
or a BoundedValueRestriction
), then
return the URI of this class.public String getOnProperty()
public MergedRestriction appendTo(MergedRestriction root, String[] path)
root
- The root restriction for the first element of the property
path. Can be null.path
- The property path.path
is nullpath
is emptyonProperty
of this object is not setonProperty
does not match the last element
of the path
onProperty
of root
does not
match the first element of the path
MergedRestriction()
that is eitherthis
if root
is null
and the length of path
is oneroot
(or a new
MergedRestriction()
if root
is null)
otherwisepublic MergedRestriction getRestrictionOnPath(String[] path)
MergedRestriction
of a property path previously set by
appendTo(MergedRestriction, String[])
path
- The property path.MergedRestriction
that is defined for the last
element of the property pathpublic Object[] getEnumeratedValues()
public MergedRestriction merge(MergedRestriction other)
MergedRestriction
that is a combination of this
restriction and the given restriction. If some parts are defined in both
restrictions, then the parts from other
will be preferred.other
- The restriction to merge withnull, if this restriction is not fully defined (has no onProperty).
this, if the onProperty of this object does not match the onProperty of the given object.
A new MergedRestriction that combines all
PropertyRestriction
s of this object and the given object.
public boolean hasMemberIgnoreCardinality(Object o)
o
- The object to test for membership.Copyright © 2018 universAAL Consortium. All rights reserved.