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


Java ConcurrentHashMap.keySet方法代碼示例

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


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

示例1: removeCookie

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
@Override
public synchronized boolean removeCookie(HttpUrl url) {
    if (!cookies.containsKey(url.host())) return false;

    //內存移除
    ConcurrentHashMap<String, Cookie> urlCookie = cookies.remove(url.host());
    //文件移除
    Set<String> cookieTokens = urlCookie.keySet();
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    for (String cookieToken : cookieTokens) {
        if (cookiePrefs.contains(COOKIE_NAME_PREFIX + cookieToken)) {
            prefsWriter.remove(COOKIE_NAME_PREFIX + cookieToken);
        }
    }
    prefsWriter.remove(url.host());
    prefsWriter.apply();

    return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:SPCookieStore.java

示例2: fetchMessageQueuesInBalance

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
public Set<MessageQueue> fetchMessageQueuesInBalance(String topic) throws MQClientException {
    this.makeSureStateOK();
    if (null == topic) {
        throw new IllegalArgumentException("topic is null");
    }

    ConcurrentHashMap<MessageQueue, ProcessQueue> mqTable = this.rebalanceImpl.getProcessQueueTable();
    Set<MessageQueue> mqResult = new HashSet<MessageQueue>();
    for (MessageQueue mq : mqTable.keySet()) {
        if (mq.getTopic().equals(topic)) {
            mqResult.add(mq);
        }
    }

    return mqResult;
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:17,代碼來源:DefaultMQPullConsumerImpl.java

示例3: removeCookie

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
@Override
public synchronized boolean removeCookie(HttpUrl url) {
    if (!cookies.containsKey(url.host())) {
        return false;
    }

    //內存移除
    ConcurrentHashMap<String, Cookie> urlCookie = cookies.remove(url.host());
    //文件移除
    Set<String> cookieTokens = urlCookie.keySet();
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    for (String cookieToken : cookieTokens) {
        if (cookiePrefs.contains(COOKIE_NAME_PREFIX + cookieToken)) {
            prefsWriter.remove(COOKIE_NAME_PREFIX + cookieToken);
        }
    }
    prefsWriter.remove(url.host());
    prefsWriter.apply();

    return true;
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:22,代碼來源:SPCookieStore.java

示例4: testKeySetAddRemove

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * keySet.add adds the key with the established value to the map;
 * remove removes it.
 */
public void testKeySetAddRemove() {
    ConcurrentHashMap map = map5();
    Set set1 = map.keySet();
    Set set2 = map.keySet(true);
    set2.add(six);
    assertSame(map, ((ConcurrentHashMap.KeySetView)set2).getMap());
    assertSame(map, ((ConcurrentHashMap.KeySetView)set1).getMap());
    assertEquals(set2.size(), map.size());
    assertEquals(set1.size(), map.size());
    assertTrue((Boolean)map.get(six));
    assertTrue(set1.contains(six));
    assertTrue(set2.contains(six));
    set2.remove(six);
    assertNull(map.get(six));
    assertFalse(set1.contains(six));
    assertFalse(set2.contains(six));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ConcurrentHashMap8Test.java

示例5: testGetMappedValue

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * KeySetView.getMappedValue returns the map's mapped value
 */
public void testGetMappedValue() {
    ConcurrentHashMap map = map5();
    assertNull(map.keySet().getMappedValue());
    try {
        map.keySet(null);
        shouldThrow();
    } catch (NullPointerException success) {}
    ConcurrentHashMap.KeySetView set = map.keySet(one);
    assertFalse(set.add(one));
    assertTrue(set.add(six));
    assertTrue(set.add(seven));
    assertSame(one, set.getMappedValue());
    assertNotSame(one, map.get(one));
    assertSame(one, map.get(six));
    assertSame(one, map.get(seven));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ConcurrentHashMap8Test.java

示例6: selectTable

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
protected HTableDescriptor selectTable(ConcurrentHashMap<TableName, HTableDescriptor> tableMap)
{
  // randomly select table from tableMap
  if (tableMap.isEmpty()){
    return null;
  }
  // synchronization to prevent removal from multiple threads
  synchronized (tableMap){
    ArrayList<TableName> tableList = new ArrayList<TableName>(tableMap.keySet());
    TableName randomKey = tableList.get(RandomUtils.nextInt(tableList.size()));
    HTableDescriptor randomHtd = tableMap.get(randomKey);
    // remove from tableMap
    tableMap.remove(randomKey);
    return randomHtd;
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:17,代碼來源:IntegrationTestDDLMasterFailover.java

示例7: testKeySet

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * keySet returns a Set containing all the keys
 */
public void testKeySet() {
    ConcurrentHashMap map = map5();
    Set s = map.keySet();
    assertEquals(5, s.size());
    assertTrue(s.contains(one));
    assertTrue(s.contains(two));
    assertTrue(s.contains(three));
    assertTrue(s.contains(four));
    assertTrue(s.contains(five));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:ConcurrentHashMapTest.java

示例8: testKeySet_empty_removeAll

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * Test keySet().removeAll on empty map
 */
public void testKeySet_empty_removeAll() {
    ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
    Set<Integer> set = map.keySet();
    set.removeAll(Collections.emptyList());
    assertTrue(map.isEmpty());
    assertTrue(set.isEmpty());
    // following is test for JDK-8163353
    set.removeAll(Collections.emptySet());
    assertTrue(map.isEmpty());
    assertTrue(set.isEmpty());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ConcurrentHashMapTest.java

示例9: testKeySetToArray

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * keySet.toArray returns contains all keys
 */
public void testKeySetToArray() {
    ConcurrentHashMap map = map5();
    Set s = map.keySet();
    Object[] ar = s.toArray();
    assertTrue(s.containsAll(Arrays.asList(ar)));
    assertEquals(5, ar.length);
    ar[0] = m10;
    assertFalse(s.containsAll(Arrays.asList(ar)));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:ConcurrentHashMapTest.java

示例10: getKeys

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * Gets the (unique) set of keys of all registered metrics of a given type.
 *
 * @param type
 *            the type
 * @return the keys
 */
public Iterable<String> getKeys(String type) {
	ConcurrentHashMap<String, Object> map = values.get(type);
	if (map == null) {
		return emptySet();
	}
	return map.keySet();
}
 
開發者ID:mevdschee,項目名稱:tqdev-metrics,代碼行數:15,代碼來源:MetricRegistry.java

示例11: aggregateResults

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * @param all ConcurrentHashMap<String, IncrementalStats>
 * @return SimpleStats
 */
private SimpleStats aggregateResults(ConcurrentHashMap<String, IncrementalStats> all)
{
    SimpleStats answer = null;

    for (String key : all.keySet())
    {
        IncrementalStats next = all.get(key);
        IncrementalStats stats = next.copy();
        if (answer == null)
        {
            answer = new SimpleStats(stats.scale, this.infoSrv);
            answer .start  = stats.start;
            answer.moments[0] = stats.moments[0];
            answer.moments[1] = stats.moments[1];
            answer.moments[2] = stats.moments[2];
            answer.max = stats.max;
            answer.min = stats.min;
            answer.copies.put(key, stats);
        }
        else
        {
            SimpleStats newAnswer = new SimpleStats(answer.scale, this.infoSrv);

            newAnswer.moments[0] = answer.moments[0] + stats.moments[0];

            newAnswer.moments[1] = answer.moments[1] * answer.moments[0] + stats.moments[1] * stats.moments[0];
            newAnswer.moments[1] /= answer.moments[0] + stats.moments[0];

            newAnswer.moments[2] = answer.moments[2] * answer.moments[0];
            newAnswer.moments[2] += (answer.moments[1] - newAnswer.moments[1]) * (answer.moments[1] - newAnswer.moments[1]) * answer.moments[0];
            newAnswer.moments[2] += stats.moments[2] * stats.moments[0];
            newAnswer.moments[2] += (stats.moments[1] - newAnswer.moments[1]) * (stats.moments[1] - newAnswer.moments[1]) * stats.moments[0];
            newAnswer.moments[2] /= answer.moments[0] + stats.moments[0];

            newAnswer.min = (stats.min < answer.min) ? stats.min : answer.min;
            newAnswer.max = (stats.max > answer.max) ? stats.max : answer.max;
            
            newAnswer.start = (stats.start.compareTo(answer.start) < 1) ? stats.start : answer.start;

            newAnswer.copies.putAll(answer.copies);
            newAnswer.copies.put(key, stats);

            answer = newAnswer;
        }

    }

    if (answer == null)
    {
        answer = new SimpleStats(1, this.infoSrv);
    }

    return answer;
}
 
開發者ID:Alfresco,項目名稱:alfresco-solrclient,代碼行數:59,代碼來源:TrackerStats.java

示例12: getAliveProviders

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/**
 * 存活的全部provider
 *
 * @return all alive providers
 */
public List<Provider> getAliveProviders() {
    ConcurrentHashMap<Provider, ClientTransport> map =
            aliveConnections.isEmpty() ? subHealthConnections : aliveConnections;
    return new ArrayList<Provider>(map.keySet());
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:11,代碼來源:ConnectionHolder.java

示例13: initClusterCenters

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
/** Initialize cluster centers. */
private Vector[] initClusterCenters(SparseDistributedMatrix points, int k) {
    // Initialize empty centers and point costs.
    int ptsCnt = points.rowSize();

    String cacheName = ((SparseDistributedMatrixStorage)points.getStorage()).cacheName();

    // Initialize the first center to a random point.
    Vector sample = localCopyOf(points.viewRow(rnd.nextInt(ptsCnt)));

    List<Vector> centers = new ArrayList<>();
    List<Vector> newCenters = new ArrayList<>();
    newCenters.add(sample);
    centers.add(sample);

    final ConcurrentHashMap<Integer, Double> costs = new ConcurrentHashMap<>();

    // On each step, sample 2 * k points on average with probability proportional
    // to their squared distance from the centers. Note that only distances between points
    // and new centers are computed in each iteration.
    int step = 0;
    UUID uid = points.getUUID();

    while (step < initSteps) {
        // We assume here that costs can fit into memory of one node.
        ConcurrentHashMap<Integer, Double> newCosts = getNewCosts(points, newCenters, cacheName);

        // Merge costs with new costs.
        for (Integer ind : newCosts.keySet())
            costs.merge(ind, newCosts.get(ind), Math::min);

        double sumCosts = costs.values().stream().mapToDouble(Double::valueOf).sum();

        newCenters = getNewCenters(k, costs, uid, sumCosts, cacheName);
        centers.addAll(newCenters);

        step++;
    }

    List<Vector> distinctCenters = centers.stream().distinct().collect(Collectors.toList());

    if (distinctCenters.size() <= k)
        return distinctCenters.toArray(new Vector[] {});
    else {
        // Finally, we might have a set of more than k distinct candidate centers; weight each
        // candidate by the number of points in the dataset mapping to it and run a local k-means++
        // on the weighted centers to pick k of them
        ConcurrentHashMap<Integer, Integer> centerInd2Weight = weightCenters(uid, distinctCenters, cacheName);

        List<Double> weights = new ArrayList<>(centerInd2Weight.size());

        for (int i = 0; i < distinctCenters.size(); i++)
            weights.add(i, Double.valueOf(centerInd2Weight.getOrDefault(i, 0)));

        DenseLocalOnHeapMatrix dCenters = MatrixUtil.fromList(distinctCenters, true);

        return new KMeansLocalClusterer(getDistanceMeasure(), 30, seed).cluster(dCenters, k, weights).centers();
    }
}
 
開發者ID:Luodian,項目名稱:Higher-Cloud-Computing-Project,代碼行數:60,代碼來源:KMeansDistributedClusterer.java

示例14: cleanup

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
private static void cleanup(ConcurrentHashMap<Integer, ConcurrentLinkedQueue<byte[]>> pool)
{
	for (int key : pool.keySet())
		cleanup(pool.get(key));
}
 
開發者ID:bp2008,項目名稱:blueirisviewer,代碼行數:6,代碼來源:ByteArrayPool.java

示例15: doGet

import java.util.concurrent.ConcurrentHashMap; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	String method=req.getParameter("method");
	String name=req.getParameter("name");
	String uri=req.getRequestURI();
	if(StringUtils.isBlank(method)){
		List<Map<String, String>> infolist = new ArrayList<>();
		ConcurrentHashMap<String, Spider> spiders = SpiderManager.get()
				.getSpiders();
		for (String key : spiders.keySet()) {
			Map<String, String> map = new HashMap<>();
			Spider spider = spiders.get(key);
			map.put("name", key);
			map.put("processor", spider.getProcessor().getClass().getName());
			map.put("status", spider.getState().name().toLowerCase());
			SimpleDateFormat sdf = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			Date start = spider.getStartTime();
			Date end = spider.getEndTime();
			end = end == null ? new Date() : end;
			long runsecs = start == null ? 0 : (end.getTime() - start
					.getTime()) / 1000;
			map.put("info",
					"開始時間:"
							+ (start == null ? "無" : sdf.format(start))
							+ ",運行時間:"
							+ runsecs
							+ "秒,"
							+ "總請求數:"
							+ spider.getScheduler().getTotalRequestsCount(
									spider)
							+ ",剩餘請求數:"
							+ spider.getScheduler().getLeftRequestsCount(
									spider));

			infolist.add(map);
		}
		req.setAttribute("root", req.getServletContext().getContextPath());
		req.setAttribute("spiders", infolist);
		req.getRequestDispatcher("/jsp/spider-list.jsp").forward(req, resp);
	}else if(method.equals("start")){
		outString(resp, String.valueOf(SpiderManager.get().start(name)));
	}else if(method.equals("stop")){
		outString(resp, String.valueOf(SpiderManager.get().stop(name)));
	}
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:48,代碼來源:MonitorServlet.java


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