当前位置: 首页>>代码示例>>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;未经允许,请勿转载。