Package net.sf.saxon.value
Class Cardinality
java.lang.Object
net.sf.saxon.value.Cardinality
This class contains static methods to manipulate the cardinality
property of a type.
Cardinality of expressions is denoted by one of the values ONE_OR_MORE, ZERO_OR_MORE,
ZERO_OR_ONE, EXACTLY_ONE, or EMPTY. These are combinations of the three bit-significant
values ALLOWS_ZERO, ALLOWS_ONE, and ALLOWS_MANY.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallows(int cardinality, int count) Determine whether a given cardinality allows a specific number of itemsstatic booleanallowsMany(int cardinality) Determine whether multiple occurrences are allowedstatic booleanallowsZero(int cardinality) Determine whether empty sequence is allowedstatic Stringdescribe(int cardinality) Display the cardinality as a stringstatic booleanexpectsMany(Expression expression) Determine whether multiple occurrences are not only allowed, but likely.static intfromMinAndMax(int min, int max) static intfromOccurrenceIndicator(String indicator) static StringgetOccurrenceIndicator(int cardinality) Get the occurrence indicator representing the cardinalitystatic OccurrenceIndicatorgetOccurrenceIndicatorForCardinality(int cardinality) Get theOccurrenceIndicatorvalue corresponding to an internal cardinality propertystatic intmultiply(int c1, int c2) Multiply two cardinalitiesstatic booleanoccurrenceIndicatorAllows(OccurrenceIndicator indicator, int size) Ask whether a given occurrence indicator allows a value of a given sizestatic intGet the internal StaticProperty value corresponding to anOccurrenceIndicatorstatic booleansubsumes(int c1, int c2) Test if one cardinality subsumes another.static intsum(int c1, int c2) Add two cardinalitiesstatic intunion(int c1, int c2) Form the union of two cardinalities.
-
Method Details
-
allowsMany
public static boolean allowsMany(int cardinality) Determine whether multiple occurrences are allowed- Parameters:
cardinality- the cardinality of a sequence- Returns:
- true if the cardinality allows the sequence to contain more than one item
-
expectsMany
Determine whether multiple occurrences are not only allowed, but likely. This returns false for an expression that is the atomization of a singleton node, since in that case it's quite unusual for the typed value to be a non-singleton sequence.- Parameters:
expression- an expression- Returns:
- true if multiple occurrences are not only allowed, but likely. Return false if multiple occurrences are unlikely, even though they might be allowed. This is typically the case for the atomized sequence that is obtained by atomizing a singleton node.
-
allowsZero
public static boolean allowsZero(int cardinality) Determine whether empty sequence is allowed- Parameters:
cardinality- the cardinality of a sequence- Returns:
- true if the cardinality allows the sequence to be empty
-
allows
public static boolean allows(int cardinality, int count) Determine whether a given cardinality allows a specific number of items- Parameters:
cardinality- the cardinalitycount- the number of items in a value- Returns:
- true if the cardinality allows a value with this number of items
-
union
public static int union(int c1, int c2) Form the union of two cardinalities. The cardinality of the expression "if (c) then e1 else e2" is the union of the cardinalities of e1 and e2.- Parameters:
c1- a cardinalityc2- another cardinality- Returns:
- the cardinality that allows both c1 and c2
-
sum
public static int sum(int c1, int c2) Add two cardinalities- Parameters:
c1- the first cardinalityc2- the second cardinality- Returns:
- the cardinality of a sequence formed by concatenating the sequences whose cardinalities are c1 and c2
-
fromMinAndMax
public static int fromMinAndMax(int min, int max) -
subsumes
public static boolean subsumes(int c1, int c2) Test if one cardinality subsumes another. Cardinality c1 subsumes c2 if every option permitted by c2 is also permitted by c1.- Parameters:
c1- a cardinalityc2- another cardinality- Returns:
- true if if every option permitted by c2 is also permitted by c1.
-
multiply
public static int multiply(int c1, int c2) Multiply two cardinalities- Parameters:
c1- the first cardinalityc2- the second cardinality- Returns:
- the product of the cardinalities, that is, the cardinality of the sequence "for $x in S1 return S2", where c1 is the cardinality of S1 and c2 is the cardinality of S2
-
describe
Display the cardinality as a string- Parameters:
cardinality- the cardinality value to be displayed- Returns:
- the representation as a string, for example "zero or one", "zero or more"
-
getOccurrenceIndicator
Get the occurrence indicator representing the cardinality- Parameters:
cardinality- the cardinality value- Returns:
- the occurrence indicator, for example "*", "+", "?", "".
-
fromOccurrenceIndicator
-
getOccurrenceIndicatorForCardinality
Get theOccurrenceIndicatorvalue corresponding to an internal cardinality property- Parameters:
cardinality- the internal cardinality property, for exampleStaticProperty.ALLOWS_ONE_OR_MORE.- Returns:
- the corresponding
OccurrenceIndicator
-
occurrenceIndicatorAllows
Ask whether a given occurrence indicator allows a value of a given size- Parameters:
indicator- the given occurrence indicatorsize- the given size (number of items)- Returns:
- true if the occurrence indicator matches a sequence of the given length
-
staticPropertyFromOccurrenceIndicator
Get the internal StaticProperty value corresponding to anOccurrenceIndicator- Parameters:
indicator-OccurrenceIndicator- Returns:
- the corresponding internal cardinality property, for example
StaticProperty.ALLOWS_ONE_OR_MORE.
-