Пример #1
0
 LinkedHashSet<LinkedHashSet<FTATransition>> intersectCartProd(
     ArrayList<ArrayList<LinkedHashSet<FTATransition>>> psi_phi_tuple, int k) {
   LinkedHashSet<LinkedHashSet<FTATransition>> result =
       new LinkedHashSet<LinkedHashSet<FTATransition>>();
   LinkedHashSet<FTATransition> t;
   if (k == psi_phi_tuple.size() - 1) {
     for (int i = 0; i < psi_phi_tuple.get(k).size(); i++) {
       result.add((LinkedHashSet<FTATransition>) (psi_phi_tuple.get(k).get(i)).clone());
     }
     return result;
   } else {
     LinkedHashSet<LinkedHashSet<FTATransition>> r = intersectCartProd(psi_phi_tuple, k + 1);
     Iterator i = r.iterator();
     while (i.hasNext()) {
       t = (LinkedHashSet<FTATransition>) i.next();
       for (int j = 0; j < psi_phi_tuple.get(k).size(); j++) {
         LinkedHashSet<FTATransition> u = (LinkedHashSet<FTATransition>) t.clone();
         u.retainAll(psi_phi_tuple.get(k).get(j));
         if (!u.isEmpty()) {
           result.add(u);
         }
       }
     }
   }
   return result;
 }
Пример #2
0
  /** Runs Program One */
  public void run() {
    System.out.println("Problem One running...\n");

    // Input
    System.out.println(
        "Type a word to be added to Set One and press Enter to add. Type -1 to finish. ");
    while (!input.equals("-1")) {
      System.out.print("Set One, Word " + (setOne.size() + 1) + ": ");
      input = in.nextLine();
      if (!(input.isEmpty() || input.equals("-1"))) {
        setOne.add(input);
      }
    }

    input = "";
    System.out.println();
    System.out.println(
        "Type a word to be added to Set Two and press Enter to add. Type -1 to finish. ");
    while (!input.equals("-1")) {
      System.out.print("Set Two, Word " + (setTwo.size() + 1) + ": ");
      input = in.nextLine();
      if (!(input.isEmpty() || input.equals("-1"))) {
        setTwo.add(input);
      }
    }

    // Clone setOne to retain original copy of data
    LinkedHashSet<String> cloneOne = (LinkedHashSet<String>) setOne.clone();
    LinkedHashSet<String> cloneTwo = (LinkedHashSet<String>) setOne.clone();
    LinkedHashSet<String> cloneThree = (LinkedHashSet<String>) setOne.clone();

    // Unionize the sets by appending setTwo to setOne (only unique elements
    // are added)
    cloneOne.addAll(setTwo);
    // Intersect sets by removing elements in setOne NOT found in setTwo
    cloneTwo.retainAll(setTwo);
    // Differentiate sets by removing elements in setOne found in setTwo
    cloneThree.removeAll(setTwo);

    // Output
    System.out.println();
    System.out.println("SetOne: " + setOne.toString());
    System.out.println("SetTwo: " + setTwo.toString());
    System.out.println("Union of SetOne to SetTwo : " + cloneOne.toString());
    System.out.println("Intersection of SetOne to SetTwo : " + cloneTwo.toString());
    System.out.println("Difference of SetOne to SetTwo " + cloneThree.toString());
  }
Пример #3
0
 /** java.util.LinkedHashSet#clear() */
 public void test_clear() {
   // Test for method void java.util.LinkedHashSet.clear()
   Set orgSet = (Set) hs.clone();
   hs.clear();
   Iterator i = orgSet.iterator();
   assertEquals("Returned non-zero size after clear", 0, hs.size());
   while (i.hasNext()) assertTrue("Failed to clear set", !hs.contains(i.next()));
 }
Пример #4
0
 public static void main(String[] args) throws Exception {
   ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("c:\\test.dat"));
   LinkedHashSet<String> set1 = new LinkedHashSet<String>();
   set1.add("New York");
   LinkedHashSet<String> set2 = (LinkedHashSet<String>) set1.clone();
   set1.add("Atlanta");
   output.writeObject(set1);
   output.writeObject(set2);
   output.close();
   ObjectInputStream input = new ObjectInputStream(new FileInputStream("c:\\test.dat"));
   set1 = (LinkedHashSet) input.readObject();
   set2 = (LinkedHashSet) input.readObject();
   System.out.println(set1);
   System.out.println(set2);
   output.close();
 }
Пример #5
0
 boolean intersectsAll(
     LinkedHashSet<FTATransition> deltaj,
     int j,
     FuncSymb f,
     ArrayList<ArrayList<LinkedHashSet<FTATransition>>> psi_tuple) {
   // check whether deltaj intersects with all members of all non-j elements of psi_tuple
   LinkedHashSet<FTATransition> ts;
   for (int k = 0; k < f.arity; k++) {
     if (k != j) {
       if (psi_tuple.get(k).isEmpty()) {
         return false;
       }
       for (int l = 0; l < psi_tuple.get(k).size(); l++) {
         ts = (LinkedHashSet<FTATransition>) deltaj.clone();
         ts.retainAll(psi_tuple.get(k).get(l));
         if (ts.isEmpty()) {
           return false;
         }
       }
     }
   }
   return true;
 }
Пример #6
0
 /** java.util.LinkedHashSet#clone() */
 public void test_clone() {
   // Test for method java.lang.Object java.util.LinkedHashSet.clone()
   LinkedHashSet hs2 = (LinkedHashSet) hs.clone();
   assertTrue("clone returned an equivalent LinkedHashSet", hs != hs2);
   assertTrue("clone did not return an equal LinkedHashSet", hs.equals(hs2));
 }
Пример #7
0
 /**
  * Creates and returns a copy of this object.
  *
  * @return The cloned object
  */
 public Object clone() {
   return delegate.clone();
 }