示例#1
0
  /**
   *
   * <!-- 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