List of usage examples for java.util Hashtable containsKey
public synchronized boolean containsKey(Object key)
From source file:com.ustadmobile.port.android.view.CatalogOPDSFragment.java
/** * Handle when the user selects to refresh *//* w w w. j a va 2s . c o m*/ @Override public void onRefresh() { if (!isLoading) { Hashtable args = UMAndroidUtil.bundleToHashtable(getArguments()); int flagArg = args.containsKey(CatalogController.KEY_FLAGS) ? (Integer) args.get(CatalogController.KEY_FLAGS) : 0; flagArg = flagArg | CatalogController.CACHE_DISABLED; args.put(CatalogController.KEY_FLAGS, flagArg); loadCatalog(args); } }
From source file:org.mule.transport.soap.axis.extensions.MuleHttpSender.java
/** * little helper function for cookies//from ww w . jav a 2s . c om * * @param cookieName * @param setCookieName * @param headers * @param msgContext */ public void handleCookie(String cookieName, String setCookieName, Hashtable headers, MessageContext msgContext) { if (headers.containsKey(setCookieName.toLowerCase())) { String cookie = (String) headers.get(setCookieName.toLowerCase()); cookie = cookie.trim(); // chop after first ; a la Apache SOAP (see HTTPUtils.java there) int index = cookie.indexOf(';'); if (index != -1) { cookie = cookie.substring(0, index); } msgContext.setProperty(cookieName, cookie); } }
From source file:org.forgerock.openam.mobile.auth.AuthenticationClient.java
/** * Interrogates a JSONObject representing an authentication module stage, and puts the appropriate * data into the appropriate location. As per the rest of this file, only works for NameCallback * and PasswordCallback types.// ww w.ja va 2 s. c o m * * @param authObj The JSON object representing the current stage of authentication * @param values The id:value pairs to insert into the JSON * * @throws org.json.JSONException If we cannot alter the JSON correctly */ public void replaceAuthenticateInputVals(JSONObject authObj, Hashtable<String, String> values) throws JSONException { JSONArray callbacks = authObj.getJSONArray(AuthNConstants.CALLBACKS); for (int i = 0; i < callbacks.length(); i++) { JSONObject callback = callbacks.getJSONObject(i); JSONArray inputs = callback.getJSONArray(AuthNConstants.INPUT); for (int k = 0; k < inputs.length(); k++) { JSONObject input = inputs.getJSONObject(k); if (values.containsKey(input.getString(AuthNConstants.NAME))) { input.put(AuthNConstants.VALUE, values.get(input.getString(AuthNConstants.NAME))); } } } }
From source file:org.adempiere.webui.dashboard.CalendarWindow.java
private void syncModel() { Hashtable<String, BigDecimal> ht = new Hashtable<String, BigDecimal>(); List<?> list = calendars.getModel().get(calendars.getBeginDate(), calendars.getEndDate(), null); int size = list.size(); for (Iterator<?> it = list.iterator(); it.hasNext();) { String key = ((ADCalendarEvent) it.next()).getR_RequestType_ID() + ""; if (!ht.containsKey(key)) ht.put(key, BigDecimal.ONE); else {/*w w w. j a v a 2 s . com*/ BigDecimal value = ht.get(key); ht.put(key, value.add(BigDecimal.ONE)); } } Hashtable<Object, String> htTypes = new Hashtable<Object, String>(); for (int i = 0; i < lbxRequestTypes.getItemCount(); i++) { Listitem li = lbxRequestTypes.getItemAtIndex(i); if (li != null && li.getValue() != null) htTypes.put(li.getValue(), li.getLabel()); } DefaultPieDataset pieDataset = new DefaultPieDataset(); Enumeration<?> keys = ht.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); BigDecimal value = ht.get(key); String name = (String) htTypes.get(key); pieDataset.setValue(name == null ? "" : name, new Double(size > 0 ? value.doubleValue() / size * 100 : 0)); } JFreeChart chart = ChartFactory.createPieChart3D(Msg.getMsg(Env.getCtx(), "EventsAnalysis"), pieDataset, true, true, true); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(600, 250); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("Pie Chart", bytes); myChart.setContent(image); } catch (IOException e) { e.printStackTrace(); } htTypes = null; ht = null; }
From source file:it.okkam.exhibit.JSONSerializer.java
protected Hashtable buildPropsTable(Resource resource, int depth) { StmtIterator it = resource.listProperties(); // set up a hashtable of property to value mappings, so it's easy to differentiate single and // multi- value props Hashtable propsTable = new Hashtable(); while (it.hasNext()) { Statement s = it.nextStatement(); // get the property name String propName = s.getPredicate().getURI(); ArrayList vals;//w ww . j a v a 2 s . c o m if (propsTable.containsKey(propName)) { vals = (ArrayList) propsTable.get(propName); } else { vals = new ArrayList(); propsTable.put(propName, vals); } RDFNode node = s.getObject(); if (node.isLiteral()) // add to the values { vals.add(node); } else // check if we should follow { if (arcs.containsKey(propName)) { int max = ((Integer) arcs.get(propName)).intValue(); if (max < 0 || depth < max) { vals.add(node); } } } } return propsTable; }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing test counts for each product area. * * @param suites List of test suites * @param areas List of product areas * // w w w .j av a2s . co m * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageAreaTestCountChart(Vector<CMnDbBuildData> builds, Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) { JFreeChart chart = null; // Collect the average of all test types Hashtable countAvg = new Hashtable(); DefaultPieDataset dataset = new DefaultPieDataset(); if ((suites != null) && (suites.size() > 0)) { // Collect test data for each of the suites in the list Enumeration suiteList = suites.elements(); while (suiteList.hasMoreElements()) { // Process the data for the current suite CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement(); Integer testCount = new Integer(suite.getTestCount()); CMnDbFeatureOwnerData area = null; // Iterate through each product area to determine who owns this suite CMnDbFeatureOwnerData currentArea = null; Iterator iter = areas.iterator(); while (iter.hasNext()) { currentArea = (CMnDbFeatureOwnerData) iter.next(); if (currentArea.hasFeature(suite.getGroupName())) { Integer avgValue = null; String areaName = currentArea.getDisplayName(); if (countAvg.containsKey(areaName)) { Integer oldAvg = (Integer) countAvg.get(areaName); avgValue = oldAvg + testCount; } else { avgValue = testCount; } countAvg.put(areaName, avgValue); } } } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = countAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Integer total = (Integer) countAvg.get(key); Integer avg = new Integer(total.intValue() / builds.size()); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Avg Test Count by Area", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatAreaChart(plot, "tests"); return chart; }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing test counts for each product area. * * @param suites List of test suites * @param areas List of product areas * /*from w w w. j a va 2 s .c o m*/ * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageAreaTestTimeChart(Vector<CMnDbBuildData> builds, Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) { JFreeChart chart = null; // Collect the average of all test types Hashtable timeAvg = new Hashtable(); DefaultPieDataset dataset = new DefaultPieDataset(); if ((suites != null) && (suites.size() > 0)) { // Collect test data for each of the suites in the list Enumeration suiteList = suites.elements(); while (suiteList.hasMoreElements()) { // Process the data for the current suite CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement(); Long elapsedTime = new Long(suite.getElapsedTime() / (1000 * 60)); CMnDbFeatureOwnerData area = null; // Iterate through each product area to determine who owns this suite CMnDbFeatureOwnerData currentArea = null; Iterator iter = areas.iterator(); while (iter.hasNext()) { currentArea = (CMnDbFeatureOwnerData) iter.next(); if (currentArea.hasFeature(suite.getGroupName())) { Long avgValue = null; String areaName = currentArea.getDisplayName(); if (timeAvg.containsKey(areaName)) { Long oldAvg = (Long) timeAvg.get(areaName); avgValue = oldAvg + elapsedTime; } else { avgValue = elapsedTime; } timeAvg.put(areaName, avgValue); } } } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = timeAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Long total = (Long) timeAvg.get(key); Long avg = new Long(total.longValue() / builds.size()); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Avg Test Time by Area", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatAreaChart(plot, "min"); return chart; }
From source file:opennlp.tools.textsimilarity.TextProcessor.java
public static Hashtable<String, Float> getAllBigramsStopWord(ArrayList<String> tokens, boolean retainPunc) { Hashtable<String, Float> bGramCandidates = new Hashtable<String, Float>(); try {/*www . j a v a2s. co m*/ ArrayList<String> r = new ArrayList<String>(); for (int i = 0; i < tokens.size() - 1; i++) { String p1 = (String) tokens.get(i).toLowerCase(); String p2 = (String) tokens.get(i + 1).toLowerCase(); // check to see if stopword /* * if(StopList.getInstance().isStopWord(p1.trim()) || * StopList.getInstance().isStopWord(p2.trim())){ continue; } */ StringBuffer buf = new StringBuffer(); buf.append(p1); buf.append(" "); buf.append(p2); String b = buf.toString().toLowerCase(); // don't add punc tokens if (b.indexOf("<punc>") != -1 && !retainPunc) continue; float freq = 1; if (bGramCandidates.containsKey(b)) { freq = bGramCandidates.get(b) + 1; } bGramCandidates.put(b, freq); } } catch (Exception e) { LOG.severe("Problem getting stoplist"); } return bGramCandidates; }
From source file:org.hdiv.filter.RequestWrapper.java
/** * Parses an http cookie request header and replace values if confidentiality is activated. * //from w w w . j a va 2 s .co m * @param cookieHader * value assigned to cookie header * @param sessionCookies * cookies stored in user session * @return cookie request header with replaced values * @since HDIV 1.1.1 */ private String replaceCookieString(String cookieHeader, Hashtable sessionCookies) { String header = cookieHeader.trim(); // Cookie fields are separated by ';' StringTokenizer tokens = new StringTokenizer(cookieHeader, ";"); while (tokens.hasMoreTokens()) { // field name is separated from value by '=' StringTokenizer t = new StringTokenizer(tokens.nextToken(), "="); String name = t.nextToken().trim(); if (name.equals(Constants.JSESSIONID)) { continue; } if (sessionCookies.containsKey(name)) { if (t.hasMoreTokens()) { String value = t.nextToken().trim(); SavedCookie savedCookie = (SavedCookie) sessionCookies.get(name); header = header.replaceFirst("=" + value, "=" + savedCookie.getValue()); } } } return header; }
From source file:org.apache.pig.impl.logicalLayer.LOFRJoin.java
@Override /**/*w w w . j a va 2 s .c om*/ * Uses the schema from its input operators and dedups * those fields that have the same alias and sets the * schema for the join */ public Schema getSchema() throws FrontendException { List<LogicalOperator> inputs = mPlan.getPredecessors(this); mType = DataType.BAG;//mType is from the super class Hashtable<String, Integer> nonDuplicates = new Hashtable<String, Integer>(); if (!mIsSchemaComputed) { List<Schema.FieldSchema> fss = new ArrayList<Schema.FieldSchema>(); int i = -1; for (LogicalOperator op : inputs) { try { Schema cSchema = op.getSchema(); if (cSchema != null) { for (FieldSchema schema : cSchema.getFields()) { ++i; if (nonDuplicates.containsKey(schema.alias)) { if (nonDuplicates.get(schema.alias) != -1) { nonDuplicates.remove(schema.alias); nonDuplicates.put(schema.alias, -1); } } else nonDuplicates.put(schema.alias, i); FieldSchema newFS = new FieldSchema(op.getAlias() + "::" + schema.alias, schema.schema, schema.type); newFS.setParent(schema.canonicalName, op); fss.add(newFS); } } else fss.add(new FieldSchema(null, DataType.BYTEARRAY)); } catch (FrontendException ioe) { mIsSchemaComputed = false; mSchema = null; throw ioe; } } mIsSchemaComputed = true; for (Entry<String, Integer> ent : nonDuplicates.entrySet()) { int ind = ent.getValue(); if (ind == -1) continue; FieldSchema prevSch = fss.get(ind); fss.set(ind, new FieldSchema(ent.getKey(), prevSch.schema, prevSch.type)); } mSchema = new Schema(fss); } return mSchema; }