Ejemplo n.º 1
0
 /**
  * @param path path to first element
  * @param pathTo path to second element
  * @return environment in which the generic parameters in the path to the first element are bound
  *     to those in the path to the second element, or null type on error
  */
 public static ResolvedName mapGenericParameters(
     final Deque<? extends INamedElement> path, final Deque<? extends INamedElement> pathTo) {
   // Construct an environment in which the current function's generic parameters
   // are bound to those of the eventual override.
   final Deque<List<? extends ResolvedName>> tableau =
       new LinkedList<>(ResolvedName.fromNamedElement(path.getLast()).tableau());
   final Iterator<? extends INamedElement> pathIt = path.descendingIterator();
   while (pathIt.hasNext()) {
     pathIt.next();
     tableau.removeLast();
   }
   CachedIterator<? extends INamedElement> itPathTo = null;
   CachedIterator<? extends IGenericParameter> itGPTo = null;
   boolean end = false;
   {
     // Initialise iterators into direct override's generic parameters.
     boolean foundValid = false;
     itPathTo = Iterators.cached(pathTo.iterator());
     while (!foundValid && itPathTo.hasItem()) {
       itGPTo = Iterators.cached(itPathTo.item().genericParameters().iterator());
       while (!foundValid && itGPTo.hasItem()) {
         foundValid = true;
         if (!foundValid) itGPTo.next();
       }
       if (!foundValid) itPathTo.next();
     }
     if (!foundValid) end = true;
   }
   for (final INamedElement elt : path) {
     final List<ResolvedName> row = new ArrayList<>();
     for (@SuppressWarnings("unused")
     final IGenericParameter genericParameter : elt.genericParameters()) {
       if (end) return null;
       row.add(ResolvedName.fromNamedElement(itGPTo.item()));
       {
         // Increment iterators into direct override's generic parameters.
         boolean init = true;
         boolean foundValid = false;
         if (!init) itPathTo = Iterators.cached(pathTo.iterator());
         while (!foundValid && itPathTo.hasItem()) {
           if (!init) itGPTo = Iterators.cached(itPathTo.item().genericParameters().iterator());
           while (!foundValid && itGPTo.hasItem()) {
             if (!init) foundValid = true;
             init = false;
             if (!foundValid) itGPTo.next();
           }
           if (!foundValid) itPathTo.next();
         }
         if (!foundValid) end = true;
       }
     }
     tableau.add(row);
   }
   if (!end) return null;
   return ResolvedName.newNameReference(path.getLast(), tableau);
 }
Ejemplo n.º 2
0
 @Test(expected = NoSuchElementException.class)
 public void Deque_iterator_throwsNoSuchElement() {
   deque.addFirst("firstString");
   deque.addFirst("secondString");
   Iterator<String> dequeIterator = deque.iterator();
   dequeIterator.next();
   dequeIterator.next();
   dequeIterator.next();
 }
Ejemplo n.º 3
0
 @Test
 public void Deque_iterator_hasNextIsFalse() {
   deque.addFirst("firstString");
   deque.addFirst("secondString");
   Iterator<String> dequeIterator = deque.iterator();
   dequeIterator.next();
   dequeIterator.next();
   assertFalse(dequeIterator.hasNext());
 }
Ejemplo n.º 4
0
 @Test(expected = NoSuchElementException.class)
 public void testNextFromEmptyIterator() {
   Deque<String> deque = new Deque<String>();
   deque.addLast("last");
   deque.addFirst("first");
   Iterator<String> i = deque.iterator();
   i.next();
   i.next();
   i.next(); // should throw exception
 }
Ejemplo n.º 5
0
 @Test(expected = UnsupportedOperationException.class)
 public void testRemoveFromIterator() {
   Deque<String> deque = new Deque<String>();
   deque.addFirst("middle");
   deque.addLast("last");
   deque.addFirst("first");
   Iterator<String> i = deque.iterator();
   i.next();
   i.remove(); // should throw exception
 }
Ejemplo n.º 6
0
 @Test
 public void Deque_iterator_iterates() {
   deque.addFirst("firstString");
   deque.addFirst("secondString");
   deque.addLast("thirdString");
   Iterator<String> dequeIterator = deque.iterator();
   assertEquals(dequeIterator.next(), "secondString");
   assertEquals(dequeIterator.next(), "firstString");
   assertEquals(dequeIterator.next(), "thirdString");
 }
Ejemplo n.º 7
0
  /**
   * Delete log segments whose contents have been turned into SSTables. NOT threadsafe.
   *
   * <p>param @ context The commitLog context . param @ id id of the columnFamily being flushed to
   * disk.
   */
  private void discardCompletedSegmentsInternal(
      CommitLogSegment.CommitLogContext context, Integer id) throws IOException {
    if (logger.isDebugEnabled())
      logger.debug("discard completed log segments for " + context + ", column family " + id + ".");

    /*
     * log replay assumes that we only have to look at entries past the last
     * flush position, so verify that this flush happens after the last. See CASSANDRA-936
     */
    assert context.position >= context.getSegment().getHeader().getPosition(id)
        : "discard at "
            + context
            + " is not after last flush at "
            + context.getSegment().getHeader().getPosition(id);
    /*
     * Loop through all the commit log files in the history. Now process
     * all files that are older than the one in the context. For each of
     * these files the header needs to modified by resetting the dirty
     * bit corresponding to the flushed CF.
     */
    Iterator<CommitLogSegment> iter = segments.iterator();
    while (iter.hasNext()) {
      CommitLogSegment segment = iter.next();
      CommitLogHeader header = segment.getHeader();
      if (segment.equals(context.getSegment())) {
        // we can't just mark the segment where the flush happened clean,
        // since there may have been writes to it between when the flush
        // started and when it finished. so mark the flush position as
        // the replay point for this CF, instead.
        if (logger.isDebugEnabled())
          logger.debug("Marking replay position " + context.position + " on commit log " + segment);
        header.turnOn(id, context.position);
        segment.writeHeader();
        break;
      }

      header.turnOff(id);
      if (header.isSafeToDelete()) {
        logger.info("Discarding obsolete commit log:" + segment);
        segment.close();
        DeletionService.submitDelete(segment.getHeaderPath());
        DeletionService.submitDelete(segment.getPath());
        // usually this will be the first (remaining) segment, but not always, if segment A contains
        // writes to a CF that is unflushed but is followed by segment B whose CFs are all flushed.
        iter.remove();
      } else {
        if (logger.isDebugEnabled())
          logger.debug(
              "Not safe to delete commit log " + segment + "; dirty is " + header.dirtyString());
        segment.writeHeader();
      }
    }
  }
  public static void main(String[] args) {
    Deque<String> myDeque = new Deque<String>();
    String[] str = new String[] {"Jrui", "Long", "Jason"};
    myDeque.addFirst(str[0]);
    myDeque.addLast(str[2]);
    myDeque.addFirst(str[1]);

    Iterator<String> test = myDeque.iterator();
    while (test.hasNext()) {
      String s = test.next();
      StdOut.println(s);
    }
  }
Ejemplo n.º 9
0
 @Test
 public void testIterator() {
   deque.addBack(3);
   deque.addBack(7);
   deque.addBack(4);
   Iterator<Integer> iterator = deque.iterator();
   assertTrue(iterator.hasNext());
   assertEquals(new Integer(3), iterator.next());
   assertTrue(iterator.hasNext());
   assertEquals(new Integer(7), iterator.next());
   assertTrue(iterator.hasNext());
   assertEquals(new Integer(4), iterator.next());
   assertFalse(iterator.hasNext());
   // The deque should not have been modified by the iteration
   assertEquals("<3, 7, 4>", deque.toString());
 }
Ejemplo n.º 10
0
  public static void main(String args[]) {
    Deque<Integer> d = new Deque<Integer>();

    Iterator<Integer> a = d.iterator();

    while (a.hasNext()) {
      StdOut.println(a.next());
    }

    for (int i = 0; i < 10; i++) {
      d.addFirst(i);
    }

    for (int i = 0; i < 10; i++) {
      StdOut.println(d.removeFirst());
    }
  }
Ejemplo n.º 11
0
  @Test
  public void testIterator() {
    deque.addFirst("1");
    deque.addFirst("2");
    deque.addFirst("3");
    deque.addFirst("4");
    deque.addFirst("5");

    deque.removeFirst();

    Iterator<String> iterator = deque.iterator();

    int i = 4;
    while (iterator.hasNext()) {
      String s = iterator.next();
      assertEquals(s, "" + i);

      i--;
    }
  }