Example usage for com.google.gson JsonArray addAll

List of usage examples for com.google.gson JsonArray addAll

Introduction

In this page you can find the example usage for com.google.gson JsonArray addAll.

Prototype

public void addAll(JsonArray array) 

Source Link

Document

Adds all the elements of the specified array to self.

Usage

From source file:com.shinwootns.common.infoblox.InfobloxWAPIHandler.java

public NextPageData getLeaseIPFirst(int splitCount, String network) throws UnknownHostException {

    if (restClient == null)
        return null;

    JsonArray resultArray = new JsonArray();

    StringBuilder sb = new StringBuilder();

    sb.append("/wapi/v2.3/lease");
    sb.append("?_paging=1");
    sb.append("&_max_results=").append(splitCount);
    sb.append("&_return_as_object=1");
    sb.append("&_return_type=json");

    IPNetwork ipNetwork = new IPNetwork(network);
    sb.append("&address%3E=").append(ipNetwork.getStartIP().toString()); // > = %3E
    sb.append("&address%3C=").append(ipNetwork.getEndIP().toString()); // < = %3C

    sb.append("&_return_fields=").append("address,network,binding_state").append(",starts,ends")
            .append(",never_ends,never_starts").append(",ipv6_duid,ipv6_iaid,ipv6_preferred_lifetime")
    //.append(",protocol,client_hostname,hardware,username")
    //.append(",discovered_data.last_discovered")
    ;//  w  ww. j  a v  a2 s .co m

    String value = restClient.Get(sb.toString());

    if (value == null)
        return null;

    // Change unescape-unicode
    value = StringUtils.unescapeUnicodeString(value);

    // JsonObject Parser
    JsonObject jObj = JsonUtils.parseJsonObject(value);

    if (jObj == null)
        return null;

    // next_page_id
    String nextPageId = JsonUtils.getValueToString(jObj, "next_page_id", "");

    // result
    JsonArray jIPAddr = (JsonArray) jObj.get("result");

    if (jIPAddr.size() > 0)
        resultArray.addAll(jIPAddr);

    return new NextPageData(resultArray, nextPageId);
}

From source file:com.shinwootns.common.infoblox.InfobloxWAPIHandler.java

public NextPageData getLeaseIPNext(int splitCount, String nextPageId) {

    if (restClient == null)
        return null;

    if (nextPageId == null || nextPageId.isEmpty())
        return null;

    //System.out.println(nextPageId);

    JsonArray resultArray = new JsonArray();

    StringBuilder sb = new StringBuilder();

    sb.append("/wapi/v2.3/lease");
    sb.append("?_return_type=json");
    sb.append("&_max_results=").append(splitCount);
    sb.append("&_page_id=").append(nextPageId);

    String value = restClient.Get(sb.toString());

    if (value == null)
        return null;

    // Change unescape-unicode
    value = StringUtils.unescapeUnicodeString(value);

    // JsonObject Parser
    JsonObject jObj = JsonUtils.parseJsonObject(value);

    if (jObj == null)
        return null;

    // next_page_id
    nextPageId = JsonUtils.getValueToString(jObj, "next_page_id", "");

    // result/* w  ww .  j a  va 2  s. c om*/
    JsonArray jIPAddr = (JsonArray) jObj.get("result");

    resultArray.addAll(jIPAddr);

    return new NextPageData(resultArray, nextPageId);
}

From source file:com.sowhoyou.twitchbot.chatbot.BotHelper.java

License:Open Source License

public void getModList() {
    try {/*from  w w  w .j  av a2s.com*/
        URL url = new URL(("http://tmi.twitch.tv/group/user/"
                + this.getBot().getBotConfig().getBotChannel().toLowerCase().replace("#", "") + "/chatters"));
        String jText = IOUtils.toString(url);
        JsonParser jPhraser = new JsonParser();
        JsonArray jArray = new JsonArray();
        JsonObject jObject = jPhraser.parse(jText).getAsJsonObject();
        String streamObject = jObject.get("chatters").toString();
        jObject = jPhraser.parse(streamObject).getAsJsonObject();
        String moderators = jObject.get("moderators").toString();
        jArray.addAll(jPhraser.parse(moderators).getAsJsonArray());
        StringBuilder sb = new StringBuilder();
        int viewerCount = 0;
        for (JsonElement s : jArray.getAsJsonArray()) {
            User u = this.getBot().getUserList()
                    .getUser(s.toString().toLowerCase().replace('"', ' ').replace(" ", ""));
            u.setMod(true);
            sb.append(", " + s.toString().replace('"', ' ').replace(" ", ""));
            viewerCount++;
        }
        if (viewerCount > 0) {
            this.getBot().sendDebug("Moderators: [" + sb.toString().replaceFirst(", ", "") + "]");
        } else {
            this.getBot().sendDebug("There are No Visable Moderators!");
        }
    } catch (Exception e) {
    }
}

From source file:com.sowhoyou.twitchbot.chatbot.BotHelper.java

License:Open Source License

public String getModListToString() {
    try {//from   w w w  .j a v  a 2 s.c o  m
        URL url = new URL(("http://tmi.twitch.tv/group/user/"
                + this.getBot().getBotConfig().getBotChannel().toLowerCase().replace("#", "") + "/chatters"));
        String jText = IOUtils.toString(url);
        JsonParser jPhraser = new JsonParser();
        JsonArray jArray = new JsonArray();
        JsonObject jObject = jPhraser.parse(jText).getAsJsonObject();
        String streamObject = jObject.get("chatters").toString();
        jObject = jPhraser.parse(streamObject).getAsJsonObject();
        String moderators = jObject.get("moderators").toString();
        jArray.addAll(jPhraser.parse(moderators).getAsJsonArray());
        StringBuilder sb = new StringBuilder();
        int viewerCount = 0;
        for (JsonElement s : jArray.getAsJsonArray()) {
            sb.append(", " + s.toString().replace('"', ' ').replace(" ", ""));
            viewerCount++;
        }
        if (viewerCount > 0) {
            return ("Moderators: [" + sb.toString().replaceFirst(", ", "") + "]");
        } else {
            return ("There are No Visable Moderators!");
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:com.sowhoyou.twitchbot.chatbot.BotHelper.java

License:Open Source License

public void getViewerList() {
    try {//from w w w.j a  v  a  2  s . c o m
        URL url = new URL(("http://tmi.twitch.tv/group/user/"
                + this.getBot().getBotConfig().getBotChannel().toLowerCase().replace("#", "") + "/chatters"));
        String jText = IOUtils.toString(url);
        JsonParser jPhraser = new JsonParser();
        JsonArray jArray = new JsonArray();
        JsonObject jObject = jPhraser.parse(jText).getAsJsonObject();
        String streamObject = jObject.get("chatters").toString();
        jObject = jPhraser.parse(streamObject).getAsJsonObject();
        String viewers = jObject.get("viewers").toString();
        jArray.addAll(jPhraser.parse(viewers).getAsJsonArray());
        StringBuilder sb = new StringBuilder();
        int viewerCount = 0;
        for (JsonElement s : jArray.getAsJsonArray()) {
            User u = this.getBot().getUserList()
                    .getUser(s.toString().toLowerCase().replace('"', ' ').replace(" ", ""));
            u.setMod(false);
            sb.append(", " + s.toString().replace('"', ' ').replace(" ", ""));
            viewerCount++;
        }
        if (viewerCount > 0) {
            this.getBot().sendDebug("Viewers: [" + sb.toString().replaceFirst(", ", "") + "]");
        } else {
            this.getBot().sendDebug("There are No Visable Viewers!");
        }
    } catch (Exception e) {
    }
}

From source file:com.sowhoyou.twitchbot.chatbot.BotHelper.java

License:Open Source License

public String getViewerListToString() {
    try {//  w w w  . java  2s . co m
        URL url = new URL(("http://tmi.twitch.tv/group/user/"
                + this.getBot().getBotConfig().getBotChannel().toLowerCase().replace("#", "") + "/chatters"));
        String jText = IOUtils.toString(url);
        JsonParser jPhraser = new JsonParser();
        JsonArray jArray = new JsonArray();
        JsonObject jObject = jPhraser.parse(jText).getAsJsonObject();
        String streamObject = jObject.get("chatters").toString();
        jObject = jPhraser.parse(streamObject).getAsJsonObject();
        String viewers = jObject.get("viewers").toString();
        jArray.addAll(jPhraser.parse(viewers).getAsJsonArray());
        StringBuilder sb = new StringBuilder();
        int viewerCount = 0;
        for (JsonElement s : jArray.getAsJsonArray()) {
            sb.append(", " + s.toString().replace('"', ' ').replace(" ", ""));
            viewerCount++;
        }
        if (viewerCount > 0) {
            return ("Viewers: [" + sb.toString().replaceFirst(", ", "") + "]");
        } else {
            return ("There are No Visable Viewers!");
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:eu.betaas.taas.contextmanager.api.impl.ThingsServiceManagerImpl.java

License:Apache License

private JsonObject setContextThingServices(String sjoThingServiceNameList_new,
        JsonObject joThingServiceNameList) {
    JsonParser jp = new JsonParser();
    JsonObject joThingServiceNameList_new = (JsonObject) jp.parse(sjoThingServiceNameList_new);

    JsonArray jaThingServiceNameList_old = new JsonArray();

    JsonArray jaThingServiceNameList_new_list = (JsonArray) joThingServiceNameList_new.get(LIST);
    jaThingServiceNameList_old = joThingServiceNameList.getAsJsonArray(LIST);
    jaThingServiceNameList_old.addAll(jaThingServiceNameList_new_list);

    joThingServiceNameList.add(LIST, jaThingServiceNameList_old);

    JsonArray jaThingServiceNameList_new_listEq = (JsonArray) joThingServiceNameList_new.get(LIST_EQ);
    joThingServiceNameList.getAsJsonArray(LIST_EQ).addAll(jaThingServiceNameList_new_listEq);

    return joThingServiceNameList;
}

From source file:help.FlightHelper.java

private JsonArray getFlights(final String from, final String to, final String date, final int numTickets) {

    List<Future<JsonArray>> list = new ArrayList<>();
    ExecutorService executor = Executors.newFixedThreadPool(8);
    List<Airline> apiUrls = new AirlineFacade().getAirlines();

    for (final Airline airline : apiUrls) {
        Callable<JsonArray> task = new FlightGetterCallable(from, to, date, numTickets, airline.getUrl());
        list.add(executor.submit(task));
    }//from  w w w . jav  a 2s.  c om
    executor.shutdown();
    JsonArray allFlights = new JsonArray();
    for (Future<JsonArray> array : list) {
        try {
            allFlights.addAll(array.get());
        } catch (InterruptedException | ExecutionException ex) {
            Logger.getLogger(Flights.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return allFlights;
}

From source file:io.grpc.internal.DnsNameResolver.java

License:Open Source License

@VisibleForTesting
static JsonArray parseTxtResults(List<String> txtRecords) {
    JsonArray serviceConfigs = new JsonArray();
    Gson gson = new Gson();

    for (String txtRecord : txtRecords) {
        if (txtRecord.startsWith(SERVICE_CONFIG_PREFIX)) {
            JsonArray choices;//from  www .  j a v a 2 s .co m
            try {
                choices = gson.fromJson(txtRecord.substring(SERVICE_CONFIG_PREFIX.length()), JsonArray.class);
            } catch (JsonSyntaxException e) {
                logger.log(Level.WARNING, "Bad service config: " + txtRecord, e);
                continue;
            }
            serviceConfigs.addAll(choices);
        } else {
            logger.log(Level.FINE, "Ignoring non service config {0}", new Object[] { txtRecord });
        }
    }

    return serviceConfigs;
}

From source file:it.noovle.dataflow.TwitterProcessor.java

License:Open Source License

/**
 * Flattens nested JsonArrays/*w  ww  .ja v  a  2 s .  co m*/
 */
private static JsonArray flatten(JsonElement el) {
    JsonArray result = new JsonArray();
    if (el.isJsonArray()) {
        for (JsonElement arrayEl : el.getAsJsonArray()) {
            result.addAll(flatten(arrayEl));
        }
    } else {
        result.add(el);
    }
    return result;
}