Class PuzzlePieceSet
- java.lang.Object
-
- schema2template.model.PuzzlePieceSet
-
- All Implemented Interfaces:
Iterable<PuzzlePiece>
,Collection<PuzzlePiece>
,PuzzleComponent
,QNamed
,QNamedPuzzleComponent
public class PuzzlePieceSet extends Object implements QNamedPuzzleComponent, Collection<PuzzlePiece>
Collection Class for RelaxNG definitions of an Element, Attribute, Value or Datatype.Conventions:
- PuzzlePiece sorting is done by ns:local tag names as first key and hashCode as second key (see class PuzzlePiece).
- Since it is a Collection, PuzzlePieceSet is not meant to be used in a Collection. So equals(o) and hashCode() are not overwritten
- All returned PuzzlePieceSet objects are immutable to protect them against naive usage in velocity templates
-
-
Constructor Summary
Constructors Constructor Description PuzzlePieceSet()
PuzzlePieceSet(Collection<PuzzlePiece> c)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(PuzzlePiece e)
boolean
addAll(Collection<? extends PuzzlePiece> c)
PuzzlePieceSet
byParent(QNamedPuzzleComponent parents)
Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but only those which have at least one element from the QNamedPuzzleComponent parameter as one of their parent Definitions.boolean
canHaveText()
Determines whether the Definitions can have text - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name.void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
boolean
containsName(String aDefinitionName)
Check whether this List contains an Element by this Nameboolean
containsName(QNamed aNamed)
Check whether this List contains an Element by this Nameboolean
equals(Object o)
PuzzlePieceSet
getAttributes()
ELEMENT PuzzlePiece only: Get all attribute DefinitionsPuzzlePieceSet
getChildElements()
ELEMENT PuzzlePiece only: Get all child element DefinitionsCollection<PuzzlePiece>
getCollection()
Method to treat NamedDefined as a Collection of PuzzlePiecePuzzlePieceSet
getDatatypes()
ATTRIBUTE PuzzlePiece only: Get all datatype DefinitionsString
getLocalName()
Get only localnameString
getNamespace()
Get only namespacePuzzlePieceSet
getParents()
Get all parent DefinitionsString
getQName()
Gets the ns:local tag name of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions share the same tag name.MSVExpressionType
getType()
Gets the type of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name.PuzzlePieceSet
getValues()
ATTRIBUTE PuzzlePiece only: Get all value Definitionsint
hashCode()
boolean
isEmpty()
boolean
isMandatory(QNamedPuzzleComponent child)
ELEMENT Definition only: Determine solely by child type and name whether child is mandatory.boolean
isSingleton(PuzzleComponent child)
Determines whether the child PuzzlePiece(s) is/are singleton(s)Iterator<PuzzlePiece>
iterator()
void
makeImmutable()
Make PuzzlePieceSet immutable.boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
String
toString()
Returns String representation (convenient method for getQName())PuzzlePieceSet
without(QNamedPuzzleComponent removeAll)
Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but without the elements of the parameter removeAllPuzzlePieceSet
withoutMultiples()
Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but restricted to one PuzzlePiece per Name.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Constructor Detail
-
PuzzlePieceSet
public PuzzlePieceSet()
-
PuzzlePieceSet
public PuzzlePieceSet(Collection<PuzzlePiece> c)
-
-
Method Detail
-
equals
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection<PuzzlePiece>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<PuzzlePiece>
- Overrides:
hashCode
in classObject
-
makeImmutable
public void makeImmutable()
Make PuzzlePieceSet immutable. Cannot be undone.Template Usage: Not for use in templates as all PuzzlePieceSet already have been made immutable.
-
withoutMultiples
public PuzzlePieceSet withoutMultiples()
Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but restricted to one PuzzlePiece per Name.Template Usage: #foreach ($element in $elements.withoutMultiples())
- Returns:
- new PuzzlePieceSet
-
without
public PuzzlePieceSet without(QNamedPuzzleComponent removeAll)
Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but without the elements of the parameter removeAllTemplate Usage: #set ($non_base_attributes = $element.getAttributes().without($baseclass.getAttributes())
- Parameters:
removeAll
- QNamedPuzzleComponent which (or which elements) should be removed from the new PuzzlePieceSet- Returns:
- new PuzzlePieceSet
-
byParent
public PuzzlePieceSet byParent(QNamedPuzzleComponent parents)
Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but only those which have at least one element from the QNamedPuzzleComponent parameter as one of their parent Definitions.Template Usage: Imagine we have one attribute name and we're not interested in the differences between Definitions sharing the same name. We're now printing the resulting allowed attribute values for each parent element name:
#set ( $oneOrMoreAttributes = $model.getAttribute($atttributename) )
## we want to write information about only _one_ parent per Name...
#foreach ($parent in $oneOrMoreAttributes.getParents().withoutMultiples())
- Allowed Values for Parent Element $parent :
## but we want the attribute values displayed which are allowed in _all_ parents with the same Name...
#foreach ($value in $oneOrMoreAttributes.byParent($parent.withMultiples()).getValues())
-- "$value"
#end
#end- Parameters:
parents
-- Returns:
- new PuzzlePieceSet
-
containsName
public boolean containsName(String aDefinitionName)
Check whether this List contains an Element by this Name- Parameters:
aDefinitionName
-- Returns:
- True if an element by this name exists
-
containsName
public boolean containsName(QNamed aNamed)
Check whether this List contains an Element by this Name- Parameters:
aNamed
-- Returns:
- True if an element by this name exists
-
getQName
public String getQName()
Gets the ns:local tag name of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions share the same tag name. Throws Exception otherwise.
-
getType
public MSVExpressionType getType()
Gets the type of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name. Throws Exception otherwise.- Specified by:
getType
in interfacePuzzleComponent
- Returns:
- The type of this PuzzleComponent
-
canHaveText
public boolean canHaveText()
Determines whether the Definitions can have text - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name. Throws Exception otherwise.- Specified by:
canHaveText
in interfacePuzzleComponent
- Returns:
- True if a text node is allowed, false otherwise
-
isSingleton
public boolean isSingleton(PuzzleComponent child)
Description copied from interface:PuzzleComponent
Determines whether the child PuzzlePiece(s) is/are singleton(s)Convention: If child is a collection this method returns false if one child element is no singleton. If this is a collection this method returns false if child is no singleton for one element of this.
- Specified by:
isSingleton
in interfacePuzzleComponent
- Parameters:
child
- PuzzleComponent child- Returns:
- True if child is defined as Singleton, falso otherwise.
-
getLocalName
public String getLocalName()
Description copied from interface:QNamed
Get only localname- Specified by:
getLocalName
in interfaceQNamed
- Returns:
- localname
-
getNamespace
public String getNamespace()
Description copied from interface:QNamed
Get only namespace- Specified by:
getNamespace
in interfaceQNamed
- Returns:
- namespace
-
toString
public String toString()
Returns String representation (convenient method for getQName())Template Usage: Just use $aDefinitionSet as you would use a string variable
-
add
public boolean add(PuzzlePiece e)
- Specified by:
add
in interfaceCollection<PuzzlePiece>
-
addAll
public boolean addAll(Collection<? extends PuzzlePiece> c)
- Specified by:
addAll
in interfaceCollection<PuzzlePiece>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<PuzzlePiece>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<PuzzlePiece>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<PuzzlePiece>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<PuzzlePiece>
-
iterator
public Iterator<PuzzlePiece> iterator()
- Specified by:
iterator
in interfaceCollection<PuzzlePiece>
- Specified by:
iterator
in interfaceIterable<PuzzlePiece>
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<PuzzlePiece>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<PuzzlePiece>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<PuzzlePiece>
-
size
public int size()
- Specified by:
size
in interfaceCollection<PuzzlePiece>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<PuzzlePiece>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<PuzzlePiece>
-
getChildElements
public PuzzlePieceSet getChildElements()
Description copied from interface:PuzzleComponent
ELEMENT PuzzlePiece only: Get all child element Definitions- Specified by:
getChildElements
in interfacePuzzleComponent
- Returns:
- The child Definitions of this PuzzleComponent
-
isMandatory
public boolean isMandatory(QNamedPuzzleComponent child)
Description copied from interface:QNamedPuzzleComponent
ELEMENT Definition only: Determine solely by child type and name whether child is mandatory.Here's why we're not using the child Definition object(s) for this: An element often has a mandatory attribute, but two (or more) different content definitions for this attribute. This is done by defining this attribute twice and creating a CHOICE between both Definitions. If you'd ask whether one of these definitions is mandatory, you'd always get false as answer as you have the choice between the two definitions. Mostly this is not the answer you're looking for.
Contract: If 'this' is a Collection, mandatory means mandatory for one member of 'this'.
- Specified by:
isMandatory
in interfaceQNamedPuzzleComponent
- Parameters:
child
- The child Definition(s) of type ELEMENT or ATTRIBUTE- Returns:
- true if child is a defined child of this and if it's mandatory. False otherwise.
-
getCollection
public Collection<PuzzlePiece> getCollection()
Description copied from interface:PuzzleComponent
Method to treat NamedDefined as a Collection of PuzzlePiece- Specified by:
getCollection
in interfacePuzzleComponent
- Returns:
- Collection of PuzzlePiece objects
-
getAttributes
public PuzzlePieceSet getAttributes()
Description copied from interface:PuzzleComponent
ELEMENT PuzzlePiece only: Get all attribute Definitions- Specified by:
getAttributes
in interfacePuzzleComponent
- Returns:
- The attribute Definitions of this PuzzleComponent
-
getDatatypes
public PuzzlePieceSet getDatatypes()
Description copied from interface:PuzzleComponent
ATTRIBUTE PuzzlePiece only: Get all datatype Definitions- Specified by:
getDatatypes
in interfacePuzzleComponent
- Returns:
- The datatype Definitions of this PuzzleComponent
-
getParents
public PuzzlePieceSet getParents()
Description copied from interface:PuzzleComponent
Get all parent Definitions- Specified by:
getParents
in interfacePuzzleComponent
- Returns:
- The parent Definitions of this PuzzleComponent
-
getValues
public PuzzlePieceSet getValues()
Description copied from interface:PuzzleComponent
ATTRIBUTE PuzzlePiece only: Get all value Definitions- Specified by:
getValues
in interfacePuzzleComponent
- Returns:
- The constant value Definitions of this PuzzleComponent
-
-