Пример #1
0
 public boolean hashSetContainsSameOperations(HashSet set1, HashSet set2) {
   boolean result = false;
   HashSet s1 = (HashSet) set1.clone();
   HashSet s2 = (HashSet) set2.clone();
   // first part, are all elements of s1 also in s2?
   boolean one = false;
   Iterator it = set1.iterator();
   while (it.hasNext()) {
     PDMOperation d = (PDMOperation) it.next();
     if (s2.contains(d)) {
       s1.remove(d);
     }
   }
   if (s1.isEmpty()) {
     one = true;
   }
   // second part, are all elements of s21 also in s1?
   boolean two = false;
   HashSet s3 = (HashSet) set1.clone();
   HashSet s4 = (HashSet) set2.clone();
   Iterator it2 = set2.iterator();
   while (it2.hasNext()) {
     PDMOperation d = (PDMOperation) it2.next();
     if (s3.contains(d)) {
       s4.remove(d);
     }
   }
   if (s4.isEmpty()) {
     two = true;
   }
   // administrative stuff
   s1.clear();
   s2.clear();
   s3.clear();
   s4.clear();
   result = one && two;
   return result;
 }
Пример #2
0
  public HashSet calculateExecutableOperations(
      HashSet dataElts, HashSet executed, HashSet failed, boolean root) {
    HashSet result = new HashSet();
    HashSet enabledOperations = new HashSet();

    if (root) {
      // Calculate the enabled operations (i.e. those operation of which
      // all input elements are in the set of available elements)
      Object[] ops = operations.values().toArray();
      for (int i = 0; i < ops.length; i++) {
        PDMOperation op = (PDMOperation) ops[i];
        HashMap inputs = op.getInputElements();
        Object[] ins = inputs.values().toArray();
        boolean enabled = true;
        int k = 0;
        while (enabled && k < ins.length) {
          PDMDataElement d = (PDMDataElement) ins[k];
          if (!(dataElts.contains(d))) {
            enabled = false;
          }
          k++;
        }
        if (enabled) {
          enabledOperations.add(op);
          // System.out.println("Enabled operation: "+ op.getID());
        }
      }
    } else if (!(dataElts.contains(this.getRootElement()))) {
      // Calculate the enabled operations (i.e. those operation of which
      // all input elements are in the set of available elements)
      Object[] ops = operations.values().toArray();
      for (int i = 0; i < ops.length; i++) {
        PDMOperation op = (PDMOperation) ops[i];
        HashMap inputs = op.getInputElements();
        Object[] ins = inputs.values().toArray();
        boolean enabled = true;
        int k = 0;
        while (enabled && k < ins.length) {
          PDMDataElement d = (PDMDataElement) ins[k];
          if (!(dataElts.contains(d))) {
            enabled = false;
          }
          k++;
        }
        if (enabled) {
          enabledOperations.add(op);
        }
      }
    }
    // remove already executed operations
    Iterator exIt = executed.iterator();
    while (exIt.hasNext()) {
      PDMOperation op = (PDMOperation) exIt.next();
      enabledOperations.remove(op);
    }
    // remove already failed operations
    Iterator fIt = failed.iterator();
    while (fIt.hasNext()) {
      PDMOperation op = (PDMOperation) fIt.next();
      enabledOperations.remove(op);
    }
    result = enabledOperations;
    return result;
  }