Beispiel #1
0
 public void testSubSetContents2() {
   NavigableSet set = set5();
   SortedSet sm = set.subSet(two, three);
   assertEquals(1, sm.size());
   assertEquals(two, sm.first());
   assertEquals(two, sm.last());
   assertFalse(sm.contains(one));
   assertTrue(sm.contains(two));
   assertFalse(sm.contains(three));
   assertFalse(sm.contains(four));
   assertFalse(sm.contains(five));
   Iterator i = sm.iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(two, k);
   assertFalse(i.hasNext());
   Iterator j = sm.iterator();
   j.next();
   j.remove();
   assertFalse(set.contains(two));
   assertEquals(4, set.size());
   assertEquals(0, sm.size());
   assertTrue(sm.isEmpty());
   assertFalse(sm.remove(three));
   assertEquals(4, set.size());
 }
 /** {@inheritDoc} */
 @Override
 public void onMatching(
     String docUri, Type type, SortedSet<Annotation> goldAnnos, SortedSet<Annotation> sysAnnos) {
   if (goldAnnos.size() == 1 && sysAnnos.size() == 1) {
     Annotation goldAnno = goldAnnos.iterator().next();
     Annotation sysAnno = sysAnnos.iterator().next();
     if (goldAnno.getBegin() == sysAnno.getBegin() && goldAnno.getEnd() == sysAnno.getEnd()) {
       printRow(
           type.getShortName(),
           "Exact",
           goldAnno.getCoveredText(),
           String.valueOf(goldAnno.getBegin()),
           sysAnno.getCoveredText(),
           String.valueOf(sysAnno.getBegin()),
           docUri);
       return;
     }
   }
   printRow(
       type.getShortName(),
       "Partial",
       Joiner.on(" /// ").join(transform(goldAnnos, annoToTxt)),
       Joiner.on(", ").join(transform(goldAnnos, annoToOffset)),
       Joiner.on(" /// ").join(transform(sysAnnos, annoToTxt)),
       Joiner.on(", ").join(transform(sysAnnos, annoToOffset)),
       docUri);
 }
  public void testTailSetInteger() {
    SortedSet<Integer> s;
    Iterator<Integer> i;

    s = this.list.tailSet(30);
    assertTrue(s.isEmpty());

    s = this.list.tailSet(21);
    assertEquals(5, s.size());
    i = s.iterator();
    assertEquals(Integer.valueOf(21), i.next());
    assertEquals(Integer.valueOf(22), i.next());
    assertEquals(Integer.valueOf(23), i.next());
    assertEquals(Integer.valueOf(24), i.next());
    assertEquals(Integer.valueOf(25), i.next());

    s = this.list.tailSet(4);
    assertEquals(7, s.size());
    i = s.iterator();
    assertEquals(Integer.valueOf(10), i.next());
    assertEquals(Integer.valueOf(20), i.next());
    assertEquals(Integer.valueOf(21), i.next());
    assertEquals(Integer.valueOf(22), i.next());
    assertEquals(Integer.valueOf(23), i.next());
    assertEquals(Integer.valueOf(24), i.next());
    assertEquals(Integer.valueOf(25), i.next());
  }
Beispiel #4
0
 public void testDescendingSubSetContents2() {
   NavigableSet set = dset5();
   SortedSet sm = set.subSet(m2, m3);
   assertEquals(1, sm.size());
   assertEquals(m2, sm.first());
   assertEquals(m2, sm.last());
   assertFalse(sm.contains(m1));
   assertTrue(sm.contains(m2));
   assertFalse(sm.contains(m3));
   assertFalse(sm.contains(m4));
   assertFalse(sm.contains(m5));
   Iterator i = sm.iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(m2, k);
   assertFalse(i.hasNext());
   Iterator j = sm.iterator();
   j.next();
   j.remove();
   assertFalse(set.contains(m2));
   assertEquals(4, set.size());
   assertEquals(0, sm.size());
   assertTrue(sm.isEmpty());
   assertFalse(sm.remove(m3));
   assertEquals(4, set.size());
 }
Beispiel #5
0
  /**
   * Takes a potentially non-sequential alignment and guesses a sequential version of it. Residues
   * from each structure are sorted sequentially and then compared directly.
   *
   * <p>The results of this method are consistent with what one might expect from an identity
   * function, and are therefore useful with {@link #getSymmetryOrder(Map, Map identity, int,
   * float)}.
   *
   * <ul>
   *   <li>Perfect self-alignments will have the same pre-image and image, so will map X->X
   *   <li>Gaps and alignment errors will cause errors in the resulting map, but only locally.
   *       Errors do not propagate through the whole alignment.
   * </ul>
   *
   * <h4>Example:</h4>
   *
   * A non sequential alignment, represented schematically as
   *
   * <pre>
   * 12456789
   * 78912345</pre>
   *
   * would result in a map
   *
   * <pre>
   * 12456789
   * 12345789</pre>
   *
   * @param alignment The non-sequential input alignment
   * @param inverseAlignment If false, map from structure1 to structure2. If true, generate the
   *     inverse of that map.
   * @return A mapping from sequential residues of one protein to those of the other
   * @throws IllegalArgumentException if the input alignment is not one-to-one.
   */
  public static Map<Integer, Integer> guessSequentialAlignment(
      Map<Integer, Integer> alignment, boolean inverseAlignment) {
    Map<Integer, Integer> identity = new HashMap<Integer, Integer>();

    SortedSet<Integer> aligned1 = new TreeSet<Integer>();
    SortedSet<Integer> aligned2 = new TreeSet<Integer>();

    for (Entry<Integer, Integer> pair : alignment.entrySet()) {
      aligned1.add(pair.getKey());
      if (!aligned2.add(pair.getValue()))
        throw new IllegalArgumentException(
            "Alignment is not one-to-one for residue "
                + pair.getValue()
                + " of the second structure.");
    }

    Iterator<Integer> it1 = aligned1.iterator();
    Iterator<Integer> it2 = aligned2.iterator();
    while (it1.hasNext()) {
      if (inverseAlignment) { // 2->1
        identity.put(it2.next(), it1.next());
      } else { // 1->2
        identity.put(it1.next(), it2.next());
      }
    }
    return identity;
  }
Beispiel #6
0
  public String toString() {
    String s = new String();
    SortedSet antecedent = getAntecedent();
    Iterator it2 = antecedent.iterator();
    SortedSet consequence = getConsequence();
    Iterator it3 = consequence.iterator();
    while (it2.hasNext()) {
      String itemCourantant = it2.next().toString();
      s = s + (itemCourantant = itemCourantant + " ");
    }
    String itemCourantcons;
    for (s = s + " --> "; it3.hasNext(); s = s + itemCourantcons + " ")
      itemCourantcons = it3.next().toString();

    s = s + "\t\t";
    s = s + "(S = ";
    String sup = Double.toString((double) (int) (getSupport() * 100D) / 100D);
    s = s + sup;
    s = s + "% ; ";
    s = s + "C = ";
    String c = Double.toString((double) (int) (getConfiance() * 100D) / 100D);
    s = s + c;
    s = s + ")";
    return s;
  }
 private void initCrossingsGraph(DependencyStructure dg) {
   crossingsGraph = new IdentityHashMap<Edge, List<Edge>>();
   SortedSet<Edge> edges = dg.getEdges();
   // System.out.println(edges.size());
   // System.out.println(dg.nEdges());
   for (Iterator<Edge> iterator1 = edges.iterator(); iterator1.hasNext(); ) {
     Edge edge1 = iterator1.next();
     for (Iterator<Edge> iterator2 = edges.iterator(); iterator2.hasNext(); ) {
       Edge edge2 = iterator2.next();
       if (edge1.getSource().getIndex() < edge2.getSource().getIndex() && cross(edge1, edge2)) {
         // System.out.println("Crossing!");
         List<Edge> crossingEdge1 = crossingsGraph.get(edge1);
         if (crossingEdge1 == null) {
           crossingEdge1 = new LinkedList<Edge>();
           crossingsGraph.put(edge1, crossingEdge1);
         }
         crossingEdge1.add(edge2);
         List<Edge> crossingEdge2 = crossingsGraph.get(edge2);
         if (crossingEdge2 == null) {
           crossingEdge2 = new LinkedList<Edge>();
           crossingsGraph.put(edge2, crossingEdge2);
         }
         crossingEdge2.add(edge1);
       }
     }
   }
 }
Beispiel #8
0
 private void buildListOfAllPatterns(Domain domain, String prefix, int level)
     throws TermWareException {
   SortedSet directSystemNames = domain.getNamesOfSystems();
   Iterator systemsIterator = directSystemNames.iterator();
   while (systemsIterator.hasNext()) {
     String name = (String) systemsIterator.next();
     TermSystem system = domain.resolveSystem(name);
     SortedSet<String> names = system.getPatternNames();
     Iterator namesIterator = names.iterator();
     while (namesIterator.hasNext()) {
       String patternName = (String) namesIterator.next();
       if (!allPatterns_.containsKey(patternName)) {
         HashSet indexEntries = new HashSet();
         allPatterns_.put(patternName, indexEntries);
       }
       HashSet systemsSet = (HashSet) allPatterns_.get(patternName);
       systemsSet.add(new APIGen.PatternIndexEntry(prefix, domain, name, level));
     }
   }
   SortedSet domainsSet = domain.getNamesOfDirectSubdomains();
   Iterator domainsIterator = domainsSet.iterator();
   while (domainsIterator.hasNext()) {
     String subdomainName = (String) domainsIterator.next();
     Domain subdomain = domain.getDirectSubdomain(subdomainName);
     buildListOfAllPatterns(subdomain, prefix + subdomainName + "/", level + 1);
   }
 }
Beispiel #9
0
 /** Returs a Collection of Collections of items forming a connected set. */
 public Collection<Collection<Item>> get_connected_sets(int p_net_no) {
   Collection<Collection<Item>> result = new LinkedList<Collection<Item>>();
   if (p_net_no <= 0) {
     return result;
   }
   SortedSet<Item> items_to_handle = new TreeSet<Item>();
   Iterator<UndoableObjects.UndoableObjectNode> it = this.item_list.start_read_object();
   for (; ; ) {
     Item curr_item = (Item) item_list.read_object(it);
     if (curr_item == null) {
       break;
     }
     if (curr_item instanceof Connectable && curr_item.contains_net(p_net_no)) {
       items_to_handle.add(curr_item);
     }
   }
   Iterator<Item> it2 = items_to_handle.iterator();
   while (it2.hasNext()) {
     Item curr_item = it2.next();
     Collection<Item> next_connected_set = curr_item.get_connected_set(p_net_no);
     result.add(next_connected_set);
     items_to_handle.removeAll(next_connected_set);
     it2 = items_to_handle.iterator();
   }
   return result;
 }
Beispiel #10
0
  private void generateSystemPages(Domain domain, String prefix, int level)
      throws IOException, TermWareException {
    SortedSet directSystemNames = domain.getNamesOfSystems();
    Iterator systemsIterator = directSystemNames.iterator();
    while (systemsIterator.hasNext()) {
      String name = (String) systemsIterator.next();
      PrintStream out = openPrintStream(prefix + name, "all-patterns.html");
      printHeader(out, "patterns for " + name);
      out.println("<BODY BGCOLOR=\"white\">");
      out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">");
      out.println("<TR>");
      out.println("<TD NOWRAP><FONT size=\"+1\">");
      out.println("Patterns");
      out.println("</FONT></TD>");
      out.println("</TR></TABLE>");
      out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">");
      out.println("<TR><TD NOWRAP><P>");
      out.println("<FONT>");

      TermSystem system = domain.resolveSystem(name);
      SortedSet names = system.getPatternNames();
      Iterator namesIterator = names.iterator();
      while (namesIterator.hasNext()) {
        String patternName = (String) namesIterator.next();
        String uri = prefix + name + "/index.html#" + patternName;
        out.print("<A href=\"../");
        for (int i = 0; i < level; ++i) {
          out.print("../");
        }
        out.print(uri + "\" TARGET=\"transformerFrame\" >");
        out.print(patternName);
        out.println("</A>");
        out.println("<BR>");
      }
      out.println("</FONT>");
      out.println("</TD>");
      out.println("</TR>");
      out.println("</TABLE>");
      out.println("<P>&nbsp;</BODY></HTML>");
      out.close();
      out = openPrintStream(prefix + name, "index.html");
      TermSystem ts = domain.resolveSystem(name);
      printSystemIndexPage(out, prefix + name, ts);
      out.close();
    }
    SortedSet domainsSet = domain.getNamesOfDirectSubdomains();
    Iterator domainsIterator = domainsSet.iterator();
    while (domainsIterator.hasNext()) {
      String subdomainName = (String) domainsIterator.next();
      Domain subdomain = domain.getDirectSubdomain(subdomainName);
      generateSystemPages(subdomain, prefix + subdomainName + "/", level + 1);
    }
  }
Beispiel #11
0
  private synchronized void updateState() {
    if (closed.get()) {
      // remove all empty queues
      for (Iterator<NamedQueue> iterator = openQueuesBySequenceId.iterator();
          iterator.hasNext(); ) {
        NamedQueue namedQueue = iterator.next();
        if (namedQueue.isEmpty()) {
          namedQueue.setFinished();
          iterator.remove();
        }
      }
      // discard queued pages (not officially in the buffer) and waiters
      for (QueuedPage queuedPage : queuedPages) {
        queuedPage.getFuture().set(null);
      }
      queuedPages.clear();
    }

    if (state == QueueState.NO_MORE_QUEUES && !openQueuesBySequenceId.isEmpty()) {
      // advance master sequence id
      long oldMasterSequenceId = masterSequenceId;
      masterSequenceId = openQueuesBySequenceId.iterator().next().getSequenceId();

      // drop consumed pages
      int pagesToRemove = Ints.checkedCast(masterSequenceId - oldMasterSequenceId);
      Preconditions.checkState(
          pagesToRemove >= 0,
          "Master sequence id moved backwards: oldMasterSequenceId=%s, newMasterSequenceId=%s",
          oldMasterSequenceId,
          masterSequenceId);

      for (int i = 0; i < pagesToRemove; i++) {
        Page page = masterQueue.removeFirst();
        bufferedBytes -= page.getDataSize().toBytes();
      }

      // refill buffer from queued pages
      while (!queuedPages.isEmpty() && bufferedBytes < maxBufferedBytes) {
        QueuedPage queuedPage = queuedPages.removeFirst();
        addInternal(queuedPage.getPage());
        queuedPage.getFuture().set(null);
      }
    }

    if (state == QueueState.NO_MORE_QUEUES && closed.get() && openQueuesBySequenceId.isEmpty()) {
      destroy();
    }

    this.notifyAll();
  }
Beispiel #12
0
  public void testToSortedSet() {
    SortedSet<Integer> set;
    Iterator<Integer> i;

    set = this.list.toSortedSet();

    i = set.iterator();
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(1), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(2), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(3), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(10), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(20), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(21), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(22), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(23), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(24), i.next());
    assertTrue(i.hasNext());
    assertEquals(Integer.valueOf(25), i.next());
    assertFalse(i.hasNext());
  }
Beispiel #13
0
  /**
   * Marks and returns the next trigger to execute, preferring the given custId. If no appropriate
   * trigger can be found for the given customerId, a trigger may be returned belonging to a
   * different custId. (Paused triggers will be ignored by this method.)
   */
  private Trigger acquireNextTrigger(SchedulingContext ctxt, long custId) {
    WrappedTrigger nonCustomerMatch = null;
    for (Iterator<WrappedTrigger> it = m_triggersByScore.iterator(); it.hasNext(); ) {
      WrappedTrigger wt = it.next();
      // compare customer first if we already have a non-customer match
      if ((custId > 0) && (custId != wt.getCustomerId()) && (nonCustomerMatch != null)) {
        continue;
      }
      if (wt.getState() != Trigger.STATE_NORMAL) {
        continue;
      }
      Trigger t = wt.getTrigger();
      if (!isEligibleGroupName(t.getGroup())) {
        continue;
      }
      if ((custId > 0) && (custId != wt.getCustomerId())) {
        nonCustomerMatch = wt;
      } else {
        //        s_logCategory.debug("acquireNextTrigger(" + custId + ") returning trigger for " +
        // wt.getCustomerId());
        return claimTrigger(wt);
      }
    }

    if (nonCustomerMatch == null) {
      return null;
    } else {
      //      s_logCategory.debug("acquireNextTrigger(" + custId + ") returning trigger for " +
      // nonCustomerMatch.getCustomerId());
      return claimTrigger(nonCustomerMatch);
    }
  }
  /**
   * Update the filtered events data structure.
   *
   * @param aInsertedToFront indicates whether events were added to front of the events. If true,
   *     then the current first event must still exist in the list after the filter is applied.
   */
  private void updateFilteredEvents(boolean aInsertedToFront) {
    final long start = System.currentTimeMillis();
    final List filtered = new ArrayList();
    final int size = mAllEvents.size();
    final Iterator it = mAllEvents.iterator();

    while (it.hasNext()) {
      final EventDetails event = (EventDetails) it.next();
      if (matchFilter(event)) {
        filtered.add(event);
      }
    }

    final EventDetails lastFirst = (mFilteredEvents.length == 0) ? null : mFilteredEvents[0];
    mFilteredEvents = (EventDetails[]) filtered.toArray(EMPTY_LIST);

    if (aInsertedToFront && (lastFirst != null)) {
      final int index = filtered.indexOf(lastFirst);
      if (index < 1) {
        LOG.warn("In strange state");
        fireTableDataChanged();
      } else {
        fireTableRowsInserted(0, index - 1);
      }
    } else {
      fireTableDataChanged();
    }

    final long end = System.currentTimeMillis();
    LOG.debug("Total time [ms]: " + (end - start) + " in update, size: " + size);
  }
Beispiel #15
0
  /**
   * Step through each FlowEntry in order and match on it. If we get EQUALS or SUBSET, then stop.
   *
   * <p>IF we get SUPERSET or INTERSECT, then keep going and merge the results.
   */
  @Override
  public List<FlowIntersect> intersects(long dpid, OFMatch match) {

    List<FlowIntersect> results = new ArrayList<FlowIntersect>();
    FlowIntersect intersect;
    MatchType matchType;
    boolean needMerge = false;

    for (Iterator<FlowEntry> it = rules.iterator(); it.hasNext(); ) {
      FlowEntry rule = it.next();
      intersect = rule.matches(dpid, match);
      matchType = intersect.getMatchType();

      if (matchType == MatchType.NONE) continue;

      results.add(intersect);
      if ((matchType == MatchType.EQUAL) || (matchType == MatchType.SUBSET)) break;
      if ((matchType == MatchType.INTERSECT) || (matchType == MatchType.SUPERSET)) needMerge = true;
      else
        // else, wtf?
        throw new RuntimeException("Unknown MatchType = " + intersect.getMatchType());
    }

    if (needMerge && (results.size() > 1))
      // BROKEN: needs to virtualize priorities
      // return priorityMerge(results); // expensive, avoid if possible
      return results;
    else return results;
  }
Beispiel #16
0
  public Usuario BuscarUsuarioDevolver(Usuario objeto) {
    boolean encontrado = false;
    Usuario auxiliar = null;

    /*
     * Se define un iterador inicializado con el iterador de la colección
     */
    Iterator iterador = UsuariosRegistrados.iterator();

    /*
     * Mientras no se encuentre el elemento y existan mas elementos en la
     * colección, se sigue entrando en el ciclo
     */
    while (!encontrado && iterador.hasNext()) {
      /*
       *  Se obtiene el siguiente objeto del iterador y se le hace un cast
       *  para asignarlo al objeto de tipo Nodo
       */
      auxiliar = (Usuario) iterador.next();

      /*
       * Se invoca al método equals de la clase Nodo para determinar si son
       * iguales. En caso de serlo, se encontró el elemento buscado
       */
      // if (objeto.equals(auxiliar))
      if ((objeto.getNickname().contentEquals(auxiliar.getNickname()))
          && (objeto.getClave().contentEquals(auxiliar.getClave()))) return (auxiliar);
    }
    return (objeto);
  }
Beispiel #17
0
  /** tailSet returns set with keys in requested range */
  public void testDescendingTailSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.tailSet(m2);
    assertFalse(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertTrue(sm.contains(m4));
    assertTrue(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(m2, k);
    k = (Integer) (i.next());
    assertEquals(m3, k);
    k = (Integer) (i.next());
    assertEquals(m4, k);
    k = (Integer) (i.next());
    assertEquals(m5, k);
    assertFalse(i.hasNext());

    SortedSet ssm = sm.tailSet(m4);
    assertEquals(m4, ssm.first());
    assertEquals(m5, ssm.last());
    assertTrue(ssm.remove(m4));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
  }
Beispiel #18
0
 /**
  * If some or all of the children of this name are versions, returns the latest version among
  * them.
  *
  * @return ContentName The latest version component
  */
 public ContentName getLatestVersionChildName() {
   // of the available names in _children that are version components,
   // find the latest one (version-wise)
   // names are sorted, so the last one that is a version should be the latest version
   // ListIterator previous doesn't work unless you've somehow gotten it to point at the end...
   ContentName theName = null;
   ContentName latestName = null;
   CCNTime latestTimestamp = null;
   Iterator<ContentName> it = _children.iterator();
   // TODO these are sorted -- we just need to iterate through them in reverse order. Having
   // trouble finding something like C++'s reverse iterators to do that (linked list iterators
   // can go backwards -- but you have to run them to the end first).
   while (it.hasNext()) {
     theName = it.next();
     if (VersioningProfile.isVersionComponent(theName.component(0))) {
       if (null == latestName) {
         latestName = theName;
         latestTimestamp = VersioningProfile.getVersionComponentAsTimestamp(theName.component(0));
       } else {
         CCNTime thisTimestamp =
             VersioningProfile.getVersionComponentAsTimestamp(theName.component(0));
         if (thisTimestamp.after(latestTimestamp)) {
           latestName = theName;
           latestTimestamp = thisTimestamp;
         }
       }
     }
   }
   return latestName;
 }
Beispiel #19
0
  /**
   * Allocates the requested space in the file.
   *
   * @param len requested space
   * @return allocated file position and length as FileEntry object
   */
  private FileEntry allocate(int len) {
    synchronized (freeList) {
      // lookup a free entry of sufficient size
      SortedSet<FileEntry> candidates = freeList.tailSet(new FileEntry(0, len));
      for (Iterator<FileEntry> it = candidates.iterator(); it.hasNext(); ) {
        FileEntry free = it.next();
        // ignore entries that are still in use by concurrent readers
        if (free.isLocked()) continue;

        // There's no race condition risk between locking the entry on
        // loading and checking whether it's locked (or store allocation),
        // because for the entry to be lockable, it needs to be in the
        // entries collection, in which case it's not in the free list.
        // The only way an entry can be found in the free list is if it's
        // been removed, and to remove it, lock on "entries" needs to be
        // acquired, which is also a pre-requisite for loading data.

        // found one, remove from freeList
        it.remove();
        return allocateExistingEntry(free, len);
      }

      // no appropriate free section available, append at end of file
      FileEntry fe = new FileEntry(filePos, len);
      filePos += len;
      if (trace)
        log.tracef(
            "New entry allocated at %d:%d, %d free entries, file size is %d",
            fe.offset, fe.size, freeList.size(), filePos);
      return fe;
    }
  }
 /**
  * Add the packages list that use the given class.
  *
  * @param contentTree the content tree to which the packages list will be added
  */
 protected void addPackageList(Content contentTree) throws IOException {
   Content table =
       HtmlTree.TABLE(
           HtmlStyle.useSummary,
           0,
           3,
           0,
           useTableSummary,
           getTableCaption(
               configuration.getResource(
                   "doclet.ClassUse_Packages.that.use.0",
                   getLink(
                       new LinkInfoImpl(
                           configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER, classdoc)))));
   table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
   Content tbody = new HtmlTree(HtmlTag.TBODY);
   Iterator<PackageDoc> it = pkgSet.iterator();
   for (int i = 0; it.hasNext(); i++) {
     PackageDoc pkg = it.next();
     HtmlTree tr = new HtmlTree(HtmlTag.TR);
     if (i % 2 == 0) {
       tr.addStyle(HtmlStyle.altColor);
     } else {
       tr.addStyle(HtmlStyle.rowColor);
     }
     addPackageUse(pkg, tr);
     tbody.addContent(tr);
   }
   table.addContent(tbody);
   Content li = HtmlTree.LI(HtmlStyle.blockList, table);
   contentTree.addContent(li);
 }
Beispiel #21
0
  /** tailSet returns set with keys in requested range */
  public void testTailSetContents() {
    NavigableSet set = set5();
    SortedSet sm = set.tailSet(two);
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertTrue(sm.contains(four));
    assertTrue(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    k = (Integer) (i.next());
    assertEquals(four, k);
    k = (Integer) (i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());

    SortedSet ssm = sm.tailSet(four);
    assertEquals(four, ssm.first());
    assertEquals(five, ssm.last());
    assertTrue(ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
  }
  /**
   * @returns the neighbour IDs
   * @param userId - the numeric ID of the target user
   * @param itemId - the numerid ID of the target item
   * @param itemProfileMap - a map containing item profiles
   * @param simMap - a map containing user-user similarities
   */
  public ArrayList<Integer> getNeighbours(
      final Integer itemId,
      final Integer userId,
      final Map<Integer, Profile> userProfileMap,
      final SimilarityMap simMap) {
    SortedSet<ScoredThingDsc> ss =
        new TreeSet<
            ScoredThingDsc>(); // store all user IDs in order of descending similarity in a sorted
                               // set

    if (userProfileMap.containsKey(userId)) {
      for (Iterator<Integer> it = userProfileMap.get(userId).getIds().iterator();
          it.hasNext(); ) // iterate over each user in the item profile
      {
        Integer id = it.next();
        double sim = simMap.getSimilarity(itemId, id);
        if (sim > 0) ss.add(new ScoredThingDsc(sim, id));
      }
    }

    ArrayList<Integer> neighbours = new ArrayList<Integer>(); // get the k most similar neighbours

    int kCounter = 0;
    for (Iterator<ScoredThingDsc> it = ss.iterator(); it.hasNext(); ) {
      kCounter++;

      ScoredThingDsc st = it.next();
      neighbours.add((Integer) st.thing);

      if (kCounter > k) break;
    }

    return neighbours;
  }
 @SuppressWarnings("EmptyCatchBlock")
 static void ensureNotDirectlyModifiable(SortedSet<Integer> unmod) {
   try {
     unmod.add(4);
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.remove(4);
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.addAll(Collections.singleton(4));
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.iterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
 }
  public static List<Integer> findMinimumVisits(Interval[] intervals) {
    SortedSet<Interval> left = new TreeSet<>(new LeftComp());
    SortedSet<Interval> right = new TreeSet<>(new RightComp());

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

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

      // Removes 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;
  }
  @Override
  public String toString() {
    if (displayName == null) {
      // We fetch the display string for the category. We start by looking
      //  in the "Tools.Prefs.Category.<categoryID>.Label" bundle. If no such
      //  key exist, we iterate through the panes (which are ordered according
      //  to their priority) and use the first display name we find. If none
      //  is found, we use the categoryID.
      Resources resources = Resources.getDashBundle(DEFAULT_DISPLAY_STRING_LOCATION);
      try {
        displayName = resources.getString(categoryID + ".Label");
      } catch (MissingResourceException e) {
      }

      if (displayName == null && panes.size() > 0) {
        Iterator<PreferencesPane> it = panes.iterator();

        while (it.hasNext() && displayName == null) {

          try {
            displayName = it.next().getCategoryDisplayName();
          } catch (MissingResourceException e) {
            displayName = null;
          }
        }

        if (displayName == null) {
          displayName = this.categoryID;
        }
      }
    }

    return displayName;
  }
Beispiel #26
0
 public static PrototypeCollection findAll() {
   SortedSet s = new TreeSet(new PrinterOrderComparator());
   PrototypeCollection p = new PrototypeVector();
   s.addAll(PrototypeSvc.findAll(NAMESPACE));
   Iterator i = s.iterator();
   while (i.hasNext()) p.add(i.next());
   return p;
 }
Beispiel #27
0
 @Produces(MediaType.TEXT_PLAIN)
 @GET
 @Path("/SortedSetParamEntityWithFromString/{id}")
 public String sortedSetParamEntityWithFromStringTest(
     @DefaultValue("PathParamTest") @PathParam("id")
         SortedSet<ParamEntityWithFromString> sortedSetParamEntityWithFromString) {
   return sortedSetParamEntityWithFromString.iterator().next().getValue();
 }
Beispiel #28
0
 /** @tests java.util.TreeSet#iterator() */
 public void test_iterator() {
   // Test for method java.util.Iterator java.util.TreeSet.iterator()
   SortedSet s = db.createTreeSet("test");
   s.addAll(ts);
   Iterator i = ts.iterator();
   Set as = new HashSet(Arrays.asList(objArray));
   while (i.hasNext()) as.remove(i.next());
   assertEquals("Returned incorrect iterator", 0, as.size());
 }
Beispiel #29
0
 /** @tests java.util.TreeSet#addAll(java.util.Collection) */
 public void test_addAllLjava_util_Collection() {
   // Test for method boolean
   // java.util.TreeSet.addAll(java.util.Collection)
   SortedSet s = db.createTreeSet("test");
   s.addAll(ts);
   assertTrue("Incorrect size after add", s.size() == ts.size());
   Iterator i = ts.iterator();
   while (i.hasNext()) assertTrue("Returned incorrect set", s.contains(i.next()));
 }
Beispiel #30
0
 private void printListOfSystems(PrintStream out, Domain domain, String prefix)
     throws TermWareException {
   SortedSet directSystemNames = domain.getNamesOfSystems();
   Iterator it = directSystemNames.iterator();
   while (it.hasNext()) {
     String name = (String) it.next();
     out.print("<A HREF=\"" + prefix + name + "/all-patterns.html\" TARGET=\"patternFrame\">");
     out.print(name);
     out.print("</A><BR>");
     out.println();
   }
   SortedSet subdomainNames = domain.getNamesOfDirectSubdomains();
   it = subdomainNames.iterator();
   while (it.hasNext()) {
     String name = (String) it.next();
     printListOfSystems(out, domain.getDirectSubdomain(name), name + "/");
   }
 }