本文整理匯總了Java中java.util.Hashtable.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java Hashtable.containsKey方法的具體用法?Java Hashtable.containsKey怎麽用?Java Hashtable.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Hashtable
的用法示例。
在下文中一共展示了Hashtable.containsKey方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: distFeaturesOnClients
import java.util.Hashtable; //導入方法依賴的package包/類
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;
}
示例2: cleanUnusedStyles
import java.util.Hashtable; //導入方法依賴的package包/類
/**
* 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;
}
示例3: getParamsString
import java.util.Hashtable; //導入方法依賴的package包/類
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();
}
示例4: cosem
import java.util.Hashtable; //導入方法依賴的package包/類
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);
}
示例5: buildTrapEntries
import java.util.Hashtable; //導入方法依賴的package包/類
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);
}
}
示例6: buildInformEntries
import java.util.Hashtable; //導入方法依賴的package包/類
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);
}
}
示例7: restoreEnvironmentParameter
import java.util.Hashtable; //導入方法依賴的package包/類
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
}
}
示例8: parseQueryString
import java.util.Hashtable; //導入方法依賴的package包/類
/**
* 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 & 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;
}
示例9: getReward
import java.util.Hashtable; //導入方法依賴的package包/類
@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) {
}
}
示例10: is16Hashtable
import java.util.Hashtable; //導入方法依賴的package包/類
public static boolean is16Hashtable(Hashtable<Object, Object> ht) {
return ht.containsKey(DEFINED_KEY);
}
示例11: processChildren
import java.util.Hashtable; //導入方法依賴的package包/類
/**
* 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);
}
}
示例12: parseStanzaTable
import java.util.Hashtable; //導入方法依賴的package包/類
/**
* 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;
}
示例13: conflictInfo
import java.util.Hashtable; //導入方法依賴的package包/類
@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;
}
示例14: esInputValidoDeEstado
import java.util.Hashtable; //導入方法依賴的package包/類
/**
* 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));
}