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

The following are Jave code examples for showing how to use containsKey() 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: EvoServ   File: SGHSystem.java   View Source Code Vote up 6 votes
public int[] distFeaturesOnClients() {
    Hashtable<SGHFeature, Integer> count = new Hashtable<SGHFeature, Integer>();
    for (SGHClientApp c : clients) {
        for (SGHFeature f : c.featureSet) {
            if (!count.containsKey(f)) {
                count.put(f, 1);
            }
            else {
                count.put(f, count.get(f) + 1);
            }
        }
    }
    ArrayList<Integer> counts = new ArrayList<Integer>(count.values());
    Collections.sort(counts);
    int[] result = new int[counts.size()];
    for (int i=0; i<counts.size(); i++) result[counts.size()-i-1] = counts.get(i);
    return result;
}
 
Example 2
Project: aos-Video   File: TimedTextObject.java   View Source Code Vote up 6 votes
/**
 * This method simply checks the style list and eliminate any style not referenced by any caption
 * This might come useful when default styles get created and cover too much.
 * It require a unique iteration through all captions.
 * 
 */
protected void cleanUnusedStyles(){
	//here all used styles will be stored
	Hashtable<String, Style> usedStyles = new Hashtable<>();
	//we iterate over the captions
	Iterator<Caption> itrC = captions.values().iterator();
	while(itrC.hasNext()){
		//new caption
    	Caption current = itrC.next();
    	//if it has a style
    	if(current.style != null){
    		String iD = current.style.iD;
    		//if we haven't saved it yet
    		if(!usedStyles.containsKey(iD))
    			usedStyles.put(iD, current.style);
    	}
	}
	//we saved the used styles
	this.styling = usedStyles;
}
 
Example 3
Project: joai-project   File: DDSAdminQueryAction.java   View Source Code Vote up 6 votes
private final String getParamsString(Hashtable excludeParams, HttpServletRequest request) {
	if (request == null)
		return null;

	Enumeration params = request.getParameterNames();
	String param;
	String vals[];
	StringBuffer addParams = new StringBuffer();
	try {
		while (params.hasMoreElements()) {
			param = (String) params.nextElement();
			if (!excludeParams.containsKey(param)) {
				vals = request.getParameterValues(param);
				for (int i = 0; i < vals.length; i++) {
					addParams.append("&" + param + "=" + URLEncoder.encode(vals[i], "utf-8"));
				}
			}
		}
	} catch (Exception e) {
		addParams.toString();
	}
	return addParams.toString();
}
 
Example 4
Project: joai-project   File: HarvestReportAction.java   View Source Code Vote up 6 votes
private final String getParamsString(Hashtable excludeParams, HttpServletRequest request) {
	if (request == null)
		return null;

	Enumeration params = request.getParameterNames();
	String param;
	String vals[];
	StringBuffer addParams = new StringBuffer();
	try {
		while (params.hasMoreElements()) {
			param = (String) params.nextElement();
			if (!excludeParams.containsKey(param)) {
				vals = request.getParameterValues(param);
				for (int i = 0; i < vals.length; i++) {
					addParams.append("&" + param + "=" + URLEncoder.encode(vals[i], "utf-8"));
				}
			}
		}
	} catch (Exception e) {
		addParams.toString();
	}
	return addParams.toString();
}
 
Example 5
Project: joai-project   File: OdlSearchAction.java   View Source Code Vote up 6 votes
private final String getParamsString(Hashtable excludeParams, HttpServletRequest request) {
	if (request == null)
		return null;

	Enumeration params = request.getParameterNames();
	String param;
	String vals[];
	StringBuffer addParams = new StringBuffer();
	try {
		while (params.hasMoreElements()) {
			param = (String) params.nextElement();
			if (!excludeParams.containsKey(param)) {
				vals = request.getParameterValues(param);
				for (int i = 0; i < vals.length; i++) {
					addParams.append("&" + param + "=" + URLEncoder.encode(vals[i], "utf-8"));
				}
			}
		}
	} catch (Exception e) {
		addParams.toString();
	}
	return addParams.toString();
}
 
Example 6
Project: joai-project   File: SimpleQueryAction.java   View Source Code Vote up 6 votes
private final String getParamsString(Hashtable excludeParams, HttpServletRequest request) {
	if (request == null)
		return null;

	Enumeration params = request.getParameterNames();
	String param;
	String vals[];
	StringBuffer addParams = new StringBuffer();
	try {
		while (params.hasMoreElements()) {
			param = (String) params.nextElement();
			if (!excludeParams.containsKey(param)) {
				vals = request.getParameterValues(param);
				for (int i = 0; i < vals.length; i++) {
					addParams.append("&" + param + "=" + URLEncoder.encode(vals[i], "utf-8"));
				}
			}
		}
	} catch (Exception e) {
		addParams.toString();
	}
	return addParams.toString();
}
 
Example 7
Project: rgse.ttc17.emoflon.tgg   File: GlueModelCreator.java   View Source Code Vote up 6 votes
public static void cosem(Resource cosemResource, Root root, Hashtable<String, MeterAsset> allMeterAssets) {
	HashSet<PhysicalDevice> devices = new HashSet<>();
	HashSet<MeterAssetPhysicalDevicePair> devicePairs = new HashSet<>();
	TreeIterator<EObject> cosemIterator = cosemResource.getAllContents();
	while (cosemIterator.hasNext()) {
		EObject eOb = cosemIterator.next();
		if (eOb instanceof PhysicalDevice) {
			PhysicalDevice device = (PhysicalDevice) eOb;
			devices.add(device);
			String idNs = device.getID();
			if (allMeterAssets.containsKey(idNs)) {
				MeterAssetPhysicalDevicePair pair = GluemodelFactory.eINSTANCE
						.createMeterAssetPhysicalDevicePair();
				pair.setB(device);
				pair.setA(allMeterAssets.get(idNs));
				devicePairs.add(pair);
			}
		}
	}

	root.getMeterAssetToPhysicalDevice().addAll(devicePairs);
}
 
Example 8
Project: jdk8u-jdk   File: Host.java   View Source Code Vote up 5 votes
public void buildTrapEntries(Hashtable<InetAddress, Vector<String>> dest) {

        JDMHostTrap host= (JDMHostTrap) jjtGetParent();
        JDMTrapInterestedHost hosts= (JDMTrapInterestedHost) host.jjtGetParent();
        JDMTrapItem trap = (JDMTrapItem) hosts.jjtGetParent();
        JDMTrapCommunity community = trap.getCommunity();
        String comm = community.getCommunity();

        InetAddress add = null;
        try {
            add = java.net.InetAddress.getByName(getHname());
        } catch(UnknownHostException e) {
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
                        "buildTrapEntries",
                        "Cannot create TRAP entry; got exception", e);
            }
            return;
        }

        Vector<String> list = null;
        if (dest.containsKey(add)){
            list = dest.get(add);
            if (!list.contains(comm)){
                list.addElement(comm);
            }
        } else {
            list = new Vector<String>();
            list.addElement(comm);
            dest.put(add,list);
        }
    }
 
Example 9
Project: OpenJSharp   File: Host.java   View Source Code Vote up 5 votes
public void buildInformEntries(Hashtable<InetAddress, Vector<String>> dest) {

        JDMHostInform host= (JDMHostInform) jjtGetParent();
        JDMInformInterestedHost hosts= (JDMInformInterestedHost) host.jjtGetParent();
        JDMInformItem inform = (JDMInformItem) hosts.jjtGetParent();
        JDMInformCommunity community = inform.getCommunity();
        String comm = community.getCommunity();

        InetAddress add = null;
        try {
            add = java.net.InetAddress.getByName(getHname());
        } catch(UnknownHostException e) {
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
                        "buildTrapEntries",
                        "Cannot create INFORM entry; got exception", e);
            }
            return;
        }

        Vector<String> list = null;
        if (dest.containsKey(add)){
            list = dest.get(add);
            if (!list.contains(comm)){
                list.addElement(comm);
            }
        } else {
            list = new Vector<String>();
            list.addElement(comm);
            dest.put(add,list);
        }
    }
 
Example 10
Project: jdk8u-jdk   File: Host.java   View Source Code Vote up 5 votes
public void buildInformEntries(Hashtable<InetAddress, Vector<String>> dest) {

        JDMHostInform host= (JDMHostInform) jjtGetParent();
        JDMInformInterestedHost hosts= (JDMInformInterestedHost) host.jjtGetParent();
        JDMInformItem inform = (JDMInformItem) hosts.jjtGetParent();
        JDMInformCommunity community = inform.getCommunity();
        String comm = community.getCommunity();

        InetAddress add = null;
        try {
            add = java.net.InetAddress.getByName(getHname());
        } catch(UnknownHostException e) {
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
                        "buildTrapEntries",
                        "Cannot create INFORM entry; got exception", e);
            }
            return;
        }

        Vector<String> list = null;
        if (dest.containsKey(add)){
            list = dest.get(add);
            if (!list.contains(comm)){
                list.addElement(comm);
            }
        } else {
            list = new Vector<String>();
            list.addElement(comm);
            dest.put(add,list);
        }
    }
 
Example 11
Project: tomcat7   File: JNDIRealm.java   View Source Code Vote up 5 votes
private void restoreEnvironmentParameter(DirContext context,
        String parameterName, Hashtable<?, ?> preservedEnvironment) {
    try {
        context.removeFromEnvironment(parameterName);
        if (preservedEnvironment != null && preservedEnvironment.containsKey(parameterName)) {
            context.addToEnvironment(parameterName,
                    preservedEnvironment.get(parameterName));
        }
    } catch (NamingException e) {
        // Ignore
    }
}
 
Example 12
Project: apache-tomcat-7.0.73-with-comment   File: JNDIRealm.java   View Source Code Vote up 5 votes
private void restoreEnvironmentParameter(DirContext context,
        String parameterName, Hashtable<?, ?> preservedEnvironment) {
    try {
        context.removeFromEnvironment(parameterName);
        if (preservedEnvironment != null && preservedEnvironment.containsKey(parameterName)) {
            context.addToEnvironment(parameterName,
                    preservedEnvironment.get(parameterName));
        }
    } catch (NamingException e) {
        // Ignore
    }
}
 
Example 13
Project: lams   File: HttpUtils.java   View Source Code Vote up 5 votes
/**
    * Parses a query string passed from the client to the
    * server and builds a <code>HashTable</code> object
    * with key-value pairs. 
    * The query string should be in the form of a string
    * packaged by the GET or POST method, that is, it
    * should have key-value pairs in the form <i>key=value</i>,
    * with each pair separated from the next by a &amp; character.
    *
    * <p>A key can appear more than once in the query string
    * with different values. However, the key appears only once in 
    * the hashtable, with its value being
    * an array of strings containing the multiple values sent
    * by the query string.
    * 
    * <p>The keys and values in the hashtable are stored in their
    * decoded form, so
    * any + characters are converted to spaces, and characters
    * sent in hexadecimal notation (like <i>%xx</i>) are
    * converted to ASCII characters.
    *
    * @param s		a string containing the query to be parsed
    *
    * @return		a <code>HashTable</code> object built
    * 			from the parsed key-value pairs
    *
    * @exception IllegalArgumentException if the query string is invalid
    */
   public static Hashtable<String, String[]> parseQueryString(String s) {

       String valArray[] = null;

       if (s == null) {
           throw new IllegalArgumentException();
       }

       Hashtable<String, String[]> ht = new Hashtable<String, String[]>();
       StringBuilder sb = new StringBuilder();
       StringTokenizer st = new StringTokenizer(s, "&");
       while (st.hasMoreTokens()) {
       String pair = st.nextToken();
       int pos = pair.indexOf('=');
       if (pos == -1) {
           // XXX
           // should give more detail about the illegal argument
           throw new IllegalArgumentException();
       }
       String key = parseName(pair.substring(0, pos), sb);
       String val = parseName(pair.substring(pos+1, pair.length()), sb);
       if (ht.containsKey(key)) {
           String oldVals[] = ht.get(key);
           valArray = new String[oldVals.length + 1];
           for (int i = 0; i < oldVals.length; i++) {
               valArray[i] = oldVals[i];
           }
           valArray[oldVals.length] = val;
       } else {
           valArray = new String[1];
           valArray[0] = val;
       }
       ht.put(key, valArray);
   }

return ht;
   }
 
Example 14
Project: Proyecto-DASI   File: RewardForMissionEndImplementation.java   View Source Code Vote up 5 votes
@Override
public void getReward(MissionInit missionInit, MultidimensionalReward reward) {
    super.getReward(missionInit, reward);
    try {
        Hashtable<String, Object> properties = MalmoMod.getPropertiesForCurrentThread();
        if (properties.containsKey("QuitCode")) {
            float reward_value = parseQuitCode((String) properties.get("QuitCode"));
            reward.add( this.params.getDimension(), reward_value);
        }
    } catch (Exception e) {
    }
}
 
Example 15
Project: OpenJSharp   File: AttributeValues.java   View Source Code Vote up 4 votes
public static boolean is16Hashtable(Hashtable<Object, Object> ht) {
    return ht.containsKey(DEFINED_KEY);
}
 
Example 16
Project: incubator-netbeans   File: CPUCCTClassContainer.java   View Source Code Vote up 4 votes
/**
 * Given this target node, and the array of its source-level children, treat them as follows:
 * 1. The info for a source child who has the same class as this node, is added to this node.
 * Its own children are processed recursively by calling this same method.
 * 2. The first source child whose class is different and was not observed before (not contained
 * in uniqChildCache) is added to uniqChildCache, and to allSourceChildren.
 * 3. All other source children are added to allSourceChildren, but not to uniqChildCache.
 */
protected void processChildren(int dataOfs, int methodNodeOfs, int nChildren, IntVector allSourceChildren,
                               Hashtable uniqChildCache) {
    int thisNodeClassOrPackageId = getMethodIdForNodeOfs(dataOfs);

    int nCalls = 0;
    long time0 = 0;
    long time1 = 0;

    for (int i = 0; i < nChildren; i++) {
        int sourceChildOfs = sourceContainer.getChildOfsForNodeOfs(methodNodeOfs, i);
        int sourceChildClassOrPackageId = methodIdMap.getClassOrPackageIdForMethodId(sourceContainer.getMethodIdForNodeOfs(sourceChildOfs));

        if (sourceChildClassOrPackageId == thisNodeClassOrPackageId) { // A child node has the same class as this node
            nCalls += sourceContainer.getNCallsForNodeOfs(sourceChildOfs);
            time0 += sourceContainer.getSelfTime0ForNodeOfs(sourceChildOfs);

            if (collectingTwoTimeStamps) {
                time1 += sourceContainer.getSelfTime1ForNodeOfs(sourceChildOfs);
            }

            // sourceChild's children logically become this node's children now.
            int nSourceChildChildren = sourceContainer.getNChildrenForNodeOfs(sourceChildOfs);

            if (nSourceChildChildren > 0) {
                this.processChildren(dataOfs, sourceChildOfs, nSourceChildChildren, allSourceChildren, uniqChildCache);
            }
        } else { // A child node belongs to a different class

            Integer key = Integer.valueOf(sourceChildClassOrPackageId);

            if (!uniqChildCache.containsKey(key)) {
                uniqChildCache.put(key, key);
            }

            allSourceChildren.add(sourceChildOfs);
        }
    }

    nCalls += getNCallsForNodeOfs(dataOfs);
    time0 += getSelfTime0ForNodeOfs(dataOfs);

    if (collectingTwoTimeStamps) {
        time1 += getSelfTime1ForNodeOfs(dataOfs);
    }

    setNCallsForNodeOfs(dataOfs, nCalls);
    setSelfTime0ForNodeOfs(dataOfs, time0);

    if (collectingTwoTimeStamps) {
        setSelfTime1ForNodeOfs(dataOfs, time1);
    }
}
 
Example 17
Project: jdk8u-jdk   File: Config.java   View Source Code Vote up 4 votes
/**
 * Parses stanza names and values from configuration file to
 * stanzaTable (Hashtable). Hashtable key would be stanza names,
 * (libdefaults, realms, domain_realms, etc), and the hashtable value
 * would be another hashtable which contains the key-value pairs under
 * a stanza name. The value of this sub-hashtable can be another hashtable
 * containing another sub-sub-section or a vector of strings for
 * final values (even if there is only one value defined).
 * <p>
 * For duplicates section names, the latter overwrites the former. For
 * duplicate value names, the values are in a vector in its appearing order.
 * </ol>
 * Please note that this behavior is Java traditional. and it is
 * not the same as the MIT krb5 behavior, where:<ol>
 * <li>Duplicated root sections will be merged
 * <li>For duplicated sub-sections, the former overwrites the latter
 * <li>Duplicate keys for values are always saved in a vector
 * </ol>
 * @param v the strings in the file, never null, might be empty
 * @throws KrbException if there is a file format error
 */
@SuppressWarnings("unchecked")
private Hashtable<String,Object> parseStanzaTable(List<String> v)
        throws KrbException {
    Hashtable<String,Object> current = stanzaTable;
    for (String line: v) {
        // There are 3 kinds of lines
        // 1. a = b
        // 2. a = {
        // 3. }
        if (line.equals("}")) {
            // Go back to parent, see below
            current = (Hashtable<String,Object>)current.remove(" PARENT ");
            if (current == null) {
                throw new KrbException("Unmatched close brace");
            }
        } else {
            int pos = line.indexOf('=');
            if (pos < 0) {
                throw new KrbException("Illegal config content:" + line);
            }
            String key = line.substring(0, pos).trim();
            String value = trimmed(line.substring(pos+1));
            if (value.equals("{")) {
                Hashtable<String,Object> subTable;
                if (current == stanzaTable) {
                    key = key.toLowerCase(Locale.US);
                }
                subTable = new Hashtable<>();
                current.put(key, subTable);
                // A special entry for its parent. Put whitespaces around,
                // so will never be confused with a normal key
                subTable.put(" PARENT ", current);
                current = subTable;
            } else {
                Vector<String> values;
                if (current.containsKey(key)) {
                    Object obj = current.get(key);
                    // If a key first shows as a section and then a value,
                    // this is illegal. However, we haven't really forbid
                    // first value then section, which the final result
                    // is a section.
                    if (!(obj instanceof Vector)) {
                        throw new KrbException("Key " + key
                                + "used for both value and section");
                    }
                    values = (Vector<String>)current.get(key);
                } else {
                    values = new Vector<String>();
                    current.put(key, values);
                }
                values.add(value);
            }
        }
    }
    if (current != stanzaTable) {
        throw new KrbException("Not closed");
    }
    return current;
}
 
Example 18
Project: jdk8u-jdk   File: AttributeValues.java   View Source Code Vote up 4 votes
public static boolean is16Hashtable(Hashtable<Object, Object> ht) {
    return ht.containsKey(DEFINED_KEY);
}
 
Example 19
Project: unitimes   File: TimetableSolver.java   View Source Code Vote up 4 votes
@Override
  public Hashtable conflictInfo(Collection hints) {
  	Hashtable conflictTable = new Hashtable();
  	Lock lock = currentSolution().getLock().readLock();
lock.lock();
try {
	HashSet done = new HashSet();
	for (Iterator i=hints.iterator();i.hasNext();) {
		Hint hint = (Hint)i.next();
		Placement p = hint.getPlacement((TimetableModel)currentSolution().getModel());
		if (p==null) continue;
        for (Constraint constraint: p.variable().hardConstraints()) {
            HashSet conflicts = new HashSet();
            constraint.computeConflicts(currentSolution().getAssignment(), p, conflicts);
            if (conflicts!=null && !conflicts.isEmpty()) {
            	for (Iterator j=conflicts.iterator();j.hasNext();) {
            		Placement conflict = (Placement)j.next();
            		Hint confHint = new Hint(this, conflict);
            		if (done.contains(confHint)) continue;
            		if (!conflictTable.containsKey(confHint)) {
            			String name = constraint.getName();
        				if (constraint instanceof RoomConstraint) {
        					name = "Room "+constraint.getName();
        				} else if (constraint instanceof InstructorConstraint) {
        					name = "Instructor "+constraint.getName();
        				} else if (constraint instanceof GroupConstraint) {
        					name = "Distribution "+constraint.getName();
        				} else if (constraint instanceof DepartmentSpreadConstraint) {
        					name = "Balancing of department "+constraint.getName();
        				} else if (constraint instanceof SpreadConstraint) {
        					name = "Same subpart spread "+constraint.getName();
        				} else if (constraint instanceof ClassLimitConstraint) {
        					name = "Class limit "+constraint.getName();
        				}
        				conflictTable.put(confHint, name);
            		}
            	}
            }
        }
        done.add(hint);
	}
} finally {
	lock.unlock();
}
return conflictTable;
  }
 
Example 20
Project: Proyecto-DASI   File: TablaEstadosAutomataEF.java   View Source Code Vote up 2 votes
/**
 *  Determina si el input dado es uno de los inputs que se esperan en el estado
 *  dado
 *
 *@param  estado  Estado a evaluar
 *@param  input   Input que se desea comprobar
 *@return         Dice si es vlido o no
 */
public boolean esInputValidoDeEstado(String estado, String input)
{
	Hashtable inp = (Hashtable) inputsDeEstados.get(estado);
	return (inp.containsKey(input));
}