コード例 #1
0
ファイル: GraphImpl.java プロジェクト: teropa/stem
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 public void putNodeLabel(NodeLabel label) {
   getNodeLabels().put(label.getURI(), label);
   // Dynamic?
   if (label instanceof DynamicLabel) {
     // Yes
     addDynamicLabel((DynamicLabel) label);
   } // if DynamicLabel
 } // putNodeLabel
コード例 #2
0
ファイル: GraphImpl.java プロジェクト: teropa/stem
  /** @see org.eclipse.stem.common.impl.IdentifiableImpl#sane() */
  @Override
  public boolean sane() {
    boolean retValue = super.sane();

    // This is the number of labels that each node references
    int nodeLabelCount = 0;
    int dynamicLabelCount = 0;

    // Nodes
    if (nodes != null) {
      // Yes
      for (final Iterator<Node> nodeIter = getNodes().values().iterator();
          nodeIter.hasNext() && retValue; ) {
        final Node node = nodeIter.next();
        retValue = retValue && node.sane();
        assert retValue;

        nodeLabelCount += node.getLabels().size();

        // How many dynamic labels?
        for (final Iterator<NodeLabel> labelIter = node.getLabels().iterator();
            labelIter.hasNext(); ) {
          final Label label = labelIter.next();
          if (label instanceof DynamicLabel) {
            dynamicLabelCount++;
            retValue = false;

            // The dynamic label should be in the collection of
            // dynamic labels maintained by the graph
            for (DynamicLabel dl : getDynamicLabels()) {
              if (dl == label) {
                retValue = true;
                break;
              }
            } // for each dynamic label
            assert retValue;
          } // if DynamicLabel
          // The label should be in the collection of node labels
          retValue = retValue && getNodeLabels().containsKey(label.getURI());
          assert retValue;
        } // for each label of the node
      } // for each node
    } // if

    // Edges?
    if (edges != null) {
      // Yes
      for (final Iterator<Edge> edgeIter = getEdges().values().iterator();
          edgeIter.hasNext() && retValue; ) {
        final Edge edge = edgeIter.next();
        retValue = retValue && edge.sane();
        assert retValue;

        // Is the edge's label dynamic?
        if (edge.getLabel() instanceof DynamicLabel) {
          // Yes
          dynamicLabelCount++;
        }
      } // for each edge
    } // if

    // Node Labels?
    if (nodeLabels != null) {
      // Yes
      // The number of node labels should match the number we counted
      // above...not true for graph fragments that might have labels for
      // nodes in other (sub) graph fragments.
      // retValue = retValue && nodeLabelCount ==
      // getNodeLabels().getSize();
      // assert retValue;

      for (final Iterator<NodeLabel> labelIter = getNodeLabels().values().iterator();
          labelIter.hasNext() && retValue; ) {
        final NodeLabel nodeLabel = labelIter.next();
        retValue = retValue && nodeLabel.sane();
        assert retValue;
      } // for each node label
    } // if

    if (graphLabels != null) {
      // Yes
      for (final Iterator<Label> graphLabelIter = getGraphLabels().values().iterator();
          graphLabelIter.hasNext(); ) {
        final Label graphLabel = graphLabelIter.next();
        retValue = retValue && graphLabel.sane();
        assert retValue;

        if (graphLabel instanceof DynamicLabel) {
          dynamicLabelCount++;
        }
      }
    } // if graphLabels

    // Dynamic Labels?
    if (dynamicLabels != null) {
      // Yes
      // The number of dynamic labels should equal the count
      retValue = dynamicLabelCount == getNumDynamicLabels();
      assert retValue;

      for (final Iterator<DynamicLabel> dynamiclIter = getDynamicLabels().iterator();
          dynamiclIter.hasNext() && retValue; ) {
        final DynamicLabel dynamicLabel = dynamiclIter.next();
        retValue = retValue && dynamicLabel.sane();
        assert retValue;
      } // for each dynamic label
    } // if

    return retValue;
  } // sane
コード例 #3
0
ファイル: GraphImpl.java プロジェクト: teropa/stem
  /**
   *
   * <!-- begin-user-doc -->
   * Return all of the Node Labels in the graph that have a particular type URI.
   * <!-- end-user-doc -->
   *
   * @generated NOT
   */
  public EList<NodeLabel> getNodeLabelsByTypeURI(URI typeURI) {
    // We could perform this function in a number of ways. We could, for
    // instance, create a Map between the type URI's and the instances,
    // however if we do that then we do two things: 1) make management of
    // the collection of instances more complicated (we have to add them to
    // two maps), and, 2) we "bloat" the serialization as we now basically
    // double the size of the serialized collection(s).
    // Given that this method is called infrequently it's probably better to
    // just do a "dumb" sequential scan of the instances and match them.
    // We can always change out minds later.

    final EList<NodeLabel> retValue = new BasicEList<NodeLabel>();

    for (final Iterator<NodeLabel> nodeLabelIter = getNodeLabels().values().iterator();
        nodeLabelIter.hasNext(); ) {
      final NodeLabel nodeLabel = nodeLabelIter.next();
      // Does this one the type we're looking for?
      if (nodeLabel.getTypeURI().equals(typeURI)) {
        // Yes
        retValue.add(nodeLabel);
      }
    } // for each nodeLabel

    // Stefan 7/23/09. If need to guarantee the order of objects this list
    // being the same for each call since the list is used to partition
    // the work up among multiple worker threads. Luckily this call
    // is only made once for every decorator in the beginning of a simulation
    // so sorting is not expensive.

    ECollections.sort(
        retValue,
        new Comparator<NodeLabel>() {

          public int compare(NodeLabel arg0, NodeLabel arg1) {
            Node n1 = arg0.getNode();
            Node n2 = arg1.getNode();
            if (n1 == null) {
              CorePlugin.logError(
                  "Label "
                      + arg0.getClass()
                      + " "
                      + arg0
                      + " uri:"
                      + arg0.getURI()
                      + " node is null",
                  new Exception());
              return 0;
            }
            if (n2 == null) {
              CorePlugin.logError(
                  "Label "
                      + arg1.getClass()
                      + " "
                      + arg1
                      + " uri:"
                      + arg1.getURI()
                      + " node is null",
                  new Exception());
              return 0;
            }
            URI u1 = n1.getURI();
            URI u2 = n2.getURI();
            if (u1 == null) {
              CorePlugin.logError("Node " + n1 + " missing URI", new Exception());
              return 0;
            }
            if (u2 == null) {
              CorePlugin.logError("Node " + n2 + " missing URI", new Exception());
              return 0;
            }

            return u1.toString().compareTo(u2.toString());
          }
        });

    return retValue;
  } // getNodeLabelsByTypeURI