List of usage examples for java.util HashMap size
int size
To view the source code for java.util HashMap size.
Click Source Link
From source file:iudex.da.ContentUpdater.java
protected void update(List<UniMap> references, Connection conn) throws SQLException { final HashMap<String, UniMap> uhashes = new HashMap<String, UniMap>(references.size()); final String qry = formatSelect(references, uhashes); final UpdateQueryRunner runner = new UpdateQueryRunner(); runner.query(conn, qry, new RefUpdateHandler(uhashes)); final ArrayList<UniMap> remains = new ArrayList<UniMap>(uhashes.size()); for (UniMap rem : uhashes.values()) { UniMap out = _transformer.transformReference(rem, null); if (out != null) remains.add(out);//from w w w . j a va2 s . com } if (remains.size() > 0) write(remains, conn); }
From source file:loadTest.loadTestLib.LUtil.java
private Entry<String, Integer> getLowestDockerHost() { HashMap<String, Integer> dockerNodes = getDockerNodes(); Entry<String, Integer> lowest = null; if (this.startedClusterContainer.size() < dockerNodes.size()) { for (Entry<String, Integer> entry : dockerNodes.entrySet()) { if (!this.startedClusterContainer.containsKey(entry.getKey())) { return new AbstractMap.SimpleEntry<>(entry.getKey(), 0); }//ww w. jav a2s .c o m } } for (Entry<String, Integer> entry : startedClusterContainer.entrySet()) { if (entry.getValue() < dockerNodes.get(entry.getKey())) { if (lowest == null) { lowest = entry; } else { if (lowest.getValue() > entry.getValue()) { lowest = entry; } } } } return lowest; }
From source file:babel.content.pages.Page.java
public Page(String url, Iterator<NutchChunk> values) { HashMap<String, List<NutchChunk>> verChunks = splitIntoVersions(values); m_pageProps = new MetaData("PageProperties"); m_pageURL = (url == null) ? new String() : url; // TODO: Is URL already normalized? m_versions = new ArrayList<PageVersion>(verChunks.size()); PageVersion curVer;/* w w w. j av a 2 s . c o m*/ for (String segId : verChunks.keySet()) { curVer = new PageVersion(segId, verChunks.get(segId), this); if (curVer.isNutchComplete()) { addVersion(curVer); } } m_versions.trimToSize(); }
From source file:com.redhat.victims.database.VictimsSqlDB.java
public HashSet<String> getVulnerabilities(HashMap<String, String> props) throws VictimsException { try {//from w w w .j av a 2 s. com HashSet<String> cves = new HashSet<String>(); int requiredMinCount = props.size(); ResultSet rs; PreparedStatement ps; Connection connection = getConnection(); try { ps = setObjects(connection, Query.PROPERTY_MATCH, props.keySet().toArray(), props.values().toArray()); rs = ps.executeQuery(); while (rs.next()) { Integer id = rs.getInt("record"); Integer count = rs.getInt("count"); if (count == requiredMinCount) { cves.addAll(getVulnerabilities(id)); } } rs.close(); ps.close(); } finally { connection.close(); } return cves; } catch (SQLException e) { throw new VictimsException("Failed to search on properties", e); } }
From source file:org.metis.utils.Utils.java
/** * Recursively steps through JSON object and arrays of objects. We support * only a single object or an array of objects, where each object represents * an entity (e.g., a student, a customer, an account, etc.). * /* w ww .ja v a 2 s . c o m*/ * All objects must have the same identical set of keys. * * @param jp * @param params * @throws Exception */ private static void parseJson(JsonParser jp, List<Map<String, String>> rows) throws Exception { // get the next json token JsonToken current = jp.nextToken(); // base case: return if we've reached end of json stream if (current == null) { return; } // all rows must have the identical set of keys! Map<String, String> firstRow = null; if (!rows.isEmpty()) { firstRow = rows.get(0); } // we only accept objects or arrays of objects switch (current) { case START_OBJECT: HashMap<String, String> row = new HashMap<String, String>(); while (jp.nextToken() != END_OBJECT) { // parser should be on 'key' token String key = jp.getCurrentName().toLowerCase(); // ensure all rows have the identical set of keys! if (firstRow != null && firstRow.get(key) == null) { String eStr = "parseJson: given list of json objects do " + "not have identical set of keys"; LOG.error(eStr); throw new Exception(eStr); } // now advance to 'value' token jp.nextToken(); String value = jp.getText(); row.put(key, value); } // if row is not null, add it to the rows list if (!row.isEmpty()) { // ensure all rows have the identical set of keys! if (firstRow != null && firstRow.size() != row.size()) { String eStr = "parseJson: given list of json objects do " + "not have identical set of keys; number of " + "keys vary"; LOG.error(eStr); throw new Exception(eStr); } rows.add(row); } break; case START_ARRAY: case END_ARRAY: break; default: LOG.error("parseJson: ERROR, json token is neither object nor array"); throw new Exception("parseJson: ERROR, json token is neither object nor array"); } // go on to the next start-of-array, end-of-array, start-of-object, or // end of stream parseJson(jp, rows); }
From source file:com.yahoo.ycsb.db.AsyncHBaseClient.java
/** * Update a record in the database. Any field/value pairs in the specified values HashMap will be written into the record with the specified * record key, overwriting any existing values with the same field name. * * @param table The name of the table/* ww w . java 2s. co m*/ * @param key The record key of the record to write * @param values A HashMap of field/value pairs to update in the record * @return Zero on success, a non-zero error code on error */ public int update(String table, String key, HashMap<String, ByteIterator> values) { if (_debug) { System.out.println("Setting up put for key: " + key); } byte[][] qualifiers = new byte[values.size()][]; byte[][] valuesArr = new byte[values.size()][]; int idx = 0; for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { final byte[] keyBytes = entry.getKey().getBytes(UTF8); final byte[] valueBytes = entry.getValue().toArray().clone(); if (_debug) { System.out.println("Adding field/value " + Bytes.pretty(keyBytes) + "/" + Bytes.pretty(valueBytes) + " to put request"); } qualifiers[idx] = keyBytes; valuesArr[idx] = valueBytes; idx++; } final PutRequest put = new PutRequest(table.getBytes(UTF8), key.getBytes(UTF8), _columnFamilyBytes, qualifiers, valuesArr); put.setBufferable(_buffered); put.setDurable(_durable); final Deferred<Object> d = _client.put(put).addErrback(errback); if (_failed) { return ServerError; } tryThrottle(d); return Ok; }
From source file:org.wise.portal.presentation.web.controllers.admin.AdminIndexController.java
@RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { ModelAndView modelAndView = new ModelAndView("admin/index"); String thisWISEVersion = null; // local WISE version e.g. "4.8", "4.9.1", etc String globalWISEVersion = null; // master WISE version e.g. "4.8", "4.9.1", etc // get WISE version from src/main/resources/version.json try {//from ww w.ja v a 2s . co m thisWISEVersion = portalService.getWISEVersion(); modelAndView.addObject("thisWISEVersion", thisWISEVersion); } catch (Exception e) { modelAndView.addObject("thisWISEVersion", "error retrieving current WISE version"); e.printStackTrace(); } // add if this WISE instance allows batch creation of user accounts modelAndView.addObject("isBatchCreateUserAccountsEnabled", Boolean.valueOf(wiseProperties.getProperty("isBatchCreateUserAccountsEnabled", "false"))); // get latest WISE info from master location String globalWISEVersionJSONString = retrieveGlobalWISEVersionJSONString(); try { // now parse global WISE version JSON and add to ModelAndView. JSONObject globalWISEVersionJSON = new JSONObject(globalWISEVersionJSONString); String globalWISEMajorVersion = globalWISEVersionJSON.getString("major"); String globalWISEMinorVersion = globalWISEVersionJSON.getString("minor"); globalWISEVersion = globalWISEMajorVersion + "." + globalWISEMinorVersion; modelAndView.addObject("globalWISEVersion", globalWISEVersion); } catch (Exception e) { modelAndView.addObject("globalWISEVersion", "error retrieving latest WISE version"); e.printStackTrace(); } try { // now compare the two versions and add version notes to ModelAndView obj String versionNotes = "WISE is up to date!"; if (Integer.parseInt(thisWISEVersion.replace(".", "")) < Integer .parseInt(globalWISEVersion.replace(".", ""))) { versionNotes = "A new version of WISE is available. Please update!"; modelAndView.addObject("wiseUpdateUrl", WISE_UPDATE_URL); } modelAndView.addObject("versionNotes", versionNotes); } catch (Exception e) { // do nothing e.printStackTrace(); } // now fetch recent commits String recentCommitHistoryJSONString = retrieveRecentCommitHistoryJSONString(); try { // now parse commit history json and add to ModelAndView. JSONArray recentCommitHistoryJSONArray = new JSONArray(recentCommitHistoryJSONString); modelAndView.addObject("recentCommitHistoryJSON", recentCommitHistoryJSONArray); } catch (Exception e) { modelAndView.addObject("recentCommitHistoryJSON", "error retrieving WISE commit history"); e.printStackTrace(); } // add number of curently-logged in users to model HashMap<String, User> allLoggedInUsers = (HashMap<String, User>) request.getSession().getServletContext() .getAttribute(WISESessionListener.ALL_LOGGED_IN_USERS); if (allLoggedInUsers != null) { modelAndView.addObject("numCurrentlyLoggedInUsers", allLoggedInUsers.size()); } else { modelAndView.addObject("numCurrentlyLoggedInUsers", 0); } // add number of users logged in today to model Calendar todayZeroHour = Calendar.getInstance(); todayZeroHour.set(Calendar.HOUR_OF_DAY, 0); // set hour to midnight todayZeroHour.set(Calendar.MINUTE, 0); // set minute in hour todayZeroHour.set(Calendar.SECOND, 0); // set second in minute todayZeroHour.set(Calendar.MILLISECOND, 0); // set millis in second Date dateMin = todayZeroHour.getTime(); Date dateMax = new java.util.Date(Calendar.getInstance().getTimeInMillis()); adminJob.setYesterday(dateMin); adminJob.setToday(dateMax); List<User> studentsWhoLoggedInToday = adminJob.findUsersWhoLoggedInSinceYesterday("studentUserDetails"); List<User> teachersWhoLoggedInToday = adminJob.findUsersWhoLoggedInSinceYesterday("teacherUserDetails"); if (studentsWhoLoggedInToday != null && teachersWhoLoggedInToday != null) { modelAndView.addObject("numUsersWhoLoggedInToday", studentsWhoLoggedInToday.size() + teachersWhoLoggedInToday.size()); } else { modelAndView.addObject("numUsersWhoLoggedInToday", 0); } return modelAndView; }
From source file:org.mobicents.charging.server.ratingengine.http.HTTPClientSbb.java
private HttpPost buildHTTPRequest(HashMap params) { HttpPost httpPost = new HttpPost(httpURLString); tracer.info("------ HTTP Request Params to Rating Engine ------"); String httpRequestParams = ""; List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.size()); for (Object o : params.entrySet()) { Map.Entry entry = (Map.Entry) o; String key = null;//from w w w . ja v a 2 s.c o m String val = null; if (entry.getKey() != null) { key = entry.getKey().toString(); } if (entry.getValue() != null) { val = entry.getValue().toString(); } if (key == null || val == null) { continue; } nameValuePairs.add(new BasicNameValuePair(key, val)); httpRequestParams += key + "=" + val + "; "; } try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } tracer.info(httpRequestParams); return httpPost; }
From source file:at.treedb.util.SevenZip.java
/** * Extracts some data (files and directories) from the archive without * extracting the whole archive.//from ww w . j a v a2 s . com * * @param archive * 7-zip archive * @param fileList * file extraction list, a path with an ending '/' denotes a * directory * @return file list as a map file name/file data * @throws IOException */ public static HashMap<String, byte[]> exctact(File archive, String... fileList) throws IOException { HashSet<String> fileSet = new HashSet<String>(); ArrayList<String> dirList = new ArrayList<String>(); for (String f : fileList) { if (!f.endsWith("/")) { fileSet.add(f); } else { dirList.add(f); } } HashMap<String, byte[]> resultMap = new HashMap<String, byte[]>(); SevenZFile sevenZFile = new SevenZFile(archive); do { SevenZArchiveEntry entry = sevenZFile.getNextEntry(); if (entry == null) { break; } // convert window path to unix style String name = entry.getName().replace('\\', '/'); if (!entry.isDirectory()) { boolean storeFile = false; if (fileSet.contains(name)) { storeFile = true; } else { // search directories for (String s : dirList) { if (name.startsWith(s)) { storeFile = true; break; } } } // store the file if (storeFile) { int size = (int) entry.getSize(); byte[] data = new byte[size]; sevenZFile.read(data, 0, size); resultMap.put(name, data); // in this case we can finish the extraction loop if (dirList.isEmpty() && resultMap.size() == fileSet.size()) { break; } } } } while (true); sevenZFile.close(); return resultMap; }
From source file:heartware.com.heartware_master.MainActivity.java
/** * Update user information using the ProfileDialogFragment * @param dialog//from w ww .j a v a2 s .c om * @param user * @param disability */ @Override public void onProfilePositiveClick(DialogFragment dialog, final String user, final String skill, final String disability) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String token = preferences.getString(UpPlatformSdkConstants.UP_PLATFORM_REFRESH_TOKEN, "NULL"); HashMap<String, String> profile = mDBAdapter.getProfileByUserAndToken(user, token); if (profile.size() == 0) { // user does not exist in SQL storage HashMap<String, String> newProfile = new HashMap<>(); newProfile.put(DBAdapter.USERNAME, user); newProfile.put(DBAdapter.PASSWORD, token); newProfile.put(DBAdapter.DIFFICULTY, skill); newProfile.put(DBAdapter.DISABILITY, disability); mDBAdapter.createProfile(newProfile); // // this is sloppy, but once the profile is created a new profileId is made and we need to keep track of it // String currentId = mDBAdapter.getProfileByUserAndToken(user, token).get(DBAdapter.PROFILE_ID); // HeartwareApplication app = (HeartwareApplication) getApplication(); // app.setCurrentProfileId(currentId); SendProfileData sp = (SendProfileData) new SendProfileData().execute(user, newProfile.get(DBAdapter.PASSWORD), skill, disability); Toast.makeText(this, "Creating " + user, Toast.LENGTH_SHORT).show(); } else { // user is already in database and now we should update their info HashMap<String, String> updateProfile = new HashMap<>(); HeartwareApplication app = (HeartwareApplication) getApplication(); updateProfile.put(DBAdapter.PROFILE_ID, app.getCurrentProfileId()); updateProfile.put(DBAdapter.USERNAME, user); updateProfile.put(DBAdapter.PASSWORD, token); updateProfile.put(DBAdapter.DIFFICULTY, skill); updateProfile.put(DBAdapter.DISABILITY, disability); mDBAdapter.updateProfile(updateProfile); SendProfileData sp = (SendProfileData) new SendProfileData().execute(user, updateProfile.get(DBAdapter.PASSWORD), skill, disability); Toast.makeText(this, "Updating " + user, Toast.LENGTH_SHORT).show(); } }