Пример #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;
 }
  private static List<XmlElementDescriptor> computeRequiredSubTags(XmlElementsGroup group) {

    if (group.getMinOccurs() < 1) return Collections.emptyList();
    switch (group.getGroupType()) {
      case LEAF:
        XmlElementDescriptor descriptor = group.getLeafDescriptor();
        return descriptor == null
            ? Collections.<XmlElementDescriptor>emptyList()
            : Collections.singletonList(descriptor);
      case CHOICE:
        LinkedHashSet<XmlElementDescriptor> set = null;
        for (XmlElementsGroup subGroup : group.getSubGroups()) {
          List<XmlElementDescriptor> descriptors = computeRequiredSubTags(subGroup);
          if (set == null) {
            set = new LinkedHashSet<XmlElementDescriptor>(descriptors);
          } else {
            set.retainAll(descriptors);
          }
        }
        if (set == null || set.isEmpty()) {
          return Collections.singletonList(null); // placeholder for smart completion
        }
        return new ArrayList<XmlElementDescriptor>(set);

      default:
        ArrayList<XmlElementDescriptor> list = new ArrayList<XmlElementDescriptor>();
        for (XmlElementsGroup subGroup : group.getSubGroups()) {
          list.addAll(computeRequiredSubTags(subGroup));
        }
        return list;
    }
  }
Пример #3
0
 public ListValue intersect(ListValue other) {
   LinkedHashSet<SingleValue> set = new LinkedHashSet<SingleValue>();
   set.addAll(this.values);
   set.retainAll(other.values);
   ListValue result = new ListValue();
   result.values.addAll(set);
   return result;
 }
Пример #4
0
  public void test_retainAllLjava_util_Collection() {
    LinkedHashSet<Integer> lhs = new LinkedHashSet<Integer>();
    Vector v = new Vector<Float>();
    v.add(new Float(3.14));
    lhs.add(new Integer(1));
    assertEquals(1, lhs.size());
    lhs.retainAll(v);
    assertEquals(0, lhs.size());
    v = new Vector<Integer>();
    v.add(new Integer(1));
    v.add(new Integer(2));
    v.add(new Integer(3));
    v.add(new Integer(4));
    v.add(new Integer(5));
    v.add(new Integer(6));
    lhs.add(new Integer(1));
    lhs.add(new Integer(6));
    lhs.add(new Integer(7));
    lhs.add(new Integer(8));
    lhs.add(new Integer(9));
    lhs.add(new Integer(10));
    lhs.add(new Integer(11));
    lhs.add(new Integer(12));
    lhs.add(new Integer(13));
    assertEquals(9, lhs.size());
    lhs.retainAll(v);
    assertEquals(2, lhs.size());

    try {
      lhs.retainAll(null);
      fail("NullPointerException expected");
    } catch (NullPointerException e) {
      // expected
    }

    lhs = new Mock_LinkedHashSet();

    try {
      lhs.retainAll(v);
      fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
      // expected
    }
  }
Пример #5
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());
  }
Пример #6
0
  LinkedHashSet<FTATransition> intersect(ArrayList<LinkedHashSet<FTATransition>> d) {
    int smallest = 0;
    int smallestSize = d.get(0).size();
    for (int i = 1; i < d.size(); i++) {
      if (d.get(i).size() < smallestSize) {
        smallest = i;
        smallestSize = d.get(i).size();
      }
    }
    LinkedHashSet<FTATransition> result = (LinkedHashSet<FTATransition>) d.get(smallest).clone();
    for (int i = 0; i < d.size(); i++) {
      if (i != smallest) {
        result.retainAll(d.get(i));
      }
    }

    return result;
  }
Пример #7
0
 ArrayList<LinkedHashSet<FTATransition>> pruneSets(
     LinkedHashSet<LinkedHashSet<FTATransition>> psi_f_k, LinkedHashSet<FTATransition> newtrs) {
   ArrayList<LinkedHashSet<FTATransition>> result = new ArrayList<LinkedHashSet<FTATransition>>();
   LinkedHashSet<FTATransition> set1, set2;
   Iterator i = psi_f_k.iterator();
   int y = newtrs.size();
   System.out.print("Before " + psi_f_k.size() + " --- ");
   while (i.hasNext()) {
     set1 = (LinkedHashSet<FTATransition>) i.next();
     set2 = new LinkedHashSet<FTATransition>(newtrs);
     set2.retainAll(set1);
     // System.out.print(set1.size()+"."+set2.size()+": ");
     if (!set2.isEmpty()) {
       result.add(set2);
     }
   }
   System.out.println("After " + result.size());
   return result;
 }
Пример #8
0
  /**
   * Method to retain a Collection of elements (and remove all others).
   *
   * @param c The collection to retain
   * @return Whether they were retained successfully.
   */
  public boolean retainAll(java.util.Collection c) {
    if (c == null) {
      throw new NullPointerException("Input collection was null");
    }
    Collection collToRemove = new java.util.LinkedHashSet();
    for (Object o : delegate) {
      if (!c.contains(o)) {
        collToRemove.add(o);
      }
    }

    boolean success = delegate.retainAll(c);
    if (success) {
      makeDirty();
      if (SCOUtils.useQueuedUpdate(ownerOP)) {
        // Queue any cascade delete
        Iterator iter = collToRemove.iterator();
        while (iter.hasNext()) {
          ownerOP
              .getExecutionContext()
              .addOperationToQueue(
                  new CollectionRemoveOperation(
                      ownerOP, ownerMmd.getAbsoluteFieldNumber(), iter.next(), true));
        }
      } else if (SCOUtils.hasDependentElement(ownerMmd)) {
        // Perform the cascade delete
        Iterator iter = collToRemove.iterator();
        while (iter.hasNext()) {
          ownerOP.getExecutionContext().deleteObjectInternal(iter.next());
        }
      }

      if (ownerOP != null && !ownerOP.getExecutionContext().getTransaction().isActive()) {
        ownerOP.getExecutionContext().processNontransactionalUpdate();
      }
    }
    return success;
  }
Пример #9
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;
 }
Пример #10
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
      // String to = args[0];
      // String search = args[1];

      String query = "sachin";

      long time1 = System.currentTimeMillis();
      // 1-Title 2-Body 3-Infobox 4-Link 5-Category

      String searchvalues[] = query.split(" ");
      String[] s = new String[100];
      int wcount = 0;
      for (String sea : searchvalues) {
        int type = 0;
        String search;
        String cat[] = sea.split(":");
        if (cat.length == 2) {
          if (cat[0].equalsIgnoreCase("t")) type = 1;
          else if (cat[0].equalsIgnoreCase("b")) type = 2;
          else if (cat[0].equalsIgnoreCase("i")) type = 3;
          else if (cat[0].equalsIgnoreCase("l")) type = 4;
          else if (cat[0].equalsIgnoreCase("c")) type = 5;
          search = cat[1];
        } else {
          search = cat[0];
        }

        StringBuilder sb = new StringBuilder();
        sb.append(search);
        StringBuilder sb2 = new StringBuilder();
        for (int i = 0; i < search.length(); i++) {
          char c = sb.charAt(i);
          if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a)
            sb.setCharAt(i, ' ');
          else sb2.append(c);
        }
        search = sb2.toString();
        search = search.trim();
        Stemmer stemmer = new Stemmer();
        search = search.toLowerCase();
        char[] cArray = search.toCharArray();
        stemmer.add(cArray, search.length());
        stemmer.stem();
        search = stemmer.toString();

        // System.out.println(search);

        char ch = search.charAt(0);
        File toread = new File(to + "\\" + ch + ".txt");
        // System.out.println(to + "/" + search.charAt(0) + ".txt");
        FileReader fr = new FileReader(toread);
        BufferedReader br = new BufferedReader(fr);

        s[wcount] = binarySearch(search, toread, type);
        // System.out.println(s[wcount]);
        wcount++;
        br.close();
        fr.close();
      }

      LinkedHashSet<String> lhs = new LinkedHashSet<String>();

      String set1[] = s[0].split(",");
      TreeMap<Integer, Integer> tmap = new TreeMap<Integer, Integer>();
      // System.out.println(set1.length);
      tmap.put(set1.length, 0);
      for (String s2 : set1) {
        lhs.add(s2);
      }
      for (int i = 1; i < wcount; i++) {
        LinkedHashSet<String> lhs2 = new LinkedHashSet<String>();
        set1 = s[i].split(",");
        tmap.put(set1.length, i);

        for (String s1 : set1) {
          lhs2.add(s1);
        }
        lhs.retainAll(lhs2);
      }

      int count = 0;
      TreeSet<String> answerset = new TreeSet<String>();
      for (String ans : lhs) {

        // System.out.print(ans+",");
        String result = searchtitle(ans);
        System.out.print(result);
        if (!(result.equalsIgnoreCase(""))) {
          count++;
          System.out.println();
        }
        answerset.add(ans);
        count++;
        if (count == 10) break;
      }
      // System.out.println("Here"+wcount);
      if (count < 10) {
        for (Map.Entry<Integer, Integer> entry : tmap.entrySet()) {

          int index = entry.getValue();
          String arr[] = s[index].split(",");
          for (String rem : arr) {
            if (!answerset.contains(rem)) {
              // System.out.print(rem+",");
              String result = searchtitle(rem);
              System.out.print(result);
              if (!(result.equalsIgnoreCase(""))) {
                count++;
                System.out.println();
              }
              answerset.add(rem);
            }
            if (count == 10) break;
          }
          if (count == 10) break;
        }
      }

      long time2 = System.currentTimeMillis() - time1;
      System.out.println("\n\nTotal time taken:" + time2 / 1000.0);
    } catch (Exception e) {
      // e.printStackTrace();
    }
  }