List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.ichi2.libanki.Utils.java
public static boolean unzipFiles(ZipFile zipFile, String targetDirectory, String[] zipEntries, HashMap<String, String> zipEntryToFilenameMap) { byte[] buf = new byte[FILE_COPY_BUFFER_SIZE]; File dir = new File(targetDirectory); if (!dir.exists() && !dir.mkdirs()) { Timber.e("Utils.unzipFiles: Could not create target directory: " + targetDirectory); return false; }//from www. j a v a2 s .c o m if (zipEntryToFilenameMap == null) { zipEntryToFilenameMap = new HashMap<String, String>(); } BufferedInputStream zis = null; BufferedOutputStream bos = null; try { for (String requestedEntry : zipEntries) { ZipEntry ze = zipFile.getEntry(requestedEntry); if (ze != null) { String name = ze.getName(); if (zipEntryToFilenameMap.containsKey(name)) { name = zipEntryToFilenameMap.get(name); } File destFile = new File(dir, name); File parentDir = destFile.getParentFile(); if (!parentDir.exists() && !parentDir.mkdirs()) { return false; } if (!ze.isDirectory()) { Timber.i("uncompress %s", name); zis = new BufferedInputStream(zipFile.getInputStream(ze)); bos = new BufferedOutputStream(new FileOutputStream(destFile), FILE_COPY_BUFFER_SIZE); int n; while ((n = zis.read(buf, 0, FILE_COPY_BUFFER_SIZE)) != -1) { bos.write(buf, 0, n); } bos.flush(); bos.close(); zis.close(); } } } } catch (IOException e) { Timber.e(e, "Utils.unzipFiles: Error while unzipping archive."); return false; } finally { try { if (bos != null) { bos.close(); } } catch (IOException e) { Timber.e(e, "Utils.unzipFiles: Error while closing output stream."); } try { if (zis != null) { zis.close(); } } catch (IOException e) { Timber.e(e, "Utils.unzipFiles: Error while closing zip input stream."); } } return true; }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testContainsKey() { HashMap<String, Integer> hashMap = new HashMap<String, Integer>(); checkEmptyHashMapAssumptions(hashMap); assertFalse(hashMap.containsKey(KEY_TEST_CONTAINS_KEY)); hashMap.put(KEY_TEST_CONTAINS_KEY, VALUE_TEST_CONTAINS_KEY); assertTrue(hashMap.containsKey(KEY_TEST_CONTAINS_KEY)); assertFalse(hashMap.containsKey(VALUE_TEST_CONTAINS_DOES_NOT_EXIST)); assertFalse(hashMap.containsKey(null)); hashMap.put(null, VALUE_TEST_CONTAINS_KEY); assertTrue(hashMap.containsKey(null)); }
From source file:com.bah.applefox.main.plugins.fulltextindex.FTAccumuloSampler.java
/** * Overridden method to create the sample *//*from ww w . ja v a 2 s.com*/ public void createSample() { try { // HashMap to write the sample table to HashMap<String, Integer> output = new HashMap<String, Integer>(); // Scan the data table Scanner scan = AccumuloUtils.connectRead(dataTable); Map<String, String> properties = new HashMap<String, String>(); IteratorSetting cfg2 = new IteratorSetting(11, SamplerCreator.class, properties); scan.addScanIterator(cfg2); for (Entry<Key, Value> entry : scan) { try { // Write the data from the table to the sample table String row = entry.getKey().getRow().toString(); // get rid of the timestamp at the end row = row.substring(0, row.lastIndexOf(" ")); int value = output.containsKey(row) ? output.get(row) : 0; value += (Integer) IngestUtils.deserialize(entry.getValue().get()); output.put(row, value); } catch (Exception e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } } // get the total number of docs from the urls table Scanner scann = AccumuloUtils.connectRead(urlTable); IteratorSetting cfg3 = new IteratorSetting(11, TotalDocFinder.class, properties); scann.addScanIterator(cfg3); for (Entry<Key, Value> entry : scann) { try { output.put(entry.getKey().getRow().toString(), (Integer) IngestUtils.deserialize(entry.getValue().get())); } catch (Exception e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } } // Create the sample table file File f = new File(sampleFile); f.createNewFile(); // use buffering OutputStream file = new FileOutputStream(f); OutputStream buffer = new BufferedOutputStream(file); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(output); out.flush(); out.close(); } catch (AccumuloException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } catch (AccumuloSecurityException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } catch (TableNotFoundException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } catch (IOException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } }
From source file:com.otway.picasasync.syncutil.AlbumSync.java
private List<ImageSync> buildImageList(PicasawebClient webClient, File localFolder, AlbumEntry albumEntry, final LocalDateTime oldestDate) throws IOException, ServiceException { List<ImageSync> allImages = new ArrayList<ImageSync>(); syncManager.getSyncState().setStatus("Querying Google for album " + albumEntry.getTitle().getPlainText()); // Get the list of remote photos List<PhotoEntry> photos = webClient.getPhotos(albumEntry); // Deal with the fact that an album can have multiple images with the same local filename. HashMap<String, List<PhotoEntry>> fileGroups = new HashMap<String, List<PhotoEntry>>(); for (PhotoEntry photo : photos) { String imageName = photo.getTitle().getPlainText().toLowerCase(); if (FilenameUtils.getExtension(imageName).toLowerCase().equals(".mov")) { log.info("Skipping file " + imageName + " with .mov file extension."); continue; }/*from w w w . ja v a2 s . c o m*/ List<PhotoEntry> photoList = null; if (!fileGroups.containsKey(imageName)) { photoList = new ArrayList<PhotoEntry>(); fileGroups.put(imageName, photoList); } else photoList = fileGroups.get(imageName); photoList.add(photo); } // So now we have a map of image name => List of photo entries which use that name. List<PhotoEntry> nonDupePhotos = new ArrayList<PhotoEntry>(); int dupesDiscarded = 0; for (List<PhotoEntry> list : fileGroups.values()) { String maxId = null; PhotoEntry photoToUse = null; for (PhotoEntry photo : list) { String id = PicasawebClient.getPhotoId(photo); // We'll arbitrarily pick the one with the lowest ID, and ignore the rest. if (maxId == null || maxId.compareTo(id) == -1) { maxId = id; photoToUse = photo; } } nonDupePhotos.add(photoToUse); dupesDiscarded += list.size() - 1; } if (dupesDiscarded > 0) { log.info("Ignoring " + dupesDiscarded + " duplicate photos of " + photos.size() + " from album " + getAlbumName()); } List<ImageSync> remoteImages = new ArrayList<ImageSync>(); for (PhotoEntry photo : nonDupePhotos) { String imageFile = photo.getTitle().getPlainText(); if (settings.getExcludeVideos() && photo.getMediaContents().size() > 1) { log.info("Exclude Video enabled: skipping " + imageFile); continue; } File localFileName = new File(localFolder, imageFile); remoteImages.add(new ImageSync(photo, localFileName)); } log.debug(remoteImages.size() + " remote images found in " + albumEntry.getTitle().getPlainText()); // Get the local file list File[] files = localFolder.listFiles(new FilenameFilter() { public boolean accept(File current, String name) { File file = new File(current, name); return file.isFile() && !file.isHidden(); } }); List<ImageSync> localFiles = new ArrayList<ImageSync>(); if (files != null && files.length > 0) { log.info(files.length + " local files found in " + localFolder); // Now, pull out all the local files that aren't in the list. // These are the new files that we'll upload for (File localFile : files) { if (!fileGroups.containsKey(localFile.getName().toLowerCase())) { localFiles.add(new ImageSync(null, localFile)); } } } log.debug(localFiles.size() + " local images found in " + localFolder); allImages.addAll(localFiles); // Add the remote images after. Uploads are higher priority than downloads allImages.addAll(remoteImages); log.debug(allImages.size() + " images found (new local + remote)"); // And finally, filter out anything that's too old. List<ImageSync> result = new ArrayList<ImageSync>(); for (ImageSync image : allImages) if (image.newerThan(oldestDate)) result.add(image); log.debug(result.size() + " total images after date filter applied."); return result; }
From source file:com.mirth.connect.plugins.dashboardstatus.DashboardConnectorStatusMonitor.java
public synchronized Object invoke(String method, Object object, String sessionId) { if (method.equals(METHOD_GET_STATES)) { return connectorStateMap; } else if (method.equals(METHOD_GET_CONNECTION_INFO_LOGS)) { String channelName;/*from w ww . j a v a2 s. c o m*/ LinkedList<String[]> channelLog; if (object == null) { /* * object is null - no channel is selected. return the latest * entire log entries of all channels combined. ONLY new * entries. */ channelName = STATE_NO_SELECTION; channelLog = entireConnectorInfoLogs; } else { // object is not null - a channel is selected. return the latest // (LOG_SIZE) of that particular channel. channelName = object.toString(); // return only the newly added log entries for the client with // matching sessionId. channelLog = connectorInfoLogs.get(channelName); if (channelLog == null) { channelLog = new LinkedList<String[]>(); connectorInfoLogs.put(channelName, channelLog); } } HashMap<String, Long> lastDisplayedLogIdByChannel; if (lastDisplayedLogIndexBySessionId.containsKey(sessionId)) { // client exist with the sessionId. lastDisplayedLogIdByChannel = lastDisplayedLogIndexBySessionId.get(sessionId); if (lastDisplayedLogIdByChannel.containsKey(channelName)) { // existing channel on an already open client. // -> only display new log entries. long lastDisplayedLogId = lastDisplayedLogIdByChannel.get(channelName); LinkedList<String[]> newChannelLogEntries = new LinkedList<String[]>(); // FYI, channelLog.size() will never be larger than LOG_SIZE // = 1000. for (String[] aChannelLog : channelLog) { if (lastDisplayedLogId < Long.parseLong(aChannelLog[0])) { newChannelLogEntries.addLast(aChannelLog); } } if (newChannelLogEntries.size() > 0) { /* * put the lastDisplayedLogId into the HashMap. index 0 * is the most recent entry, and index0 of that entry * contains the logId. */ lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(newChannelLogEntries.get(0)[0])); lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); } try { return SerializationUtils.clone(newChannelLogEntries); } catch (SerializationException e) { logger.error(e); } } else { /* * new channel viewing on an already open client. -> all log * entries are new. display them all. put the * lastDisplayedLogId into the HashMap. index0 is the most * recent entry, and index0 of that entry object contains * the logId. */ if (channelLog.size() > 0) { lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(channelLog.get(0)[0])); lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); } try { return SerializationUtils.clone(channelLog); } catch (SerializationException e) { logger.error(e); } } } else { // brand new client. // thus also new channel viewing. // -> all log entries are new. display them all. lastDisplayedLogIdByChannel = new HashMap<String, Long>(); if (channelLog.size() > 0) { lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(channelLog.get(0)[0])); } else { // no log exist at all. put the currentLogId-1, which is the // very latest logId. lastDisplayedLogIdByChannel.put(channelName, logId - 1); } lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); try { return SerializationUtils.clone(channelLog); } catch (SerializationException e) { logger.error(e); } } } else if (method.equals(METHOD_CHANNELS_DEPLOYED)) { if (channelsDeployedFlagForEachClient.containsKey(sessionId)) { // sessionId found. no (re)deploy occurred. return false; } else { // no sessionId found, which means channels have just been // (re)deployed - clear out all clients' Dashboard Connector // Logs. channelsDeployedFlagForEachClient.put(sessionId, true); return true; } } else if (method.equals(METHOD_REMOVE_SESSIONID)) { // client shut down, or user logged out -> remove everything // involving this sessionId. if (lastDisplayedLogIndexBySessionId.containsKey(sessionId)) { lastDisplayedLogIndexBySessionId.remove(sessionId); } if (channelsDeployedFlagForEachClient.containsKey(sessionId)) { channelsDeployedFlagForEachClient.remove(sessionId); } return null; } return null; }
From source file:amie.keys.CSAKey.java
/** * Construction of the maps from properties -> id and id -> properties */// www.ja v a 2s. c om private static void buildDictionaries(List<List<String>> nonKeys, HashSet<HashSet<Integer>> nonKeysInt, HashMap<String, Integer> property2Id, HashMap<Integer, String> id2Property, List<Integer> propertiesList, int support, KB kb) { int id = 0; HashSet<HashSet<Integer>> nonKeysIntTmp = new HashSet<>(); for (List<String> nonKey : nonKeys) { HashSet<Integer> nonKeyInt = new HashSet<>(); for (int k = 0; k < nonKey.size(); ++k) { // Ignore String property = nonKey.get(k); //**** Debugging code ***/ /*// List<String> testingProperties = Arrays.asList("db:campus", "db:mascot", "db:officialschoolcolour", "db:athletics", "db:country"); // if (getPropertySupport(property, kb) < support || !testingProperties.contains(property)) { // continue; // } */ //**** Debugging code ***/ if (!property2Id.containsKey(property)) { property2Id.put(property, id); id2Property.put(id, property); propertiesList.add(id); ++id; } Integer idProperty = property2Id.get(property); nonKeyInt.add(idProperty); } nonKeysIntTmp.add(nonKeyInt); } nonKeysInt.addAll(simplifyHashNonKeySet(nonKeysIntTmp)); //System.out.println("Simplified " + nonKeysInt + "\tThread " + Thread.currentThread().getId() + "\t" + id2Property); }
From source file:com.alibaba.jstorm.ui.controller.NettyController.java
private List<UINettyMetric> getNettyData(MetricInfo nettyMetrics, String host, int window) { HashMap<String, UINettyMetric> nettyData = new HashMap<>(); if (nettyMetrics == null || nettyMetrics.get_metrics_size() == 0) { return new ArrayList<>(nettyData.values()); }//from w ww . j a v a2s . co m for (Map.Entry<String, Map<Integer, MetricSnapshot>> metric : nettyMetrics.get_metrics().entrySet()) { String name = metric.getKey(); String[] split_name = name.split("@"); String metricName = UIMetricUtils.extractMetricName(split_name); String connection = null; if (metricName != null) { connection = metricName.substring(metricName.indexOf(".") + 1); metricName = metricName.substring(0, metricName.indexOf(".")); } MetricSnapshot snapshot = metric.getValue().get(window); UINettyMetric netty; if (nettyData.containsKey(connection)) { netty = nettyData.get(connection); } else { netty = new UINettyMetric(host, connection); nettyData.put(connection, netty); } netty.setMetricValue(snapshot, metricName); } return new ArrayList<>(nettyData.values()); }
From source file:com.krawler.spring.crm.common.ImportRecordAdvisor.java
private void BeforeGetRefModuleData(MethodInvocation mi) throws DataInvalidateException { Object arguments[] = mi.getArguments(); String module = (String) arguments[1]; try {/*w ww .j a v a2 s. c om*/ HashMap<String, Object> requestParams = (HashMap<String, Object>) arguments[0]; String companyid = requestParams.get(Constants.companyid).toString(); ArrayList<String> filterNames = (ArrayList<String>) arguments[4]; ArrayList<Object> filterValues = (ArrayList<Object>) arguments[5]; if (module.equalsIgnoreCase(Constants.DefaultMasterItem)) { String configid = (String) arguments[3]; if (requestParams.containsKey(Constants.defaultheader) && requestParams.get(Constants.defaultheader) != null) { // handled case for Lead Source having conbined entries of Lead Source from master configuation + Campaign source if (StringUtil.equal(requestParams.get(Constants.defaultheader).toString(), Constants.Lead_Source)) { filterNames.add(Constants.INcrmCombomaster_masterid); configid = "'" + configid + "','" + Constants.CRMCOMBOMASTERID_CAMPAIGNSOURCE + "'"; } else { filterNames.add(Constants.crmCombomaster_masterid); } } else { filterNames.add(Constants.crmCombomaster_masterid); } filterValues.add(configid); filterValues.add(companyid); filterNames.add(Constants.company_companyID); } else if (module.equalsIgnoreCase(Constants.Crm_product_pojo)) { filterValues.add(companyid); filterNames.add(Constants.company_companyID); filterValues.add(0); filterNames.add(Constants.deleteflag); filterValues.add(1); filterNames.add(Constants.validflag); } else if (module.equalsIgnoreCase(Constants.Crm_account_pojo)) { filterValues.add(companyid); filterNames.add(Constants.company_companyID); filterValues.add(0); filterNames.add(Constants.deleteflag); filterValues.add(1); filterNames.add(Constants.validflag); } else if (module.equalsIgnoreCase(Constants.Crm_case_pojo)) { filterValues.add(companyid); filterNames.add(Constants.company_companyID); filterValues.add(0); filterNames.add(Constants.deleteflag); filterValues.add(1); filterNames.add(Constants.validflag); } else if (module.equalsIgnoreCase(Constants.Crm_contact_pojo)) { filterValues.add(companyid); filterNames.add(Constants.company_companyID); filterValues.add(0); filterNames.add(Constants.deleteflag); filterValues.add(1); filterNames.add(Constants.validflag); } else if (module.equalsIgnoreCase(Constants.Crm_lead_pojo)) { filterValues.add(companyid); filterNames.add(Constants.company_companyID); filterValues.add(0); filterNames.add(Constants.deleteflag); filterValues.add(1); filterNames.add(Constants.validflag); } else if (module.equalsIgnoreCase(Constants.Crm_opportunity_pojo)) { filterValues.add(companyid); filterNames.add(Constants.company_companyID); filterValues.add(0); filterNames.add(Constants.deleteflag); filterValues.add(1); filterNames.add(Constants.validflag); } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } }
From source file:monakhv.samlib.http.HttpClientController.java
private HashMap<String, ArrayList<AuthorCard>> parseSearchAuthorData(String text) throws SamlibParseException { String[] lines = text.split("\n"); HashMap<String, ArrayList<AuthorCard>> res = new HashMap<String, ArrayList<AuthorCard>>(); for (String line : lines) { if (SamLibConfig.testSplit(line) < 7) { Log.e(DEBUG_TAG, "Line Search parse Error: length=" + SamLibConfig.testSplit(line) + "\nline: " + line + "\nlines: " + lines.length); throw new SamlibParseException("Parse Search Author error\nline: " + line); }// w ww . ja v a2 s. c o m try { AuthorCard card = new AuthorCard(line); String name = card.getName(); if (res.containsKey(name)) { res.get(name).add(card); } else { ArrayList<AuthorCard> aa = new ArrayList<AuthorCard>(); aa.add(card); res.put(name, aa); } } catch (SamLibNullAuthorException ex) { //Log.i(DEBUG_TAG,"Skip author with no book"); } } if (res.isEmpty()) { return null; } return res; }
From source file:com.example.camera360.ui.ImageDetailActivity.java
private void setImageInfo() { HashMap<String, String> map = new HashMap<String, String>(); map = arrayList.get(currentIndex);//w w w . ja va2s . c o m mImageDesc.setText(map.get("desc")); if (map.get("favorite").equals("0")) { mImageLike.setImageResource(R.drawable.photo_like_active); } else { mImageLike.setImageResource(R.drawable.photo_like); } if (map.containsKey("face")) { mImageFetcher.loadImage(map.get("face"), mUserFace); } else { mUserFace.setImageResource(R.drawable.blank_boy); } mUserNickname.setText(map.get("nickname")); doFavoriteUsers(); }