當前位置: 首頁>>代碼示例>>Java>>正文


Java ConcurrentHashMultiset.count方法代碼示例

本文整理匯總了Java中com.google.common.collect.ConcurrentHashMultiset.count方法的典型用法代碼示例。如果您正苦於以下問題:Java ConcurrentHashMultiset.count方法的具體用法?Java ConcurrentHashMultiset.count怎麽用?Java ConcurrentHashMultiset.count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.ConcurrentHashMultiset的用法示例。


在下文中一共展示了ConcurrentHashMultiset.count方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getArgmaxAlignment

import com.google.common.collect.ConcurrentHashMultiset; //導入方法依賴的package包/類
private int getArgmaxAlignment(int idx) {
  if (idx >= aCounter.size())
    return -1;
  // Linear search:
  ConcurrentHashMultiset<Integer> aCounts = aCounter.get(idx);
  int maxK = -1;
  int maxV = Integer.MIN_VALUE;
  String maxKLex = null;
  for (int k : aCounts.elementSet()) {
    int v = aCounts.count(k);
    if (v == maxV) {
      // If there is a tie, take lexicographic order as defined in Moses:
      String kLex = AlignmentTemplate.alignmentToString(aIndex.get(k));
      if (maxKLex == null)
        maxKLex = AlignmentTemplate.alignmentToString(aIndex.get(maxK));
      if (kLex.compareTo(maxKLex) < 0) {
        maxK = k;
        maxV = v;
        maxKLex = kLex;
      }
    } else if (v > maxV) {
      maxK = k;
      maxV = v;
      maxKLex = null;
    }
  }
  assert (maxK >= 0);
  return maxK;
}
 
開發者ID:stanfordnlp,項目名稱:phrasal,代碼行數:30,代碼來源:AlignmentTemplates.java

示例2: countTreeOccurences

import com.google.common.collect.ConcurrentHashMultiset; //導入方法依賴的package包/類
@Override
public int countTreeOccurences(final TreeNode<T> root) {
	final ConcurrentHashMultiset<TreeNode<T>> productions = grammar
			.get(root.getData());
	if (productions == null) {
		return 0;
	}
	return productions.count(root);
}
 
開發者ID:mast-group,項目名稱:codemining-treelm,代碼行數:10,代碼來源:TSGrammar.java

示例3: tryAdd

import com.google.common.collect.ConcurrentHashMultiset; //導入方法依賴的package包/類
/**
 * Attempts to add a single instance of the given value to the given
 * multiset without exceeding the specified maximum number of values. If
 * the value cannot be added without exceeding the maximum, false is
 * returned.
 *
 * @param <T>
 *     The type of values contained within the multiset.
 *
 * @param multiset
 *     The multiset to attempt to add a value to.
 *
 * @param value
 *     The value to attempt to add.
 *
 * @param max
 *     The maximum number of each distinct value that the given multiset
 *     should hold, or zero if no limit applies.
 *
 * @return
 *     true if the value was successfully added without exceeding the
 *     specified maximum, false if the value could not be added.
 */
private <T> boolean tryAdd(ConcurrentHashMultiset<T> multiset, T value, int max) {

    // Repeatedly attempt to add a new value to the given multiset until we
    // explicitly succeed or explicitly fail
    while (true) {

        // Get current number of values
        int count = multiset.count(value);

        // Bail out if the maximum has already been reached
        if (count >= max && max != 0)
            return false;

        // Attempt to add one more value
        if (multiset.setCount(value, count, count+1))
            return true;

        // Try again if unsuccessful

    }

}
 
開發者ID:apache,項目名稱:guacamole-client,代碼行數:46,代碼來源:RestrictedGuacamoleTunnelService.java


注:本文中的com.google.common.collect.ConcurrentHashMultiset.count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。