Exemplo n.º 1
2
  private void checkRules() {
    outputMessage("\nChecking " + m_baseUrl, TEST_SUMMARY_MESSAGE);
    outputMessage(
        "crawl depth: " + m_crawlDepth + "     crawl delay: " + m_crawlDelay + " ms.",
        PLAIN_MESSAGE);

    TreeSet crawlList = new TreeSet();
    TreeSet fetched = new TreeSet();
    // inialize with the baseUrl
    crawlList.add(m_baseUrl);
    depth_incl = new int[m_crawlDepth];
    depth_fetched = new int[m_crawlDepth];
    depth_parsed = new int[m_crawlDepth];
    long start_time = TimeBase.nowMs();
    for (int depth = 1; depth <= m_crawlDepth; depth++) {
      if (isInterrupted()) {
        return;
      }
      m_curDepth = depth;
      if (crawlList.isEmpty() && depth <= m_crawlDepth) {
        outputMessage("\nNothing left to crawl, exiting after depth " + (depth - 1), PLAIN_MESSAGE);
        break;
      }
      String[] urls = (String[]) crawlList.toArray(new String[0]);
      crawlList.clear();
      outputMessage("\nDepth " + depth, PLAIN_MESSAGE);
      for (int ix = 0; ix < urls.length; ix++) {
        if (isInterrupted()) {
          return;
        }
        pauseBeforeFetch();
        String urlstr = urls[ix];

        m_incls.clear();
        m_excls.clear();

        // crawl the page
        buildUrlSets(urlstr);
        fetched.add(urlstr);
        // output incl/excl results,
        // add the new_incls to the crawlList for next crawl depth loop
        crawlList.addAll(outputUrlResults(urlstr, m_incls, m_excls));
      }
    }
    long elapsed_time = TimeBase.nowMs() - start_time;
    outputSummary(m_baseUrl, fetched, crawlList, elapsed_time);
  }
  // @include
  public static ArrayList<Integer> findMinimumVisits(ArrayList<Interval> intervals) {
    TreeSet<Interval> left = new TreeSet<Interval>(new LeftComp());
    TreeSet<Interval> right = new TreeSet<Interval>(new RightComp());

    for (Interval interval : intervals) {
      left.add(interval);
      right.add(interval);
    }

    ArrayList<Integer> s = new ArrayList<Integer>();
    while (!left.isEmpty() && !right.isEmpty()) {
      int b = right.first().right;
      s.add(b);

      // Remove the intervals which intersect with R.cbegin().
      Iterator<Interval> it = left.iterator();
      while (it.hasNext()) {
        Interval interval = it.next();
        if (interval.left > b) {
          break;
        }

        right.remove(interval);
        it.remove();
      }
    }

    return s;
  }
Exemplo n.º 3
0
 /**
  * Same as {@link #getRequestedProjects()}, but with a variable cookieName and parameter name.
  * This way it is trivial to implement a project filter ...
  *
  * @param paramName the name of the request parameter, which possibly contains the project list in
  *     question.
  * @param cookieName name of the cookie which possible contains project lists used as fallback
  * @return a possible empty set but never {@code null}.
  */
 protected SortedSet<String> getRequestedProjects(String paramName, String cookieName) {
   TreeSet<String> set = new TreeSet<>();
   List<Project> projects = getEnv().getProjects();
   if (projects == null) {
     return set;
   }
   if (projects.size() == 1 && authFramework.isAllowed(req, projects.get(0))) {
     set.add(projects.get(0).getDescription());
     return set;
   }
   List<String> vals = getParamVals(paramName);
   for (String s : vals) {
     Project x = Project.getByDescription(s);
     if (x != null && authFramework.isAllowed(req, x)) {
       set.add(s);
     }
   }
   if (set.isEmpty()) {
     List<String> cookies = getCookieVals(cookieName);
     for (String s : cookies) {
       Project x = Project.getByDescription(s);
       if (x != null && authFramework.isAllowed(req, x)) {
         set.add(s);
       }
     }
   }
   if (set.isEmpty()) {
     Project defaultProject = env.getDefaultProject();
     if (defaultProject != null && authFramework.isAllowed(req, defaultProject)) {
       set.add(defaultProject.getDescription());
     }
   }
   return set;
 }
  /**
   * Recursive method to add list layers get by the WMSServer into tree list
   *
   * @param children Represents child layers of parentNode
   * @param tree Tree of layers
   * @param crs CRS that must have the layers to add these to the tree
   * @param parentNode Represents parent layer
   * @param layersMap Represents the map that contains the layers obtained
   * @param isCalledByWizard Indicate if the method is called by the wizard
   */
  private void generateWMSChildrenNodes(
      ArrayList<WMSLayer> children,
      List<TreeNode> tree,
      TreeSet<String> listCrs,
      TreeNode parentNode,
      Map<String, org.gvsig.framework.web.ogc.WMSLayer> layersMap,
      WMSInfo wmsInfo) {
    for (WMSLayer layerChild : children) {
      // get crs (srs) (belong to layer)
      Vector crsVector = layerChild.getAllSrs();
      // Only get the layers with have crs parameter or if crs is null
      if (listCrs.isEmpty() || !Collections.disjoint(crsVector, listCrs)) {

        ArrayList<WMSLayer> layerChildChildren = layerChild.getChildren();
        TreeNode layerChildNode = new TreeNode(layerChild.getName());
        layerChildNode.setTitle(layerChild.getTitle());

        // Get the children and their information
        if (layerChildChildren.isEmpty()) {
          layerChildNode.setFolder(false);

          // Add layer to layer map
          org.gvsig.framework.web.ogc.WMSLayer wmsLayer =
              new org.gvsig.framework.web.ogc.WMSLayer();
          TreeSet<String> crsSet = new TreeSet<String>();
          crsSet.addAll(layerChild.getAllSrs());
          wmsLayer.setCrs(crsSet);
          List<WMSStyle> wmsStyles = createListWMSStyles(layerChild.getStyles());
          wmsLayer.setStyles(wmsStyles);
          wmsLayer.setTitle(layerChild.getTitle());
          wmsLayer.setName(layerChild.getName());
          layersMap.put(layerChild.getName(), wmsLayer);

          // add to wmsinfo the layers supported by this layer
          TreeSet<String> crsSupported = wmsInfo.getCrsSupported();
          crsSupported.addAll(layerChild.getAllSrs());
          wmsInfo.setCrsSupported(crsSupported);

          // create one child for each crs of the layer
          if (listCrs.isEmpty() || listCrs.size() > 1) {
            for (String crs : crsSet) {
              if (StringUtils.isNotEmpty(crs) && (listCrs.isEmpty() || listCrs.contains(crs))) {
                TreeNode crsNode = new TreeNode(crs);
                crsNode.setHideCheckbox(true);
                crsNode.setUnselectable(true);
                crsNode.setIconclass(" ");
                layerChildNode.addChild(crsNode);
              }
            }
          }
        } else {
          layerChildNode.setFolder(true);
          layerChildNode.setExpanded(true);
          generateWMSChildrenNodes(
              layerChildChildren, tree, listCrs, layerChildNode, layersMap, wmsInfo);
        }
        parentNode.addChild(layerChildNode);
      }
    }
  }
Exemplo n.º 5
0
 public int bfs(int x, int goal) {
   TreeSet<Node> queue = new TreeSet<>();
   queue.add(new Node(x, 0));
   BitSet set = new BitSet();
   // List of all valid nodes, includes the x value and the cost to get there.
   List<Node> valid = new ArrayList<>();
   while (!queue.isEmpty()) {
     Node c = queue.pollFirst();
     // evety possible node is visited
     if (set.cardinality() == max) {
       return -1;
     }
     if (set.get(c.x)) {
       continue;
     }
     valid.add(c);
     if (c.x == goal) {
       return c.cost;
     }
     set.set(c.x);
     for (Node n : valid) {
       // the operation is not conmutative
       int r = arroba(c.x, n.x);
       if (!set.get(r)) {
         // cost of creating n + cost of creating c + 1
         queue.add(new Node(r, n.cost + c.cost + 1));
       }
       r = arroba(n.x, c.x);
       if (!set.get(r)) {
         queue.add(new Node(r, n.cost + c.cost + 1));
       }
     }
   }
   return -1;
 }
Exemplo n.º 6
0
 public static boolean print(OutputStream out, Collection<SubjectArea> subjectAreas)
     throws IOException, DocumentException {
   TreeSet courses =
       new TreeSet(
           new Comparator() {
             public int compare(Object o1, Object o2) {
               CourseOffering co1 = (CourseOffering) o1;
               CourseOffering co2 = (CourseOffering) o2;
               int cmp = co1.getCourseName().compareTo(co2.getCourseName());
               if (cmp != 0) return cmp;
               return co1.getUniqueId().compareTo(co2.getUniqueId());
             }
           });
   String subjectIds = "";
   for (SubjectArea sa : subjectAreas)
     subjectIds += (subjectIds.isEmpty() ? "" : ",") + sa.getUniqueId();
   courses.addAll(
       SessionDAO.getInstance()
           .getSession()
           .createQuery(
               "select co from CourseOffering co where  co.subjectArea.uniqueId in ("
                   + subjectIds
                   + ")")
           .list());
   if (courses.isEmpty()) return false;
   PdfWorksheet w = new PdfWorksheet(out, subjectAreas, null);
   for (Iterator i = courses.iterator(); i.hasNext(); ) {
     w.print((CourseOffering) i.next());
   }
   w.lastPage();
   w.close();
   return true;
 }
Exemplo n.º 7
0
 static TreeSet<Book> newBook(TreeSet<Book> books, String name) {
   if (books.isEmpty()) // 如果集合是空的, 書號由 1001 開始
   books.add(new Book(1001, name));
   else // 否則將新書號設為最大書號加 1
   books.add(new Book(books.last().id + 1, name));
   return books;
 }
Exemplo n.º 8
0
 public static boolean print(
     OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber)
     throws IOException, DocumentException {
   TreeSet courses =
       new TreeSet(
           new Comparator() {
             public int compare(Object o1, Object o2) {
               CourseOffering co1 = (CourseOffering) o1;
               CourseOffering co2 = (CourseOffering) o2;
               int cmp = co1.getCourseName().compareTo(co2.getCourseName());
               if (cmp != 0) return cmp;
               return co1.getUniqueId().compareTo(co2.getUniqueId());
             }
           });
   String subjectIds = "";
   for (SubjectArea sa : subjectAreas)
     subjectIds += (subjectIds.isEmpty() ? "" : ",") + sa.getUniqueId();
   String query =
       "select co from CourseOffering co where  co.subjectArea.uniqueId in (" + subjectIds + ")";
   if (courseNumber != null && !courseNumber.trim().isEmpty()) {
     query += " and co.courseNbr ";
     if (courseNumber.indexOf('*') >= 0)
       query += " like '" + courseNumber.trim().replace('*', '%').toUpperCase() + "'";
     else query += " = '" + courseNumber.trim().toUpperCase() + "'";
   }
   courses.addAll(new SessionDAO().getSession().createQuery(query).list());
   if (courses.isEmpty()) return false;
   PdfWorksheet w = new PdfWorksheet(out, subjectAreas, courseNumber);
   for (Iterator i = courses.iterator(); i.hasNext(); ) {
     w.print((CourseOffering) i.next());
   }
   w.lastPage();
   w.close();
   return true;
 }
Exemplo n.º 9
0
  private void calculateLCOM(String className) {

    int common = 0;
    int disjoint = 0;

    Map<String, Set<VariableUse>> perMethodSet = variablesUsedPerClass.get(className);
    for (String method : perMethodSet.keySet()) {
      for (String anotherMethod : perMethodSet.keySet()) {
        if (!method.equals(anotherMethod)) {
          Set<VariableUse> methodInstanceVariables = perMethodSet.get(method);
          Set<VariableUse> anotherMethodInstanceVariables = perMethodSet.get(anotherMethod);
          TreeSet<VariableUse> intersection = new TreeSet<VariableUse>(methodInstanceVariables);
          intersection.retainAll(anotherMethodInstanceVariables);
          if (intersection.isEmpty()) {
            System.out.println("Disjoint for " + method + " " + anotherMethod + "=" + disjoint);
            disjoint++;
          } else {
            common++;
          }
          int result = 0;
          if (disjoint > common) {
            result = disjoint - common;
          }
          results.put("ClassName", new Integer(result));
        }
      }
    }
  }
Exemplo n.º 10
0
  public synchronized RemoteFileDesc getBest() throws NoSuchElementException {
    if (!hasMore()) return null;
    RemoteFileDesc ret;

    // try a verified host
    if (!verifiedHosts.isEmpty()) {
      LOG.debug("getting a verified host");
      ret = (RemoteFileDesc) verifiedHosts.first();
      verifiedHosts.remove(ret);
    } else {
      LOG.debug("getting a non-verified host");
      // use the legacy ranking logic to select a non-verified host
      Iterator dual = new DualIterator(testedLocations.iterator(), newHosts.iterator());
      ret = LegacyRanker.getBest(dual);
      newHosts.remove(ret);
      testedLocations.remove(ret);
      if (ret.needsPush()) {
        for (Iterator iter = ret.getPushProxies().iterator(); iter.hasNext(); )
          pingedHosts.remove(iter.next());
      } else pingedHosts.remove(ret);
    }

    pingNewHosts();

    if (LOG.isDebugEnabled())
      LOG.debug("the best host we came up with is " + ret + " " + ret.getPushAddr());
    return ret;
  }
Exemplo n.º 11
0
 public void testNewTreeSetEmptyDerived() {
   TreeSet<Derived> set = Sets.newTreeSet();
   assertTrue(set.isEmpty());
   set.add(new Derived("foo"));
   set.add(new Derived("bar"));
   assertThat(set).containsExactly(new Derived("bar"), new Derived("foo")).inOrder();
 }
Exemplo n.º 12
0
  public final double snapAngle(double angle) {
    if (snapSet.isEmpty()) {
      return angle;
    }
    int quadrant = (int) Math.floor(angle / PI_2);
    double ang = angle % PI_2;
    Double prev = snapSet.floor(ang);
    if (prev == null) prev = snapSet.last() - PI_2;
    Double next = snapSet.ceiling(ang);
    if (next == null) next = snapSet.first() + PI_2;

    if (Math.abs(ang - next) > Math.abs(ang - prev)) {
      if (Math.abs(ang - prev) > Math.PI / 8) {
        return angle;
      } else {
        double ret = prev + PI_2 * quadrant;
        if (ret < 0) ret += 2 * Math.PI;
        return ret;
      }
    } else {
      if (Math.abs(ang - next) > Math.PI / 8) {
        return angle;
      } else {
        double ret = next + PI_2 * quadrant;
        if (ret > 2 * Math.PI) ret -= 2 * Math.PI;
        return ret;
      }
    }
  }
Exemplo n.º 13
0
    public int compare(TreeSet<Drawable3D> set1, TreeSet<Drawable3D> set2) {

      /*
      TreeSet set1 = (TreeSet) arg1;
      TreeSet set2 = (TreeSet) arg2;
      */

      // check if one set is empty
      if (set1.isEmpty()) return 1;
      if (set2.isEmpty()) return -1;

      Drawable3D d1 = (Drawable3D) set1.first();
      Drawable3D d2 = (Drawable3D) set2.first();

      return d1.comparePickingTo(d2, true);
    }
Exemplo n.º 14
0
 void solve() {
   int k = nextInt();
   char[] c = nextToken().toCharArray();
   for (int i = 0, j = c.length - 1; i < j; i++, j--) {
     if (c[i] != '?' && c[j] != '?' && c[i] != c[j]) {
       out.println("IMPOSSIBLE");
       return;
     }
   }
   int q = 0;
   TreeSet<Character> ts = new TreeSet<Character>();
   for (int i = 0; i < k; i++) {
     ts.add((char) ('a' + i));
   }
   for (int i = 0, j = c.length - 1; i <= j; i++, j--) {
     if (c[i] == '?' && c[j] == '?') {
       q++;
     }
     if (c[i] != '?') {
       ts.remove(c[i]);
     }
     if (c[j] != '?') {
       ts.remove(c[j]);
     }
   }
   for (int i = (c.length - 1) / 2, j = c.length - i - 1; i >= 0; i--, j++) {
     if (c[i] == '?' && c[j] == '?') {
       if (!ts.isEmpty()) {
         c[i] = c[j] = ts.pollLast();
       } else {
         c[i] = c[j] = 'a';
       }
     }
   }
   if (!ts.isEmpty()) {
     out.println("IMPOSSIBLE");
     return;
   }
   for (int i = 0, j = c.length - 1; i < j; i++, j--) {
     if (c[i] == '?') {
       c[i] = c[j];
     } else if (c[j] == '?') {
       c[j] = c[i];
     }
   }
   out.println(new String(c));
 }
Exemplo n.º 15
0
 /**
  * Adds a type filter to this suite, allowing certain tests to be excluded. Note that this is a
  * significantly slower option than {@link #withIFileFilter(gw.util.Predicate)} or {@link
  * #withPackageFilter(gw.util.Predicate)} If possible, it is advisable to use a file filter
  * instead.
  */
 public final T withTestTypeFilter(Predicate<IType> filter) {
   if (!_testSpecs.isEmpty()) {
     throw new IllegalStateException(
         "You should add a test filter before any tests are added to the suite.");
   }
   _typeFilters.add(filter);
   return thisAsT();
 }
  private void doPostponedFormattingInner(final FileViewProvider key) {

    final List<ASTNode> astNodes = myReformatElements.remove(key);
    final Document document = key.getDocument();
    // Sort ranges by end offsets so that we won't need any offset adjustment after reformat or
    // reindent
    if (document == null) return;

    final VirtualFile virtualFile = key.getVirtualFile();
    if (!virtualFile.isValid()) return;

    final TreeSet<PostprocessFormattingTask> postProcessTasks =
        new TreeSet<PostprocessFormattingTask>();
    Collection<Disposable> toDispose = ContainerUtilRt.newArrayList();
    try {
      // process all roots in viewProvider to find marked for reformat before elements and create
      // appropriate range markers
      handleReformatMarkers(key, postProcessTasks);
      toDispose.addAll(postProcessTasks);

      // then we create ranges by changed nodes. One per node. There ranges can intersect. Ranges
      // are sorted by end offset.
      if (astNodes != null) createActionsMap(astNodes, key, postProcessTasks);

      if ("true".equals(System.getProperty("check.psi.is.valid"))
          && ApplicationManager.getApplication().isUnitTestMode()) {
        checkPsiIsCorrect(key);
      }

      while (!postProcessTasks.isEmpty()) {
        // now we have to normalize actions so that they not intersect and ordered in most
        // appropriate way
        // (free reformatting -> reindent -> formatting under reindent)
        final List<PostponedAction> normalizedActions =
            normalizeAndReorderPostponedActions(postProcessTasks, document);
        toDispose.addAll(normalizedActions);

        // only in following loop real changes in document are made
        for (final PostponedAction normalizedAction : normalizedActions) {
          CodeStyleSettings settings =
              CodeStyleSettingsManager.getSettings(myPsiManager.getProject());
          boolean old = settings.ENABLE_JAVADOC_FORMATTING;
          settings.ENABLE_JAVADOC_FORMATTING = false;
          try {
            normalizedAction.execute(key);
          } finally {
            settings.ENABLE_JAVADOC_FORMATTING = old;
          }
        }
      }
    } finally {
      for (Disposable disposable : toDispose) {
        //noinspection SSBasedInspection
        disposable.dispose();
      }
    }
  }
Exemplo n.º 17
0
 public void testNewTreeSetEmptyNonGeneric() {
   TreeSet<LegacyComparable> set = Sets.newTreeSet();
   assertTrue(set.isEmpty());
   set.add(new LegacyComparable("foo"));
   set.add(new LegacyComparable("bar"));
   assertThat(set)
       .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo"))
       .inOrder();
 }
Exemplo n.º 18
0
  /**
   * Handle responses from CCNNameEnumerator that give us a list of single-component child names.
   * Filter out the names new to us, add them to our list of known children, postprocess them with
   * processNewChildren(SortedSet<ContentName>), and signal waiters if we have new data.
   *
   * @param prefix Prefix used for name enumeration.
   * @param names The list of names returned in this name enumeration response.
   * @return int
   */
  public int handleNameEnumerator(ContentName prefix, ArrayList<ContentName> names) {

    if (Log.isLoggable(Level.INFO)) {
      if (!_enumerating) {
        // Right now, just log if we get data out of enumeration, don't drop it on the floor;
        // don't want to miss results in case we are started again.
        Log.info(
            "ENUMERATION STOPPED: but {0} new name enumeration results: our prefix: {1} returned prefix: {2}",
            names.size(), _namePrefix, prefix);
      } else {
        Log.info(
            names.size() + " new name enumeration results: our prefix: {0} returned prefix: {1}",
            _namePrefix,
            prefix);
      }
    }
    if (!prefix.equals(_namePrefix)) {
      Log.warning("Returned data doesn't match requested prefix!");
    }
    Log.info("Handling Name Iteration {0}", prefix);
    // the name enumerator hands off names to us, we own it now
    // DKS -- want to keep listed as new children we previously had
    synchronized (_childLock) {
      TreeSet<ContentName> thisRoundNew = new TreeSet<ContentName>();
      thisRoundNew.addAll(names);
      Iterator<ContentName> it = thisRoundNew.iterator();
      while (it.hasNext()) {
        ContentName name = it.next();
        if (_children.contains(name)) {
          it.remove();
        }
      }
      if (!thisRoundNew.isEmpty()) {
        if (null != _newChildren) {
          _newChildren.addAll(thisRoundNew);
        } else {
          _newChildren = thisRoundNew;
        }
        _children.addAll(thisRoundNew);
        _lastUpdate = new CCNTime();
        if (Log.isLoggable(Level.INFO)) {
          Log.info(
              "New children found: at {0} "
                  + thisRoundNew.size()
                  + " total children "
                  + _children.size(),
              _lastUpdate);
        }
        processNewChildren(thisRoundNew);
        _childLock.notifyAll();
      }
    }
    return 0;
  }
Exemplo n.º 19
0
  /*
   * (non-Javadoc)
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  @Override
  public int compareTo(Cluster aCluster) {
    // Cluster cluster = aCluster;
    if (segmentSet.isEmpty()) {
      return -1;
    }
    if (aCluster.segmentSet.isEmpty()) {
      return -1;
    }

    return (segmentSet.first().compareTo(aCluster.segmentSet.first()));
  }
Exemplo n.º 20
0
 private NavigableSet dset5() {
   TreeSet q = new TreeSet();
   assertTrue(q.isEmpty());
   q.add(m1);
   q.add(m2);
   q.add(m3);
   q.add(m4);
   q.add(m5);
   NavigableSet s = q.descendingSet();
   assertEquals(5, s.size());
   return s;
 }
Exemplo n.º 21
0
 /** java.util.TreeSet#TreeSet(java.util.Comparator) */
 public void test_ConstructorLjava_util_Comparator() {
   // Test for method java.util.TreeSet(java.util.Comparator)
   TreeSet myTreeSet = new TreeSet(new ReversedIntegerComparator());
   assertTrue("Did not construct correct TreeSet", myTreeSet.isEmpty());
   myTreeSet.add(new Integer(1));
   myTreeSet.add(new Integer(2));
   assertTrue(
       "Answered incorrect first element--did not use custom comparator ",
       myTreeSet.first().equals(new Integer(2)));
   assertTrue(
       "Answered incorrect last element--did not use custom comparator ",
       myTreeSet.last().equals(new Integer(1)));
 }
Exemplo n.º 22
0
  /**
   * TreeSet is sorted How to iterate a TreeSet How to check empty How to retrieve first/last
   * element How to remove an element
   */
  public static void main(String[] args) {
    TreeSet<Integer> myTree = new TreeSet<>();
    myTree.add(35);
    myTree.add(45);
    myTree.add(25);
    myTree.add(35);

    // Traversal of TreeSet
    Iterator<Integer> iter = myTree.iterator();
    while (iter.hasNext()) {
      System.out.println(iter.next()); // Output : 25, 35, 45
    }

    // EmptyChecking
    if (myTree.isEmpty()) {
      System.out.println("Tree is empty");
    } else {
      System.out.println("Tree is not empty");
    }

    // retrieving First element
    System.out.println("First Element: " + myTree.first());
    System.out.println("Last Element: " + myTree.last());

    // Removing an element
    myTree.remove(35);
    Iterator<Integer> iter2 = myTree.iterator();
    while (iter2.hasNext()) {
      System.out.println(iter2.next()); // Output : 25, 45
    }

    // Clearing the tree
    myTree.clear();
    if (myTree.isEmpty()) {
      System.out.println("Tree is empty");
    } else {
      System.out.println("Tree is not empty");
    }
  }
Exemplo n.º 23
0
  /** Returns a new set of given size containing consecutive Integers 0 ... n. */
  private NavigableSet<Integer> populatedSet(int n) {
    TreeSet<Integer> q = new TreeSet<Integer>();
    assertTrue(q.isEmpty());

    for (int i = n - 1; i >= 0; i -= 2) assertTrue(q.add(new Integer(i)));
    for (int i = (n & 1); i < n; i += 2) assertTrue(q.add(new Integer(i)));
    assertTrue(q.add(new Integer(-n)));
    assertTrue(q.add(new Integer(n)));
    NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
    assertFalse(s.isEmpty());
    assertEquals(n, s.size());
    return s;
  }
Exemplo n.º 24
0
 /** Returns a new set of first 5 ints. */
 private NavigableSet set5() {
   TreeSet q = new TreeSet();
   assertTrue(q.isEmpty());
   q.add(one);
   q.add(two);
   q.add(three);
   q.add(four);
   q.add(five);
   q.add(zero);
   q.add(seven);
   NavigableSet s = q.subSet(one, true, seven, false);
   assertEquals(5, s.size());
   return s;
 }
Exemplo n.º 25
0
  private void maybeInitSuite() {
    if (!_suiteHasBeenSetUp) {

      initTypeSystem();
      if (_gosuClassSearchPath.isEmpty()
          && _javaClassSearchPath.isEmpty()
          && _testSpecs.isEmpty()) {
        _gosuClassSearchPath.addAll(createDefaultGosuClassSearchPath());
        _javaClassSearchPath.addAll(createDefaultJavaClassSearchPath());
      }

      _suiteHasBeenSetUp = true;
    }
  }
Exemplo n.º 26
0
  public GuiComponent getTopGuiComponentAt(int positionX, int positionY) {
    TreeSet<GuiComponent> guiComponents = new TreeSet<GuiComponent>(GuiComponent.zIndexComparator);
    for (GuiComponent guiComponent : getGuiComponents()) {
      if (guiComponent.intersectsWith(positionX, positionY)) {
        guiComponents.add(guiComponent);
      }
    }

    if (!guiComponents.isEmpty()) {
      return guiComponents.first();
    } else {
      return null;
    }
  }
Exemplo n.º 27
0
 public void appendVertex(ExecVertex v) {
   graph.addVertex(v);
   Task t = v.getTask();
   TreeSet<ExecVertex> vset = taskVertex.get(t);
   if (vset == null) {
     vset = new TreeSet<ExecVertex>();
     taskVertex.put(t, vset);
   }
   if (!vset.isEmpty()) {
     ExecVertex last = vset.last();
     ExecEdge e1 = graph.addEdge(last, v);
     graph.setEdgeWeight(e1, v.getTimestamp() - last.getTimestamp());
   }
   vset.add(v);
 }
Exemplo n.º 28
0
  private String[] getIntersectionEdgeMap(Connection conn, long n1, int[] c1, long n2, int[] c2)
      throws SQLException {

    TreeSet<String> em1 = getEdgeMap(conn, c1, n1);
    TreeSet<String> em2 = getEdgeMap(conn, c2, n2);

    TreeSet<String> rv = new TreeSet<String>();
    while (!em1.isEmpty()) {
      String next = em1.pollFirst();
      if (em2.contains(next)) {
        rv.add(next);
      }
    }
    return rv.toArray(new String[0]);
  }
Exemplo n.º 29
0
  /**
   * Accessor for whether a collection is contained in this Set.
   *
   * @param c The collection
   * @return Whether it is contained.
   */
  public synchronized boolean containsAll(java.util.Collection c) {
    if (useCache) {
      loadFromStore();
    } else if (backingStore != null) {
      java.util.TreeSet tree = new java.util.TreeSet(c);
      Iterator iter = iterator();
      while (iter.hasNext()) {
        tree.remove(iter.next());
      }

      return tree.isEmpty();
    }

    return delegate.containsAll(c);
  }
  public double getMonoisotopicMass() {
    if (isotopes.isEmpty()) return 0;

    Iterator<Isotope> isotopeIterator = isotopes.iterator();
    Isotope isotope;
    Isotope mostAbundant = isotopeIterator.next();

    while (isotopeIterator.hasNext()) {
      isotope = isotopeIterator.next();
      if (isotope.getAbundance() > mostAbundant.getAbundance()) {
        mostAbundant = isotope;
      }
    }

    return mostAbundant.getMass();
  }