static Optional<Address> toAddress(JsonObject json, String name) { return Optional.ofNullable(json.getJsonObject(name)) .map(Address::new); }
private Set<String> extractThemeTrackSet(JsonObject talkObject, String code, String title) { Set<String> themeTrackSet = new HashSet<>(Arrays.asList(talkObject.getJsonObject("track").getString("id"))); if (!trackIdSet.containsAll(themeTrackSet)) { throw new IllegalStateException("The talk (" + title + ") with id (" + code + ") contains trackId + (" + trackIdSet + ") that doesn't exist in the trackIdSet."); } return themeTrackSet; }
@Override public Address parseAddress(JsonObject json) { JsonObject result = json.getJsonObject("response").getJsonObject("data"); if (result != null) { Address address = new Address(); if (result.getJsonObject("street_number") != null) { address.setHouse(result.getJsonObject("street_number").getString("name")); } if (result.getJsonObject("street_name") != null) { address.setStreet(result.getJsonObject("street_name").getString("name")); } if (result.getJsonObject("locality") != null) { address.setSettlement(result.getJsonObject("locality").getString("name")); } if (result.getJsonObject("county") != null) { address.setDistrict(result.getJsonObject("county").getString("name")); } if (result.getJsonObject("region") != null) { address.setState(result.getJsonObject("region").getString("name")); } if (result.getJsonObject("country") != null) { address.setCountry(result.getJsonObject("country").getString("name")); } if (result.getJsonObject("postcode") != null) { address.setPostcode(result.getJsonObject("postcode").getString("name")); } return address; } return null; }
private int changeAnnotation(String line, boolean remove){ int tokensNum = 0; JsonReader jsonReader = Json.createReader(new StringReader(line)); JsonObject objarr = jsonReader.readObject(); for(String label: objarr.keySet()) { JsonObject obj4label = objarr.getJsonObject(label); for(String sentid: obj4label.keySet()){ JsonArray tokenArry = obj4label.getJsonArray(sentid); for(JsonValue tokenid: tokenArry){ tokensNum ++; Data.sents.get(sentid).getTokens().get(Integer.parseInt(tokenid.toString())).set(humanLabelClasses.get(label), remove ? backgroundSymbol: label); } } } return tokensNum; }
JsonObject obj = objarr.getJsonObject(o); for (String st : obj.keySet()){ seedWords.put(st, new HashSet<>());
private void scheduleTalk(JsonObject timeslotObject, Room room, Timeslot timeslot) { Talk talk = talkCodeToTalkMap.get(timeslotObject.getJsonObject("talk").getString("id")); if (talk == null) { throw new IllegalStateException("The timeslot (" + timeslotObject.getString("slotId") + ") has a talk (" + timeslotObject.getJsonObject("talk").getString("id") + ") that does not exist in the talk list"); } if (talk.isPinnedByUser()) { throw new IllegalStateException("The timeslot (" + timeslotObject.getString("slotId") + ") has a talk (" + timeslotObject.getJsonObject("talk").getString("id") + ") that is already pinned by user at another timeslot (" + talk.getTimeslot().toString() + ")."); } talk.setRoom(room); talk.setTimeslot(timeslot); talk.setPinnedByUser(true); }
if (jsonValue.getValueType() != JsonValue.ValueType.OBJECT) { final JsonObjectBuilder requiresBuilder = Json.createObjectBuilder(); final JsonObject dependencies = packageJson.getJsonObject("dependencies"); for (String moduleName: dependencies.keySet()) { final JsonObject module = dependencies.getJsonObject(moduleName); final String version = module.getString("version"); requiresBuilder.add(moduleName, version); payloadBuilder.add("dependencies", packageJson.getJsonObject("dependencies")); payloadBuilder.add("install", Json.createArrayBuilder().build()); payloadBuilder.add("remove", Json.createArrayBuilder().build());
private void importTalkList() { this.talkCodeToTalkMap = new HashMap<>(); solution.setTalkList(new ArrayList<>()); String talksUrl = conferenceBaseUrl + "/talks"; LOGGER.debug("Sending a request to: {}", talksUrl); JsonArray talkArray = readJson(talksUrl, JsonReader::readObject).getJsonObject("talks").getJsonArray("accepted"); for (int i = 0; i < talkArray.size(); i++) { JsonObject talkObject = talkArray.getJsonObject(i); String code = talkObject.getString("id"); String title = talkObject.getString("title"); String talkTypeId = talkObject.getJsonObject("talkType").getString("id"); Set<String> themeTrackSet = extractThemeTrackSet(talkObject, code, title); String language = talkObject.getString("lang"); int audienceLevel = Integer.parseInt(talkObject.getString("audienceLevel").replaceAll("[^0-9]", "")); List<Speaker> speakerList = extractSpeakerList(talkObject, code, title); Set<String> contentTagSet = extractContentTagSet(talkObject); if (!Arrays.asList(IGNORED_TALK_TYPES).contains(talkTypeId)) { createTalk(code, title, talkTypeId, themeTrackSet, language, speakerList, audienceLevel, contentTagSet); } } }
@Override public void completed(JsonObject json) { if (json.containsKey("error")) { callback.onFailure(new GeolocationException(json.getJsonObject("error").getString("message"))); } else { JsonObject location = json.getJsonObject("location"); callback.onSuccess( location.getJsonNumber("lat").doubleValue(), location.getJsonNumber("lng").doubleValue(), json.getJsonNumber("accuracy").doubleValue()); } }
private AcmeChallenge respondToChallenges(AcmeAccount account, boolean staging, JsonObject authorization) throws AcmeException { List<AcmeChallenge> challenges = null; if (authorization.getString(STATUS).equals(PENDING)) { JsonObject identifier = authorization.getJsonObject(IDENTIFIER); JsonArray challengeArray = authorization.getJsonArray(CHALLENGES); challenges = new ArrayList<>(challengeArray.size()); for (JsonObject challenge : challengeArray.getValuesAs(JsonObject.class)) { challenges.add(new AcmeChallenge(AcmeChallenge.Type.forName(challenge.getString(TYPE)), challenge.getString(URL), challenge.getString(TOKEN), identifier.getString(TYPE), identifier.getString(VALUE))); } } if (challenges != null && ! challenges.isEmpty()) { AcmeChallenge selectedChallenge = proveIdentifierControl(account, challenges); try { sendPostRequestWithRetries(account, staging, selectedChallenge.getUrl(), false, getEncodedJson(EMPTY_PAYLOAD), HttpURLConnection.HTTP_OK); return selectedChallenge; } catch (AcmeException e) { cleanupAfterChallenge(account, selectedChallenge); throw e; } } return null; }
String parentPackage, Engine engine) throws AnalysisException { if (json.containsKey("dependencies")) { final JsonObject deps = json.getJsonObject("dependencies"); for (Map.Entry<String, JsonValue> entry : deps.entrySet()) { final JsonObject jo = (JsonObject) entry.getValue();
HttpURLConnection connection = sendGetRequest(account.getServerUrl(staging), HttpURLConnection.HTTP_OK, JSON_CONTENT_TYPE); JsonObject directoryJson = getJsonResponse(connection); JsonObject metadata = directoryJson.getJsonObject(META); if (metadata == null) { return null;
dependency.setLicense(json.getJsonObject("license").getString("type"));
@Override public Address parseAddress(JsonObject json) { JsonObject result = json .getJsonObject("Response") .getJsonArray("View") .getJsonObject(0) .getJsonArray("Result") .getJsonObject(0) .getJsonObject("Location") .getJsonObject("Address");
@Override public Address parseAddress(JsonObject json) { Address address = new Address(); JsonObject result = json .getJsonObject("geocoding_results") .getJsonArray("RESULTS") .getJsonObject(0); JsonObject resultAddress = result.getJsonObject("ADDRESS"); if (result.containsKey("formatted_address")) { address.setFormattedAddress(result.getString("formatted_address")); } if (resultAddress.containsKey("street_number")) { address.setStreet(resultAddress.getString("street_number")); } if (resultAddress.containsKey("street_name")) { address.setStreet(resultAddress.getString("street_name")); } if (resultAddress.containsKey("locality")) { address.setSettlement(resultAddress.getString("locality")); } if (resultAddress.containsKey("admin_1")) { address.setState(resultAddress.getString("admin_1")); } if (resultAddress.containsKey("country")) { address.setCountry(resultAddress.getString("country")); } return address; }
break; case 6: JsonObject adc = field.getJsonObject("AnalogueData"); if (adc.containsKey("1")) { position.set(Position.KEY_BATTERY, adc.getInt("1") * 0.001);
if (result != null) { JsonObject location = result.getJsonObject(0).getJsonArray("resources").getJsonObject(0).getJsonObject("address"); if (location != null) { Address address = new Address();
@Override public Address parseAddress(JsonObject json) { JsonArray result = json.getJsonArray("features"); if (result != null && !result.isEmpty()) { JsonObject location = result.getJsonObject(0).getJsonObject("properties"); Address address = new Address(); address.setCountry("FR"); if (location.containsKey("postcode")) { address.setPostcode(location.getString("postcode")); } if (location.containsKey("context")) { address.setDistrict(location.getString("context")); } if (location.containsKey("name")) { address.setStreet(location.getString("name")); } if (location.containsKey("city")) { address.setSettlement(location.getString("city")); } if (location.containsKey("housenumber")) { address.setHouse(location.getString("housenumber")); } if (location.containsKey("label")) { address.setFormattedAddress(location.getString("label")); } return address; } return null; }
@Override public Address parseAddress(JsonObject json) { JsonObject result = json.getJsonObject("address");
JsonArray result = json.getJsonArray("results"); if (result != null) { JsonObject location = result.getJsonObject(0).getJsonObject("components"); if (location != null) { Address address = new Address();