entitiescounter.java

来自「网格agent平台(GAP ,Grid AgentsPlatform)开发包」· Java 代码 · 共 77 行

JAVA
77
字号
/*
 ****************************************************************************************
 * Copyright ? Giovanni Novelli
 * All Rights Reserved.
 ****************************************************************************************
 *
 * Title:        GAP Simulator
 * Description:  GAP (Grid Agents Platform) Toolkit for Modeling and Simulation
 *               of Mobile Agents on Grids
 * License:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * EntitiesCounter.java
 *
 * Created on 7 August 2006, 12.00 by Giovanni Novelli
 *
 ****************************************************************************************
 *
 * $Revision$
 * $Id$
 * $HeadURL$
 *
 *****************************************************************************************
 */

package net.sf.gap.util;

import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author Giovanni Novelli
 */

public class EntitiesCounter {

	private static ConcurrentHashMap<String, Integer> map;

	/**
	 * Creates a new instance of EntitiesCounter
	 */
	public EntitiesCounter() {
		setMap(new ConcurrentHashMap<String, Integer>());
	}

	public static boolean contains(String key) {
		return getMap().containsKey(key);
	}

	public static Integer create(String key) {
		if (!contains(key)) {
			return getMap().put(key, 1);
		} else {
			return getMap().get(key);
		}
	}

	public static Integer inc(String key) {
		if (!contains(key)) {
			return create(key);
		} else {
			return getMap().put(key, getMap().get(key) + 1);
		}
	}

	public static Integer get(String key) {
		return getMap().get(key);
	}

	public static ConcurrentHashMap<String, Integer> getMap() {
		return map;
	}

	public static void setMap(ConcurrentHashMap<String, Integer> aMap) {
		map = aMap;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?