List of usage examples for java.util HashMap isEmpty
public boolean isEmpty()
From source file:swift.selenium.TransactionMapping.java
@SuppressWarnings("null") public static String getCellData(String reqValue, HSSFSheet reqSheet, int rowIndex, HashMap<String, Object> inputHashTable) throws IOException { HSSFCell reqCell = null;//from w w w . j av a 2 s .c o m Object actualvalue = null; String req = ""; DataFormatter fmt = new DataFormatter(); if (inputHashTable.isEmpty() == true) { inputHashTable = getValueFromHashMap(reqSheet); } HSSFRow rowActual = reqSheet.getRow(rowIndex); if (inputHashTable.get(reqValue) == null) { report.setStrMessage("Column " + reqValue + " not Found. Please Check input Sheet"); pauseFun("Column " + reqValue + " not Found. Please Check input Sheet"); } else { actualvalue = inputHashTable.get(reqValue);// rowHeader.getCell(colIndex).toString(); if (actualvalue != null) { int colIndex = Integer.parseInt(actualvalue.toString()); reqCell = rowActual.getCell(colIndex); if (reqCell == null) { System.out.println(reqValue + " is Null"); } else { int type = reqCell.getCellType(); switch (type) { case HSSFCell.CELL_TYPE_BLANK: req = ""; break; case HSSFCell.CELL_TYPE_NUMERIC: req = fmt.formatCellValue(reqCell); break; case HSSFCell.CELL_TYPE_STRING: req = reqCell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_BOOLEAN: req = Boolean.toString(reqCell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_ERROR: req = "error"; break; case HSSFCell.CELL_TYPE_FORMULA: req = reqCell.getCellFormula(); break; } } } else { req = reqCell.getStringCellValue(); System.out.println("null"); } } return req; }
From source file:info.unyttig.helladroid.newzbin.NewzBinController.java
/** * Sends HTTP POST requests to Newzbin with given parameters. * // ww w . j a v a2 s. co m * @param url Type:String - The url to connect to * @param kvPairs Type:Map - The map of parameters to post * @return Returns a HttpResponse with results * @throws ClientProtocolException * @throws IOException */ public static HttpResponse doPost(String url, HashMap<String, String> kvPairs) throws ClientProtocolException, IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); httppost.addHeader("Content-type", "application/x-www-form-urlencoded"); if (kvPairs != null && kvPairs.isEmpty() == false) { ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(kvPairs.size() + 4); nameValuePairs .add(new BasicNameValuePair("limit", preferences.getString("newzbin_search_limit", "10"))); nameValuePairs .add(new BasicNameValuePair("retention", preferences.getString("newzbin_retention", "7"))); nameValuePairs.add(new BasicNameValuePair("username", preferences.getString("newzbin_username", ""))); nameValuePairs.add(new BasicNameValuePair("password", preferences.getString("newzbin_password", ""))); String k, v; Iterator<String> itKeys = kvPairs.keySet().iterator(); while (itKeys.hasNext()) { k = itKeys.next(); v = kvPairs.get(k); nameValuePairs.add(new BasicNameValuePair(k, v)); } httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } return httpclient.execute(httppost); }
From source file:org.apache.hadoop.hbase.backup.util.BackupServerUtil.java
/** * Loop through the RS log timestamp map for the tables, for each RS, find the min timestamp * value for the RS among the tables.//www . j a va 2 s. c om * @param rsLogTimestampMap timestamp map * @return the min timestamp of each RS */ public static HashMap<String, Long> getRSLogTimestampMins( HashMap<TableName, HashMap<String, Long>> rsLogTimestampMap) { if (rsLogTimestampMap == null || rsLogTimestampMap.isEmpty()) { return null; } HashMap<String, Long> rsLogTimestampMins = new HashMap<String, Long>(); HashMap<String, HashMap<TableName, Long>> rsLogTimestampMapByRS = new HashMap<String, HashMap<TableName, Long>>(); for (Entry<TableName, HashMap<String, Long>> tableEntry : rsLogTimestampMap.entrySet()) { TableName table = tableEntry.getKey(); HashMap<String, Long> rsLogTimestamp = tableEntry.getValue(); for (Entry<String, Long> rsEntry : rsLogTimestamp.entrySet()) { String rs = rsEntry.getKey(); Long ts = rsEntry.getValue(); if (!rsLogTimestampMapByRS.containsKey(rs)) { rsLogTimestampMapByRS.put(rs, new HashMap<TableName, Long>()); rsLogTimestampMapByRS.get(rs).put(table, ts); } else { rsLogTimestampMapByRS.get(rs).put(table, ts); } } } for (String rs : rsLogTimestampMapByRS.keySet()) { rsLogTimestampMins.put(rs, BackupClientUtil.getMinValue(rsLogTimestampMapByRS.get(rs))); } return rsLogTimestampMins; }
From source file:br.net.fabiozumbi12.RedProtect.hooks.MojangUUIDs.java
public static String getName(String UUID) { try {//from w w w .j ava 2 s. co m URL url = new URL("https://api.mojang.com/user/profiles/" + UUID.replaceAll("-", "") + "/names"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line = in.readLine(); if (line == null) { return null; } JSONArray array = (JSONArray) new JSONParser().parse(line); HashMap<Long, String> names = new HashMap<Long, String>(); String name = ""; for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; if (jsonProfile.containsKey("changedToAt")) { names.put((long) jsonProfile.get("changedToAt"), (String) jsonProfile.get("name")); continue; } name = (String) jsonProfile.get("name"); } if (!names.isEmpty()) { Long key = Collections.max(names.keySet()); return names.get(key); } else { return name; } } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:mml.handler.scratch.Scratch.java
/** * Get a version that may or may not be in scratch. If not put it there. * @param docid the docid /*ww w . j ava 2s. c o m*/ * @param version the desired single version or null if default * @param dbase the database it is in * @return a ScratchVersion object or null * @throws MMLException */ public static ScratchVersion getVersion(String docid, String version, String dbase) throws MMLException { try { ScratchVersion sv = null; if (version != null) sv = getScratchVersion(docid, version, dbase); if (sv == null) { EcdosisMVD mvd = doGetMVD(dbase, docid); if (mvd != null) { if (version == null) version = mvd.getVersion1(); String base = Layers.stripLayer(version); HashMap<String, char[]> layers = new HashMap<String, char[]>(); int numVersions = mvd.numVersions(); for (int i = 1; i <= numVersions; i++) { String vName = mvd.getVersionId((short) i); if (vName.lastIndexOf(base) == 0) layers.put(vName, mvd.getVersion(i)); } if (!layers.isEmpty()) { Set<String> keys = layers.keySet(); String[] arr = new String[keys.size()]; keys.toArray(arr); Arrays.sort(arr); String[] all = mvd.getAllVersions(); short id = mvd.getVersionId(version); String longName = mvd.getVersionLongName(id); sv = new ScratchVersion(base, longName, docid, dbase, null, false); for (int i = 0; i < arr.length; i++) { String updatedName = Layers.upgradeLayerName(all, arr[i]); sv.addLayer(layers.get(arr[i]), ScratchVersion.layerNumber(updatedName)); } // save it for next time Connection conn = Connector.getConnection(); conn.putToDb(Database.SCRATCH, dbase, docid, version, sv.toJSON()); return sv; } } return null; } else return sv; } catch (DbException e) { throw new MMLException(e); } }
From source file:org.gcaldaemon.core.FeedUtilities.java
private static final byte[] removeDuplicatedEntries(SyndFeed feed, HashMap feedCache, double duplicationRatio) throws Exception { // Remove duplicated feed entries if (feedCache.isEmpty()) { return null; }// w w w . jav a2 s .com SyndEntry[] entries = getFeedEntries(feed); LinkedList duplicatedEntries = new LinkedList(); HashMap syndEntryCache = new HashMap(); SyndEntry entry; boolean found; for (int i = 0; i < entries.length; i++) { entry = entries[i]; found = false; // Find entry Iterator urls = feedCache.keySet().iterator(); while (urls.hasNext()) { String url = (String) urls.next(); if (url.endsWith(".ics")) { continue; } SyndEntry[] otherEntries = (SyndEntry[]) syndEntryCache.get(url); if (otherEntries == null) { CachedCalendar container = (CachedCalendar) feedCache.get(url); SyndFeed otherFeed = parseFeed(container.previousBody); otherEntries = getFeedEntries(otherFeed); syndEntryCache.put(url, otherEntries); } found = foundDuplicatedEntry(entry, otherEntries, duplicationRatio); if (found) { break; } } // Store duplicated entry if (found) { duplicatedEntries.addLast(entry); log.debug("Duplicated feed entry: " + entry.getTitle().trim()); } } // Convert to byte array if (!duplicatedEntries.isEmpty()) { List list = feed.getEntries(); list.removeAll(duplicatedEntries); WireFeed wire = feed.createWireFeed(); WireFeedOutput out = new WireFeedOutput(); StringWriter writer = new StringWriter(); out.output(wire, writer); byte[] bytes = StringUtils.encodeString(writer.toString(), StringUtils.UTF_8); return bytes; } return null; }
From source file:gov.nist.healthcare.ttt.webapp.api.GetCCDAFolderTest.java
public static HashMap<String, Object> buildJson2(HashMap<String, Object> child, String[] path, boolean isFile, boolean isFirst) { if (path.length > 0) { String current = path[path.length - 1]; HashMap<String, Object> res = new HashMap<>(); res.put("name", current); if (Pattern.matches(extensionRegex, current)) { return buildJson2(res, Arrays.copyOf(path, path.length - 1), true, false); } else {/*w w w .jav a 2 s. c o m*/ List childs = new ArrayList<>(); if (!child.isEmpty()) { childs.add(child); } if (isFile) { res.put("files", childs); } else { res.put("dirs", childs); } return buildJson2(res, Arrays.copyOf(path, path.length - 1), false, false); } } else { return child; } }
From source file:org.wso2.carbon.core.multitenancy.utils.TenantAxisUtils.java
/** * Create Tenant Axis2 ConfigurationContexts & add them to the main Axis2 ConfigurationContext * * @param mainConfigCtx Super-tenant Axis2 ConfigurationContext * @param tenantDomain Tenant domain (e.g. foo.com) * @return The newly created Tenant ConfigurationContext * @throws Exception If an error occurs while creating tenant ConfigurationContext *///from w w w .j av a 2 s .c o m private static ConfigurationContext createTenantConfigurationContext(ConfigurationContext mainConfigCtx, String tenantDomain) throws Exception { synchronized (tenantDomain.intern()) { // lock based on tenant domain Map<String, ConfigurationContext> tenantConfigContexts = getTenantConfigurationContexts(mainConfigCtx); ConfigurationContext tenantConfigCtx = tenantConfigContexts.get(tenantDomain); if (tenantConfigCtx != null) { return tenantConfigCtx; } long tenantLoadingStartTime = System.currentTimeMillis(); int tenantId = getTenantId(tenantDomain); if (tenantId == MultitenantConstants.SUPER_TENANT_ID || tenantId == MultitenantConstants.INVALID_TENANT_ID) { throw new Exception("Tenant " + tenantDomain + " does not exist"); } PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); carbonContext.setTenantId(tenantId); carbonContext.setTenantDomain(tenantDomain); tenantConfigCtx = tenantConfigContexts.get(tenantDomain); if (tenantConfigCtx != null) { return tenantConfigCtx; } AxisConfiguration mainAxisConfig = mainConfigCtx.getAxisConfiguration(); dataHolder.getTenantRegistryLoader().loadTenantRegistry(tenantId); try { UserRegistry tenantConfigRegistry = dataHolder.getRegistryService() .getConfigSystemRegistry(tenantId); UserRegistry tenantLocalUserRegistry = dataHolder.getRegistryService().getLocalRepository(tenantId); TenantAxisConfigurator tenantAxisConfigurator = new TenantAxisConfigurator(mainAxisConfig, tenantDomain, tenantId, tenantConfigRegistry, tenantLocalUserRegistry); doPreConfigContextCreation(tenantId); tenantConfigCtx = ConfigurationContextFactory.createConfigurationContext(tenantAxisConfigurator); AxisConfiguration tenantAxisConfig = tenantConfigCtx.getAxisConfiguration(); tenantConfigCtx.setServicePath(CarbonUtils.getAxis2ServicesDir(tenantAxisConfig)); tenantConfigCtx.setContextRoot("local:/"); TenantTransportSender transportSender = new TenantTransportSender(mainConfigCtx); // Adding transport senders HashMap<String, TransportOutDescription> transportSenders = mainAxisConfig.getTransportsOut(); if (transportSenders != null && !transportSenders.isEmpty()) { for (String strTransport : transportSenders.keySet()) { TransportOutDescription outDescription = new TransportOutDescription(strTransport); outDescription.setSender(transportSender); tenantAxisConfig.addTransportOut(outDescription); } } // Set the work directory tenantConfigCtx.setProperty(ServerConstants.WORK_DIR, mainConfigCtx.getProperty(ServerConstants.WORK_DIR)); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); new TransportPersistenceManager(tenantAxisConfig).updateEnabledTransports( tenantAxisConfig.getTransportsIn().values(), tenantAxisConfig.getTransportsOut().values()); // Notify all observers BundleContext bundleContext = dataHolder.getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, Axis2ConfigurationContextObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((Axis2ConfigurationContextObserver) service) .createdConfigurationContext(tenantConfigCtx); } } tracker.close(); } tenantConfigCtx.setProperty(MultitenantConstants.LAST_ACCESSED, System.currentTimeMillis()); // Register Capp deployer for this tenant Utils.addCAppDeployer(tenantAxisConfig); //deploy the services since all the deployers are initialized by now. tenantAxisConfigurator.deployServices(); //tenant config context must only be made after the tenant is fully loaded, and all its artifacts //are deployed. // -- THIS SHOULD BE THE LAST OPERATION OF THIS METHOD -- tenantConfigContexts.put(tenantDomain, tenantConfigCtx); log.info("Loaded tenant " + tenantDomain + " in " + (System.currentTimeMillis() - tenantLoadingStartTime) + " ms"); return tenantConfigCtx; } catch (Exception e) { String msg = "Error occurred while running deployment for tenant "; log.error(msg + tenantDomain, e); throw new Exception(msg, e); } } }
From source file:com.gsma.rcs.ri.messaging.geoloc.DisplayGeoloc.java
/** * Show geolocation for a set of contacts * //from www . j a v a 2 s . c om * @param ctx context * @param contacts set of contacts */ public static void showContactsOnMap(Context ctx, Set<ContactId> contacts) { HashMap<String, Geoloc> mapContactGeoloc = new HashMap<>(); RcsContactUtil rcsContactUtil = RcsContactUtil.getInstance(ctx); for (ContactId contact : contacts) { Geoloc geoloc = getLastGeoloc(ctx, contact); if (geoloc != null) { mapContactGeoloc.put(rcsContactUtil.getDisplayName(contact), geoloc); } } Geoloc myGeoloc = getMyLastGeoloc(ctx); if (myGeoloc != null) { mapContactGeoloc.put(ctx.getString(R.string.label_me), myGeoloc); } if (mapContactGeoloc.isEmpty()) { Utils.displayLongToast(ctx, ctx.getString(R.string.label_geoloc_not_found)); return; } Intent intent = new Intent(ctx, DisplayGeoloc.class); intent.putExtra(DisplayGeoloc.EXTRA_GEOLOC, mapContactGeoloc); ctx.startActivity(intent); }
From source file:org.apache.hadoop.hbase.backup.util.BackupUtils.java
/** * Loop through the RS log timestamp map for the tables, for each RS, find the min timestamp * value for the RS among the tables./*w ww. j a v a2s .c o m*/ * @param rsLogTimestampMap timestamp map * @return the min timestamp of each RS */ public static HashMap<String, Long> getRSLogTimestampMins( HashMap<TableName, HashMap<String, Long>> rsLogTimestampMap) { if (rsLogTimestampMap == null || rsLogTimestampMap.isEmpty()) { return null; } HashMap<String, Long> rsLogTimestampMins = new HashMap<String, Long>(); HashMap<String, HashMap<TableName, Long>> rsLogTimestampMapByRS = new HashMap<String, HashMap<TableName, Long>>(); for (Entry<TableName, HashMap<String, Long>> tableEntry : rsLogTimestampMap.entrySet()) { TableName table = tableEntry.getKey(); HashMap<String, Long> rsLogTimestamp = tableEntry.getValue(); for (Entry<String, Long> rsEntry : rsLogTimestamp.entrySet()) { String rs = rsEntry.getKey(); Long ts = rsEntry.getValue(); if (!rsLogTimestampMapByRS.containsKey(rs)) { rsLogTimestampMapByRS.put(rs, new HashMap<TableName, Long>()); rsLogTimestampMapByRS.get(rs).put(table, ts); } else { rsLogTimestampMapByRS.get(rs).put(table, ts); } } } for (Entry<String, HashMap<TableName, Long>> entry : rsLogTimestampMapByRS.entrySet()) { String rs = entry.getKey(); rsLogTimestampMins.put(rs, BackupUtils.getMinValue(entry.getValue())); } return rsLogTimestampMins; }