List of usage examples for org.json.simple JSONArray iterator
public Iterator<E> iterator()
From source file:net.phyloviz.goeburst.GoeBurstItemFactory.java
private void updateEdgeStats(JSONArray edgesStatsArray, Map<Integer, GOeBurstClusterWithStats> groups) { for (Iterator<JSONObject> esIt = edgesStatsArray.iterator(); esIt.hasNext();) { JSONObject edgeStat = esIt.next(); Integer groupId = (int) (long) edgeStat.get("group"); JSONArray ne = (JSONArray) edgeStat.get("ne"); JSONArray fne = (JSONArray) edgeStat.get("fne"); JSONArray xLV = (JSONArray) edgeStat.get("xLV"); Integer withoutTies = (int) (long) edgeStat.get("withoutTies"); GOeBurstClusterWithStats group = groups.get(groupId); group.setEdgeTieStatsWithoutTies(withoutTies); int i = 0; for (; i < ne.size(); i++) { group.setEdgeTieStatsNE(i, (int) (long) ne.get(i)); group.setEdgeTieStatsFNE(i, (int) (long) fne.get(i)); group.setEdgeTieStatsNE(i, (int) (long) xLV.get(i)); }/*from ww w . j av a2 s .c om*/ for (; i < xLV.size(); i++) group.setEdgeTieStatsXlv(i, (int) (long) xLV.get(i)); } }
From source file:msgclient.ServerConnection.java
public ArrayList<EncryptedMessage> lookupMessages() { ArrayList<EncryptedMessage> result = new ArrayList<EncryptedMessage>(); JSONObject jsonObject = makeGetToServer(MESSAGELOOKUP_PATH + "/" + mUsername); if (jsonObject == null) { return null; }//from w w w .j a v a 2 s . c om try { long numMessages = (long) jsonObject.get("numMessages"); if (numMessages <= 0) { return result; } JSONArray msg = (JSONArray) jsonObject.get("messages"); Iterator<JSONObject> iterator = msg.iterator(); while (iterator.hasNext()) { JSONObject nextMessage = iterator.next(); long sentTime = (long) nextMessage.get("sentTime"); long messageID = (long) nextMessage.get("messageID"); String encryptedMessage = (String) nextMessage.get("message"); String fromID = (String) nextMessage.get("senderID"); if (encryptedMessage != null) { if (encryptedMessage.trim().isEmpty() == false) { EncryptedMessage eMsg = new EncryptedMessage(fromID.trim(), mUsername.trim(), encryptedMessage.trim(), sentTime, messageID); result.add(eMsg); } } } } catch (Exception e) { // Some kind of problem return null; } // Return the resulting list return result; }
From source file:net.phyloviz.upgma.json.UPGMAItemFactory.java
private Map<Integer, UPGMAUnionNode> createUnions(JSONArray union, Map<Integer, UPGMALeafNode> leafs) { int size = leafs.size(); HashMap<Integer, UPGMAUnionNode> unions = new HashMap(size); for (Iterator<JSONObject> it = union.iterator(); it.hasNext();) { JSONObject l = it.next();// w w w. j a v a 2 s . co m float distance = (float) (double) l.get("distance"); Integer uid = (int) (long) l.get("uid"); Integer n1 = (int) (long) l.get("leftID"); Integer n2 = (int) (long) l.get("rightID"); NodeType node1 = n1 >= size ? unions.get(n1) : leafs.get(n1); NodeType node2 = n2 >= size ? unions.get(n2) : leafs.get(n2); unions.put(uid, new UPGMAUnionNode(uid, node1, node2, distance, leafs.size(), node1.getNodeIdx() - 1)); } return unions; }
From source file:com.shootoff.session.io.JSONSessionReader.java
public Map<String, List<Event>> load() { Map<String, List<Event>> events = new HashMap<String, List<Event>>(); try {/*from w w w . j av a 2 s . co m*/ JSONObject session = (JSONObject) new JSONParser() .parse(new InputStreamReader(new FileInputStream(sessionFile), "UTF-8")); JSONArray cameras = (JSONArray) session.get("cameras"); @SuppressWarnings("unchecked") Iterator<JSONObject> itCameras = cameras.iterator(); while (itCameras.hasNext()) { JSONObject camera = itCameras.next(); String cameraName = (String) camera.get("name"); events.put(cameraName, new ArrayList<Event>()); JSONArray cameraEvents = (JSONArray) camera.get("events"); @SuppressWarnings("unchecked") Iterator<JSONObject> itEvents = cameraEvents.iterator(); while (itEvents.hasNext()) { JSONObject event = itEvents.next(); String eventType = (String) event.get("type"); switch (eventType) { case "shot": Color c; if (event.get("color").equals("0xff0000ff")) { c = Color.RED; } else { c = Color.GREEN; } Shot shot = new Shot(c, (double) event.get("x"), (double) event.get("y"), (Long) event.get("shotTimestamp"), ((Long) event.get("markerRadius")).intValue()); boolean isMalfunction = (boolean) event.get("isMalfunction"); boolean isReload = (boolean) event.get("isReload"); Optional<Integer> targetIndex; int index = ((Long) event.get("targetIndex")).intValue(); if (index == -1) { targetIndex = Optional.empty(); } else { targetIndex = Optional.of(index); } Optional<Integer> hitRegionIndex; index = ((Long) event.get("hitRegionIndex")).intValue(); if (index == -1) { hitRegionIndex = Optional.empty(); } else { hitRegionIndex = Optional.of(index); } Optional<String> videoString = Optional.ofNullable((String) event.get("videos")); events.get(cameraName).add(new ShotEvent(cameraName, (Long) event.get("timestamp"), shot, isMalfunction, isReload, targetIndex, hitRegionIndex, videoString)); break; case "targetAdded": events.get(cameraName).add(new TargetAddedEvent(cameraName, (Long) event.get("timestamp"), (String) event.get("name"))); break; case "targetRemoved": events.get(cameraName).add(new TargetRemovedEvent(cameraName, (Long) event.get("timestamp"), ((Long) event.get("index")).intValue())); break; case "targetResized": events.get(cameraName) .add(new TargetResizedEvent(cameraName, (Long) event.get("timestamp"), ((Long) event.get("index")).intValue(), (Double) event.get("newWidth"), (Double) event.get("newHeight"))); break; case "targetMoved": events.get(cameraName).add(new TargetMovedEvent(cameraName, (Long) event.get("timestamp"), ((Long) event.get("index")).intValue(), ((Long) event.get("newX")).intValue(), ((Long) event.get("newY")).intValue())); break; case "exerciseFeedMessage": events.get(cameraName).add(new ExerciseFeedMessageEvent(cameraName, (Long) event.get("timestamp"), (String) event.get("message"))); break; } } } } catch (IOException | ParseException e) { logger.error("Error reading JSON session", e); } return events; }
From source file:net.phyloviz.goeburst.GoeBurstItemFactory.java
private Map<Integer, GOeBurstNodeExtended> getNodes(Map<String, GOeBurstNodeExtended> td, JSONArray onodes) { Map<Integer, GOeBurstNodeExtended> nodes = new HashMap<>(); for (Iterator<JSONObject> nIt = onodes.iterator(); nIt.hasNext();) { JSONObject node = nIt.next();/*w w w . ja va2 s . c o m*/ Integer uid = (int) (long) node.get("id"); String profile = (String) node.get("profile"); JSONArray group_lvs = (JSONArray) node.get("group-lvs"); JSONArray graph_lvs = (JSONArray) node.get("graph-lvs"); JSONArray slvs = (JSONArray) node.get("slvs"); JSONArray dlvs = (JSONArray) node.get("dlvs"); GOeBurstNodeExtended n = td.get(profile); n.setLV(SLV, (int) (long) group_lvs.get(SLV)); n.setLV(DLV, (int) (long) group_lvs.get(DLV)); n.setLV(TLV, (int) (long) group_lvs.get(TLV)); n.setLV(SAT, (int) (long) group_lvs.get(SAT)); goeburstStats.setSTlvs(n, (int) (long) graph_lvs.get(SLV), (int) (long) graph_lvs.get(DLV), (int) (long) graph_lvs.get(TLV), (int) (long) graph_lvs.get(SAT)); for (Iterator profileIt = slvs.iterator(); profileIt.hasNext();) { String p = (String) profileIt.next(); GOeBurstNodeExtended pNode = td.get(p); n.addSLV(pNode); } for (Iterator profileIt = dlvs.iterator(); profileIt.hasNext();) { String p = (String) profileIt.next(); GOeBurstNodeExtended pNode = td.get(p); n.addDLV(pNode); } nodes.put(uid, n); } return nodes; }
From source file:luceneprueba.Reader.java
public void retriveReviewsByDate() { try {/*from ww w . j a v a 2 s . c om*/ BufferedReader br = new BufferedReader(new FileReader("files/output/review_date.json")); JSONParser parser = new JSONParser(); JSONArray datesReviews = (JSONArray) parser.parse(br.readLine()); Iterator i = datesReviews.iterator(); while (i.hasNext()) { JSONObject json = (JSONObject) i.next(); System.out.println("Recuperando los top-60 reviews del da " + (String) json.get("date")); searchOnIndex((String) json.get("review"), (String) json.get("date")); } br.close(); //indexReader.close(); } catch (FileNotFoundException | org.json.simple.parser.ParseException ex) { for (StackTraceElement st : ex.getStackTrace()) { System.out.println(st.toString()); } System.out.println(ex.getLocalizedMessage()); } catch (IOException ex) { for (StackTraceElement st : ex.getStackTrace()) { System.out.println(st.toString()); } System.out.println(ex.getLocalizedMessage()); } }
From source file:de.ingrid.external.gemet.GEMETMapper.java
/** * Map Concepts (JSON) to API Terms. Only use concepts containing keywords. * //from w w w .jav a 2s .c o m * @param jsonArrayList * JSON concepts from GEMET request * @param keywordsFilter * filter concepts: only use concepts containing all keywords. * Pass null if no filter. * @param locale * only used when filtering * @return mapped API Terms */ public List<Term> mapToTermsWithKeywordsFilter(List<JSONArray> jsonArrayList, String[] keywordsFilter, Locale locale) { List<Term> resultList = new ArrayList<Term>(); for (JSONArray jsonArray : jsonArrayList) { Iterator<JSONObject> iterator = jsonArray.iterator(); while (iterator.hasNext()) { Term myTerm = mapToTerm(iterator.next()); boolean addTerm = true; // check whether term contains all keywords if keywords passed ! if (keywordsFilter != null) { for (String keywordFilter : keywordsFilter) { if (!myTerm.getName().toLowerCase(locale) .contains(keywordFilter.trim().toLowerCase(locale))) { addTerm = false; break; } } } // add term if not already present if (addTerm) { if (!resultList.contains(myTerm)) { resultList.add(myTerm); } } } } return resultList; }
From source file:fr.free.movierenamer.scrapper.impl.movie.TracktScrapper.java
@Override protected List<Movie> searchMedia(URL searchUrl, AvailableLanguages language) throws Exception { Map<Integer, Movie> resultSet = new LinkedHashMap<Integer, Movie>(); JSONArray json = URIRequest.getJsonArrayDocument(searchUrl.toURI()); Iterator<JSONObject> iterator = json.iterator(); JSONObject node;//w w w . j ava 2 s. c o m while (iterator.hasNext()) { node = iterator.next(); int id = JSONUtils.selectInteger("tmdb_id", node); String imId = JSONUtils.selectString("imdb_id", node); IdInfo imdbId = null; if (imId != null && !imId.equals("")) { imdbId = new IdInfo(Integer.parseInt(imId.replace("tt", "")), ScrapperUtils.AvailableApiIds.IMDB); } String title = JSONUtils.selectString("title", node); Integer year = -1; String syear = JSONUtils.selectString("year", node); if (syear != null && !syear.equals("")) { year = Integer.parseInt(syear); } JSONObject posterNode = JSONUtils.selectObject("images", node); String imageNode = null; if (posterNode != null) { imageNode = JSONUtils.selectString("poster", posterNode); } URL thumb = null; try { if (imageNode != null) { thumb = new URL(imageNode); } } catch (Exception e) { Settings.LOGGER.log(Level.WARNING, "Invalid image: " + imageNode, e); } if (!resultSet.containsKey(id)) { resultSet.put(id, new Movie(imdbId, new IdInfo(id, ScrapperUtils.AvailableApiIds.THEMOVIEDB), title, title, thumb, year)); } } return new ArrayList<Movie>(resultSet.values()); }
From source file:eumetsat.pn.elasticsearch.webapp.ElasticsearchApp.java
@Override protected Map<String, Object> describeProduct(String id) throws MalformedURLException, ParseException { Map<String, Object> data = new HashMap<>(); //create the url with the id passed in argument URL url = new URL(this.productEndpointUrlString + id); HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> params = new HashMap<>(); String body = null;/*from www.j a v a 2 s . c om*/ boolean debug = true; WebResponse response = rClient.doGetRequest(url, headers, params, body, debug); log.trace("response = " + response); JSONParser parser = new JSONParser(); JSONObject jsObj = (JSONObject) parser.parse(response.body); Map<String, Object> identificationInfo = ((Map<String, Object>) (((Map<String, Object>) jsObj .get("_source")).get("identificationInfo"))); data.put("id", id); data.put("title", identificationInfo.get("title")); if (identificationInfo.containsKey("keywords")) { data.put("abstract", identificationInfo.get("abstract")); } if (identificationInfo.containsKey("keywords")) { JSONArray keywords = (JSONArray) identificationInfo.get("keywords"); data.put("keywords", Joiner.on(", ").join(keywords.iterator())); } if (identificationInfo.containsKey("thumbnail")) { data.put("thumbnail", identificationInfo.get("thumbnail").toString()); } if (identificationInfo.containsKey("status")) { data.put("status", identificationInfo.get("status").toString()); } if (identificationInfo.containsKey("satellite")) { data.put("satellite", identificationInfo.get("satellite").toString()); } return data; }
From source file:net.phyloviz.goeburst.GoeBurstItemFactory.java
private Map<Integer, EdgeInfo> createEdges(JSONArray edgesArray, Map<Integer, GOeBurstNodeExtended> nodes) { HashMap<Integer, EdgeInfo> edges = new HashMap(); for (Iterator<JSONObject> eIt = edgesArray.iterator(); eIt.hasNext();) { JSONObject edge = eIt.next();/*from w w w.j av a2 s . c o m*/ Integer id = (int) (long) edge.get("id"); Integer u = (int) (long) edge.get("u"); Integer v = (int) (long) edge.get("v"); boolean visible = (Boolean) edge.get("visible"); Integer maxTie = (int) (long) edge.get("maxTie"); Edge<GOeBurstNodeExtended> e = new Edge<>(nodes.get(u), nodes.get(v)); e.setVisible(visible); EdgeInfo ei = new EdgeInfo(e, maxTie); edges.put(id, ei); } return edges; }