Java Code Examples for java.util.Hashtable#keySet()

The following examples show how to use java.util.Hashtable#keySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorHandler.java    From DroidUIBuilder with Apache License 2.0 6 votes vote down vote up
public static void dump(Writer w, Hashtable<String, Color> colors)
	throws IOException
{
	PrintWriter pw = new PrintWriter(w);
	pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
	pw.println("<resources>");
	for (String key : colors.keySet())
	{
		Color value = colors.get(key);
		String clr = String.format("#%02x%02x%02x%02x", value.getAlpha(),
				value.getRed(), value.getGreen(), value.getBlue());
		pw.println("<color name=\"" + key + "\">" + clr + "</color>");
	}
	pw.println("</resources>");
	pw.flush();
	w.flush();
}
 
Example 2
Source File: InterestingFailureCaseTest.java    From algorithms-nutshell-2ed with MIT License 6 votes vote down vote up
/**
 * Horizontal edges cause PROBLEMS!
 */
public void testHorizontal2() {
	LineSweep dba = new LineSweep();


	// showed a problem
	ILineSegment[] segments = new ILineSegment[]{
			new TwoDLineSegment(new TwoDPoint(2,20),new TwoDPoint(5,17)),
			new TwoDLineSegment(new TwoDPoint(0,18),new TwoDPoint(6,18)),
			new TwoDLineSegment(new TwoDPoint(6, 3),new TwoDPoint(8,4)),
	};

	Hashtable<IPoint, List<ILineSegment>> res = dba.intersections(segments);

	for (IPoint ip : res.keySet()) {
		List<ILineSegment> ilss = res.get(ip);
		System.out.println (ip);
		for (ILineSegment ils : ilss) {
			System.out.println ("  " + ils);
		}
		System.out.println();
	}

	assertEquals (1, res.size());
}
 
Example 3
Source File: Validator.java    From Hidden-Markov-Model with MIT License 6 votes vote down vote up
public boolean isValidInitialProbabilities(Vector<String> states, Hashtable<String, Double> initialProbabilities) {
    if (states.size() != initialProbabilities.size())
        return false;

    for (int i = 0; i < states.size(); i++) {
        boolean found = false;
        for (String state : initialProbabilities.keySet()) {
            if (state.equals(states.get(i))) {
                found = true;
                break;
            }
        }

        if (!found)
            return false;
    }

    return true;
}
 
Example 4
Source File: ResourceManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void mergeTables(Hashtable<? super String, Object> props1,
                                Hashtable<? super String, Object> props2) {
    for (Object key : props2.keySet()) {
        String prop = (String)key;
        Object val1 = props1.get(prop);
        if (val1 == null) {
            props1.put(prop, props2.get(prop));
        } else if (isListProperty(prop)) {
            String val2 = (String)props2.get(prop);
            props1.put(prop, ((String)val1) + ":" + val2);
        }
    }
}
 
Example 5
Source File: Main.java    From glitchify with MIT License 5 votes vote down vote up
private SpannableStringBuilder injectBadges(XC_MethodHook.MethodHookParam param, Class mediaSpanClass, SpannableStringBuilder chatMsg, Hashtable customBadges) {
    String chatSender = (String) callMethod(param.args[0], "getDisplayName");
    int location = chatMsg.toString().indexOf(chatSender);
    if (location == -1) { return chatMsg; }

    int badgeCount;
    if (location == 0) {
        badgeCount = location;
    } else {
        badgeCount = chatMsg.toString().substring(0, location - 1).split(" ").length;
    }

    for (Object key : customBadges.keySet()) {
        if (badgeCount >= 3) {
            // Already at 3 badges, anymore will clog up chat box
            return chatMsg;
        }
        String keyString = (String) key;
        if (preferences.hiddenBadges().contains(keyString)) {
            continue;
        }
        if (!((ArrayList) ((Hashtable) customBadges.get(keyString)).get("users")).contains(chatSender)) {
            continue;
        }
        String url = (String) ((Hashtable) customBadges.get(keyString)).get("image");
        SpannableString badgeSpan = (SpannableString) callMethod(param.thisObject, "a", param.thisObject, url, Enum.valueOf(mediaSpanClass, "Badge"), keyString + " ", null, true, 8, null);
        chatMsg.insert(location, badgeSpan);
        location += badgeSpan.length();
        badgeCount++;
    }
    return chatMsg;
}
 
Example 6
Source File: StringTool.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void dumpHashtable(final Log log, final Hashtable table){
	Set<String> keys = table.keySet();
	log.log("Dump Hashtable\n", Log.INFOS);
	for (String key : keys) {
		log.log(key + ": " + table.get(key).toString(), Log.INFOS);
	}
	log.log("End dump\n", Log.INFOS);
}
 
Example 7
Source File: SearchTheMovieDbProxyResource.java    From movieapp-dialog with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the URI from the URI parameter hash
 * <p>
 * This will append each of the {key, value} pairs in uriParamsHash to the URI.
 * 
 * @param uriParamsHash the hashtable containing parameters to be added to the URI for making the call to TMDB
 * @return URI for making the HTTP call to TMDB API
 * @throws URISyntaxException if the uri being built is in the incorrect format
 */
private static URI buildUriStringFromParamsHash(Hashtable<String, String> uriParamsHash, String path) throws URISyntaxException {
    URIBuilder urib = new URIBuilder();
    urib.setScheme("http"); //$NON-NLS-1$
    urib.setHost(TMDB_BASE_URL);
    urib.setPath(path);
    urib.addParameter("api_key", themoviedbapikey); //$NON-NLS-1$
    if (uriParamsHash != null) {
        Set<String> keys = uriParamsHash.keySet();
        for (String key : keys) {
            urib.addParameter(key, uriParamsHash.get(key));
        }
    }
    return urib.build();
}
 
Example 8
Source File: GetSetViewOfKeysFromHashtableExample.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {

        //create Hashtable object
        Hashtable ht = new Hashtable();

        //add key value pairs to Hashtable
        ht.put("1", "One");
        ht.put("2", "Two");
        ht.put("3", "Three");

    /*
      get Set of keys contained in Hashtable using
      Set keySet() method of Hashtable class
    */

        Set st = ht.keySet();

        System.out.println("Set created from Hashtable Keys contains :");
        //iterate through the Set of keys
        Iterator itr = st.iterator();
        while (itr.hasNext()) System.out.println(itr.next());

    /*
       Please note that resultant Set object is backed by the Hashtable.
       Any key that is removed from Set will also be removed from
       original Hashtable object. The same is not the case with the element
       addition.
    */

        //remove 2 from Set
        st.remove("2");

        //print keys of original Hashtable
        System.out.println("Hashtable keys after removal from Set are :");
        Enumeration e = ht.keys();
        while (e.hasMoreElements()) System.out.println(e.nextElement());
    }
 
Example 9
Source File: ResourceManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void mergeTables(Hashtable<? super String, Object> props1,
                                Hashtable<? super String, Object> props2) {
    for (Object key : props2.keySet()) {
        String prop = (String)key;
        Object val1 = props1.get(prop);
        if (val1 == null) {
            props1.put(prop, props2.get(prop));
        } else if (isListProperty(prop)) {
            String val2 = (String)props2.get(prop);
            props1.put(prop, ((String)val1) + ":" + val2);
        }
    }
}
 
Example 10
Source File: EditableResources.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void removeMultiConstants(Hashtable h) {
    for(Object k : h.keySet()) {
        String key = (String)k;
        if(key.startsWith("@")) {
            Object val = h.get(k);
            if(val instanceof MultiImage) {
                h.put(k, ((MultiImage)val).getBest());
                removeMultiConstants(h);
                return;
            }
        }
    }
}
 
Example 11
Source File: SCDynamicStoreConfig.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void WrapAllStringInVector(
        Hashtable<String, Object> stanzaTable) {
    for (String s: stanzaTable.keySet()) {
        Object v = stanzaTable.get(s);
        if (v instanceof Hashtable) {
            WrapAllStringInVector((Hashtable<String,Object>)v);
        } else if (v instanceof String) {
            Vector<String> vec = new Vector<>();
            vec.add((String)v);
            stanzaTable.put(s, vec);
        }
    }
}
 
Example 12
Source File: Validator.java    From Hidden-Markov-Model with MIT License 5 votes vote down vote up
public boolean isValidEmissionMatrix(Hashtable<Pair<String, String>, Double> emissionMatrix, Vector<String> states, Vector<String> observations) {
    if (emissionMatrix.size() != observations.size() * states.size()) {
        return false;
    }

    for (Pair<String, String> item : emissionMatrix.keySet()) {
        boolean found = false;
        double sum = 0.0;
        int count = 0;
        for (int i = 0; i < states.size(); i++) {
            for (int j = 0; j < observations.size(); j++) {
                if (item.getKey().equals(states.get(i)) && item.getValue().equals(observations.get(j))) {
                    found = true;
                    break;
                }
            }

            if (found)
                break;
        }

        if (!found)
            return false;

        for (Pair<String, String> item2 : emissionMatrix.keySet()) {
            if (item.getKey().equals(item2.getKey())) {
                sum += emissionMatrix.get(item2);
                count++;
            }
        }

        if (sum != 1.0 && count > 0)
            return false;
    }

    return true;
}
 
Example 13
Source File: Debug.java    From algorithms-nutshell-2ed with MIT License 5 votes vote down vote up
/**
 * Given an input file of "a b c d" values representing points of each
 * line segment, generate all intersections and produce a report.
 * 
 * @param f
 */
public boolean executeFile (File f) {
	LineSweep dba = new LineSweep();
	
	ArrayList<ILineSegment> als = new ArrayList<ILineSegment>();
	
	try {
		Scanner sc = new Scanner (f);
		while (sc.hasNext()) {
			double[]vals = new double[4];
			for(int i = 0; i < vals.length;i++) {
				vals[i] = sc.nextDouble();
			}
			
			als.add(new TwoDLineSegment(new TwoDPoint(vals[0], vals[1]),
					new TwoDPoint(vals[2], vals[3])));
		}
		sc.close();
	} catch (FileNotFoundException fnfe) {
		System.err.println ("Unable to locate file:" + f);
		return false;
	}
	
	Hashtable<IPoint, List<ILineSegment>> res = dba.intersections(als.iterator());
	
	for (IPoint ip : res.keySet()) {
		List<ILineSegment> ilss = res.get(ip);
		System.out.println (ip);
		for (ILineSegment ils : ilss) {
			System.out.println ("  " + ils);
		}
		System.out.println();
	}
	
	// something was calculated.
	return true;
}
 
Example 14
Source File: ResourceManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void mergeTables(Hashtable<? super String, Object> props1,
                                Hashtable<? super String, Object> props2) {
    for (Object key : props2.keySet()) {
        String prop = (String)key;
        Object val1 = props1.get(prop);
        if (val1 == null) {
            props1.put(prop, props2.get(prop));
        } else if (isListProperty(prop)) {
            String val2 = (String)props2.get(prop);
            props1.put(prop, ((String)val1) + ":" + val2);
        }
    }
}
 
Example 15
Source File: SCDynamicStoreConfig.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * convertRealmConfigs: Maps the Object graph that we get from JNI to the
 * object graph that Config expects. Also the items inside the kdc array
 * are wrapped inside Hashtables
 */
@SuppressWarnings("unchecked")
private static Hashtable<String, Object>
        convertRealmConfigs(Hashtable<String, ?> configs) {
    Hashtable<String, Object> realmsTable = new Hashtable<String, Object>();

    for (String realm : configs.keySet()) {
        // get the kdc
        Hashtable<String, Collection<?>> map =
                (Hashtable<String, Collection<?>>) configs.get(realm);
        Hashtable<String, Vector<String>> realmMap =
                new Hashtable<String, Vector<String>>();

        // put the kdc into the realmMap
        Collection<Hashtable<String, String>> kdc =
                (Collection<Hashtable<String, String>>) map.get("kdc");
        if (kdc != null) realmMap.put("kdc", unwrapHost(kdc));

        // put the admin server into the realmMap
        Collection<Hashtable<String, String>> kadmin =
                (Collection<Hashtable<String, String>>) map.get("kadmin");
        if (kadmin != null) realmMap.put("admin_server", unwrapHost(kadmin));

        // add the full entry to the realmTable
        realmsTable.put(realm, realmMap);
    }

    return realmsTable;
}
 
Example 16
Source File: ResourceManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void mergeTables(Hashtable<? super String, Object> props1,
                                Hashtable<? super String, Object> props2) {
    for (Object key : props2.keySet()) {
        String prop = (String)key;
        Object val1 = props1.get(prop);
        if (val1 == null) {
            props1.put(prop, props2.get(prop));
        } else if (isListProperty(prop)) {
            String val2 = (String)props2.get(prop);
            props1.put(prop, ((String)val1) + ":" + val2);
        }
    }
}
 
Example 17
Source File: ClusterVectorStore.java    From semanticvectors with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Adds the totals of newTable into mainTable. Presumes keys are identical.
 */
private static void mergeTables(
    Hashtable<String, int[]> newTable, Hashtable<String, int[]> mainTable) {
  for (String key : mainTable.keySet()) {
    int[] values = mainTable.get(key);
    int[] newValues = newTable.get(key);
    for (int i = 0; i < mainTable.get(key).length; ++i) {
      values[i] += newValues[i];
    }
  }
}
 
Example 18
Source File: StringHandler.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
public static void dump(Writer w, Hashtable<String, String> strings)
	throws IOException
{
	PrintWriter pw = new PrintWriter(w);
	pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
	pw.println("<resources>");
	for (String key : strings.keySet())
	{
		String value = strings.get(key);
		pw.println("<string name=\"" + key + "\">" + value + "</string>");
	}
	pw.println("</resources>");
	pw.flush();
	w.flush();
}
 
Example 19
Source File: DuplicateOccurrence.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(Wandora wandora, Context context)  throws TopicMapException {
    Object contextSource = context.getContextSource();
    
    if(contextSource instanceof OccurrenceTable) {
        OccurrenceTable ot = (OccurrenceTable) contextSource;
        ot.duplicateType();
    }
    else {
        Iterator<Topic> topics = null;
        if(masterTopic != null) {
            ArrayList<Topic> topicArray = new ArrayList();
            topicArray.add(masterTopic);
            topics = topicArray.iterator();
        }
        else {
            topics = context.getContextObjects();
        }
        
        if(topics != null) {
            Topic type = occurrenceType;
            if(type == null || type.isRemoved()) {
                type = wandora.showTopicFinder("Select occurrence type to be duplicated");
            }
            if(type != null && !type.isRemoved()) {
                Topic newType = wandora.showTopicFinder("Select new occurrence type");
                if(newType != null && !newType.isRemoved()) {
                    while(topics.hasNext()) {
                        Topic topic = topics.next();
                        if(topic != null && !topic.isRemoved()) {
                            Hashtable<Topic,String> os = topic.getData(occurrenceType);
                            if(os != null && !os.isEmpty()) {
                                for(Topic scope : os.keySet()) {
                                    if(scope != null && !scope.isRemoved()) {
                                        String occurrenceText = os.get(scope);
                                        topic.setData(newType, scope, occurrenceText);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 20
Source File: AndroidSessionWrapper.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public static AndroidSessionWrapper mockEasiestRoute(CommCarePlatform platform, String formNamespace, String selectedValue) {
    AndroidSessionWrapper wrapper = null;
    int curPredicates = -1;

    Hashtable<String, Entry> menuMap = platform.getCommandToEntryMap();
    for (String key : menuMap.keySet()) {
        Entry e = menuMap.get(key);
        if (!(e.isView() || e.isRemoteRequest()) && formNamespace.equals(((FormEntry)e).getXFormNamespace())) {
            //We have an entry. Don't worry too much about how we're supposed to get there for now.

            //The ideal is that we only need one piece of data
            if (e.getSessionDataReqs().size() == 1) {
                //This should fit the bill. Single selection.
                SessionDatum datum = e.getSessionDataReqs().firstElement();
                // we only know how to mock a single case selection
                if (datum instanceof ComputedDatum) {
                    // Allow mocking of routes that need computed data, useful for case creation forms
                    wrapper = new AndroidSessionWrapper(platform);
                    wrapper.session.setCommand(platform.getModuleNameForEntry((FormEntry)e));
                    wrapper.session.setCommand(e.getCommandId());
                    wrapper.session.setComputedDatum(wrapper.getEvaluationContext());
                } else if (datum instanceof EntityDatum) {
                    EntityDatum entityDatum = (EntityDatum)datum;
                    //The only thing we need to know now is whether we have a better option available
                    int countPredicates = CommCareUtil.countPreds(entityDatum.getNodeset());

                    if (wrapper == null) {
                        //No previous value! Yay.
                        //Record the degree of specificity of this selection for now (we'll
                        //actually create the wrapper later
                        curPredicates = countPredicates;
                    } else {
                        //There's already a path to this form. Only keep going
                        //if the current choice is less specific
                        if (countPredicates >= curPredicates) {
                            continue;
                        }
                    }

                    wrapper = new AndroidSessionWrapper(platform);
                    wrapper.session.setCommand(platform.getModuleNameForEntry((FormEntry)e));
                    wrapper.session.setCommand(e.getCommandId());
                    wrapper.session.setDatum(entityDatum.getDataId(), selectedValue);
                }
            }

            //We don't really have a good thing to do with this yet. For now, just
            //hope there's another easy path to this form
        }
    }

    return wrapper;
}