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


Java TreeMap.containsKey方法代碼示例

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


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

示例1: main

import java.util.TreeMap; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    TreeMap<Byte, Integer> frequencyMap = new TreeMap<Byte, Integer>();
    FileInputStream f = new FileInputStream(args[0]);

    while (f.available() > 0) {
        byte[] buf = new byte[f.available()];
        f.read(buf);

        for (int i = 0; i < buf.length; i++) {
            if (frequencyMap.containsKey(buf[i]))
                frequencyMap.put(buf[i], frequencyMap.get(buf[i]) + 1);
            else
                frequencyMap.put(buf[i], 1);
        }
    }
    f.close();

    for (Map.Entry pair : frequencyMap.entrySet()) {
        System.out.println((char)((byte) pair.getKey()) + " " + pair.getValue());
    }
}
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:22,代碼來源:Solution.java

示例2: UploadCdnEntity

import java.util.TreeMap; //導入方法依賴的package包/類
public String UploadCdnEntity(TreeMap<String, Object> params) throws NoSuchAlgorithmException, IOException {
	String actionName = "UploadCdnEntity";

       String entityFile = params.get("entityFile").toString();
       params.remove("entityFile");
       File file = new File(entityFile);        
       if (!file.exists()) {
       	throw new FileNotFoundException();
       }
       
       if (!params.containsKey("entityFileMd5")) {
           params.put("entityFileMd5", MD5.fileNameToMD5(entityFile));
       }
       
       return call(actionName, params, entityFile);
}
 
開發者ID:BennyThink,項目名稱:qcloudClient,代碼行數:17,代碼來源:Cdn.java

示例3: ensureUniqueHost

import java.util.TreeMap; //導入方法依賴的package包/類
public void ensureUniqueHost (	String adminHostName, StringBuffer resultsBuf,
								TreeMap<String, String> hostDuplicateCheck,
								ReleasePackage model ) {

	logger.debug( "checking {} in \n\t {}", adminHostName, hostDuplicateCheck );

	if ( hostDuplicateCheck.containsKey( adminHostName ) ) {

		String message = CSAP.CONFIG_PARSE_ERROR
				+ " Host: "
				+ adminHostName
				+ " was found in multiple release packages: "
				+ hostDuplicateCheck.get( adminHostName )
				+ " and "
				+ model.getReleasePackageFileName()
				+ ". To ensure package isolation, a host can only appear in 1 package\n";
		resultsBuf.append( message );
		logger.warn( message );
	}
	hostDuplicateCheck.put( adminHostName, model.getReleasePackageFileName() );

}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:23,代碼來源:DefinitionParser.java

示例4: MultipartUploadVodFile

import java.util.TreeMap; //導入方法依賴的package包/類
public String MultipartUploadVodFile(TreeMap<String, Object> params) throws NoSuchAlgorithmException, IOException {
	serverHost = "vod.qcloud.com";
	
	String actionName = "MultipartUploadVodFile";

       String fileName = params.get("file").toString();
       params.remove("file");
       File f= new File(fileName);  
       
       if (!params.containsKey("fileSize")){
       	params.put("fileSize", f.length());
       }
       if (!params.containsKey("fileSha")){
       	params.put("fileSha", SHA1.fileNameToSHA(fileName));
       }
       
       return call(actionName, params, fileName);
}
 
開發者ID:BennyThink,項目名稱:qcloudClient,代碼行數:19,代碼來源:Vod.java

示例5: currentlog

import java.util.TreeMap; //導入方法依賴的package包/類
@RequestMapping(value = "/apistatisticday", method = RequestMethod.GET)
public String currentlog(Model model,
                         @RequestParam(value = "topdatarange", required = false, defaultValue = "0") String topdaterange,
                         @RequestParam(value = "url", required = false, defaultValue = "") String url
) {

    //date list
    List<String> timelist = DateTimeHelper.getDateTimeListForPage(fieryConfig.getKeepdataday());
    model.addAttribute("datelist", timelist);
    model.addAttribute("datelist_selected", topdaterange);

    model.addAttribute("url", url);

    //now the date render
    long shardtime = DateTimeHelper.getTimesMorning(DateTimeHelper.getBeforeDay(Integer.parseInt(topdaterange)));

    TreeMap<Long, APIStatisticStruct> urlList = apiStatisticTimeSet.getHourDetail(url, shardtime);

    //log.info("size:" + urlList.size());

    model.addAttribute("urllist", urlList);

    //http code
    TreeMap<String, Long> httpCodeMap = new TreeMap<>();
    for (Map.Entry<Long, APIStatisticStruct> timeItem : urlList.entrySet()) {
        for (ConcurrentHashMap.Entry<String, AtomicLong> httpitem : timeItem.getValue().getCode_count().entrySet()) {
            if (!httpCodeMap.containsKey(httpitem.getKey())) {
                httpCodeMap.put(httpitem.getKey(), httpitem.getValue().longValue());
            } else {
                httpCodeMap.put(httpitem.getKey(), httpCodeMap.get(httpitem.getKey()) + httpitem.getValue().longValue());
            }
        }

    }

    model.addAttribute("httpcode", httpCodeMap);

    return "apistatisticday";
}
 
開發者ID:weiboad,項目名稱:fiery,代碼行數:40,代碼來源:APIStatisticDayPage.java

示例6: haveSameTransitions

import java.util.TreeMap; //導入方法依賴的package包/類
/**
 * 是否含有相同的轉移函數
 * @param node1
 * @param node2
 * @return
 */
public static boolean haveSameTransitions(MDAGNode node1, MDAGNode node2)
{
    TreeMap<Character, MDAGNode> outgoingTransitionTreeMap1 = node1.outgoingTransitionTreeMap;
    TreeMap<Character, MDAGNode> outgoingTransitionTreeMap2 = node2.outgoingTransitionTreeMap;
    
    if(outgoingTransitionTreeMap1.size() == outgoingTransitionTreeMap2.size())
    {
        //For each _transition in outgoingTransitionTreeMap1, get the identically lableed _transition
        //in outgoingTransitionTreeMap2 (if present), and test the equality of the transitions' target nodes
        for(Entry<Character, MDAGNode> transitionKeyValuePair : outgoingTransitionTreeMap1.entrySet())
        {
            Character currentCharKey = transitionKeyValuePair.getKey();
            MDAGNode currentTargetNode = transitionKeyValuePair.getValue();
            
            if(!outgoingTransitionTreeMap2.containsKey(currentCharKey) || !outgoingTransitionTreeMap2.get(currentCharKey).equals(currentTargetNode))
                return false;
        }
        /////
    }
    else
        return false;
    
    return true;
}
 
開發者ID:priester,項目名稱:hanlpStudy,代碼行數:31,代碼來源:MDAGNode.java

示例7: generateUrl

import java.util.TreeMap; //導入方法依賴的package包/類
public String generateUrl(String actionName, TreeMap<String, Object> params) {
	actionName = ucFirst(actionName);
	if(params == null)
		params = new TreeMap<String, Object>();
	params.put("Action", actionName);
	if (!params.containsKey("Region")) {
		params.put("Region", defaultRegion);
	}
	return Request.generateUrl(params, secretId, secretKey, requestMethod,
			serverHost, serverUri);
}
 
開發者ID:BennyThink,項目名稱:qcloudClient,代碼行數:12,代碼來源:Base.java

示例8: getCount

import java.util.TreeMap; //導入方法依賴的package包/類
public static int getCount(String word, TreeMap<String, Integer> frequencyData){
	if (frequencyData.containsKey(word)){
		return frequencyData.get(word);
	}
	else{
		return 0;
	}
}
 
開發者ID:DivyendraPatil,項目名稱:MS-Cyber-Security-Solutions,代碼行數:9,代碼來源:PageRanking.java

示例9: main

import java.util.TreeMap; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    TreeMap<String, Double> map = new TreeMap<>();
    BufferedReader fileReader = new BufferedReader(new FileReader(args[0]));

    double max = Double.MIN_VALUE;
    while (fileReader.ready()) {
        String s = fileReader.readLine();
        String[] strs = s.split("[\\s\\t\\n\\x0B\\f\\r]");
        String key = strs[0];
        double value = Double.parseDouble(strs[1]);
        if (map.containsKey(key)) {
            map.put(key, map.get(strs[0]) + value);
        } else
            map.put(key, value);
    }
    fileReader.close();

    //Max
    for (Double a : map.values())
        if (max < a)
            max = a;

    //show
    for (Map.Entry<String, Double> pair : map.entrySet())
        if (pair.getValue().equals(max))
            System.out.println(pair.getKey());
}
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:28,代碼來源:Solution.java

示例10: put

import java.util.TreeMap; //導入方法依賴的package包/類
private void put(TreeMap<Date, Long> map, Date date, boolean start) {
	Long count;
	if (map.containsKey(date)) {
		count = map.get(date);
	} else {
		count = 0l;
	}
	map.put(date, count + (start ? 1l : -1l));
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:10,代碼來源:OverlapFinder.java

示例11: testContainsKey

import java.util.TreeMap; //導入方法依賴的package包/類
public void testContainsKey()
{
	// create an empty tree map
	TreeMap<TreeMapKey,Object> tree = new TreeMap<TreeMapKey,Object>();
	// look for a key
	assertFalse("Found a key in an empty tree", tree.containsKey(new TreeMapKey(2)));
	
	// create a list of ints 0..TreeMapFactory.SIZE-1 in random order
	ArrayList<Integer> intList = new ArrayList<Integer>(TreeMapFactory.SIZE);
	
	for (int i=0; i<TreeMapFactory.SIZE; i++)
	{
		intList.add(new Integer(i));
	}
	Collections.shuffle(intList, new Random(173417));
	
	// add keys to tree
	while (intList.size()>0)
	{
		tree.put(new TreeMapKey(((Integer)intList.remove(0)).intValue()), null);
	}
	
	// check that the tree contains all keys from 0 to TreeMapFactory.SIZE-1
	for (int i=0; i<TreeMapFactory.SIZE; i++)
	{
		assertTrue("Tree doesn't contain key " + i, tree.containsKey(new TreeMapKey(i)));
	}
	
	// try null key
	try
	{
		tree.containsKey(null);
		fail("Attempt to call TreeMap.containsKey with null should throw NullPointerException");
	}
	catch (NullPointerException e)
	{
		// expected behaviour
	}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:40,代碼來源:TreeMapAPITest.java

示例12: expandPossibleGoalsDGM

import java.util.TreeMap; //導入方法依賴的package包/類
/**
	 * expandPossibleGoalsDGM is the goaldegeneralization version of expandPossibleGoals.
	 * Like expandPossibleGoals, it has two arguments:
	 * An ArrayList of (Goal,Double) entries created from the current DegeneralizedGoal
	 * to be generalized and a ConditioDirectionPair extracted from that DegeneralizeGoal.
	 * For each goal It creates a new Node and adds an adjacency with a calculated Probability from
	 * the actual node to the newly generated node.
	 * @param goals an ArrayList of (Goal,Double)-Entries
	 * @param cdp   a CollisionDirectionPair
	 */
	private void expandPossibleGoalsDGM(ArrayList<Entry<Goal,Double>> goals,ConditionDirectionPair cdp){
		for(Entry<Goal,Double> goal: goals){
			GlobalCoarse positionAfterInteraction = goal.getKey().getPosition();
			SimulatedLevelScene newScene =
					new SimulatedLevelScene(this.scene,true);
			CollisionAtPosition cap =
					new CollisionAtPosition(cdp, positionAfterInteraction, goal.getKey().getTargetSprite(), goal.getKey().getActorSprite());
			System.out.println("CURRENT COLLISION AT POSITION");
			System.out.println(cap);
			TreeMap<Effect, Double> simulatedEffectList = newScene.simulateCollision(cap, true);
//			if (simulatedEffectList.size() == 0) System.out.println("SD: Seems like no effects are simulated!");
			newScene.getPlanningPlayer().setPosition(positionAfterInteraction.toGlobalContinuous());
			//newScene.recomputeReachabilityMap();
			System.out.println(newScene);
			System.out.println("PREVIOUS GOAL: " + this.previousInteraction);
			//newScene.Rmap.showMap("DEPTH: " + this.depth);
			double prob = 1.0;
			
			Effect topEffect = getMostImportantEffect(simulatedEffectList);
			double newTopProbability = 1.0;
//			System.out.println("Checking top probability for goal " + ((topEffect != null) ? topEffect.getType() : ActionEffect.UNDEFINED));
			if ((topEffect != null) && (simulatedEffectList.containsKey(topEffect))){
//				System.out.println("SD: Set vertex probability to: " + simulatedEffectList.get(topEffect) + " for top effect " + ((topEffect != null) ? topEffect.getType() : ActionEffect.UNDEFINED));
				newTopProbability = simulatedEffectList.get(topEffect);
			}
			
			ConditionVertex next =
					new ConditionVertex(cap, newScene, knowledge, simulatedEffectList, this.depth + 1, goal.getKey(), topEffect, newTopProbability);
			adjacencies.add(new ProbabilityEdge(next, -Math.log(prob)));
		}
	}
 
開發者ID:CognitiveModeling,項目名稱:BrainControl,代碼行數:42,代碼來源:ConditionVertex.java

示例13: reduce

import java.util.TreeMap; //導入方法依賴的package包/類
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {

			//this -> <is=1000, is book=10>
			
			TreeMap<Integer, List<String>> tm = new TreeMap<Integer, List<String>>(Collections.reverseOrder());
			for (Text val : values) {
				String cur_val = val.toString().trim();
				String word = cur_val.split("=")[0].trim();
				int count = Integer.parseInt(cur_val.split("=")[1].trim());
				if(tm.containsKey(count)) {
					tm.get(count).add(word);
				}
				else {
					List<String> list = new ArrayList<>();
					list.add(word);
					tm.put(count, list);
				}
			}

			Iterator<Integer> iter = tm.keySet().iterator();
			
			for(int j=0 ; iter.hasNext() && j < n; j++) {
				int keyCount = iter.next();
				List<String> words = tm.get(keyCount);
				for(String curWord: words) {
					context.write(new DBOutputWritable(key.toString(), curWord, keyCount), NullWritable.get());
					j++;
				}
			}
		}
 
開發者ID:yogykwan,項目名稱:mapreduce-samples,代碼行數:31,代碼來源:LanguageModel.java

示例14: getKeywordMap

import java.util.TreeMap; //導入方法依賴的package包/類
/**
 * Returns a map of the keywords and values, or null if there are none.
 */
public Map<String, String> getKeywordMap() {
    if (keywords == null) {
        TreeMap<String, String> m = null;
        if (setToKeywordStart()) {
            // trim spaces and convert to lower case, both keywords and values.
            do {
                String key = getKeyword();
                if (key.length() == 0) {
                    break;
                }
                char c = next();
                if (c != KEYWORD_ASSIGN) {
                    // throw new IllegalArgumentException("key '" + key + "' missing a value.");
                    if (c == DONE) {
                        break;
                    } else {
                        continue;
                    }
                }
                String value = getValue();
                if (value.length() == 0) {
                    // throw new IllegalArgumentException("key '" + key + "' missing a value.");
                    continue;
                }
                if (m == null) {
                    m = new TreeMap<String, String>(getKeyComparator());
                } else if (m.containsKey(key)) {
                    // throw new IllegalArgumentException("key '" + key + "' already has a value.");
                    continue;
                }
                m.put(key, value);
            } while (next() == ITEM_SEPARATOR);
        }
        keywords = m != null ? m : Collections.<String, String>emptyMap();
    }

    return keywords;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:42,代碼來源:LocaleIDParser.java

示例15: testContainsKey_NullPointerException

import java.util.TreeMap; //導入方法依賴的package包/類
/**
 * containsKey(null) of nonempty map throws NPE
 */
public void testContainsKey_NullPointerException() {
    TreeMap c = map5();
    try {
        c.containsKey(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:TreeMapTest.java


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