Beispiel #1
0
 /**
  * A Set of all allowed relations of a certain role between two builders. Distinction is made
  * between source and destination depending on passed directionality.
  *
  * @since MMBase-1.6.2
  */
 public Set<MMObjectNode> getAllowedRelations(
     int builder1, int builder2, int role, int directionality) {
   Set<MMObjectNode> res = new HashSet<MMObjectNode>();
   if (directionality != RelationStep.DIRECTIONS_SOURCE) {
     res.addAll(typeRelNodes.getBySourceDestinationRole(builder1, builder2, role));
   }
   if (directionality != RelationStep.DIRECTIONS_DESTINATION
       && (directionality != RelationStep.DIRECTIONS_EITHER || res.isEmpty())) {
     res.addAll(inverseTypeRelNodes.getByDestinationSourceRole(builder2, builder1, role));
   }
   return res;
 }
Beispiel #2
0
 /**
  * Tests if a specific relation type is defined.
  *
  * <p>Note that this routine returns false both when a snumber/dnumber are swapped, and when a
  * typecombo does not exist - it is not possible to derive whether one or the other has occurred.
  *
  * <p>
  *
  * @param n1 The source type number.
  * @param n2 The destination type number.
  * @param r The relation definition (role) number, or -1 if the role does not matter r can only be
  *     -1 if virtual is <code>true</code>
  * @param restriction if {@link #STRICT}, contains only returns true if the typerel occurs as-is
  *     in the database. if {@link #INCLUDE_DESCENDANTS}, contains returns true if the typerel
  *     occurs as a virtual (derived) node, where source or destination may also be descendants of
  *     the specified type. if {@link #INCLUDE_PARENTS}, contains returns true if the typerel
  *     occurs as a virtual (derived) node, where source or destination may also be parents of the
  *     specified type. if {@link #INCLUDE_PARENTS_AND_DESCENDANTS}, contains returns true if the
  *     typerel occurs as a virtual (derived) node, where source or destination may also be
  *     descendants or parents of the specified type.
  * @return <code>true</code> when the relation exists, false otherwise.
  * @since MMBase-1.6.2
  */
 public boolean contains(int n1, int n2, int r, int restriction) {
   switch (restriction) {
     case INCLUDE_DESCENDANTS:
       return typeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r));
     case INCLUDE_PARENTS:
       return parentTypeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r));
     case INCLUDE_PARENTS_AND_DESCENDANTS:
       return typeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r))
           || parentTypeRelNodes.contains(new VirtualTypeRelNode(n1, n2, r));
     case STRICT:
       SortedSet<MMObjectNode> existingNodes = typeRelNodes.getBySourceDestinationRole(n1, n2, r);
       return (existingNodes.size() > 0 && !existingNodes.first().isVirtual());
     default:
       log.error("Unknown restriction " + restriction);
       return false;
   }
 }