List of usage examples for com.google.gson JsonArray iterator
public Iterator<JsonElement> iterator()
From source file:com.cloudbees.gasp.fragment.GaspReviewsResponderFragment.java
License:Apache License
@Override public void onRESTResult(int code, String result) { // Here is where we handle our REST response. This is similar to the // LoaderCallbacks<D>.onLoadFinished() call from the previous tutorial. // Check to see if we got an HTTP 200 code and have some data. if (code == 200 && result != null) { JsonParser parser = new JsonParser(); JsonArray array = parser.parse(result).getAsJsonArray(); Iterator<JsonElement> reviews = array.iterator(); mList.clear();//w w w .j a va 2s . c o m while (reviews.hasNext()) { String theReview = reviews.next().toString(); mList.add(theReview); Log.d(TAG, "Review: " + theReview); } setReviews(); } else { Activity activity = getActivity(); if (activity != null) { Toast.makeText(activity, getResources().getString(R.string.gasp_network_error), Toast.LENGTH_SHORT) .show(); } } }
From source file:com.collective.celos.ci.testing.fixtures.compare.json.JsonElementConstructor.java
License:Apache License
private JsonArray deepCopyJsonArray(String path, JsonArray el, Set<String> ignorePaths) { JsonArray array = new JsonArray(); Iterator<JsonElement> element1Iterator = el.iterator(); while (element1Iterator.hasNext()) { array.add(deepCopy(path, element1Iterator.next(), ignorePaths)); }//from w w w. j a v a 2 s .c o m return array; }
From source file:com.couchbase.plugin.basement.api.Client.java
License:Open Source License
private void addJsonElement(String key, JsonElement value, HashMap<String, Object> map) { if (value.isJsonArray()) { JsonArray jsonArray = value.getAsJsonArray(); ArrayList listAsValue = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> listElementMap = new HashMap<String, Object>(); Iterator<JsonElement> jsonArrayIterator = jsonArray.iterator(); while (jsonArrayIterator.hasNext()) { JsonElement jsonElement = jsonArrayIterator.next(); listAsValue.add(parse(jsonElement.toString())); }/*www .ja v a2 s .com*/ map.put(key, listAsValue); } else if (value.isJsonPrimitive()) { // check the type using JsonPrimitive // TODO: check all types JsonPrimitive jsonPrimitive = value.getAsJsonPrimitive(); if (jsonPrimitive.isNumber()) { map.put(key, jsonPrimitive.getAsInt()); } else { map.put(key, jsonPrimitive.getAsString()); } } else { map.put(key, parse(value.toString())); } }
From source file:com.dangdang.ddframe.job.cloud.scheduler.mesos.FacadeService.java
License:Apache License
/** * ?360?.//w w w. j a va 2s.c o m * * @param jobName ?? * @return 360?? */ public Collection<TaskFullViewInfo> getTaskFullViewInfo(final String jobName) { Optional<CloudJobConfiguration> cloudJobConfigurationOptional = this.load(jobName); CloudJobConfiguration cloudJobConfiguration; String appName = null; CloudJobExecutionType cloudJobExecutionType = null; if (cloudJobConfigurationOptional.isPresent()) { cloudJobConfiguration = cloudJobConfigurationOptional.get(); appName = cloudJobConfiguration.getAppName(); cloudJobExecutionType = cloudJobConfiguration.getJobExecutionType(); } Collection<TaskContext> runningTasks = this.getJobRunningTasks(jobName); Collection<FailoverTaskInfo> failoverTasks = this.getJobFailoverTasks(jobName); Collection<TaskFullViewInfo> result = Lists.newArrayList(); if (runningTasks.size() > 0) { for (TaskContext each : runningTasks) { String statusInfo = RUNNING_STATUS; if (null != cloudJobExecutionType && cloudJobExecutionType.equals(CloudJobExecutionType.DAEMON) && !this.getRunningTaskInZookeeper(each.getId())) { statusInfo = RUNNING_STATUS_COMMENT; } String taskId = each.getId(); result.add(new TaskFullViewInfo(taskId, this.getHostNameByTaskId(taskId), statusInfo, mesosStateService.getMesosSandbox(each.getId()))); } } if (failoverTasks.size() > 0) { JsonArray slaves = mesosSlaveService.findAllSlaves(); for (FailoverTaskInfo each : failoverTasks) { final TaskContext taskContext = TaskContext.from(each.getOriginalTaskId()); String serverIp = ""; Optional<JsonElement> slaveOptional = Iterators.tryFind(slaves.iterator(), new Predicate<JsonElement>() { @Override public boolean apply(final JsonElement input) { return input.getAsJsonObject().get("id").getAsString() .equals(taskContext.getSlaveId()); } }); if (slaveOptional.isPresent()) { serverIp = slaveOptional.get().getAsJsonObject().get("hostname").getAsString(); } result.add(new TaskFullViewInfo(taskContext.getId(), serverIp, FAILOVER_STATUS, mesosStateService.getMesosSandbox(each.getOriginalTaskId()))); } } return result; }
From source file:com.dangdang.ddframe.job.cloud.scheduler.state.running.RunningService.java
License:Apache License
/** * ??.//from w w w . j av a2s . c o m */ public void start() { clear(); List<String> jobKeys = regCenter.getChildrenKeys(RunningNode.ROOT); for (String each : jobKeys) { if (!configurationService.load(each).isPresent()) { remove(each); continue; } RUNNING_TASKS.put(each, Sets.newCopyOnWriteArraySet( Lists.transform(regCenter.getChildrenKeys(RunningNode.getRunningJobNodePath(each)), new Function<String, TaskContext>() { @Override public TaskContext apply(final String input) { return TaskContext .from(regCenter.get(RunningNode.getRunningTaskNodePath( TaskContext.MetaInfo.from(input).toString()))); } }))); } if (RUNNING_TASKS.isEmpty()) { return; } Executors .newSingleThreadExecutor( new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Init-RunningService-%d").build()) .execute(new Runnable() { @Override public void run() { JsonArray slaves; while ((slaves = mesosSlaveService.findAllSlaves()).size() < 1) { try { Thread.sleep(5000); } catch (final InterruptedException ignored) { } } for (Set<TaskContext> each : RUNNING_TASKS.values()) { for (final TaskContext taskContext : each) { Optional<JsonElement> slaveOptional = Iterators.tryFind(slaves.iterator(), new Predicate<JsonElement>() { @Override public boolean apply(final JsonElement input) { return input.getAsJsonObject().get("id").getAsString() .equals(taskContext.getSlaveId()); } }); if (slaveOptional.isPresent()) { TASK_HOSTNAME_MAPPER.putIfAbsent(taskContext.getId(), slaveOptional.get().getAsJsonObject().get("hostname").getAsString()); } } } } }); }
From source file:com.example.com.benasque2014.mercurio.FamiliaMapaFragment.java
License:Apache License
private void startUpdateHandler() { if (updateRunnable == null) { updateRunnable = new Runnable() { @Override/* w w w.j ava2 s .c o m*/ public void run() { // llamada con handler // en el handler hacer CCPClient.verBuses(recorrido.getCodigo(), new CCPClient.CCPClientHandle() { @Override public void result(boolean error, JsonArray data) { if (data == null || error) return; flushBuses(); Iterator<JsonElement> i = data.iterator(); while (i.hasNext()) { Bus b = new Bus(); JsonObject j = i.next().getAsJsonObject(); b.Nombre = j.get("Nombre").getAsString(); b.IdTelefono = j.get("IdTelefono").getAsString(); b.Codigo = j.get("Codigo").getAsString(); b.Mensaje = j.get("Mensaje").getAsString(); String[] posiciones = j.get("Posiciones").getAsString().split(":"); if (b.Posiciones == null) b.Posiciones = new ArrayList<SLatLng>(); for (int w = 0; w < posiciones.length; w++) { String[] pos = posiciones[w].split(","); SLatLng ll = new SLatLng(Double.parseDouble(pos[0]), Double.parseDouble(pos[1])); b.Posiciones.add(ll); } addBus(b); } updateHandler.postDelayed(updateRunnable, UPDATE_DELAY); } }); } }; } updateHandler.removeMessages(0); updateHandler.post(updateRunnable); }
From source file:com.github.dpsm.android.print.gson.model.GsonPrinterSearchResult.java
License:Apache License
public GsonPrinterSearchResult(final JsonObject jsonObject) { super(jsonObject); printers = new LinkedList<GsonPrinter>(); final JsonArray printersArray = mJsonObject.getAsJsonArray(PRINTERS); if (printersArray != null) { final Iterator<JsonElement> iterator = printersArray.iterator(); while (iterator.hasNext()) { printers.add(new GsonPrinter(iterator.next().getAsJsonObject())); }//from w w w.j av a2 s. c om } }
From source file:com.github.zhanhb.ishadowsocks.Application.java
License:Open Source License
public static void main(String[] args) throws IOException { try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) { WebClientOptions options = webClient.getOptions(); options.setCssEnabled(false);//w ww .j a va 2 s. c o m options.setDoNotTrackEnabled(true); options.setDownloadImages(false); options.setGeolocationEnabled(false); options.setJavaScriptEnabled(false); options.setThrowExceptionOnFailingStatusCode(false); options.setThrowExceptionOnScriptError(false); HtmlPage page = webClient.getPage("https://xxx.ishadowx.org"); Stream<JsonObject> parsed = page.querySelectorAll("#portfolio .portfolio-item").stream() .map(node -> node.getTextContent().trim()).map(Server::newServer).filter(Objects::nonNull) .map(Server::toJsonObject); if (args.length > 0) { Path path = Paths.get(args[0]); GuiConfigs guiConfigs = GuiConfigs.parse(path); JsonArray configs = guiConfigs.getConfigs(); Collection<JsonObject> servers = Stream.concat(StreamSupport .stream(Spliterators.spliterator(configs.iterator(), configs.size(), Spliterator.ORDERED), false) .map(JsonElement::getAsJsonObject), parsed).collect(Collectors.toMap(jo -> { return jo.get("server").getAsString() + ":" + jo.get("server_port").getAsString(); }, identity(), (a, b) -> b, LinkedHashMap::new)).values(); guiConfigs.setConfigs(servers); guiConfigs.writeTo(path); } else { parsed.forEach(System.out::println); } } }
From source file:com.google.dart.server.generated.types.AddContentOverlay.java
License:Open Source License
public static List<AddContentOverlay> fromJsonArray(JsonArray jsonArray) { if (jsonArray == null) { return EMPTY_LIST; }/*from ww w .j ava 2 s . c o m*/ ArrayList<AddContentOverlay> list = new ArrayList<AddContentOverlay>(jsonArray.size()); Iterator<JsonElement> iterator = jsonArray.iterator(); while (iterator.hasNext()) { list.add(fromJson(iterator.next().getAsJsonObject())); } return list; }
From source file:com.google.dart.server.generated.types.AnalysisError.java
License:Open Source License
public static List<AnalysisError> fromJsonArray(JsonArray jsonArray) { if (jsonArray == null) { return EMPTY_LIST; }/*from w w w . j ava 2 s .c om*/ ArrayList<AnalysisError> list = new ArrayList<AnalysisError>(jsonArray.size()); Iterator<JsonElement> iterator = jsonArray.iterator(); while (iterator.hasNext()) { list.add(fromJson(iterator.next().getAsJsonObject())); } return list; }