java.util.HashMap#keySet ( )源码实例Demo

下面列出了java.util.HashMap#keySet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

static void serializeCrossCorpus (String outputFilePath, CorefSaxParser corefSaxParser, HashMap<String, CoRefSetAgata> lemmaMap) {
    try {
        FileOutputStream fos = new FileOutputStream(outputFilePath);
        String str ="";
        str ="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
        str += "<co-ref-sets corpus=\""+corefSaxParser.corpusName+"\"";
        if (!corefSaxParser.method.isEmpty()) str += " method=\""+corefSaxParser.method+"\"";
        if (!corefSaxParser.threshold.isEmpty()) str += " threshold=\""+corefSaxParser.threshold+"\"";
        str += ">\n";
        fos.write(str.getBytes());
        Set keySet = lemmaMap.keySet();
        Iterator keys = keySet.iterator();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            CoRefSetAgata coRefSetAgata = lemmaMap.get(key);
            str = coRefSetAgata.toString();
            fos.write(str.getBytes());
        }
        str = "</co-ref-sets>\n";
        fos.write(str.getBytes());
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }
}
 
源代码2 项目: toxiclibs   文件: IndexedTriangleMesh.java
public HashMap<String, int[]> addFaceAttributes(AttributedFace f,
        HashMap<String, Object[]> attribs) {
    HashMap<String, int[]> fattribs = null;
    if (attribs != null) {
        fattribs = (f != null) ? f.attribs : new HashMap<String, int[]>(
                attribs.size(), 1);
        for (String attID : attribs.keySet()) {
            Object[] items = attribs.get(attID);
            if (items.length >= 3) {
                ItemIndex<Object> idx = getAttributeIndex(attID);
                int[] ids = new int[] {
                        idx.index(items[0]), idx.index(items[1]),
                        idx.index(items[2])
                };
                fattribs.put(attID, ids);
            }
        }
    }
    return fattribs;
}
 
源代码3 项目: jStyleParser   文件: MultiMap.java
/**
 * Gets all the pseudo elements that are available for the given element.
 * @param el The given element
 * @return A set of all pseudo elements available for the element
 */
public Set<P> pseudoSet(E el)
{
    HashMap<P, D> map = pseudoMaps.get(el);
    if (map == null)
        return Collections.emptySet();
    else
        return map.keySet();
}
 
源代码4 项目: NeurophFramework   文件: OcrPlugin.java
/**
 * This private method sorts the result of the recogntion, in order to
 * see which letter has the highest probability
 *
 * @param passedMap the HashMap that holds the resault of the recognition process
 *
 * @return LinkedHashMap that represents the combination of letters with the
 *                       probability of the correct recognition
 */
private LinkedHashMap sortHashMapByValues(HashMap passedMap) {
    List mapKeys = new ArrayList(passedMap.keySet());
    List mapValues = new ArrayList(passedMap.values());
    Collections.sort(mapValues);
    Collections.sort(mapKeys);
    Collections.reverse(mapValues);

    LinkedHashMap sortedMap = new LinkedHashMap();

    Iterator valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        Object val = valueIt.next();
        Iterator keyIt = mapKeys.iterator();

        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            String comp1 = passedMap.get(key).toString();
            String comp2 = val.toString();

            if (comp1.equals(comp2)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                Character charKey = Character.valueOf(key.toString().charAt(0));
                sortedMap.put(charKey, (Double) val);
                break;
            }

        }

    }
    return sortedMap;
}
 
源代码5 项目: openjdk-8   文件: UIManager.java
/**
 * If the user has specified a default look and feel, use that.
 * Otherwise use the look and feel that's native to this platform.
 * If this code is called after the application has explicitly
 * set it's look and feel, do nothing.
 *
 * @see #maybeInitialize
 */
private static void initializeDefaultLAF(Properties swingProps)
{
    if (getLAFState().lookAndFeel != null) {
        return;
    }

    // Try to get default LAF from system property, then from AppContext
    // (6653395), then use cross-platform one by default.
    String lafName = null;
    HashMap lafData =
            (HashMap) AppContext.getAppContext().remove("swing.lafdata");
    if (lafData != null) {
        lafName = (String) lafData.remove("defaultlaf");
    }
    if (lafName == null) {
        lafName = getCrossPlatformLookAndFeelClassName();
    }
    lafName = swingProps.getProperty(defaultLAFKey, lafName);

    try {
        setLookAndFeel(lafName);
    } catch (Exception e) {
        throw new Error("Cannot load " + lafName);
    }

    // Set any properties passed through AppContext (6653395).
    if (lafData != null) {
        for (Object key: lafData.keySet()) {
            UIManager.put(key, lafData.get(key));
        }
    }
}
 
源代码6 项目: EvilCoder   文件: Get_call_graph.java
public static void print_call_graph(HashMap<Pair<String, Long>, Pair<String, HashSet<Pair<String, Long>>>> cg)
{
  for(Pair<String, Long> func : cg.keySet())
   {
    print_call_graph_entry(func, cg);
   }
}
 
/**
 * Copy a ORG file in the destination file replacing all the vars.
 * 
 * Vars are indicated in the ORG file like this: ${var1}
 * 
 * @param tmpl Template (Org file)
 * @param dest Destination file. It can be the ORG file for overwriting.
 * @param vars Variables to replace in the template
 * @throws IOException 
 */
public static void copyTemplate(File tmpl, File dest, HashMap<String,String> vars) throws IOException {
	  // we need to store all the lines
    List<String> lines = new ArrayList<String>();

    // first, read the file and store the changes
    BufferedReader in = new BufferedReader(new FileReader(tmpl));
    String line = in.readLine();
    while (line != null) {
       
    	for(String var:vars.keySet()) {
    		String orgStr = "\\$\\{" + var +"\\}";
    		String destStr = vars.get(var);
    	
    		line.replaceAll(orgStr, destStr);
    	}
    	
    	lines.add(line);
        line = in.readLine();
    }
    in.close();

    // now, write the file again with the changes
    PrintWriter out = new PrintWriter(dest);
    for (String l : lines)
        out.println(l);
    out.close();
}
 
源代码8 项目: compiler   文件: TreedBuilder.java
private void add(HashMap<String, Integer> vector, HashMap<String, Integer> other) {
	for (String key : other.keySet()) {
		int c = other.get(key);
		if (vector.containsKey(key))
			c += vector.get(key);
		vector.put(key, c);
	}
}
 
源代码9 项目: dubbo-2.6.5   文件: ExchangeCodecTest.java
@Test
public void test_Decode_Error_MagicNum() throws IOException {
    HashMap<byte[], Object> inputBytes = new HashMap<byte[], Object>();
    inputBytes.put(new byte[]{0}, TelnetCodec.DecodeResult.NEED_MORE_INPUT);
    inputBytes.put(new byte[]{MAGIC_HIGH, 0}, TelnetCodec.DecodeResult.NEED_MORE_INPUT);
    inputBytes.put(new byte[]{0, MAGIC_LOW}, TelnetCodec.DecodeResult.NEED_MORE_INPUT);

    for (byte[] input : inputBytes.keySet()) {
        testDecode_assertEquals(assemblyDataProtocol(input), inputBytes.get(input));
    }
}
 
源代码10 项目: development   文件: AppConfigurationCtrl.java
private HashMap<String, String> initControllerOrganizations() {
    HashMap<String, String> map = getAppConfigService()
            .getControllerOrganizations();
    LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
    if (map != null) {
        List<String> sortedKeys = new ArrayList<String>(map.keySet());
        Collections.sort(sortedKeys);
        for (String key : sortedKeys) {
            result.put(key, map.get(key));
        }
    }
    return result;
}
 
源代码11 项目: j2objc   文件: OldAndroidHashMapTest.java
public void testKeyIterator() throws Exception {
    HashMap<String, Integer> map = new HashMap<String, Integer>();

    boolean[] slots = new boolean[4];

    addItems(map);

    for (String s : map.keySet()) {
        int slot = 0;

        if (s.equals("one")) {
            slot = 0;
        } else if (s.equals("two")) {
            slot = 1;
        } else if (s.equals("three")) {
            slot = 2;
        } else if (s.equals("four")) {
            slot = 3;
        } else {
            fail("Unknown key in HashMap");
        }

        if (slots[slot]) {
            fail("key returned more than once");
        } else {
            slots[slot] = true;
        }
    }

    assertTrue(slots[0]);
    assertTrue(slots[1]);
    assertTrue(slots[2]);
    assertTrue(slots[3]);
}
 
源代码12 项目: gemfirexd-oss   文件: DiskRegionTestingBase.java
protected void compareVersionTags(HashMap<String, VersionTag> map1, HashMap<String, VersionTag> map2) {
  assertEquals(map1.size(), map2.size());
  
  for (String key: map1.keySet()) {
    VersionTag tag1 = map1.get(key);
    VersionTag tag2 = map2.get(key);
    assertEquals(tag1.getEntryVersion(), tag2.getEntryVersion());
    assertEquals(tag1.getRegionVersion(), tag2.getRegionVersion());
    assertEquals(tag1.getMemberID(), tag2.getMemberID());
  }
}
 
源代码13 项目: NeurophFramework   文件: ImageRecognitionHelper.java
private static List<String> createLabels(HashMap<String,?> map)
{
    List<String> imageLabels = new ArrayList<String>();
    for (String imgName : map.keySet()) {
        StringTokenizer st = new StringTokenizer(imgName, "._");
        String imageLabel = st.nextToken();
        if (!imageLabels.contains(imageLabel)) {
            imageLabels.add(imageLabel);
        }
    }
    Collections.sort(imageLabels);
    return imageLabels;
}
 
源代码14 项目: openjdk-jdk9   文件: UIManager.java
/**
 * If the user has specified a default look and feel, use that.
 * Otherwise use the look and feel that's native to this platform.
 * If this code is called after the application has explicitly
 * set it's look and feel, do nothing.
 *
 * @see #maybeInitialize
 */
private static void initializeDefaultLAF(Properties swingProps)
{
    if (getLAFState().lookAndFeel != null) {
        return;
    }

    // Try to get default LAF from system property, then from AppContext
    // (6653395), then use cross-platform one by default.
    String lafName = null;
    @SuppressWarnings("unchecked")
    HashMap<Object, String> lafData =
            (HashMap) AppContext.getAppContext().remove("swing.lafdata");
    if (lafData != null) {
        lafName = lafData.remove("defaultlaf");
    }
    if (lafName == null) {
        lafName = getCrossPlatformLookAndFeelClassName();
    }
    lafName = swingProps.getProperty(defaultLAFKey, lafName);

    try {
        setLookAndFeel(lafName);
    } catch (Exception e) {
        throw new Error("Cannot load " + lafName);
    }

    // Set any properties passed through AppContext (6653395).
    if (lafData != null) {
        for (Object key: lafData.keySet()) {
            UIManager.put(key, lafData.get(key));
        }
    }
}
 
源代码15 项目: blip   文件: NewBrutalTest.java
@Test
public void compare() throws Exception {

    for (String prob : new String[] {
        "plants.ts", "accidents.valid", "test",
        "what"}) { // "accidents", , "test", "simple" , "what", "accidents.test"

        HashMap<String, BrutalSolver> solvers = new HashMap<String, BrutalSolver>();

        /*
         for (String r: new String[] {"null", "ent", "r_ent"}) { //
         addBrutal(solvers, "def", r);
         } */

        addBrutal(solvers, "max2");
        addBrutal(solvers, "max");
        addBrutal(solvers, "def");

        /*
         for (String r: new String[] {"null", "ent", "r_ent"}) { //
         addAsobs(solvers, "inasobs2", r);
         }             */

        for (String s : solvers.keySet()) { //
            go(prob, solvers.get(s), s, 10, 7, 1);
        }

        p("");
    }
}
 
源代码16 项目: EvilCoder   文件: Get_call_graph.java
public static HashMap<Pair<String, Long>, HashSet<Pair<String, Long>>> get_simple_call_graph(HashMap<Pair<String, Long>, Pair<String, HashSet<Pair<String, Long>>>> cg)
{
HashMap<Pair<String, Long>, HashSet<Pair<String, Long>>> simple = new HashMap<>();
  for(Pair<String, Long> k : cg.keySet())
   {
    simple.put(k, cg.get(k).second);
   }
 return simple;
}
 
源代码17 项目: Concurnas   文件: NamedType.java
public static HashMap<GenericType, Type> qualifyGenericMethodTypes(ScopeAndTypeChecker satc, List<GenericType> genericsWanted, List<Type> inputs, List<Type> argsWanted ){
	//TODO: oops i think this got implemented as in attemptGenericBinding of TypeCheckUtils
	HashMap<GenericType, HashSet<Type>> qualifications = new HashMap<GenericType, HashSet<Type>>();
	
	int inpis = inputs.size();
	if(inpis == argsWanted.size()){//have to match else no hope!
		for(int n=0; n < inpis; n++){
			Type input = inputs.get(n);
			Type wantedarg = argsWanted.get(n);//has qualification within in
			if(wantedarg instanceof VarNull) {
				continue;
			}
			
			//have to search down the nesting of the type for one of the genericals
			ArrayList<GenericTypeAndQuali> qualiFound = new ArrayList<GenericTypeAndQuali>();
			qualifyMethodGenericFromArg(genericsWanted, input, wantedarg, qualiFound);
			if(!qualiFound.isEmpty()){
				for(GenericTypeAndQuali qualified : qualiFound){
					HashSet<Type> addTo;
					if(!qualifications.containsKey(qualified.q)) {
						addTo = new HashSet<Type>();
						qualifications.put(qualified.q, addTo);
					}else {
						addTo = qualifications.get(qualified.q);
					}
					addTo.add(qualified.quali);
				}
			}
		}
	}

	HashMap<GenericType, Type> ret = new HashMap<GenericType, Type>();
	for(GenericType key : qualifications.keySet()) {
		ErrorRaiseable ers = satc!=null?satc.getErrorRaiseableSupression():new DummyErrorRaiseable();
		//Type qual = TypeCheckUtils.getMoreGeneric(ers , satc, 0, 0, new ArrayList<Type>(qualifications.get(key).stream().filter(a -> !key.equals(a)).collect(Collectors.toList())), null, true);
		
		HashSet<Type> quals = qualifications.get(key);
		ArrayList<Type> cadis;
		if(quals.size() == 1) {
			cadis = new ArrayList<Type>(quals);
		}else {//filter out: T from T -> [F, T]
			cadis = new ArrayList<Type>(quals.stream().filter(a -> !key.equals(a)).collect(Collectors.toList()));
		}
		
		Type qual = TypeCheckUtils.getMoreGeneric(ers , satc, 0, 0, cadis, null, true);
		ret.put(key, qual);
	}
	
	
	return ret;
}
 
源代码18 项目: android-maps-utils   文件: KmlRenderer.java
/**
 * Iterates over the placemarks, gets its style or assigns a default one and adds it to the map
 *
 * @param placemarks
 */
private void addPlacemarksToMap(HashMap<? extends Feature, Object> placemarks) {
    for (Feature kmlPlacemark : placemarks.keySet()) {
        addFeature(kmlPlacemark);
    }
}
 
源代码19 项目: hottub   文件: P11KeyStore.java
/**
 * for each private key CKA_ID, find corresponding cert with same CKA_ID.
 * if found cert, see if cert CKA_LABEL is unique.
 *     if CKA_LABEL unique, map private key/cert alias to that CKA_LABEL.
 *     if CKA_LABEL not unique, map private key/cert alias to:
 *                   CKA_LABEL + ALIAS_SEP + ISSUER + ALIAS_SEP + SERIAL
 * if cert not found, ignore private key
 * (don't support private key entries without a cert chain yet)
 *
 * @return a list of AliasInfo entries that represents all matches
 */
private ArrayList<AliasInfo> mapPrivateKeys(ArrayList<byte[]> pkeyIDs,
                    HashMap<String, HashSet<AliasInfo>> certMap)
            throws PKCS11Exception, CertificateException {

    // reset global alias map
    aliasMap = new HashMap<String, AliasInfo>();

    // list of matched certs that we will return
    ArrayList<AliasInfo> matchedCerts = new ArrayList<AliasInfo>();

    for (byte[] pkeyID : pkeyIDs) {

        // try to find a matching CKA_ID in a certificate

        boolean foundMatch = false;
        Set<String> certLabels = certMap.keySet();
        for (String certLabel : certLabels) {

            // get cert CKA_IDs (if present) for each cert

            HashSet<AliasInfo> infoSet = certMap.get(certLabel);
            for (AliasInfo aliasInfo : infoSet) {
                if (Arrays.equals(pkeyID, aliasInfo.id)) {

                    // found private key with matching cert

                    if (infoSet.size() == 1) {
                        // unique CKA_LABEL - use certLabel as alias
                        aliasInfo.matched = true;
                        aliasMap.put(certLabel, aliasInfo);
                    } else {
                        // create new alias
                        aliasInfo.matched = true;
                        aliasMap.put(getID(certLabel, aliasInfo.cert),
                                    aliasInfo);
                    }
                    matchedCerts.add(aliasInfo);
                    foundMatch = true;
                    break;
                }
            }
            if (foundMatch) {
                break;
            }
        }

        if (!foundMatch) {
            if (debug != null) {
                debug.println
                    ("did not find match for private key with CKA_ID [" +
                    getID(pkeyID) +
                    "] (ignoring entry)");
            }
        }
    }

    return matchedCerts;
}
 
源代码20 项目: gemfirexd-oss   文件: CountStarTest.java
public void testCountStarOnCollection() {
  String collection = "$1";
  HashMap<String, Integer> countStarQueriesWithParms = new HashMap<String, Integer>();
  countStarQueriesWithParms.put("select COUNT(*) from " + collection , 100);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID > 0",100);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID < 0", 0);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID > 0 LIMIT 50",50);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID > 0 AND status='active'", 50);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID > 0 OR status='active'", 100);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID > 0 AND status LIKE 'act%'", 50);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID > 0 OR status LIKE 'ina%'", 100);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where ID IN SET(1, 2, 3, 4, 5)", 5);
  countStarQueriesWithParms.put("select COUNT(*) from " + collection + " where NOT (ID > 5)", 5);
  

  Cache cache = CacheUtils.getCache();

  QueryService queryService = cache.getQueryService();
  //Run queries
  Query query1 = null;
  Query query2 = null;
  
  //Create a collection
  ArrayList<Portfolio> portfolios = new ArrayList<Portfolio>(100);
  for (int i=1; i<=100; i++) {
    portfolios.add(new Portfolio(i, i));
  }
  // Without Indexes
  try {
    for(String queryStr: countStarQueriesWithParms.keySet()){
      query1 = queryService.newQuery(queryStr);
      query2 = queryService.newQuery(queryStr.replace("COUNT(*)", "*"));
      
      SelectResults result1 = (SelectResults)query1.execute(new Object[]{portfolios});
      SelectResults result2 = (SelectResults)query2.execute(new Object[]{portfolios});
      assertEquals(queryStr, 1, result1.size());
      assertTrue(result1.asList().get(0) instanceof Integer);
      
      int count = ((Integer)result1.asList().get(0)).intValue();
      
      //Also verify with size of result2 to count
      assertEquals("COUNT(*) query result is wrong for query: " + queryStr , result2.size(), count);
      
      assertEquals("Query: "+ queryStr, countStarQueriesWithParms.get(queryStr).intValue(), count);
    }
  } catch (Exception e){
    e.printStackTrace();
    fail("Query "+ query1+" Execution Failed!");
  }
}