List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:com.linkedin.pinot.util.TestUtils.java
public static void assertJSONArrayApproximation(JSONArray jsonArrayEstimate, JSONArray jsonArrayActual, double precision) { LOGGER.info("====== assertJSONArrayApproximation ======"); try {// w w w. ja v a 2 s . co m HashMap<String, Double> mapEstimate = genMapFromJSONArray(jsonArrayEstimate); HashMap<String, Double> mapActual = genMapFromJSONArray(jsonArrayActual); // estimation should not affect number of groups formed Assert.assertEquals(mapEstimate.keySet().size(), mapActual.keySet().size()); LOGGER.info("estimate: " + mapEstimate.keySet()); LOGGER.info("actual: " + mapActual.keySet()); int cnt = 0; for (String key : mapEstimate.keySet()) { // Not strictly enforced, since in quantile, top 100 groups from accurate maybe not be top 100 from estimate // Assert.assertEquals(mapActual.keySet().contains(key), true); if (mapActual.keySet().contains(key)) { assertApproximation(mapEstimate.get(key), mapActual.get(key), precision); cnt += 1; } } LOGGER.info("group overlap rate: " + (cnt + 0.0) / mapEstimate.keySet().size()); } catch (JSONException e) { e.printStackTrace(); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils.java
/** Make a copy of a Map<String,List<String>> */ public static Map<String, List<String>> copyListMap(Map<String, List<String>> source) { HashMap<String, List<String>> map = new HashMap<String, List<String>>(); Set<String> keys = map.keySet(); for (String key : keys) { List<String> vals = map.get(key); map.put(new String(key), copy(vals)); }/*from w w w . ja v a2s . co m*/ return map; }
From source file:playground.wrashid.parkingSearch.ppSim.jdepSim.searchStrategies.analysis.ComparisonGarageCounts.java
private static void init() { String filePath = ZHScenarioGlobal.loadStringParam("ComparisonGarageCounts.garageParkingCountsFile"); Double countsScalingFactor = ZHScenarioGlobal.loadDoubleParam("ComparisonGarageCounts.countsScalingFactor"); countsMatrix = GeneralLib.readStringMatrix(filePath, "\t"); HashMap<String, Double[]> occupancyOfAllSelectedParkings = SingleDayGarageParkingsCount .getOccupancyOfAllSelectedParkings(countsMatrix); selectedParkings = occupancyOfAllSelectedParkings.keySet(); sumOfOccupancyCountsOfSelectedParkings = new double[96]; for (String parkingName : selectedParkings) { Double[] occupancyBins = occupancyOfAllSelectedParkings.get(parkingName); if (occupancyBins == null) { DebugLib.stopSystemAndReportInconsistency(); }/*from w w w. j a v a2 s . com*/ for (int i = 0; i < 96; i++) { sumOfOccupancyCountsOfSelectedParkings[i] += countsScalingFactor * occupancyBins[i]; } } mappingOfParkingNameToParkingId = SingleDayGarageParkingsCount.getMappingOfParkingNameToParkingId(); }
From source file:eionet.util.SecurityUtil.java
/** * * @param usr// ww w. ja v a 2s .com * @param aclPath * @param prm * @return * @throws Exception */ public static boolean hasChildPerm(String usr, String aclPath, String prm) throws Exception { HashMap acls = AccessController.getAcls(); Iterator aclNames = acls.keySet().iterator(); AccessControlListIF acl; while (aclNames.hasNext()) { String aclName = (String) aclNames.next(); if (aclName.startsWith(aclPath)) { acl = (AccessControlListIF) acls.get(aclName); if (acl.checkPermission(usr, prm)) { return true; } } } return false; }
From source file:com.caris.oscarexchange4j.proxy.PreviewCoverage.java
/** * @param serviceEndpoint//from ww w . ja v a 2 s. com * The service end point. * @param parameterMap * A map of parameters. * @return A url generated based on the end point and the parameters. * @throws MalformedURLException * If something goes wrong. */ public static URL generateUrl(String serviceEndpoint, HashMap<String, String> parameterMap) throws MalformedURLException { verifyParameters(parameterMap); List<String> params = new ArrayList<>(); Set<String> keys = parameterMap.keySet(); for (String key : keys) { params.add(key + "=" + parameterMap.get(key)); } if (!serviceEndpoint.endsWith("?")) { serviceEndpoint += "?"; } serviceEndpoint += StringUtils.join(params, "&"); return new URL(serviceEndpoint); }
From source file:org.jdbcluster.dao.Dao.java
/** * creates new instance of a Dao using given Dao class * @param daoClass class of Object to create * @return created dao instance// w w w . j av a 2 s. com */ public static Object newInstance(Class<?> daoClass) { Object dao = JDBClusterUtil.createClassObject(daoClass); //get property of DAO and initial value from jdbcluster.dao.conf.xml HashMap<String, String> hm; synchronized (classToPropsMap) { hm = classToPropsMap.get(daoClass); if (hm == null) hm = putCacheMap(daoClass); } BeanWrapper beanWrapper = new BeanWrapperImpl(); beanWrapper.setWrappedInstance(dao); for (String prop : hm.keySet()) { String value = hm.get(prop); //get property of DAO Class<?> propClass = beanWrapper.getPropertyType(prop); //convert to Type if necessary Object o = beanWrapper.convertIfNecessary(value, propClass); //set the value of the predefined property read from jdbcluster.dao.conf.xml beanWrapper.setPropertyValue(new PropertyValue(prop, o)); } return dao; }
From source file:org.artags.android.app.util.http.HttpUtil.java
/** * Post data and attachements/*from w ww . j ava 2s .c om*/ * @param url The POST url * @param params Parameters * @param files Files * @return The return value * @throws HttpException If an error occurs */ public static String post(String url, HashMap<String, String> params, HashMap<String, File> files) throws HttpException { String ret = ""; try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for (String key : files.keySet()) { FileBody bin = new FileBody(files.get(key)); reqEntity.addPart(key, bin); } for (String key : params.keySet()) { String val = params.get(key); reqEntity.addPart(key, new StringBody(val, Charset.forName("UTF-8"))); } post.setEntity(reqEntity); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { ret = EntityUtils.toString(resEntity); Log.i("ARTags:HttpUtil:Post:Response", ret); } //return response; } catch (Exception e) { Log.e("ARTags:HttpUtil", "Error : " + e.getMessage()); throw new HttpException(e.getMessage()); } return ret; }
From source file:bammerbom.ultimatecore.bukkit.resources.utils.UuidUtil.java
public static void loadPlayers() { File directory = new File(r.getUC().getDataFolder() + File.separator + "Players"); if (!directory.exists()) { directory.mkdirs();//from w w w . j a v a 2s. co m } ArrayList<UUID> request = null; for (OfflinePlayer p : r.getOfflinePlayers()) { if (p.getUniqueId() == null) { continue; } final File file = new File(r.getUC().getDataFolder() + File.separator + "Players" + File.separator + p.getUniqueId() + ".yml"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { ErrorLogger.log(e, "Failed to create new file for " + p.getUniqueId()); } } Config conf = new Config(file); if (p.getName() == null) { if (!conf.contains("name")) { if (request == null) { request = new ArrayList<>(); } request.add(p.getUniqueId()); } } else { if (!conf.contains("name")) { conf.set("name", p.getName()); conf.save(); if (!conf.contains("names")) { ArrayList<String> names = new ArrayList<>(); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); names.add(p.getName() + " - " + date); conf.set("names", names); conf.save(); } } else { if (!conf.contains("names")) { ArrayList<String> names = new ArrayList<>(); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); names.add(p.getName() + " - " + date); conf.set("names", names); conf.save(); } if (!conf.getString("name").equals(p.getName())) { String oldname = conf.getString("name"); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); List<String> names = conf.getStringList("names"); if (names == null) { names = new ArrayList<>(); } names.add(p.getName() + " - " + date); conf.set("names", names); conf.set("name", p.getName()); if (p.isOnline()) { r.sendMes((CommandSender) p, "nameChanged", "%Oldname", oldname, "%Newname", p.getName()); } else { conf.set("oldname", oldname); } conf.save(); } } } } if (request != null) { final ArrayList<UUID> req = request; try { r.log("Starting playerfile update..."); HashMap<UUID, String> s = new UuidToName(req).call(); for (UUID u : s.keySet()) { String n = s.get(u); File f = new File( r.getUC().getDataFolder() + File.separator + "Players" + File.separator + u + ".yml"); Config conf = new Config(f); conf.set("name", n); conf.save(); // if (!conf.contains("names")) { ArrayList<String> names = new ArrayList<>(); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); names.add(n + " - " + date); conf.set("names", names); conf.save(); } // } r.log("Playerfile update complete."); } catch (Exception e) { ErrorLogger.log(e, "Failed to convert uuids to names."); } } }
From source file:bammerbom.ultimatecore.spongeapi.resources.utils.UuidUtil.java
public static void loadPlayers() { File directory = new File(r.getUC().getDataFolder() + File.separator + "Players"); if (!directory.exists()) { directory.mkdirs();//from w w w . j a va2 s . c om } ArrayList<UUID> request = null; for (User p : r.getOfflinePlayers()) { if (p.getUniqueId() == null) { continue; } final File file = new File(r.getUC().getDataFolder() + File.separator + "Players" + File.separator + p.getUniqueId() + ".yml"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { ErrorLogger.log(e, "Failed to create new file for " + p.getUniqueId()); } } Config conf = new Config(file); if (p.getName() == null) { if (!conf.contains("name")) { if (request == null) { request = new ArrayList<>(); } request.add(p.getUniqueId()); } } else { if (!conf.contains("name")) { conf.set("name", p.getName()); conf.save(); if (!conf.contains("names")) { ArrayList<String> names = new ArrayList<>(); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); names.add(p.getName() + " - " + date); conf.set("names", names); conf.save(); } } else { if (!conf.contains("names")) { ArrayList<String> names = new ArrayList<>(); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); names.add(p.getName() + " - " + date); conf.set("names", names); conf.save(); } if (!conf.getString("name").equals(p.getName())) { String oldname = conf.getString("name"); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); List<String> names = conf.getStringList("names"); if (names == null) { names = new ArrayList<>(); } names.add(p.getName() + " - " + date); conf.set("names", names); conf.set("name", p.getName()); if (p.isOnline()) { r.sendMes((CommandSource) p, "nameChanged", "%Oldname", oldname, "%Newname", p.getName()); } else { conf.set("oldname", oldname); } conf.save(); } } } } if (request != null) { final ArrayList<UUID> req = request; try { r.log("Starting playerfile update..."); HashMap<UUID, String> s = new UuidToName(req).call(); for (UUID u : s.keySet()) { String n = s.get(u); File f = new File( r.getUC().getDataFolder() + File.separator + "Players" + File.separator + u + ".yml"); Config conf = new Config(f); conf.set("name", n); conf.save(); // if (!conf.contains("names")) { ArrayList<String> names = new ArrayList<>(); Calendar timeCal = Calendar.getInstance(); timeCal.setTimeInMillis(System.currentTimeMillis()); String date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(timeCal.getTime()); names.add(n + " - " + date); conf.set("names", names); conf.save(); } // } r.log("Playerfile update complete."); } catch (Exception e) { ErrorLogger.log(e, "Failed to convert uuids to names."); } } }
From source file:bb.mcmc.analysis.ConvergeStatUtils.java
public static HashMap<String, double[]> traceInfoToArrays(HashMap<String, ArrayList<Double>> traceInfo, int burnin) { HashMap<String, double[]> newValues = new HashMap<String, double[]>(); final Set<String> names = traceInfo.keySet(); for (String key : names) { final List<Double> t = getSubList(traceInfo.get(key), burnin); newValues.put(key, Doubles.toArray(t)); }// w w w . j av a 2s .com return newValues; }