lisa/src/main/java/it/unive/lisa/analysis/nonrelational/value/impl/stringgraphdomain/SGNUtils.java
public static boolean partialOrderAux(StringGraphNode<?> n, StringGraphNode<?> m, Set<Map.Entry<StringGraphNode<?>, StringGraphNode<?>>> edges) {

        // case (1)
        if (edges.contains(StringGraphNode.createEdge(n, m)))
            return true;

            // case (2)
        else if (m instanceof ConstStringGraphNode) {
            ConstValues constValue = ((ConstStringGraphNode)m).getValue();
            if (ConstValues.MAX == constValue) {
                return true;
            }
        }

        // case (3)
        else if (n instanceof ConcatStringGraphNode && m instanceof ConcatStringGraphNode) {
            ConcatStringGraphNode concatN = (ConcatStringGraphNode)n;
            ConcatStringGraphNode concatM = (ConcatStringGraphNode)m;
            List<StringGraphNode<?>> childrenN = n.getChildren();
            List<StringGraphNode<?>> childrenM = m.getChildren();
            if (Objects.equals(concatN.getValue(), concatM.getValue())) {
                // add current edge to edgeSet
                edges.add(StringGraphNode.createEdge(n, m));
                // for each i in [0,k] must hold: <=(n/i, m/i, edges+{m,n})
                for (int i=0; i<concatN.getValue(); i++) {
                    boolean isLessOrEqual = partialOrderAux(childrenN.get(i), childrenM.get(i), edges);
                    if (!isLessOrEqual) return false;
                }
                return true;
            }
        }
        // case (4)
        else if (n instanceof OrStringGraphNode && m instanceof OrStringGraphNode) {
            int k = n.getOutDegree();
            List<StringGraphNode<?>> children = n.getChildren();
            // add current edge to edgeSet
            edges.add(StringGraphNode.createEdge(n, m));
            // for each i in [0,k] must hold: <=(n/i, m, edges+{m,n})
            for (int i=0; i<k; i++) {
                boolean isLessOrEqual = partialOrderAux(children.get(i), m, edges);
                if (!isLessOrEqual) return false;
            }
            return true;
        }

        // case (5)
        else if (m instanceof OrStringGraphNode) {
            StringGraphNode<?> md = null;
            // look for a node (named md) in prnd(m) such that lb(n) == lb(md)
            for (StringGraphNode<?> prnd: m.getPrincipalNodes()) {
                String prndLbl = prnd.getLabel();
                if ( (prndLbl == null && n.getLabel() == null) ||
                        (prndLbl != null && prnd.getLabel().equals(n.getLabel()))) {
                    md = prnd; // found one
                    break;
                }
            }

            if (md != null) {
                edges.add(StringGraphNode.createEdge(n, m));
                return partialOrderAux(n, md, edges);
            }
        }
        // case (6)
        return (n.getLabel().equals( m.getLabel() ));
    }
/**
     * Auxiliary function for implementing partial ordering.
     * Following Section 4.4.2, this recursive algorithm checks the denotations of two nodes and returns true if
     * the denotation of node n is contained or equal to the denotation of node m.
     * The cases implemented in this function are the following:
     * <ul>
     *     <li><strong>Case 1:</strong> if the edge that links the two roots is already in the set, return true</li>
     *     <li><strong>Case 2:</strong> if the label of the right root is MAX, return true</li>
     *     <li><strong>Case 3:</strong> if the two roots are concat node, with same length k, check for each child if the property holds,
     *     		while adding to the current set of edges a new edge formed by the current nodes n and m.</li>
     *     <li><strong>Case 4:</strong> if the two roots are OR node, take all the children of the left node n and check if the property holds for each of them,
     *     		comparing with the root m, while adding to the current set of edges a new edge formed by the current nodes n and m.</li>
     *     <li><strong>Case 5:</strong> if the right root m is an OR node, look for a node in the Principal Nodes of m which has the same label as the label of n.
     *     		Then check if the property holds for n and this particular node, adding to the current set of edge the edge (n,m)</li>
     *     <li><strong>Case 6:</strong> last check, if none of the previous checks has passed, is to verify that the label of node n is equal to the label of node m.</li>
     * </ul>
     *
     * @param n the root of the graph tree to compare
     * @param m the root of the other graph tree to compare
     * @param edges set of edges represented with the Map.Entry entity
     * @return true if n is less or equal then m, false otherwise
     */
Auxiliary function for implementing partial ordering.
Following Section 4.4.2, this recursive algorithm checks the denotations of two nodes and returns true if
the denotation of node n is contained or equal to the denotation of node m.

@param n the root of the graph tree to compare
@param m the root of the other graph tree to compare
@param edges set of edges represented with the Map.Entry entity
@return true if n is less or equal then m, false otherwise
Auxiliary function for implementing partial ordering . Following Section 4 . 4 . 2 this recursive algorithm checks the denotations of two nodes and returns true if the denotation of node n is contained or equal to the denotation of node m . @param n the root of the graph tree to compare @param m the root of the other graph tree to compare @param edges set of edges represented with the Map . Entry entity @return true if n is less or equal then m false otherwise
public static boolean partialOrderAux(StringGraphNode<?> n, StringGraphNode<?> m, Set<Map.Entry<StringGraphNode<?>, StringGraphNode<?>>> edges) {
        if (edges.contains(StringGraphNode.createEdge(n, m)))
            return true;
        else if (m instanceof ConstStringGraphNode) {
            ConstValues constValue = ((ConstStringGraphNode)m).getValue();
            if (ConstValues.MAX == constValue) {
                return true;
            }
        }
        else if (n instanceof ConcatStringGraphNode && m instanceof ConcatStringGraphNode) {
            ConcatStringGraphNode concatN = (ConcatStringGraphNode)n;
            ConcatStringGraphNode concatM = (ConcatStringGraphNode)m;
            List<StringGraphNode<?>> childrenN = n.getChildren();
            List<StringGraphNode<?>> childrenM = m.getChildren();
            if (Objects.equals(concatN.getValue(), concatM.getValue())) {
                edges.add(StringGraphNode.createEdge(n, m));
                for (int i=0; i<concatN.getValue(); i++) {
                    boolean isLessOrEqual = partialOrderAux(childrenN.get(i), childrenM.get(i), edges);
                    if (!isLessOrEqual) return false;
                }
                return true;
            }
        }
        else if (n instanceof OrStringGraphNode && m instanceof OrStringGraphNode) {
            int k = n.getOutDegree();
            List<StringGraphNode<?>> children = n.getChildren();
            edges.add(StringGraphNode.createEdge(n, m));
            for (int i=0; i<k; i++) {
                boolean isLessOrEqual = partialOrderAux(children.get(i), m, edges);
                if (!isLessOrEqual) return false;
            }
            return true;
        }
        else if (m instanceof OrStringGraphNode) {
            StringGraphNode<?> md = null;
            for (StringGraphNode<?> prnd: m.getPrincipalNodes()) {
                String prndLbl = prnd.getLabel();
                if ( (prndLbl == null && n.getLabel() == null) ||
                        (prndLbl != null && prnd.getLabel().equals(n.getLabel()))) {
                    md = prnd; 
                    break;
                }
            }
            if (md != null) {
                edges.add(StringGraphNode.createEdge(n, m));
                return partialOrderAux(n, md, edges);
            }
        }
        return (n.getLabel().equals( m.getLabel() ));
    }
public static boolean partialOrderAux ( StringGraphNode < ? > n , StringGraphNode < ? > m , Set < Map . Entry < StringGraphNode < ? > , StringGraphNode < ? > > > edges ) { if ( edges . contains ( StringGraphNode . createEdge ( n , m ) ) ) return true ; else if ( m instanceof ConstStringGraphNode ) { ConstValues constValue = ( ( ConstStringGraphNode ) m ) . getValue ( ) ; if ( ConstValues . MAX == constValue ) { return true ; } } else if ( n instanceof ConcatStringGraphNode && m instanceof ConcatStringGraphNode ) { ConcatStringGraphNode concatN = ( ConcatStringGraphNode ) n ; ConcatStringGraphNode concatM = ( ConcatStringGraphNode ) m ; List < StringGraphNode < ? > > childrenN = n . getChildren ( ) ; List < StringGraphNode < ? > > childrenM = m . getChildren ( ) ; if ( Objects . equals ( concatN . getValue ( ) , concatM . getValue ( ) ) ) { edges . add ( StringGraphNode . createEdge ( n , m ) ) ; for ( int i = 0 ; i < concatN . getValue ( ) ; i ++ ) { boolean isLessOrEqual = partialOrderAux ( childrenN . get ( i ) , childrenM . get ( i ) , edges ) ; if ( ! isLessOrEqual ) return false ; } return true ; } } else if ( n instanceof OrStringGraphNode && m instanceof OrStringGraphNode ) { int k = n . getOutDegree ( ) ; List < StringGraphNode < ? > > children = n . getChildren ( ) ; edges . add ( StringGraphNode . createEdge ( n , m ) ) ; for ( int i = 0 ; i < k ; i ++ ) { boolean isLessOrEqual = partialOrderAux ( children . get ( i ) , m , edges ) ; if ( ! isLessOrEqual ) return false ; } return true ; } else if ( m instanceof OrStringGraphNode ) { StringGraphNode < ? > md = null ; for ( StringGraphNode < ? > prnd : m . getPrincipalNodes ( ) ) { String prndLbl = prnd . getLabel ( ) ; if ( ( prndLbl == null && n . getLabel ( ) == null ) || ( prndLbl != null && prnd . getLabel ( ) . equals ( n . getLabel ( ) ) ) ) { md = prnd ; break ; } } if ( md != null ) { edges . add ( StringGraphNode . createEdge ( n , m ) ) ; return partialOrderAux ( n , md , edges ) ; } } return ( n . getLabel ( ) . equals ( m . getLabel ( ) ) ) ; }
Auxiliary function for implementing partial ordering.
Auxiliary function for implementing partial ordering .
// case (1) // case (2) // case (3) // add current edge to edgeSet // for each i in [0,k] must hold: <=(n/i, m/i, edges+{m,n}) // case (4) // add current edge to edgeSet // for each i in [0,k] must hold: <=(n/i, m, edges+{m,n}) // case (5) // look for a node (named md) in prnd(m) such that lb(n) == lb(md) // found one // case (6)