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

The following are Jave code examples for showing how to use keySet() of the java.util.Hashtable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: TuLiPA-frames   File: Environment.java   View Source Code Vote up 6 votes
/**
 * method merging env into nenv
 * 
 * @throws UnifyException
 */
public static void addBindings(Environment env, Environment nenv)
        throws UnifyException {
    Hashtable<String, Value> eTable = env.getTable();
    Set<String> keys = eTable.keySet();
    Iterator<String> it = keys.iterator();
    while (it.hasNext()) {
        // we look if the variable is bound
        String eVar = it.next();
        Value val = new Value(Value.VAR, eVar);
        Value eVal = env.deref(val);
        if (!(eVal.equals(val))) {
            // if it is, we unify the bound values in the new environment
            Value.unify(val, eVal, nenv);
        }
    }
}
 
Example 2
Project: rapidminer   File: RapidLookAndFeel.java   View Source Code Vote up 6 votes
@Override
public UIDefaults getDefaults() {
	getColors();

	UIDefaults table = new UIDefaults();
	// copy existing default values over
	// enables AntiAliasing if AntiAliasing is enabled in the OS
	// EXCEPT for key "Menu.opaque" which will glitch out JMenues
	UIDefaults lookAndFeelDefaults = UIManager.getLookAndFeelDefaults();
	Hashtable copy = new Hashtable<>(lookAndFeelDefaults);
	for (Object key : copy.keySet()) {
		if (!String.valueOf(key).equals("Menu.opaque")) {
			table.put(key, lookAndFeelDefaults.get(key));
		}
	}

	initClassDefaults(table);
	initSystemColorDefaults(table);
	initComponentDefaults(table);
	COLORS.addCustomEntriesToTable(table);

	return table;
}
 
Example 3
Project: JAlgoArena   File: SingleNumber.java   View Source Code Vote up 6 votes
public int singleNumber(int[] arr) {
    Hashtable<Integer, Integer> set = new Hashtable<>();
    int number = 0;

    for (int i = 0; i < arr.length; i++) {
        if (set.containsKey(arr[i])) {
            set.put(arr[i], set.get(arr[i]) + 1);
        } else {
            set.put(arr[i], 1);
        }
    }

    for (Integer key: set.keySet()) {
        if (set.get(key) == 1)
            return (int) key;
    }

    return number;
}
 
Example 4
Project: ShotgunWSD   File: Automation.java   View Source Code Vote up 6 votes
public static Hashtable<Integer, List<WindowConfiguration>> clone(Hashtable<Integer, List<WindowConfiguration>> obj) {
    Hashtable<Integer, List<WindowConfiguration>> newObj = new Hashtable<>();
    List<WindowConfiguration> list, clonedList;

    for(Integer key : obj.keySet()){
        list = obj.get(key);

        clonedList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            clonedList.add(list.get(i).clone());
        }

        newObj.put(key, clonedList);
    }

    return newObj;
}
 
Example 5
Project: elements-of-programming-interviews-solutions   File: PalindromicPermutations.java   View Source Code Vote up 6 votes
public static boolean canFormPalindrome(String s) {
    Hashtable<Character, AtomicInteger> count = new Hashtable<>();
    for (Character c : s.toLowerCase().toCharArray()) {
        if (!count.containsKey(c))
            count.put(c, new AtomicInteger(1));
        else
            count.get(c).getAndIncrement();
    }
    boolean hasOdd = false;
    for (Character key : count.keySet()) {
        if (count.get(key).get() % 2 != 0)
            if (hasOdd)
                return false;
            else
                hasOdd = true;

    }
    return true;
}
 
Example 6
Project: openddr-java   File: DDRTestRunner.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws Exception {
	final String ASPECT_DEVICE = "device";
	final String nexusUA = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
       final String iri = "http://www.w3.org/2008/01/ddr-core-vocabulary";
	final Evidence uaEvidence = new UserAgentEvidence(nexusUA);
	final DDRSimpleAPITester tester = new DDRSimpleAPITester(DDRTestService.ODDR_SERVICE, uaEvidence, 
			iri, ASPECT_DEVICE, "webBrowser", 
			13, 
			"version", "jpeg", ASPECT_DEVICE, ASPECT_DEVICE, "", "", "",
			1,
			"", "",
			false,
			"", "",
			new String[] {""}
			);
	final Hashtable<?, ?> report = tester.getReport();
	if (report.size() > 0) {
		System.out.println(report.size() + " entries found.");
		for (Object key : report.keySet()) {
			System.out.println("Key: " + key + "; " + "Value: " + report.get(key));
		}
	}
	
}
 
Example 7
Project: TuLiPA-frames   File: GrammarConvertor.java   View Source Code Vote up 5 votes
public static String print(Hashtable<String, LinkedList<Object>> psi) {
    String res = "";
    Set<String> knodes = psi.keySet();
    Iterator<String> i = knodes.iterator();
    while (i.hasNext()) {
        String k = (String) i.next();
        res += "Node address " + k + " - trees: { ";
        LinkedList<Object> atrees = psi.get(k);
        for (int j = 0; j < atrees.size(); j++) {
            res += atrees.get(j) + " ";
        }
        res += "}\n";
    }
    return res;
}
 
Example 8
Project: openjdk-jdk10   File: ResourceManager.java   View Source Code Vote up 5 votes
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 9
Project: openjdk-jdk10   File: SCDynamicStoreConfig.java   View Source Code Vote up 5 votes
/**
 * 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 10
Project: jdk8u-jdk   File: LdapAttribute.java   View Source Code Vote up 5 votes
/**
 * sets the information needed to reconstruct the baseCtx if
 * we are serialized. This must be called _before_ the object is
 * serialized!!!
 */
@SuppressWarnings("unchecked") // clone()
private void setBaseCtxInfo() {
    Hashtable<String, Object> realEnv = null;
    Hashtable<String, Object> secureEnv = null;

    if (baseCtx != null) {
        realEnv = ((LdapCtx)baseCtx).envprops;
        this.baseCtxURL = ((LdapCtx)baseCtx).getURL();
    }

    if(realEnv != null && realEnv.size() > 0 ) {
        // remove any security credentials - otherwise the serialized form
        // would store them in the clear
        for (String key : realEnv.keySet()){
            if (key.indexOf("security") != -1 ) {

                //if we need to remove props, we must do it to a clone
                //of the environment. cloning is expensive, so we only do
                //it if we have to.
                if(secureEnv == null) {
                    secureEnv = (Hashtable<String, Object>)realEnv.clone();
                }
                secureEnv.remove(key);
            }
        }
    }

    // set baseCtxEnv depending on whether we removed props or not
    this.baseCtxEnv = (secureEnv == null ? realEnv : secureEnv);
}
 
Example 11
Project: AgentWorkbench   File: OntologyClassTreeObject.java   View Source Code Vote up 5 votes
/**
 * This returns the 'DefaultTableModel' for a single
 * class out of the ontology-classes.
 *
 * @return the table model4 slot
 */
public DefaultTableModel getTableModel4Slot() {
	
	DefaultTableModel tm4s = new DefaultTableModel();
	tm4s.addColumn("Name");
	tm4s.addColumn("Cardinality");
	tm4s.addColumn("Type");
	tm4s.addColumn("Other Facets");		

	if (ontologySubClass == null) {
		return tm4s;
	}
	
	// --- Nach den entsprechenden Slots im Vokabular filtern ---
	Hashtable<String, String> ontoSlotHash = ontologyClass.ontologieVocabulary.getSlots(ontologySubClass);
	ReflectClass reflectedClass = new ReflectClass(ontologySubClass, ontoSlotHash);
	
	Vector<String> v = new Vector<String>( ontoSlotHash.keySet() );
    Collections.sort(v);
    Iterator<String> it = v.iterator();
    while (it.hasNext()) {
    	
    	// --- Get Word of the ontology ------------------------- 
    	String key = it.next();
    	String word = ontoSlotHash.get(key);
    	
    	// --- Get Slot... --------------------------------------
    	Slot currSlot = reflectedClass.getSlot(word);
    	
    	// --- Add table row ------------------------------------	    	
    	Vector<String> rowData = new Vector<String>(); 
    	rowData.add(word );
    	rowData.add(currSlot.Cardinality);
    	rowData.add(currSlot.VarType);
    	rowData.add(currSlot.OtherFacts);
    	tm4s.addRow(rowData);
    }	
    
    // ----------------------------------------------------------
    // --- Are there slots from the parent Node? ----------------
    // ----------------------------------------------------------
    if (parentOntologyClassTreeObject!=null) {
    	DefaultTableModel subTBmodel = parentOntologyClassTreeObject.getTableModel4Slot();
    	Vector<?> subDataVector = subTBmodel.getDataVector();
    	for (int i = 0; i < subDataVector.size(); i++) {
    		Vector<?> rowVector = (Vector<?>) subDataVector.get(i);
    		tm4s.addRow(rowVector);
		}
    	Sorter.sortTableModel(tm4s, 0);
    }
    // ----------------------------------------------------------
    return tm4s;		
}
 
Example 12
Project: jdk8u-jdk   File: ResourceManager.java   View Source Code Vote up 5 votes
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 13
Project: jdk8u-jdk   File: SCDynamicStoreConfig.java   View Source Code Vote up 5 votes
@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 14
Project: OpenJSharp   File: SCDynamicStoreConfig.java   View Source Code Vote up 5 votes
@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 15
Project: OpenJSharp   File: LdapAttribute.java   View Source Code Vote up 5 votes
/**
 * sets the information needed to reconstruct the baseCtx if
 * we are serialized. This must be called _before_ the object is
 * serialized!!!
 */
@SuppressWarnings("unchecked") // clone()
private void setBaseCtxInfo() {
    Hashtable<String, Object> realEnv = null;
    Hashtable<String, Object> secureEnv = null;

    if (baseCtx != null) {
        realEnv = ((LdapCtx)baseCtx).envprops;
        this.baseCtxURL = ((LdapCtx)baseCtx).getURL();
    }

    if(realEnv != null && realEnv.size() > 0 ) {
        // remove any security credentials - otherwise the serialized form
        // would store them in the clear
        for (String key : realEnv.keySet()){
            if (key.indexOf("security") != -1 ) {

                //if we need to remove props, we must do it to a clone
                //of the environment. cloning is expensive, so we only do
                //it if we have to.
                if(secureEnv == null) {
                    secureEnv = (Hashtable<String, Object>)realEnv.clone();
                }
                secureEnv.remove(key);
            }
        }
    }

    // set baseCtxEnv depending on whether we removed props or not
    this.baseCtxEnv = (secureEnv == null ? realEnv : secureEnv);
}
 
Example 16
Project: OpenJSharp   File: ResourceManager.java   View Source Code Vote up 5 votes
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
Project: TuLiPA-frames   File: Fs.java   View Source Code Vote up 4 votes
/**
 * This method update some FS according to an environment (ie a list of
 * bindings)
 */
public static Fs updateFS(Fs fs, Environment env, boolean finalUpdate)
        throws UnifyException {
    // System.err.println("updating [" + fs.toString() + "] env: " +
    // env.toString());
    // System.out.println("Starting UpdateFS");
    Fs res = null;
    if (fs.isTyped()) {
        Value coref = fs.getCoref();
        Value vderef = env.deref(coref);
        if (!(vderef.equals(fs.getCoref()))) { // it is bound:
            res = new Fs(fs.getSize(), fs.getType(),
                    Value.unify(vderef, coref, env));
        } else { // it is not:
            res = new Fs(fs.getSize(), fs.getType(), vderef);
            // This was added for testing
            // env.bind(vderef,coref);
        }
        // System.out.println("Deref of "+fs.getCoref()+":
        // "+env.deref(fs.getCoref()));
    } else {
        res = new Fs(fs.getSize());
    }

    Hashtable<String, Value> avm = fs.getAVlist();
    Set<String> keys = avm.keySet();
    Iterator<String> i = keys.iterator();
    while (i.hasNext()) {
        String k = (String) i.next();
        Value fval = avm.get(k);

        // System.err.println("Processing ... " +
        // k+":"+fval.toString());

        switch (fval.getType()) {
        case Value.VAL: // for semantic labels
            fval.update(env, finalUpdate);
            res.setFeat(k, fval);
            break;
        case Value.VAR:
            // if the feature value is a variable,
            // we look if it is bound to something in the environment
            Value v = env.deref(fval);

            if (!(v.equals(fval))) { // it is bound:
                res.setFeat(k, Value.unify(fval, v, env));
            } else { // it is not:
                // System.err.println("Variable not bound ... " + k +
                // ":"
                // + fval.toString());
                res.setFeat(k, fval);
                // This was added for testing
                // env.bind(k,fval);
            }
            break;
        case Value.AVM: // the value is an avm, we go on updating
            res.setFeat(k, new Value(
                    updateFS(fval.getAvmVal(), env, finalUpdate)));
            break;
        case Value.ADISJ:
            fval.update(env, finalUpdate);
            res.setFeat(k, fval);
            break;
        default:
            res.setFeat(k, fval);
        }
    }
    // System.out.println("Finished UpdateFS");
    return res;
}
 
Example 18
Project: TuLiPA-frames   File: XMLTTMCTAGReader.java   View Source Code Vote up 4 votes
/**
 * Process a narg XML tag to extract a TagNode label
 * 
 * @param e
 *            the DOM Element corresponding to the feature structure
 * 
 */
public static Fs getNarg(Element e, int from, NameFactory nf) {
    Fs res = null;
    try {
        NodeList l = e.getChildNodes();

        // we declare the hash that will be used for features
        // that have to be added to both top and bot
        Hashtable<String, Value> toAdd = new Hashtable<String, Value>();
        for (int i = 0; i < l.getLength(); i++) {
            Node n = l.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                Element el = (Element) n;
                if (el.getTagName().equals("fs")) {
                    res = getFeats(el, NOFS, toAdd, nf);
                }
            }
        }
        if (from == FROM_NODE && toAdd.size() > 0) {
            // we post-process the features to add
            Value top = res.getFeat("top");
            if (top == null) {
                top = new Value(new Fs(5));
                res.setFeat("top", top);
            }
            Value bot = res.getFeat("bot");
            if (bot == null) {
                bot = new Value(new Fs(5));
                res.setFeat("bot", bot);
            }

            Set<String> keys = toAdd.keySet();
            Iterator<String> it = keys.iterator();
            while (it.hasNext()) {
                String f = it.next();
                if (!(top.getAvmVal().hasFeat(f))) {
                    top.getAvmVal().setFeat(f, toAdd.get(f));
                }
                if (!(bot.getAvmVal().hasFeat(f))) {
                    bot.getAvmVal().setFeat(f, toAdd.get(f));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return res;
}
 
Example 19
Project: AgentWorkbench   File: OntologyClassTreeObject.java   View Source Code Vote up 4 votes
/**
 * This returns the a ArrayList of Slots for a single
 * class out of the ontology-classes.
 *
 * @return the class description
 */
public OntologySingleClassDescription getClassDescription() {
	
	OntologySingleClassDescription ocd = null;
	OntologySingleClassSlotDescription osd = null;

	if ( ontologySubClass == null ) {
		return null;
	}
	
	// --- Beschreibungsobjekt initialisieren -------------------
	ocd = new OntologySingleClassDescription();
	ocd.setClazz(ontologySubClass);
	ocd.setClassReference(this.getClassReference()); // Package und Class werden hier automatisch gesetzt
	
	// --- Nach den entsprechenden Slots im Vokabular filtern ---
	Hashtable<String, String> ontoSlotHash = ontologyClass.ontologieVocabulary.getSlots(ontologySubClass);
	ReflectClass reflectedClass = new ReflectClass(ontologySubClass, ontoSlotHash);

	Vector<String> v = new Vector<String>(ontoSlotHash.keySet());
    Collections.sort(v);
    Iterator<String> it = v.iterator();
    while (it.hasNext()) {
    	
    	// --- Wort/Slot der Ontologie ermitteln --------------- 
    	String key = it.next();
    	String word = ontoSlotHash.get(key);
    	
    	// --- Slot untersuchen ... -----------------------------
    	Slot currSlot = reflectedClass.getSlot(word);
    	
    	// --- Objekt v. Typ 'OntologySlotDescription' erzeugen -	    	
    	osd = new OntologySingleClassSlotDescription();
    	osd.setSlotName(word);
    	osd.setSlotCardinality(currSlot.Cardinality);
    	osd.setSlotVarType(currSlot.VarType);
    	osd.setSlotOtherFacts(currSlot.OtherFacts);
    	osd.setSlotMethodList(currSlot.MethodList);
    	
    	ocd.getArrayList4SlotDescriptions().add(osd);
    }		
    
    // ----------------------------------------------------------
    // --- Are there slots from the parent Node? ----------------
    // ----------------------------------------------------------
    if (parentOntologyClassTreeObject!=null) {
    	OntologySingleClassDescription subOCD = parentOntologyClassTreeObject.getClassDescription();
    	ocd.getArrayList4SlotDescriptions().addAll(subOCD.getArrayList4SlotDescriptions());
    	Sorter.sortSlotDescriptionArray(ocd.getArrayList4SlotDescriptions());
    }
    // ----------------------------------------------------------
	return ocd;
}
 
Example 20
Project: uclapi-java   File: UCLApiConnection.java   View Source Code Vote up 4 votes
/**
 * Perform a generic API query on our connection.
 *
 * @param Endpoint The URL endpoint (e.g. roombookings/bookings)
 * @param Parameters The parameters to query with.
 * @return A string containing the JSON response.
 */
public String queryAPI(String Endpoint, Hashtable<String, String> Parameters) {

    // Unpack the Hashtable of parameters into a query string.
    String query = "";
    for (String key : Parameters.keySet()) {
        String value = (String) Parameters.get(key).replace(" ", "+");
        query = new String(query + "&" + key + "=" + value);
    }

    // Construct a URL out of base url, our endpoint, our API key and the query.
    String url = new String(UCLApiEndpoint + Endpoint + "?token=" + APIKey + query);

    // It's not clear this is necessary but I had enough encoding horrors at #hackbentham...
    String charset = "UTF-8"; 

    try {

        // Open our connection.
        URLConnection conn = new URL(url).openConnection();
        conn.setRequestProperty("Accept-Charset", charset);
        conn.addRequestProperty("User-Agent", "Owain's UCL API wrapper for Java");
        InputStream response = conn.getInputStream();

        // Pull data out and return it.
        try (Scanner rReader = new Scanner(response)) {
            String rBody = rReader.useDelimiter("\\A").next();
            response.close();
            return rBody;
        }
        

    } catch(Exception e) {
        // Annoyingly we don't get our Error response, just a 403 exception which is less helpful.
        String error = new String(e.toString());
        if (this.ProtectKey) {
            error = new String(error.replace(this.APIKey, "<API KEY HIDDEN>"));
        }
        System.err.println(error);
        if (uclapi.UCLApiConnection.ExitOnException) {
            System.exit(1);
        }
    }

    // If we get here something has gone very wrong...
    return "";
}