List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ViewLabelsServlet.java
@Override protected ResponseValues processRequest(VitroRequest vreq) { Map<String, Object> body = new HashMap<String, Object>(); String subjectUri = vreq.getParameter("subjectUri"); body.put("subjectUri", subjectUri); try {/*from w ww. j av a2s. com*/ //Get all language codes/labels in the system, and this list is sorted by language name List<HashMap<String, String>> locales = this.getLocales(vreq); //Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales); //the labels already added by the user ArrayList<Literal> existingLabels = this.getExistingLabels(subjectUri, vreq); //existing labels keyed by language name and each of the list of labels is sorted by language name HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this .getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, vreq, subjectUri); //Get available locales for the drop down for adding a new label, also sorted by language name HashSet<String> existingLanguageNames = new HashSet<String>(existingLabelsByLanguageName.keySet()); body.put("labelsSortedByLanguageName", existingLabelsByLanguageName); Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri); if (subject != null && subject.getName() != null) { body.put("subjectName", subject.getName()); } else { body.put("subjectName", null); } } catch (Throwable e) { log.error(e, e); return new ExceptionResponseValues(e); } String template = "viewLabelsForIndividual.ftl"; return new TemplateResponseValues(template, body); }
From source file:fast.servicescreen.server.RequestServiceImpl.java
@Override public String sendHttpRequest_PUT(String url, HashMap<String, String> headers, String body) { //create client and method appending to url DefaultHttpClient httpclient_PUT = new DefaultHttpClient(); httpput = new HttpPut(url); //add all headers if (headers != null) { for (Iterator<String> iterator = headers.keySet().iterator(); iterator.hasNext();) { String tmpKey = (String) iterator.next(); String tmpVal = headers.get(tmpKey); httpput.addHeader(tmpKey, tmpVal); }/*from w ww . ja v a 2 s . co m*/ } // Create response handler responseHandler = new BasicResponseHandler(); try { // send the POST request responseBody = httpclient_PUT.execute(httpput, responseHandler); } catch (Exception e) { e.printStackTrace(); responseBody = "-1"; } return responseBody; }
From source file:com.ehdev.chronos.lib.Chronos.java
static public boolean getDataOnSDCard(Context context, boolean oldFormat) { if (getCardReadStatus() == false) { CharSequence text = "Could not read to SD Card!."; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show();/*w ww . ja v a 2 s .co m*/ return false; } //Create 1 Job DateTime jobMidnight = DateTime.now().withDayOfWeek(7).minusWeeks(1).toDateMidnight().toDateTime() .withZone(DateTimeZone.getDefault()); Job currentJob = new Job("", 10, jobMidnight, PayPeriodDuration.TWO_WEEKS); currentJob.setDoubletimeThreshold(60); currentJob.setOvertimeThreshold(40); currentJob.setOvertimeOptions(OvertimeOptions.WEEK); List<Punch> punches = new LinkedList<Punch>(); List<Task> tasks = new LinkedList<Task>(); List<Note> notes = new LinkedList<Note>(); Task newTask; //Basic element newTask = new Task(currentJob, 0, "Regular"); tasks.add(newTask); newTask = new Task(currentJob, 1, "Lunch Break"); newTask.setEnablePayOverride(true); newTask.setPayOverride(0.0f); tasks.add(newTask); newTask = new Task(currentJob, 2, "Other Break"); newTask.setEnablePayOverride(true); newTask.setPayOverride(0.0f); tasks.add(newTask); newTask = new Task(currentJob, 3, "Travel"); tasks.add(newTask); newTask = new Task(currentJob, 4, "Admin"); tasks.add(newTask); newTask = new Task(currentJob, 5, "Sick Leave"); tasks.add(newTask); newTask = new Task(currentJob, 6, "Personal Time"); tasks.add(newTask); newTask = new Task(currentJob, 7, "Other"); tasks.add(newTask); newTask = new Task(currentJob, 8, "Holiday Pay"); tasks.add(newTask); try { File directory = Environment.getExternalStorageDirectory(); File backup; if (!oldFormat) backup = new File(directory, "Chronos_Backup.csv"); else backup = new File(directory, "Chronos_Backup.cvs"); if (!backup.exists()) { return false; } BufferedReader br = new BufferedReader(new FileReader(backup)); String strLine = br.readLine(); //id,date,name,task name, date in ms, job num, task num //1,Sun Mar 11 2012 15:46,null,Regular,1331498803269,1,1 while (strLine != null) { //Log.d(TAG, strLine); String[] parcedString = strLine.split(","); long time; int task; if (!oldFormat) { time = Long.parseLong(parcedString[4]); task = Integer.parseInt(parcedString[6]); } else { time = Long.parseLong(parcedString[1]); task = Integer.parseInt(parcedString[2]); //System.out.println(parcedString.length); if (parcedString.length > 4 && StringUtils.isNotBlank(parcedString[4])) { String noteContent = parcedString[4]; Note note = new Note(Chronos.getDateFromStartOfPayPeriod(currentJob, new DateTime(time)), currentJob, noteContent); notes.add(note); } } //Job iJob, Task iPunchTask, DateTime iTime punches.add(new Punch(currentJob, tasks.get(task - 1), new DateTime(time))); strLine = br.readLine(); } } catch (Exception e) { e.printStackTrace(); if (e != null && e.getCause() != null) { Log.e(TAG, e.getCause().toString()); } return false; } //Log.d(TAG, "Number of punches: " + punches.size()); try { Chronos chronos = new Chronos(context); TableUtils.dropTable(chronos.getConnectionSource(), Punch.class, true); //Punch - Drop all TableUtils.dropTable(chronos.getConnectionSource(), Task.class, true); //Task - Drop all TableUtils.dropTable(chronos.getConnectionSource(), Job.class, true); //Job - Drop all TableUtils.dropTable(chronos.getConnectionSource(), Note.class, true); //Note - Drop all //Recreate DB TableUtils.createTable(chronos.getConnectionSource(), Punch.class); //Punch - Create Table TableUtils.createTable(chronos.getConnectionSource(), Task.class); //Task - Create Table TableUtils.createTable(chronos.getConnectionSource(), Job.class); //Job - Create Table TableUtils.createTable(chronos.getConnectionSource(), Note.class); //Task - Create Table //recreate entries Dao<Task, String> taskDAO = chronos.getTaskDao(); Dao<Job, String> jobDAO = chronos.getJobDao(); Dao<Punch, String> punchDOA = chronos.getPunchDao(); Dao<Note, String> noteDOA = chronos.getNoteDao(); jobDAO.create(currentJob); for (Task t : tasks) { taskDAO.create(t); } for (Punch p : punches) { punchDOA.create(p); } HashMap<DateTime, Note> merger = new HashMap<DateTime, Note>(); for (Note n : notes) { merger.put(n.getTime(), n); } for (DateTime dt : merger.keySet()) { noteDOA.create(merger.get(dt)); } chronos.close(); } catch (Exception e) { Log.e(TAG, e.getMessage()); return false; } return true; }
From source file:com.esri.geoevent.solutions.processor.eventjoiner.EventJoinerProcessor.java
private GeoEvent CreateGeoEvent(HashMap<String, GeoEvent> rec) throws Exception { try {/*from w ww . ja v a 2s .c om*/ GeoEventCreator creator = messaging.createGeoEventCreator(); GeoEvent evt = creator.create(outDef.getGuid()); Set<String> keys = rec.keySet(); Iterator<String> it = keys.iterator(); while (it.hasNext()) { GeoEvent ge = rec.get(it.next()); List<FieldDefinition> fldDefs = ge.getGeoEventDefinition().getFieldDefinitions(); for (FieldDefinition fd : fldDefs) { String name = fd.getName(); FieldItem item = fldMgr.get(name); if (item.getCount() > 1) { if (name.equals(joinfield)) { evt.setField(joinfield, ge.getField(joinfield)); } else { String gedname = ge.getGeoEventDefinition().getName(); String groupName = name + "." + gedname; evt.setField(groupName, ge.getField(name)); } } else { evt.setField(name, ge.getField(name)); } } } evt.setProperty(GeoEventPropertyName.TYPE, "event"); evt.setProperty(GeoEventPropertyName.OWNER_ID, getId()); evt.setProperty(GeoEventPropertyName.OWNER_URI, definition.getUri()); return evt; } catch (MessagingException e) { LOG.error(e.getMessage()); throw (e); } catch (FieldException e) { LOG.error(e.getMessage()); throw (e); } catch (Exception e) { LOG.error(e.getMessage()); throw (e); } }
From source file:edu.csupomona.nlp.tool.crawler.Facebook.java
/** * Start crawling Facebook using keyword. * Crawled data includes information for Posts and their Comments. * Will be stored in the file for each Page. * @param keyword Keyword for searching * @throws JSONException//from w ww .j av a2 s. co m * @throws IOException */ public void crawl(String keyword) throws JSONException, IOException { //trace System.out.println("Start crawling with keyword=" + keyword); // get pages according to keyword HashMap<String, Page> pages = getPages(keyword, true); // crawl each page for (String pageId : pages.keySet()) { String filename = pageId + "_" + pages.get(pageId).getName().replaceAll(" ", "_") + "_" + pages.get(pageId).getLikes().toString() + ".txt"; String fullPath = BASE_DIR_ + keyword + "/" + filename; System.out.println(fullPath); // start writing FileWriter fw = new FileWriter(fullPath); try (BufferedWriter bw = new BufferedWriter(fw)) { // get posts from the page HashMap<String, Post> posts = getPosts(pages.get(pageId)); for (String postId : posts.keySet()) { Post post = posts.get(postId); // get likes HashMap<String, Like> likes = getLikes(post); int shareCount = (post.getSharesCount() != null ? post.getSharesCount() : 0); // write post information String line = "[P][" // type + post.getCreatedTime().toString() + "][" // date + post.getId() + "][" // id + likes.size() + "][" // number of likes + shareCount + "]:" // number of shares + post.getMessage() // content + "\n"; System.out.println(line); bw.write(line); // get comments HashMap<String, Comment> comments = getComments(post); // write comment information for (String comId : comments.keySet()) { Comment comment = comments.get(comId); line = "[C][" // type + comment.getCreatedTime().toString() + "][" // date + comment.getId() + "][" // id + comment.getLikeCount().toString() + "]:" // number of likes + comment.getMessage() + "\n"; System.out.println(line); bw.write(line); } } // save the time stamp DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); bw.write("#### Finished at: " + df.format(Calendar.getInstance().getTime()) + " ####\n"); } } }
From source file:com.sinosoft.one.showcase.rule.test.RuleServiceTest.java
@Test public void testSpecialClausService() { try {/*from ww w. j a va 2 s . co m*/ ProVehicle pv = new ProVehicle(); pv.setIsNewVehicle("01"); pv.setGlassType("303011001"); pv.setUseNatureCode("359000"); pv.setLicensePlateNo("121212"); String areaCode = "37000000"; KindInputBOM kib = new KindInputBOM(); ProOrder po = new ProOrder(); List<ProKind> proKinds = new ArrayList<ProKind>(0); ProKind pk1 = new ProKind(); pk1.setKindCode("030004"); proKinds.add(pk1); ProKind pk2 = new ProKind(); pk2.setKindCode("030012"); proKinds.add(pk2); ProKind pk3 = new ProKind(); pk3.setKindCode("030059"); // ProKind pk4 = new ProKind(); // pk4.setKindCode("030050"); proKinds.add(pk3); po.setProKinds(proKinds); kib.setPo(po); HashMap<String, String> global = new HashMap<String, String>(); ArrayList<String> kinds = new ArrayList<String>(); kinds.add("030004"); kinds.add("030012"); kinds.add("030059"); specialClausRuleService.executeRule(global, pv, kib, areaCode); // global.put("001", "test"); for (String key : global.keySet()) { System.out.println(key + ":" + global.get(key)); } System.out.println("change your rule....."); Thread.sleep(30 * 1000); specialClausRuleService.executeRule(global, pv, kib, areaCode); // global.put("001", "test"); for (String key : global.keySet()) { System.out.println(key + ":" + global.get(key)); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fast.servicescreen.server.RequestServiceImpl.java
@Override public String sendHttpRequest_DELETE(String url, HashMap<String, String> headers, String body) { //create client and method appending to url DefaultHttpClient httpclient_DELETE = new DefaultHttpClient(); httpdelete = new HttpDelete(url); //add all headers if (headers != null) { for (Iterator<String> iterator = headers.keySet().iterator(); iterator.hasNext();) { String tmpKey = (String) iterator.next(); String tmpVal = headers.get(tmpKey); httpdelete.addHeader(tmpKey, tmpVal); }/* ww w . ja v a 2 s.c om*/ } // Create response handler responseHandler = new BasicResponseHandler(); try { // send the POST request responseBody = httpclient_DELETE.execute(httpdelete, responseHandler); } catch (Exception e) { e.printStackTrace(); responseBody = "-1"; } return responseBody; }
From source file:gash.router.app.DemoApp.java
/*** * Two parts from two different concurrent threads we receive a file blocks * This constitues a parallel approach for file read *//*w w w . ja v a2s . com*/ public void rearrangeFileBlocks(HashMap<String, ArrayList<ByteString>> partitionedMap, File file) { try { FileOutputStream fOutputStream = new FileOutputStream(file); while (firstHalfValue == true && secondHalfValue == true) { for (String key : partitionedMap.keySet()) { if (key == "firstHalf") { this.firstHalfValue = true; firstHalfChunkList = partitionedMap.get("firstHalf"); } else { this.secondHalfValue = true; partitionedMap.get("secondHalf"); secondHalfChunkList = partitionedMap.get("secondHalf"); } } ; } ArrayList<ByteString> completeChunkList = new ArrayList<ByteString>(); completeChunkList.addAll(firstHalfChunkList); completeChunkList.addAll(secondHalfChunkList); ByteString bs = ByteString.copyFrom(completeChunkList); // File has been created after ordering the two seperate halves/ fOutputStream.write(bs.toByteArray()); fOutputStream.flush(); fOutputStream.close(); } catch (Exception e) { e.printStackTrace(); } System.out.flush(); }
From source file:com.clustercontrol.hinemosagent.util.AgentConnectUtil.java
/** * ???/*from w ww. ja v a 2 s. c o m*/ */ public static ArrayList<String> getValidAgent() { try { _agentCacheLock.writeLock(); HashMap<String, AgentInfo> agentMap = getAgentCache(); Set<AgentInfo> removedSet = new HashSet<AgentInfo>(); for (Entry<String, AgentInfo> entry : new HashSet<Entry<String, AgentInfo>>(agentMap.entrySet())) { if (!entry.getValue().isValid()) { removedSet.add(agentMap.remove(entry.getKey())); m_log.info("remove " + entry.getValue()); } } if (removedSet.size() > 0) { storeAgentCache(agentMap); } } finally { _agentCacheLock.writeUnlock(); } try { _agentCacheLock.readLock(); Map<String, AgentInfo> agentMap = getAgentCache(); ArrayList<String> list = new ArrayList<String>(); for (String fid : agentMap.keySet()) { list.add(fid); } return list; } finally { _agentCacheLock.readUnlock(); } }
From source file:com.handsome.frame.android.volley.stack.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request) throws IOException, AuthFailureError { HashMap<String, String> map = new HashMap<String, String>(); if (!TextUtils.isEmpty(mUserAgent)) { map.put(HTTP.USER_AGENT, mUserAgent); }// www . jav a 2s.com map.putAll(request.getHeaders()); URL parsedUrl = new URL(request.getUrl()); HttpURLConnection connection = openConnection(parsedUrl, request); for (String headerName : map.keySet()) { connection.addRequestProperty(headerName, map.get(headerName)); } if (HandsomeApplication.getCookies() != null) { HDLog.d(TAG + "-Req-Cookie:", HandsomeApplication.getCookies().toString()); connection.addRequestProperty("Cookie", HandsomeApplication.getCookies()); } else { HDLog.d(TAG + "-Req-Cookie:", "null"); } setConnectionParametersForRequest(connection, request); int responseCode = connection.getResponseCode(); if (responseCode == -1) { // -1 is returned by getResponseCode() if the response code could not be retrieved. // Signal to the caller that something was wrong with the connection. throw new IOException("Could not retrieve response code from HttpUrlConnection."); } StatusLine responseStatus = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), connection.getResponseCode(), connection.getResponseMessage()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); response.setEntity(entityFromConnection(connection)); for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { if (header.getKey().equalsIgnoreCase("Set-Cookie")) { List<String> cookies = header.getValue(); HashMap<String, HttpCookie> cookieMap = new HashMap<String, HttpCookie>(); for (String string : cookies) { List<HttpCookie> cookie = HttpCookie.parse(string); for (HttpCookie httpCookie : cookie) { cookieMap.put(httpCookie.getName(), httpCookie); } } HandsomeApplication.setCookies(cookieMap); HDLog.d(TAG + "-Rsp-Cookie:", HandsomeApplication.getCookies().toString()); } else { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } } return response; }