Пример #1
0
  @Override
  public float[] getBlock(int timeout) {
    // TODO Auto-generated method stub
    float[] frame = null;
    lock.lock();
    try {

      if (listFrame.size() > 0) {
        frame = listFrame.removeFirst();
      }
      if (frame == null && timeout != 0) {
        try {
          if (timeout > 0) {

            condition.await(timeout, TimeUnit.MILLISECONDS);

          } else {
            condition.await();
          }
        } catch (InterruptedException e) {
          // TODO: handle exception
        }
      }
      if (listFrame.size() > 0) {
        frame = listFrame.removeFirst();
      }
    } finally {
      lock.unlock();
    }
    return frame;
  }
Пример #2
0
  public void weavelists(
      LinkedList<Integer> first,
      LinkedList<Integer> second,
      ArrayList<LinkedList<Integer>> results,
      LinkedList<Integer> prefix) {
    if (first.size() == 0 || second.size() == 0) {
      LinkedList<Integer> result = (LinkedList<Integer>) prefix.clone();
      result.addAll(first);
      result.addAll(second);
      results.add(result);
      return;
    }

    int headFirst = first.removeFirst();
    prefix.addLast(headFirst);
    weavelists(first, second, results, prefix);
    prefix.removeLast();
    first.addFirst(headFirst);

    int secondHead = second.removeFirst();
    prefix.addLast(secondHead);
    weavelists(first, second, results, prefix);
    prefix.removeLast();
    second.addFirst(secondHead);
  }
Пример #3
0
  void mixLists(
      LinkedList<Integer> left,
      LinkedList<Integer> right,
      ArrayList<LinkedList<Integer>> mix,
      LinkedList<Integer> before) {
    if (before.isEmpty() || right.isEmpty()) {
      LinkedList<Integer> l = new LinkedList<>();
      l = (LinkedList<Integer>) before.clone();
      l.addAll(left);
      l.addAll(right);
      mix.add(l);
      return;
    }
    int hl = left.removeFirst();
    before.addLast(hl);
    mixLists(left, right, mix, before);
    before.removeLast();
    left.addFirst(hl);

    int hr = right.removeFirst();
    before.addLast(hr);
    mixLists(left, right, mix, before);
    before.removeLast();
    right.addFirst(hr);
  }
Пример #4
0
 private void expandSelect() {
   if (fPathToSelect == null) return;
   if (fPathToSelect.isEmpty()) {
     fPathToSelect = null;
     fFileToSelect = null;
     return;
   }
   do {
     String name = fPathToSelect.getFirst();
     if (name.length() == 0) {
       fPathToSelect.removeFirst();
       continue;
     }
     FileInfo info = findFileInfo(fLastSelectedFileInfo, name);
     if (info == null) break;
     TreeItem item = findItem(info);
     if (item == null) break;
     fPathToSelect.removeFirst();
     if (fPathToSelect.isEmpty()) {
       fileTree.setSelection(item);
       fileTree.showItem(item);
     } else {
       item.setExpanded(true);
       fileTree.showItem(item);
     }
     fLastSelectedFileInfo = info;
   } while (!fPathToSelect.isEmpty());
 }
Пример #5
0
 private boolean repOkColors() {
   // RedHasOnlyBlackChildren
   java.util.LinkedList workList = new java.util.LinkedList();
   workList.add(root);
   while (!workList.isEmpty()) {
     Node current = (Node) workList.removeFirst();
     Node cl = current.left;
     Node cr = current.right;
     if (current.color == RED) {
       if (cl != null && cl.color == RED) return debug("RedHasOnlyBlackChildren1");
       if (cr != null && cr.color == RED) return debug("RedHasOnlyBlackChildren2");
     }
     if (cl != null) workList.add(cl);
     if (cr != null) workList.add(cr);
   }
   // SimplePathsFromRootToNILHaveSameNumberOfBlackNodes
   int numberOfBlack = -1;
   workList = new java.util.LinkedList();
   workList.add(new Pair(root, 0));
   while (!workList.isEmpty()) {
     Pair p = (Pair) workList.removeFirst();
     Node e = p.e;
     int n = p.n;
     if (e != null && e.color == BLACK) n++;
     if (e == null) {
       if (numberOfBlack == -1) numberOfBlack = n;
       else if (numberOfBlack != n)
         return debug("SimplePathsFromRootToNILHaveSameNumberOfBlackNodes");
     } else {
       workList.add(new Pair(e.left, n));
       workList.add(new Pair(e.right, n));
     }
   }
   return true;
 }
  public static void main(String args[]) {
    String file_name = null;
    float hit_ratio = 0.0f;

    LinkedList<Integer> file_elements = new LinkedList<Integer>();
    LinkedList<Integer> sizes = new LinkedList<Integer>();

    Scanner in = new Scanner(System.in);
    System.out.println("Please Enter the FileName (e.g Filename.lis): ");
    file_name = in.nextLine();
    System.out.println("Please Enter the Cache Size (e.g 1024, 2048) : ");
    cache_size = in.nextInt();
    String[] ch;

    BufferedReader file_br = null;

    try {
      file_br = new BufferedReader(new FileReader(file_name));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    try {
      while (true) {
        s = file_br.readLine();
        if (s == null) break;
        else {
          ch = s.split(" ");
          file_elements.add(Integer.parseInt(ch[0]));
          sizes.add(Integer.parseInt(ch[1]));
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    int temp, temp_size;
    int num_of_times = file_elements.size();
    System.out.println("Total number of elements : " + num_of_times);
    try {
      for (int i = 0; i < num_of_times; i++) {
        temp = file_elements.removeFirst();
        temp_size = sizes.removeFirst();
        insert_element(temp, temp_size);
      }
      System.out.println("Reslts");
      System.out.println("-------");
      System.out.println("1. Hit count : " + hit_count);
      System.out.println("2. Miss count : " + miss_count);
      System.out.println("3. Total count : " + miss_count + hit_count);

      hit_ratio = ((float) hit_count) / ((float) (hit_count + miss_count)) * 100;

      System.out.println(hit_ratio);
      System.out.println("4. Hit ratio (%) : " + (float) round_the_number(hit_ratio));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #7
0
  private static SymbolList convertList(LinkedList<String> tokens) {
    List<Symbol> contents = new ArrayList<>();

    tokens.removeFirst();
    while (!tokens.getFirst().equals(")")) {
      contents.add(convert(tokens));
    }
    tokens.removeFirst();

    return SymbolPool.getList(contents);
  }
Пример #8
0
  public static void main(String[] args) throws Exception {
    String portName = null;
    String portVersion = null;
    String portVendor = null;
    String portDesc = null;
    String ymzFilename = null;

    boolean invalid = true;
    LinkedList<String> list = new LinkedList<>(Arrays.asList(args));
    argCheck:
    while (!list.isEmpty()) {
      String arg = list.removeFirst();
      switch (arg) {
        case "--midi-name":
          if (list.isEmpty()) {
            break argCheck;
          }
          portName = list.removeFirst();
          break;
        case "--midi-version":
          if (list.isEmpty()) {
            break argCheck;
          }
          portVersion = list.removeFirst();
          break;
        case "--midi-vendor":
          if (list.isEmpty()) {
            break argCheck;
          }
          portVendor = list.removeFirst();
          break;
        case "--midi-desc":
          if (list.isEmpty()) {
            break argCheck;
          }
          portDesc = list.removeFirst();
          break;
        default:
          ymzFilename = arg;
          invalid = false;
          break argCheck;
      }
    }

    if (invalid || !(list.isEmpty())) {
      usage();
      System.exit(1);
    }

    File input = new File(ymzFilename);
    YMZPlayer player = new YMZPlayer(input);
    player.play(portName, portVersion, portVendor, portDesc);
  }
Пример #9
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();
  }
Пример #10
0
 protected Object get(Object value) {
   Object obj = null;
   while (size() > 0) {
     obj = getFirst();
     if (obj instanceof LeasedReference) obj = ((LeasedReference) obj).get();
     if (obj == null) {
       data.removeFirst();
       File f = new File((String) stored.removeFirst());
       f.delete();
       continue;
     }
     break;
   }
   return obj;
 }
  @Override
  public boolean incrementToken() throws IOException {
    if (!tokens.isEmpty()) {
      applyToken(tokens.removeFirst());
    } else if (input.incrementToken()) {
      splitIntoTokens();

      if (!tokens.isEmpty()) {
        if (!returnOriginalTerm()) applyToken(tokens.removeFirst());
      }
    } else {
      return false; // does not have any more tokens
    }

    return true;
  }
Пример #12
0
  /** lend an object from the pool. */
  public Object lendObject() {
    checkIsInitialized();

    Object _result = null;

    synchronized (pool_) {
      if (!pool_.isEmpty()) {
        _result = pool_.removeFirst();
      }

      if (_result == null) {
        while (!isCreationAllowed()) {
          poolIsEmpty();
        }
      }
    }

    if (_result == null) {
      _result = createInstance();
    }

    try {
      ((Configurable) _result).configure(this.config_);
    } catch (ClassCastException cce) {
      // no worries, just don't configure
    } catch (ConfigurationException ce) {
      throw new RuntimeException("Could not configure instance");
    }

    doActivateObject(_result);
    active_.add(_result);

    return _result;
  }
Пример #13
0
  @Override
  public void run() {
    super.run(); // To change body of generated methods, choose Tools | Templates.

    this.f = new File(String.valueOf(this.m_listening_port) + ".txt");
    try {
      this.pw = new PrintWriter(new BufferedWriter(new FileWriter(f)));
    } catch (IOException exception) {
      System.out.println("Erreur lors de la lecture : " + exception.getMessage());
      System.exit(-1);
    }

    while (true) {
      synchronized (this.m_delivered_messages) {
        if (!this.m_delivered_messages.isEmpty()) {
          byte[] data = m_delivered_messages.removeFirst();
          Message message = new Message(null, data);

          this.pw.print(message);

          this.pw.println();
        } else if (has_to_finish) {
          has_finished = true;
          break;
        }
      }
    }
  }
Пример #14
0
  /** Parses the command line arguments. */
  public void parseArguments(String[] arguments) {
    LinkedList<String> args = new LinkedList<String>(Arrays.asList(arguments));

    boolean valid = true;
    while (!args.isEmpty()) {
      String arg = args.removeFirst();

      boolean handled = false;
      for (Option option : options) {
        if (option.processOption(arg, args)) {
          handled = true;
          break;
        }
      }
      if (!handled) {
        System.out.println("Unknown option: " + arg);
        System.out.println();
        valid = false;
        break;
      }
    }
    if (!valid) {
      showOptions();
      completed();
    }
  }
Пример #15
0
 private boolean bfs_cirle(boolean[] visited, Map<Integer, ArrayList<Integer>> graph, int i) {
   LinkedList<Integer> queue = new LinkedList<>();
   if (visited[i]) {
     return true;
   }
   visited[i] = true;
   queue.addLast(i);
   int top;
   List<Integer> edges;
   while (!queue.isEmpty()) {
     top = queue.getFirst();
     queue.removeFirst();
     edges = graph.get(top);
     if (edges != null) {
       for (int j = 0; j < edges.size(); j++) {
         if (visited[edges.get(j)]) {
           return true;
         } else {
           visited[edges.get(j)] = true;
           queue.add(edges.get(j));
         }
       }
     }
   }
   return false;
 }
 public SortedSet<File> collect(File dir) {
   if (!dir.isDirectory()) {
     throw new IllegalArgumentException();
   }
   LinkedList<File> queue = new LinkedList<File>(Arrays.asList(dir.listFiles()));
   while (!queue.isEmpty()) {
     File f = queue.removeFirst();
     if (f.isDirectory() && myIsRecursive) {
       queue.addAll(Arrays.asList(f.listFiles()));
       continue;
     }
     if (f.isFile()) {
       if (myFilters.isEmpty()) {
         myResult.add(f);
         continue;
       } else {
         for (Pattern p : myFilters) {
           if (p.matcher(f.getName()).matches()) {
             myResult.add(f);
             break; // continue outer cycle
           }
         }
       }
     }
   }
   return getResult();
 }
  private void undeploy(WebApp webApp) {

    String contextName = webApp.getContextName();
    LinkedList<WebApp> queue = contexts.get(contextName);
    if (queue != null) {

      // Are we the published web app??
      if (queue.get(0) == webApp) {

        webApp.setDeploymentState(WebApp.UNDEPLOYED_STATE);
        eventDispatcher.webEvent(
            new WebEvent(
                WebEvent.UNDEPLOYING,
                "/" + contextName,
                webApp.getBundle(),
                bundleContext.getBundle()));
        m_publisher.unpublish(webApp);
        eventDispatcher.webEvent(
            new WebEvent(
                WebEvent.UNDEPLOYED,
                "/" + contextName,
                webApp.getBundle(),
                bundleContext.getBundle()));
        queue.removeFirst();

        // Below checks if another webapp is waiting for the context, if so the webapp is published.
        LOG.debug("Check for a waiting webapp.");
        if (!queue.isEmpty()) {
          LOG.debug("Found another bundle waiting for the context");
          WebApp next = queue.getFirst();

          eventDispatcher.webEvent(
              new WebEvent(
                  WebEvent.DEPLOYING,
                  "/" + contextName,
                  next.getBundle(),
                  bundleContext.getBundle()));

          // let the publisher set the deployment state and send web event
          m_publisher.publish(next, eventDispatcher, bundleContext);
        } else {
          contexts.remove(contextName);
        }

      } else if (queue.remove(webApp)) {
        webApp.setDeploymentState(WebApp.UNDEPLOYED_STATE);
        eventDispatcher.webEvent(
            new WebEvent(
                WebEvent.UNDEPLOYED,
                "/" + contextName,
                webApp.getBundle(),
                bundleContext.getBundle()));
      } else {
        LOG.debug("Web application was not in the deployment queue");
      }

    } else {
      LOG.debug(String.format("No web application published under context: %s", contextName));
    }
  }
Пример #18
0
 public void run() {
   while (true) {
     synchronized (JobManagerImpl.this.mySemaphor) {
       if (JobManagerImpl.this.mySemaphor.isClosed()) {
         try {
           JobManagerImpl.this.mySemaphor.wait();
         } catch (InterruptedException e) {
           cleanJobs();
         }
       }
     }
     synchronized (myJobs) {
       if (myJobs.isEmpty()) {
         try {
           myJobs.wait();
         } catch (InterruptedException e) {
           cleanJobs();
         }
       } else {
         InternalJobImpl next = (InternalJobImpl) myJobs.removeFirst();
         IStatus result = next.run(myProgressMonitor);
         next.setResult(result);
         if (result.isOK()) {
         } else {
           cleanJobs();
         }
       }
     }
   }
 }
  @Override
  public boolean incrementToken() throws IOException {
    while (!done && queue.size() < windowSize) {
      if (!input.incrementToken()) {
        done = true;
        break;
      }

      // reverse iterating for better efficiency since we know the
      // list is already sorted, and most token start offsets will be too.
      ListIterator<OrderedToken> iter = queue.listIterator(queue.size());
      while (iter.hasPrevious()) {
        if (offsetAtt.startOffset() >= iter.previous().startOffset) {
          // insertion will be before what next() would return (what
          // we just compared against), so move back one so the insertion
          // will be after.
          iter.next();
          break;
        }
      }
      OrderedToken ot = new OrderedToken();
      ot.state = captureState();
      ot.startOffset = offsetAtt.startOffset();
      iter.add(ot);
    }

    if (queue.isEmpty()) {
      return false;
    } else {
      restoreState(queue.removeFirst().state);
      return true;
    }
  }
Пример #20
0
  public static boolean isBinaryTreeBST(BinaryTreeNode<Integer> tree) {
    LinkedList<QueueEntry> BFSQueue = new LinkedList<>();
    BFSQueue.addLast(new QueueEntry(tree, Integer.MIN_VALUE, Integer.MAX_VALUE));

    while (!BFSQueue.isEmpty()) {
      if (BFSQueue.getFirst().treeNode != null) {
        if (BFSQueue.getFirst().treeNode.getData() < BFSQueue.getFirst().lowerBound
            || BFSQueue.getFirst().treeNode.getData() > BFSQueue.getFirst().upperBound) {
          return false;
        }

        BFSQueue.addLast(
            new QueueEntry(
                BFSQueue.getFirst().treeNode.getLeft(),
                BFSQueue.getFirst().lowerBound,
                BFSQueue.getFirst().treeNode.getData()));
        BFSQueue.addLast(
            new QueueEntry(
                BFSQueue.getFirst().treeNode.getRight(),
                BFSQueue.getFirst().treeNode.getData(),
                BFSQueue.getFirst().upperBound));
      }
      BFSQueue.removeFirst();
    }
    return true;
  }
  @Override
  public final boolean incrementToken() throws IOException {
    if (!tokens.isEmpty()) {
      assert current != null;
      CompoundToken token = tokens.removeFirst();
      restoreState(current); // keep all other attributes untouched
      termAtt.setEmpty().append(token.txt);
      offsetAtt.setOffset(token.startOffset, token.endOffset);
      posIncAtt.setPositionIncrement(0);
      return true;
    }

    current = null; // not really needed, but for safety
    if (input.incrementToken()) {
      // Only words longer than minWordSize get processed
      if (termAtt.length() >= this.minWordSize) {
        decompose();
        // only capture the state if we really need it for producing new tokens
        if (!tokens.isEmpty()) {
          current = captureState();
        }
      }
      // return original token:
      return true;
    } else {
      return false;
    }
  }
Пример #22
0
 public CObject nextToken() {
   if (!tokenQueue.isEmpty()) {
     return tokenQueue.removeFirst();
   } else {
     return getNextToken();
   }
 }
Пример #23
0
  private void convertToDFA(NFA nfa) {
    DFAState curr, temp;
    List<String> tokens = new ArrayList<String>();
    LinkedList<DFAState> queue = new LinkedList<DFAState>();
    findStart(nfa);
    queue.add(start);

    MAINWHILE:
    while (!queue.isEmpty()) {
      curr = queue.removeFirst();
      for (DFAState sta : checked) {
        if (curr.equals(sta)) {
          //            		System.out.println("NOPE");
          continue MAINWHILE;
        }
      }
      checked.add(curr);
      // Pull out all keys
      for (State s : curr.getStates()) {
        for (String k : s.getTransitionTable().keySet()) {
          tokens.add(k);
          // System.out.println(tokens);
        }
      }
      // Iterate over all possible iterations and link states together
      for (String j : tokens) {
        if (!j.equals("")) {
          temp = goTo(curr, j);
          queue.add(temp);
        }
      }
    }
  }
Пример #24
0
 public BehaviorInfo popBehavior() {
   if (!behaviorStack.isEmpty()) {
     return behaviorStack.removeFirst();
   } else {
     return null;
   }
 }
Пример #25
0
  /**
   * Merges pairs of rows by making them identical and marking them as equivalent. For each merged
   * pair, also merges each pair of not yet merged images by the same generator, and so on
   * recursively, until no more pairs need to be merged.
   *
   * @param Q a list of row pairs to merge.
   * @param P the row equivalence classes (modified by this method).
   * @return the number of individual merges performed.
   */
  private int performIdentifications(final LinkedList Q, final IntPartition P) {
    int count = 0;
    while (Q.size() > 0) {
      final IntPair pair = (IntPair) Q.removeFirst();
      final int a = P.find(pair.getFirst());
      final int b = P.find(pair.getSecond());
      if (a == b) {
        continue;
      }
      P.unite(a, b);
      ++count;

      final int row_a[] = (int[]) this.table.get(a);
      final int row_b[] = (int[]) this.table.get(b);
      for (int g = 0; g < this.ngens; ++g) {
        final int ag = row_a[g];
        final int bg = row_b[g];
        if (ag == 0) {
          row_a[g] = bg;
        } else if (bg == 0) {
          row_b[g] = ag;
        } else if (!P.areEquivalent(ag, bg)) {
          Q.addLast(new IntPair(ag, bg));
        }
      }
      this.table.set(b, row_a);
    }

    return count;
  }
Пример #26
0
 public void doFilter(HttpExchange exchange) throws IOException {
   if (filters.isEmpty()) {
     context.getHandler().handle(exchange);
   } else {
     filters.removeFirst().doFilter(exchange, this);
   }
 }
Пример #27
0
  /**
   * maintains a list of last <i>committedLog</i> or so committed requests. This is used for fast
   * follower synchronization.
   *
   * @param request committed request
   */
  public void addCommittedProposal(Request request) {
    WriteLock wl = logLock.writeLock();
    try {
      wl.lock();
      if (committedLog.size() > commitLogCount) {
        committedLog.removeFirst();
        minCommittedLog = committedLog.getFirst().packet.getZxid();
      }
      if (committedLog.isEmpty()) {
        minCommittedLog = request.zxid;
        maxCommittedLog = request.zxid;
      }

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
      try {
        request.getHdr().serialize(boa, "hdr");
        if (request.getTxn() != null) {
          request.getTxn().serialize(boa, "txn");
        }
        baos.close();
      } catch (IOException e) {
        LOG.error("This really should be impossible", e);
      }
      QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid, baos.toByteArray(), null);
      Proposal p = new Proposal();
      p.packet = pp;
      p.request = request;
      committedLog.add(p);
      maxCommittedLog = p.packet.getZxid();
    } finally {
      wl.unlock();
    }
  }
Пример #28
0
  public static boolean findShortestPath(Node a, Node b, HashMap<Node, Node> path) {

    Node prev = null;
    if (a == b) {
      prev = a;
    }

    // Starting node has no prev (unless start equals end)
    path.put(a, prev);

    LinkedList<Node> q = new LinkedList<Node>();
    q.add(a);

    while (!q.isEmpty()) {
      Node r = q.removeFirst();
      for (Node c : r.adj) {
        // Use path datastructure to track whether nodes are visited
        if (!path.containsKey(c)) {
          path.put(c, r);
        }
      }
    }

    if (!path.containsKey(b)) {
      return false;
    }

    return true;
  }
Пример #29
0
 /*
  * Removes the URI at the top of the stack of URIs to which the given
  * prefix is mapped.
  *
  * @param prefix The prefix whose stack of URIs is to be popped
  */
 public void popPrefixMapping(String prefix) {
   LinkedList stack = (LinkedList) xmlPrefixMapper.get(prefix);
   if (stack == null || stack.size() == 0) {
     // XXX throw new Exception("XXX");
   }
   stack.removeFirst();
 }
 /**
  * Fills {@link #inputWindow} with input stream tokens, if available, shifting to the right if the
  * window was previously full.
  *
  * <p>Resets {@link #gramSize} to its minimum value.
  *
  * @throws IOException if there's a problem getting the next token
  */
 private void shiftInputWindow() throws IOException {
   InputWindowToken firstToken = null;
   if (inputWindow.size() > 0) {
     firstToken = inputWindow.removeFirst();
   }
   while (inputWindow.size() < maxShingleSize) {
     if (null != firstToken) { // recycle the firstToken, if available
       if (null != getNextToken(firstToken)) {
         inputWindow.add(firstToken); // the firstToken becomes the last
         firstToken = null;
       } else {
         break; // end of input stream
       }
     } else {
       InputWindowToken nextToken = getNextToken(null);
       if (null != nextToken) {
         inputWindow.add(nextToken);
       } else {
         break; // end of input stream
       }
     }
   }
   if (outputUnigramsIfNoShingles
       && noShingleOutput
       && gramSize.minValue > 1
       && inputWindow.size() < minShingleSize) {
     gramSize.minValue = 1;
   }
   gramSize.reset();
   isOutputHere = false;
 }