Sorts the children of the given nodes.

@param sourceParent     Source node.
@param targetParent     Target node.
@param semanticRelation the relation to use for comparison.
164184
private void filterMappingsOfChildren(INode sourceParent, INode targetParent, char semanticRelation) {
        List<INode> source = new ArrayList<INode>(sourceParent.getChildrenList());
        List<INode> target = new ArrayList<INode>(targetParent.getChildrenList());

        sourceIndex.add(sourceParent.getLevel(), 0);
        targetIndex.add(targetParent.getLevel(), 0);

        if (source.size() >= 1 && target.size() >= 1) {
            //sorts the siblings first with the strongest relation, and then with the others
            filterMappingsOfSiblingsByRelation(source, target, semanticRelation);
        }

        sourceIndex.remove(sourceParent.getLevel());
        targetIndex.remove(targetParent.getLevel());
    }
962603
protected void orderNode(SquareNode target, SquareNode node, boolean pointingX) {

		int index0 = findIntersection(target,node);
		int index1 = (index0+1)%4;

		int index2 = (index0+2)%4;
		int index3 = (index0+3)%4;

		if( index0 < 0 )
			throw new RuntimeException("Couldn't find intersection.  Probable bug");

		lineCenters.a = target.center;
		lineCenters.b = node.center;
		UtilLine2D_F64.convert(lineCenters,general);

		Polygon2D_F64 poly = target.square;
		if( pointingX ) {
			if (sign(general, poly.get(index0)) > 0) {
				ordered[1] = poly.get(index1);
				ordered[2] = poly.get(index0);
			} else {
				ordered[1] = poly.get(index0);
				ordered[2] = poly.get(index1);
			}
			if (sign(general, poly.get(index2)) > 0) {
				ordered[3] = poly.get(index2);
				ordered[0] = poly.get(index3);
			} else {
				ordered[3] = poly.get(index3);
				ordered[0] = poly.get(index2);
			}
		} else {
			if (sign(general, poly.get(index0)) > 0) {
				ordered[2] = poly.get(index1);
				ordered[3] = poly.get(index0);
			} else {
				ordered[2] = poly.get(index0);
				ordered[3] = poly.get(index1);
			}
			if (sign(general, poly.get(index2)) > 0) {
				ordered[0] = poly.get(index2);
				ordered[1] = poly.get(index3);
			} else {
				ordered[0] = poly.get(index3);
				ordered[1] = poly.get(index2);
			}
		}
	}
580132
private void resolveStrongestMappingConflicts(INode source, List<IMappingElement<INode>> strongest) {
        //copy the relations to a string to log it
        int strongestIndex = -1;
        String sourceString = source.getNodeData().getName().trim();

        if (log.isEnabledFor(Level.DEBUG)) {
            StringBuilder strongRelations = new StringBuilder();
            for (IMappingElement<INode> aStrongest : strongest) {
                strongRelations.append(aStrongest.getTarget().toString()).append("|");
            }

            log.debug("More than one strongest relation for " + sourceString + ": |" + strongRelations.toString());
        }

        //looks the first related node that is equal to the source node
        for (int i = 0; i < strongest.size(); i++) {
            String strongString = strongest.get(i).getTarget().getNodeData().getName().trim();
            if (sourceString.equalsIgnoreCase(strongString)) {
                strongestIndex = i;
                break;
            }
        }

        //if there was no equal string, then set it to the first one
        if (strongestIndex == -1) {
            strongestIndex = 0;
        }

        if (strongest.get(strongestIndex).getRelation() != IMappingElement.IDK) {
            spsmMapping.add(strongest.get(strongestIndex));

            // Remove the relations from the same column and row
            deleteRemainingRelationsFromMatrix(strongest.get(strongestIndex));
        }
    }
289066
public void sortChildrenByNode(Comparator<TreeNode<T>> comparator) {
		Collections.sort(children, comparator);
		for (TreeNode<T> child : children) {
			child.sortChildrenByNode(comparator);
		}
	}
759440
public void addFirstChild( AstNode child ) {
        assert child != null;
        this.children.addFirst(child);
        child.removeFromParent();
        child.parent = this;
    }
301332
protected static void applyRelationships(final ContentSpec contentSpec, final Map<Integer, Node> nodes,
            final Map<String, SpecTopic> targetTopics, final List<CSNodeWrapper> relationshipFromNodes, final List<Process> processes,
            final DataProviderFactory providerFactory) {
        // Apply the user defined relationships stored in the database
        for (final CSNodeWrapper node : relationshipFromNodes) {
            boolean initialContentTopic = node.getNodeType() == CommonConstants.CS_NODE_INITIAL_CONTENT_TOPIC;
            boolean level = EntityUtilities.isNodeALevel(node);

            // In 1.3 or lower initial content relationships were stored on the topic, however in 1.4+ they are now on the initial
            // content level, so do the migration here
            final SpecNodeWithRelationships fromNode;
            if (initialContentTopic) {
                final CSNodeWrapper parentNode = node.getParent();
                final SpecNodeWithRelationships parent = (SpecNodeWithRelationships) nodes.get(parentNode.getId());
                if (parent instanceof InitialContent) {
                    fromNode = parent;
                } else {
                    final Level parentLevel = (Level) parent;
                    if (parentLevel.getFirstSpecNode() instanceof InitialContent) {
                        fromNode = (SpecNodeWithRelationships) parentLevel.getFirstSpecNode();
                    } else {
                        fromNode = new InitialContent(parent.getLineNumber(), CSConstants.LEVEL_INITIAL_CONTENT + ":");
                        if (parentLevel.getChildNodes().isEmpty()) {
                            parentLevel.appendChild(fromNode);
                        } else {
                            parentLevel.insertBefore(fromNode, parentLevel.getChildNodes().get(0));
                        }
                    }
                }
            } else {
                fromNode = (SpecNodeWithRelationships) nodes.get(node.getId());
            }

            // Check if we have any relationships to process
            if (node.getRelatedToNodes() == null || node.getRelatedToNodes().isEmpty()) continue;
            final List<CSRelatedNodeWrapper> relatedToNodes = node.getRelatedToNodes().getItems();

            // Sort the relationships into the correct order based on the sort variable
            Collections.sort(relatedToNodes, new CSRelatedNodeSorter());

            // Add the relationships to the topic
            for (final CSRelatedNodeWrapper relatedToNode : relatedToNodes) {
                final Node toNode = nodes.get(relatedToNode.getId());
                if (toNode == null) {
                    throw new IllegalStateException("The related node does not exist in the content specification");
                } else if (toNode instanceof Level) {
                    // Relationships to levels
                    final Level toLevel = (Level) toNode;

                    // Ensure that the level has a target id if not create one.
                    if (toLevel.getTargetId() == null) {
                        toLevel.setTargetId("T00" + relatedToNode.getId());
                    }

                    // Add the relationship
                    fromNode.addRelationshipToTarget(toLevel, RelationshipType.getRelationshipType(relatedToNode.getRelationshipType()),
                            initialContentTopic || level ? null : toLevel.getTitle());
                } else {
                    // Relationships to topics
                    final SpecTopic toSpecTopic = (SpecTopic) toNode;
                    final String title = toSpecTopic.getTitle();

                    // Add the relationship
                    if (relatedToNode.getRelationshipMode().equals(CommonConstants.CS_RELATIONSHIP_MODE_TARGET)) {
                        fromNode.addRelationshipToTarget(toSpecTopic,
                                RelationshipType.getRelationshipType(relatedToNode.getRelationshipType()),
                                initialContentTopic || level ? null : title);
                    } else {
                        fromNode.addRelationshipToTopic(toSpecTopic,
                                RelationshipType.getRelationshipType(relatedToNode.getRelationshipType()),
                                initialContentTopic || level ? null : title);
                    }
                }
            }
        }

        // Create the unique id map
        final Map<String, SpecTopic> uniqueIdSpecTopicMap = ContentSpecUtilities.getUniqueIdSpecTopicMap(contentSpec);

        // Apply the process relationships
        for (final Process process : processes) {
            process.processTopics(uniqueIdSpecTopicMap, targetTopics, providerFactory.getProvider(TopicProvider.class),
                    providerFactory.getProvider(ServerSettingsProvider.class));
        }
    }
1016263
public void getRelativePath(StringBuilder result, INode parserNode, INode node) {
		if (parserNode == node)
			return;
		if (isAncestor(parserNode, node)) {
			ICompositeNode parent = node.getParent();
			getRelativePath(result, parserNode, parent);
			int idx = 0;
			INode child = parent.getFirstChild();
			while(child != node && child.hasNextSibling()) {
				idx++;
				child = child.getNextSibling();
			}
			result.append("/").append(idx);
		} else {
			result.append("/..");
			getRelativePath(result, parserNode.getParent(), node);
		}
	}
992235
public boolean isRelated(Class<? extends ElementBase> sourceClass, Class<? extends ElementBase> targetClass) {
        return getCardinality(sourceClass, targetClass).maxOccurrences > 0;
    }
271382
public static <T extends HierarchyEntity<T, ?>> void addParent(Collection<T> nodes) {
    addParent(nodes, null);
  }
290687
public void setRelatedResources(java.util.Collection<RelatedResource> relatedResources) {
        if (relatedResources == null) {
            this.relatedResources = null;
            return;
        }

        this.relatedResources = new java.util.ArrayList<RelatedResource>(relatedResources);
    }
395449
public void sortByInstanceList(final List<Instance> _targetList,
                                   final Map<Instance, Integer> _currentList)
    {
        final List<Long> idListNew = new ArrayList<>();
        final List<Object> objectListNew = new ArrayList<>();
        for (final Instance instance : _targetList) {
            if (_currentList.containsKey(instance)) {
                final Integer i = _currentList.get(instance);
                idListNew.add(this.idList.get(i));
                objectListNew.add(this.objectList.get(i));
            }
        }
        this.idList.clear();
        this.idList.addAll(idListNew);
        this.objectList.clear();
        this.objectList.addAll(objectListNew);
    }
673319
function merge(target, source) {
                target.additionalNodes = target.additionalNodes || [];
                target.additionalNodes.push(source.node);
                if (source.additionalNodes) {
                    (_a = target.additionalNodes).push.apply(_a, source.additionalNodes);
                }
                target.children = ts.concatenate(target.children, source.children);
                if (target.children) {
                    mergeChildren(target.children);
                    sortChildren(target.children);
                }
                var _a;
            }
1318139
@Override
	public void process(Node externs, Node root) {
		this.expandedDepsList.clear();
		List<DependencyList> enclosingDependencies = new LinkedList<DependencyList>();
		try {
			processChildren(root, enclosingDependencies);
		} catch (ProcessingDependenciesException e) {
			throw new RuntimeProcessingDependenciesException(e);
		} catch (DependencyVerificationException e) {
			throw new RuntimeDependencyVerificationException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		appendConsoleLogging(root);
	}
48369
protected CSRelatedNodeWrapper findExistingRelatedNode(final Relationship relationship,
            final List<CSRelatedNodeWrapper> topicRelatedNodes) {
        if (topicRelatedNodes != null) {
            // Loop over the current nodes and see if any match
            for (final CSRelatedNodeWrapper relatedNode : topicRelatedNodes) {
                if (relationship instanceof TargetRelationship) {
                    if (doesRelationshipMatch((TargetRelationship) relationship, relatedNode)) {
                        return relatedNode;
                    }
                } else {
                    if (doesRelationshipMatch((TopicRelationship) relationship, relatedNode)) {
                        return relatedNode;
                    }
                }
            }
        }

        return null;
    }
281539
@Override
    public List<EnhanceEntity> populateRelation(EntityMetadata m, Client client, int maxResults)
    {
        // TODO: maxresults to be taken care after work on pagination.

        List<EnhanceEntity> ls = null;
        List<String> relationNames = m.getRelationNames();
        boolean isParent = m.isParent();
        if (!isParent)
        {
            // if it is not a parent.
            String sqlQuery = null;
            if (MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata()))
            {
                sqlQuery = getSqlQueryFromJPA(m, relationNames, null);
            }
            else
            {
                // prepare lucene query and find.
                Set<String> rSet = fetchDataFromLucene(m.getEntityClazz(), client);
                if (rSet != null && !rSet.isEmpty())
                {
                    filter = "WHERE";
                }
                sqlQuery = getSqlQueryFromJPA(m, relationNames, rSet);
            }
            // call client with relation name list and convert to sql query.

            ls = populateEnhanceEntities(m, relationNames, client, sqlQuery);
        }
        else
        {
            if (MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata()))
            {
                try
                {
                    List entities = ((HibernateClient) client).find(getSqlQueryFromJPA(m, relationNames, null),
                            new ArrayList<String>(), m);
                    ls = new ArrayList<EnhanceEntity>(entities.size());
                    ls = transform(m, ls, entities);
                }
                catch (Exception e)
                {
                    log.error("Error while executing handleAssociation for RDBMS, Caused by {}.", e);
                    throw new QueryHandlerException(e);
                }
            }
            else
            {
                ls = onAssociationUsingLucene(m, client, ls);
            }
        }

        return ls;
    }
1171765
public synchronized boolean changeParent(int depStreamID, int newPriority, int newParentStreamID, boolean exclusive) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "changeParent entry: depStreamID: " + depStreamID + " newParentStreamID: " + newParentStreamID + " exclusive: " + exclusive);
        }

        // notice that the new dependent node and parent do not have to be directly related coming into this method.
        // Therefore, find both nodes starting at the root.
        Node depNode = root.findNode(depStreamID);
        Node newParentNode = root.findNode(newParentStreamID);
        if ((depNode == null) || (newParentNode == null)) {
            return false;
        }

        // If the new parent can not be found in the tree under the dependent node, then changing parents is straight forward.
        if (depNode.findNode(newParentStreamID) == null) {
            // simple move, since the new parent is not a dependent of the stream that is changing parents
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "new parent is not a dependent of the stream that is changing parents");
            }
            Node oldParent = depNode.getParent();

            // move the dependent node, reset write counters, and re-sort the affected set of siblings according to original priorities
            depNode.setParent(newParentNode, true);
            depNode.setPriority(newPriority);

            newParentNode.clearDependentsWriteCount();
            newParentNode.sortDependents();

            // where it left from needs to be re-sorted also
            oldParent.clearDependentsWriteCount();
            oldParent.sortDependents();

            // according to spec: after setting the new parent, if this node is to be exclusive, then invode the exclusive algorithm on it.
            if (exclusive) {
                makeExclusiveDependency(depNode, newParentNode);
            }

        } else {
            // so much for simple.  The parent is in the dependency tree underneath the node that we now want to be dependent on the new Parent.
            // in the above example: A - depNode,  D - newParentNode.
            // The below steps are following how that spec says to handle this case (or at least it is suppose to).
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "new parent is a dependent of the stream that is changing parents");
            }

            // move the current newParentNode to be the dependent on the new dependent node's previous parent.
            Node grandParent = depNode.getParent();
            Node oldDepParent = newParentNode.getParent();
            newParentNode.setParent(grandParent, true); // set Parent will also remove newParentNode as a dependent of its current/old parent

            // now make the new dependent node depend on the newParentNode
            depNode.setParent(newParentNode, true);
            depNode.setPriority(newPriority);

            // clear and re-sort the effective levels we touched
            grandParent.clearDependentsWriteCount();
            grandParent.sortDependents();

            newParentNode.clearDependentsWriteCount();
            newParentNode.sortDependents();

            oldDepParent.clearDependentsWriteCount();
            oldDepParent.sortDependents();

            // and finally if the new dependency node is suppose to end up exclusive, make it so now.
            if (exclusive) {
                makeExclusiveDependency(depNode, newParentNode);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "changeParent exit: depNode on exit: " + depNode.toStringDetails());
        }

        return true;

    }
1270361
private static void analyzeNode(TreeGraphNode t, TreeGraphNode root, Collection<GrammaticalRelation> relations) {
    // if (t.numChildren() > 0) {          // don't do leaves
    if (t.isPhrasal()) {    // don't do leaves or preterminals!
      TreeGraphNode tHigh = t.highestNodeWithSameHead();
      for (GrammaticalRelation egr : relations) {
        if (egr.isApplicable(t)) {
          for (Tree u : egr.getRelatedNodes(t, root)) {
            tHigh.addArc(GrammaticalRelation.getAnnotationClass(egr), (TreeGraphNode) u);
          }
        }
      }
      // now recurse into children
      for (TreeGraphNode kid : t.children()) {
        analyzeNode(kid, root, relations);
      }
    }
  }