Пример #1
0
  public Queue<Contact> makeContactQueue(Id key) throws Exception {
    Queue<Contact> contactQueue = new LinkedList<Contact>();
    NavigableMap<Id, OCPContact> nodeMap = new TreeMap<Id, OCPContact>(this.nodeMap);
    if (nodeMap.containsKey(key)) {
      contactQueue.offer(nodeMap.get(key));
    }

    NavigableMap<Id, OCPContact> s = nodeMap.headMap(key, false);
    Iterator<Id> it = s.navigableKeySet().descendingIterator();
    while (it.hasNext()) {
      Id nodeId = it.next();
      OCPContact contact = s.get(nodeId);
      if (!contactQueue.contains(contact)) {
        contactQueue.offer(contact);
      }
    }
    s = nodeMap.tailMap(key, false);
    it = s.navigableKeySet().descendingIterator();
    while (it.hasNext()) {
      Id nodeId = it.next();
      OCPContact contact = s.get(nodeId);
      if (!contactQueue.contains(contact)) {
        contactQueue.offer(contact);
      }
    }
    return contactQueue;
  }
Пример #2
0
 private static boolean a(Context context, String str) {
   boolean z = false;
   synchronized (g) {
     SharedPreferences j = m.a(context).j();
     if (c == null) {
       String[] split = j.getString("pref_msg_ids", com.xiaomi.e.a.f).split(f.i);
       c = new LinkedList();
       for (Object add : split) {
         c.add(add);
       }
     }
     if (c.contains(str)) {
       z = true;
     } else {
       c.add(str);
       if (c.size() > 10) {
         c.poll();
       }
       String a = d.a(c, f.i);
       Editor edit = j.edit();
       edit.putString("pref_msg_ids", a);
       edit.commit();
     }
   }
   return z;
 }
Пример #3
0
  /**
   * Read input commands and execute transactions
   *
   * @throws Exception
   * @author Deepti Verma
   */
  public void run() throws Exception {
    String line = null;
    // Read and execute input operations
    while ((line = br.readLine()) != null) {
      line = line.trim();
      if (!(line.startsWith("\\")
          || line.isEmpty())) { // Ignore a line that starts with \\ then it is comment or is empty
        String[] operations = line.split(";");
        for (int i = 0; i < operations.length; i++) {
          operations[i] = operations[i].trim();
          doOperation(operations[i]);
        }
      }

      // Check for transactions waiting to be executed
      Queue<Transaction> tempQueue = new ArrayDeque<>();
      while (!transactionWaitingList.isEmpty()) {
        Transaction tr = transactionWaitingList.poll();
        if (tr.isWaiting && !tempQueue.contains(tr)) {
          if (!doOperation(tr.operationWaiting)) {
            anyTransactionsWaiting = true;
            tempQueue.add(tr);
          } else {
            tr.isWaiting = false;
          }
        }
      }
      if (!tempQueue.isEmpty()) transactionWaitingList.addAll(tempQueue);
      currentTimeStamp++;
    }
    bw.flush();
  }
Пример #4
0
 /**
  * Removes a global object from the world based on object reference
  *
  * @param object the global object
  */
 public void remove(GlobalObject object) {
   if (!objects.contains(object)) {
     return;
   }
   updateObject(object, -1);
   remove.add(object);
 }
  /**
   * Performs graph search, starting with the <code>initialState</code>. <code>stateManager</code>
   * defines the successor state function and the goal test function.
   *
   * <p>
   *
   * @return The first state that satisfies the goal test function. If no such state is found, then
   *     the function returns <code>null</code>.
   */
  public T search(T initialState, IStateManager<T> stateManager) {
    queue.clear();
    queue.add(initialState);

    T currentState;

    while (true) {
      if (queue.isEmpty()) {
        currentState = null;
        break;
      }

      currentState = queue.poll();

      if (stateManager.goalTest(currentState)) break;

      for (T nextState : stateManager.nextStates(currentState)) {
        if (!queue.contains(nextState)) {
          queue.add(nextState);
        }
      }
    }

    return currentState;
  }
 /**
  * 开始下载任务
  *
  * @param downloadId
  * @param callback
  */
 public void startTask(int downloadId, FileDownloaderCallback callback) {
   FileDownloaderModel model = getFileDownloaderModelById(downloadId);
   if (model != null) {
     BridgeListener bridgeListener = mListenerManager.getBridgeListener(downloadId);
     bridgeListener.addDownloadListener(callback);
     if (mDownloadingList.size() >= mConfiguration.getMaxDownloadingCount()) { // 下载中队列已满
       if (!mWaitQueue.contains(model)) {
         mWaitQueue.offer(model);
       }
       bridgeListener.wait(downloadId);
     } else {
       mDownloadingList.add(model);
       final BaseDownloadTask task =
           FileDownloader.getImpl()
               .create(model.getUrl())
               .setPath(model.getPath())
               .setCallbackProgressTimes(100)
               .setAutoRetryTimes(mAutoRetryTimes)
               .setListener(bridgeListener);
       for (int i = 0; i < mHeaders.size(); i++) {
         task.addHeader(mHeaders.name(i), mHeaders.value(i));
       }
       bridgeListener.setDownloadTask(task);
       task.start();
     }
   } else {
     ILogger.e("Task does not exist!");
   }
 }
Пример #7
0
 /** Release all senders that has been acquired previously. */
 public void releaseAllSenders() {
   for (final MessageSender ms : allSenders) {
     if (!availableSenders.contains(ms)) {
       availableSenders.offer(ms);
     }
   }
 }
Пример #8
0
 public Cell getUnvisitedChildCell(Cell cell) {
   if (cell.gridPosX != 0
       && !Panel.cells[cell.gridPosX - 1][cell.gridPosY].wall
       && !Panel.cells[cell.gridPosX - 1][cell.gridPosY].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX - 1][cell.gridPosY])) {
     return Panel.cells[cell.gridPosX - 1][cell.gridPosY];
   } else if (cell.gridPosX != cells.length - 1
       && !Panel.cells[cell.gridPosX + 1][cell.gridPosY].wall
       && !Panel.cells[cell.gridPosX + 1][cell.gridPosY].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX + 1][cell.gridPosY])) {
     return Panel.cells[cell.gridPosX + 1][cell.gridPosY];
   } else if (cell.gridPosY != 0
       && !Panel.cells[cell.gridPosX][cell.gridPosY - 1].wall
       && !Panel.cells[cell.gridPosX][cell.gridPosY - 1].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX][cell.gridPosY - 1])) {
     return Panel.cells[cell.gridPosX][cell.gridPosY - 1];
   } else if (cell.gridPosY != cells.length - 1
       && !Panel.cells[cell.gridPosX][cell.gridPosY + 1].wall
       && !Panel.cells[cell.gridPosX][cell.gridPosY + 1].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX][cell.gridPosY + 1])) {
     return Panel.cells[cell.gridPosX][cell.gridPosY + 1];
   } else if (diagonal
       && cell.gridPosX != 0
       && cell.gridPosY != 0
       && !Panel.cells[cell.gridPosX - 1][cell.gridPosY - 1].wall
       && !Panel.cells[cell.gridPosX - 1][cell.gridPosY - 1].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX - 1][cell.gridPosY - 1])
       && !possibleWallhack(cell, true, false, false, false)) {
     return Panel.cells[cell.gridPosX - 1][cell.gridPosY - 1];
   } else if (diagonal
       && cell.gridPosX != cells.length - 1
       && cell.gridPosY != 0
       && !Panel.cells[cell.gridPosX + 1][cell.gridPosY - 1].wall
       && !Panel.cells[cell.gridPosX + 1][cell.gridPosY - 1].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX + 1][cell.gridPosY - 1])
       && !possibleWallhack(cell, false, true, false, false)) {
     return Panel.cells[cell.gridPosX + 1][cell.gridPosY - 1];
   } else if (diagonal
       && cell.gridPosX != cells.length - 1
       && cell.gridPosY != cells.length - 1
       && !Panel.cells[cell.gridPosX + 1][cell.gridPosY + 1].wall
       && !Panel.cells[cell.gridPosX + 1][cell.gridPosY + 1].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX + 1][cell.gridPosY + 1])
       && !possibleWallhack(cell, false, false, true, false)) {
     return Panel.cells[cell.gridPosX + 1][cell.gridPosY + 1];
   } else if (diagonal
       && cell.gridPosX != 0
       && cell.gridPosY != cells.length - 1
       && !Panel.cells[cell.gridPosX - 1][cell.gridPosY + 1].wall
       && !Panel.cells[cell.gridPosX - 1][cell.gridPosY + 1].solvingVisited
       && !cellStack.contains(Panel.cells[cell.gridPosX - 1][cell.gridPosY + 1])
       && !possibleWallhack(cell, false, false, false, true)) {
     return Panel.cells[cell.gridPosX - 1][cell.gridPosY + 1];
   } else {
     return null;
   }
 }
  private void loggedInCheck(StampyMessage<?> message, HostPort hostPort)
      throws NotLoggedInException {
    if (loggedInConnections.contains(hostPort)) return;

    log.error(
        "{} attempted to send a {} message without logging in", hostPort, message.getMessageType());
    throw new NotLoggedInException("Not logged in");
  }
Пример #10
0
 Boolean enqueueEpisodes(Context c) {
   List<Episode> episodes = getNewEpisodeList(true, c);
   for (Episode e : episodes) {
     if (!EpisodeQueue.contains(e)) {
       EpisodeQueue.add(e);
     }
   }
   return episodes.size() > 0;
 }
Пример #11
0
 protected synchronized boolean addCometEvent(CometEvent event) {
   boolean result = false;
   if (!events.contains(event)) {
     events.add(event);
     result = true;
   }
   event.getHttpServletRequest().setAttribute(COMET_EVENT_ATTR, this);
   return result;
 }
Пример #12
0
 protected void handleNewConsumer(Owner sender) {
   _consumerLock.lock();
   try {
     if (!_consumersAvailable.contains(sender)) {
       _consumersAvailable.add(sender);
     }
   } finally {
     _consumerLock.unlock();
   }
 }
Пример #13
0
 protected void handleNewRunRequest(Owner sender) {
   _consumerLock.lock();
   try {
     if (!_runRequests.contains(sender)) {
       _runRequests.add(sender);
     }
   } finally {
     _consumerLock.unlock();
   }
 }
Пример #14
0
  @Override
  public void bindView(View view, Context context, Cursor cursor) {

    startLoaderThreadIfStopped();
    lock.lock();
    Model inflate = ((CPOrmCursor<Model>) getCursor()).inflate();
    if (!loaderQueue.contains(inflate)) loaderQueue.offer(inflate);
    condition.signal();
    lock.unlock();
    super.bindView(view, context, cursor);
  }
Пример #15
0
 public synchronized void clear() {
   Object[] imgs = cache.values().toArray();
   cache.clear();
   for (Object img : imgs) {
     assert img == null || img instanceof Image;
     if (img != null && imagesQueue.size() < IMAGES_QUEUE_MAX_SIZE) {
       assert !imagesQueue.contains((Image) img);
       imagesQueue.add((Image) img);
     }
   }
 }
Пример #16
0
 public void a(dvg dvg1) {
   if (dvg1.equals(a)) {
     Runnable runnable = f;
     g.x().removeCallbacks(runnable);
     g.a(f, dvg1.e());
     return;
   }
   if (!d.contains(dvg1)) {
     d.add(dvg1);
   }
   b();
 }
Пример #17
0
  @Override
  public void render(GameContainer gameContainer, StateBasedGame stateBasedGame, Graphics g)
      throws SlickException {
    for (int i = 0; i < cells.length; i++) {
      for (int j = 0; j < cells.length; j++) {
        cells[i][j].draw(g, this.maze);
        if (cellStack.size() > 0) {
          if (cellStack.contains(cells[i][j])) {
            g.setColor(Color.blue);
            g.fillRect(cells[i][j].gridPosX * ratio, cells[i][j].gridPosY * ratio, ratio, ratio);
            g.setColor(Color.black);
          }
        }
        if (cells[i][j].start) {
          g.setColor(Color.green);
          g.fillRect(cells[i][j].gridPosX * ratio, cells[i][j].gridPosY * ratio, ratio, ratio);
          g.setColor(Color.black);
        }
      }
    }

    if (this.search) {
      if (dfsBacktracked.size() > 0) {
        for (int i = 0; i < dfsBacktracked.size(); i++) {
          g.setColor(Color.blue);
          g.fillRect(
              dfsBacktracked.get(i).gridPosX * ratio,
              dfsBacktracked.get(i).gridPosY * ratio,
              ratio,
              ratio);
          g.setColor(Color.black);
        }
      }
    }

    if (this.path.size() > 0) {
      for (int i = 0; i < path.size(); i++) {
        if (!foundSolution && search) {
          g.setColor(Color.yellow);
          g.fillRect(path.get(i).gridPosX * ratio, path.get(i).gridPosY * ratio, ratio, ratio);
          g.setColor(Color.black);
        } else {
          cells[path.get(i).gridPosX][path.get(i).gridPosY].way = true;
        }
      }
    }

    if (currentDFSCell != null) {
      g.setColor(Color.green);
      g.fillRect(currentDFSCell.gridPosX * ratio, currentDFSCell.gridPosY * ratio, ratio, ratio);
      g.setColor(Color.black);
    }
  }
Пример #18
0
  @Override
  public String getMultiPlayerGameId(String playerId) {
    String gameId = mpGames.get(playerId);

    if (gameId != null) {
      Logger.info(String.format("Player %s has joined game %s.", playerId, gameId));
      mpGames.remove(playerId);
    } else if (!waitingPlayers.contains(playerId)) {
      throw new IllegalArgumentException("The player isn't register for a multi player game.");
    }
    return gameId;
  }
Пример #19
0
 // return true if newURLs has this url
 public static boolean newURLsContains(String url) {
   final ReadWriteLock lock = new ReentrantReadWriteLock(); // read write lock
   boolean flg = false;
   try {
     lock.readLock().lock();
     flg = newURLs.contains(url);
     lock.readLock().unlock();
   } catch (Exception e) {
     System.err.println("newURLsContains Error\n" + e.getMessage());
     return true;
   }
   return flg;
 }
Пример #20
0
 public void handleMessage(Message msg) {
   switch (msg.what) {
     case MSG_UPDATE_SCREEN:
       update();
       break;
     case MSG_KILL_MASK:
       MovableMask mask = (MovableMask) msg.obj;
       if (mMovableMaskQueue.contains(mask)) {
         mMovableMaskQueue.remove(mask);
       }
       break;
   }
 }
Пример #21
0
  // 保证每个 url 只被访问一次
  public static void addUnvisitedUrl(String url) {

    if (url != null
        && !url.trim().equals("")
        && !visitedUrl.contains(url)
        && !unVisitedUrl.contains(url)) {
      unVisitedUrl.add(url);
      System.out.println(url + "进入unVisitedUrl队列"); // not very bad
      System.out.println("现在unVisitedUrl队列中共有:" + LinkQueue.getUnVisitedUrlNum() + "个元素"); // not
      // very
      // bad

    }
  }
Пример #22
0
 public Queue<SearchActivity> getLastSearches() {
   if (lastSearches == null) {
     lastSearches = new LinkedList<SearchActivity>();
   }
   List<SearchActivity> seList = listLastDistinctSearches();
   for (SearchActivity searchActivity : seList) {
     if (!unique.contains(searchActivity.getSearchString())
         && !searchActivity.getSearchString().equals("")) {
       unique.add(searchActivity.getSearchString());
       lastSearches.add(searchActivity);
     }
   }
   return lastSearches;
 }
  public boolean accept(T pathname) {
    synchronized (this.monitor) {
      if (seen.contains(pathname)) {
        return false;
      }

      if (!seen.offer(pathname)) {
        seen.poll();
        seen.add(pathname);
      }

      return true;
    }
  }
Пример #24
0
 private List<V> createOrderedVertexList(DirectedGraph<V, ?> graph, V start) {
   Queue<V> todo = new LinkedList<V>();
   List<V> visited = new LinkedList<V>();
   todo.add(start);
   while (!todo.isEmpty()) {
     V current = todo.poll();
     visited.add(current);
     for (V suc : Graphs.successorListOf(graph, current)) {
       if (!todo.contains(suc) && !visited.contains(suc)) {
         todo.add(suc);
       }
     }
   }
   return visited;
 }
Пример #25
0
  @Override
  public void registerForMultiPlayerGame(String playerId) {

    // A player can only exists once in the queue
    if (!waitingPlayers.contains(playerId)) {
      Logger.info(String.format("Player %s has registered for multi player game.", playerId));
      waitingPlayers.add(playerId);
      tryCreateMultiPlayerGame();
    } else {
      Logger.info(
          String.format(
              "Player %s wants to register for multi player game but is already in queue.",
              playerId));
    }
  }
Пример #26
0
 public void add(Object obj)
 {
     synchronized (mAddOnceLock)
     {
         if (!mRegistry.contains(obj))
         {
             mRegistry.add(obj);
         }
     }
     return;
     obj;
     obj1;
     JVM INSTR monitorexit ;
     throw obj;
 }
Пример #27
0
  /**
   * Checks that all map nodes can be reached from all other map nodes
   *
   * @param nodes The list of nodes to check
   * @throws SettingsError if all map nodes are not connected
   */
  private void checkMapConnectedness(List<MapNode> nodes) {
    Set<MapNode> visited = new HashSet<MapNode>();
    Queue<MapNode> unvisited = new LinkedList<MapNode>();
    MapNode firstNode;
    MapNode next = null;

    if (nodes.size() == 0) {
      throw new SimError("No map nodes in the given map");
    }

    firstNode = nodes.get(0);

    visited.add(firstNode);
    unvisited.addAll(firstNode.getNeighbors());

    while ((next = unvisited.poll()) != null) {
      visited.add(next);
      for (MapNode n : next.getNeighbors()) {
        if (!visited.contains(n) && !unvisited.contains(n)) {
          unvisited.add(n);
        }
      }
    }

    if (visited.size() != nodes.size()) { // some node couldn't be reached
      MapNode disconnected = null;
      for (MapNode n : nodes) { // find an example node
        if (!visited.contains(n)) {
          disconnected = n;
          break;
        }
      }
      throw new SettingsError(
          "SimMap is not fully connected. Only "
              + visited.size()
              + " out of "
              + nodes.size()
              + " map nodes "
              + "can be reached from "
              + firstNode
              + ". E.g. "
              + disconnected
              + " can't be reached");
    }
  }
  private void logIn(HostPort hostPort, ConnectHeader header)
      throws AlreadyLoggedInException, NotLoggedInException, MessageListenerHaltException {
    if (loggedInConnections.contains(hostPort))
      throw new AlreadyLoggedInException(hostPort + " is already logged in");

    if (!isForHeader(header))
      throw new NotLoggedInException("login and passcode not specified, cannot log in");

    try {
      getLoginHandler().login(header.getLogin(), header.getPasscode());
      loggedInConnections.add(hostPort);
    } catch (TerminateSessionException e) {
      log.error("Login handler has terminated the session", e);
      sendErrorMessage(e.getMessage(), hostPort);
      gateway.closeConnection(hostPort);
      throw new MessageListenerHaltException();
    }
  }
Пример #29
0
 public void a(dvg dvg1, dvg dvg2) {
   if (dvg1.equals(dvg2)) {
     return;
   }
   if (d.contains(dvg1)) {
     d.remove(dvg1);
     d.add(dvg2);
     return;
   }
   if (a != null && a.equals(dvg1)) {
     Runnable runnable = f;
     g.x().removeCallbacks(runnable);
     a(dvg2, dvg1.a().equals(dvg2.b()));
     return;
   } else {
     a(dvg2);
     return;
   }
 }
Пример #30
0
 /**
  * Special cache operation, intended to riddle cached tiles to avoid clearing the cache while
  * ordinary shrinking.
  *
  * @param aActualArea TilesBoundaries instance, defining are to maintain im this cache
  * @see TilesBoundaries
  */
 public synchronized void setActualArea(TilesBoundaries aActualArea) {
   List<Point> toDel = new ArrayList<>();
   for (Entry<Point, Image> tileEntry : cache.entrySet()) {
     Point tileKey = tileEntry.getKey();
     if (!aActualArea.contains(tileKey)) {
       toDel.add(tileKey);
     }
   }
   for (Point toDelKey : toDel) {
     Image img = cache.remove(toDelKey);
     // toDelKey key may be invalid and no elements will be removed.
     // So we have a simple check here rather than an assert.
     if (img != null) {
       if (imagesQueue.size() < IMAGES_QUEUE_MAX_SIZE) {
         assert !imagesQueue.contains(img);
         imagesQueue.add(img);
       }
     }
   }
   actualArea = aActualArea;
 }