Java Code Examples for com.google.gson.JsonArray#contains()

The following examples show how to use com.google.gson.JsonArray#contains() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Check to ensure that the datasource in the query exists
 * in the specified cluster.
 *
 * @param query   the query to check
 * @param cluster the druid cluster to check
 * @throws DruidException if the datasource is not found
 */
public void checkDatasource(Query query, DruidCluster cluster) throws DruidException {
    ArrayList<String> inValidDataSources = new ArrayList<>();
    JsonElement datasourceInfo = query.getDatasource();
    JsonArray druidDataSources = httpService.queryDruidDatasources(cluster);
    if (datasourceInfo.isJsonArray()) {
        JsonArray dataSources = datasourceInfo.getAsJsonArray();
        for (JsonElement dataSource :
                dataSources) {
            if (!druidDataSources.contains(dataSource)) {
                inValidDataSources.add(dataSource.getAsString());
            }
        }
    } else {
        if (!druidDataSources.contains(datasourceInfo)) {
            inValidDataSources.add(datasourceInfo.getAsString());
        }
    }

    if (inValidDataSources.size() > 0) {
        log.error("Druid datasource {} does not exist!", inValidDataSources.toString());
        throw new DruidException("Querying unknown datasource: " + inValidDataSources.toString());
    }
}
 
Example 2
public static boolean getCurrentNodeSubExist(int maparea, int mapno, int no) {
    String currentMapString = KcaUtils.format("%d-%d", maparea, mapno);
    if (helper != null) {
        JsonObject subEdgeInfo = helper.getJsonObjectValue(DB_KEY_MAPSUBDT);
        if (subEdgeInfo != null && subEdgeInfo.has(currentMapString)) {
            JsonArray sub_edges = subEdgeInfo.getAsJsonArray(currentMapString);
            return sub_edges.contains(new JsonPrimitive(no));
        }
    }
    return false;
}
 
Example 3
Source Project: elastic-rabbitmq   File: ESProductSyncHandler.java    License: MIT License 5 votes vote down vote up
private JsonArray retrieveSKUIds(JsonObject product, JsonArray skus) {
    JsonArray skuIds = new JsonArray();
    JsonArray preSKUIds = product.get("skuIds") == null? null : product.get("skuIds").getAsJsonArray();

    // change skus to just skuIds array
    for (int i = 0; i < skus.size(); ++i) {
        if (preSKUIds == null || preSKUIds.contains(skus.get(i).getAsJsonObject().get("id"))) {
            skuIds.add(skus.get(i).getAsJsonObject().get("id"));
        }
    }
    return skuIds;
}
 
Example 4
private JsonArray unlistChannelIdsArray(Long channelId, JsonArray channels) {
    // no need unlist
    if (channels == null) {
        return null;
    }

    if (channels.contains(new JsonPrimitive(channelId))) {
        channels.remove(new JsonPrimitive(channelId));
        return channels;
    } else {
        // unlist before; nothing to do
        return null;
    }
}
 
Example 5
Source Project: java-slack-sdk   File: MergeJsonBuilder.java    License: MIT License 5 votes vote down vote up
private static void mergeJsonObjects(
        JsonObject leftObj,
        JsonObject rightObj,
        ConflictStrategy conflictStrategy) throws JsonConflictException {

    for (Map.Entry<String, JsonElement> rightEntry : rightObj.entrySet()) {
        String rightKey = rightEntry.getKey();
        JsonElement rightVal = rightEntry.getValue();
        if (leftObj.has(rightKey)) {
            //conflict
            JsonElement leftVal = leftObj.get(rightKey);
            if (leftVal.isJsonArray() && rightVal.isJsonArray()) {
                JsonArray leftArr = leftVal.getAsJsonArray();
                JsonArray rightArr = rightVal.getAsJsonArray();
                for (int i = 0; i < rightArr.size(); i++) {
                    JsonElement rightArrayElem = rightArr.get(i);
                    if (!leftArr.contains(rightArrayElem)) {
                        // remove temporarily added an empty string
                        if (rightArrayElem.isJsonObject()
                                && leftArr.size() == 1
                                && leftArr.get(i).isJsonPrimitive()
                                && leftArr.get(i).getAsString().equals("")) {
                            leftArr.remove(0);
                        }
                        leftArr.add(rightArrayElem);
                    }
                }
            } else if (leftVal.isJsonObject() && rightVal.isJsonObject()) {
                //recursive merging
                mergeJsonObjects(leftVal.getAsJsonObject(), rightVal.getAsJsonObject(), conflictStrategy);
            } else {//not both arrays or objects, normal merge with conflict resolution
                handleMergeConflict(rightKey, leftObj, leftVal, rightVal, conflictStrategy);
            }
        } else {//no conflict, add to the object
            leftObj.add(rightKey, rightVal);
        }
    }
}
 
Example 6
Source Project: java-slack-sdk   File: MergeJsonBuilder.java    License: MIT License 5 votes vote down vote up
private static void mergeJsonObjects(
        JsonObject leftObj,
        JsonObject rightObj,
        ConflictStrategy conflictStrategy) throws JsonConflictException {

    for (Map.Entry<String, JsonElement> rightEntry : rightObj.entrySet()) {
        String rightKey = rightEntry.getKey();
        JsonElement rightVal = rightEntry.getValue();
        if (leftObj.has(rightKey)) {
            //conflict
            JsonElement leftVal = leftObj.get(rightKey);
            if (leftVal.isJsonArray() && rightVal.isJsonArray()) {
                JsonArray leftArr = leftVal.getAsJsonArray();
                JsonArray rightArr = rightVal.getAsJsonArray();
                for (int i = 0; i < rightArr.size(); i++) {
                    JsonElement rightArrayElem = rightArr.get(i);
                    if (!leftArr.contains(rightArrayElem)) {
                        // remove temporarily added an empty string
                        if (rightArrayElem.isJsonObject()
                                && leftArr.size() == 1
                                && leftArr.get(i).isJsonPrimitive()
                                && leftArr.get(i).getAsString().equals("")) {
                            leftArr.remove(0);
                        }
                        leftArr.add(rightArrayElem);
                    }
                }
            } else if (leftVal.isJsonObject() && rightVal.isJsonObject()) {
                //recursive merging
                mergeJsonObjects(leftVal.getAsJsonObject(), rightVal.getAsJsonObject(), conflictStrategy);
            } else {//not both arrays or objects, normal merge with conflict resolution
                handleMergeConflict(rightKey, leftObj, leftVal, rightVal, conflictStrategy);
            }
        } else {//no conflict, add to the object
            leftObj.add(rightKey, rightVal);
        }
    }
}
 
Example 7
Source Project: java-slack-sdk   File: MergeJsonBuilder.java    License: MIT License 5 votes vote down vote up
private static void mergeJsonObjects(
        JsonObject leftObj,
        JsonObject rightObj,
        ConflictStrategy conflictStrategy) throws JsonConflictException {

    for (Map.Entry<String, JsonElement> rightEntry : rightObj.entrySet()) {
        String rightKey = rightEntry.getKey();
        JsonElement rightVal = rightEntry.getValue();
        if (leftObj.has(rightKey)) {
            //conflict
            JsonElement leftVal = leftObj.get(rightKey);
            if (leftVal.isJsonArray() && rightVal.isJsonArray()) {
                JsonArray leftArr = leftVal.getAsJsonArray();
                JsonArray rightArr = rightVal.getAsJsonArray();
                for (int i = 0; i < rightArr.size(); i++) {
                    JsonElement rightArrayElem = rightArr.get(i);
                    if (!leftArr.contains(rightArrayElem)) {
                        leftArr.add(rightArrayElem);
                    }
                }
            } else if (leftVal.isJsonObject() && rightVal.isJsonObject()) {
                //recursive merging
                mergeJsonObjects(leftVal.getAsJsonObject(), rightVal.getAsJsonObject(), conflictStrategy);
            } else {//not both arrays or objects, normal merge with conflict resolution
                handleMergeConflict(rightKey, leftObj, leftVal, rightVal, conflictStrategy);
            }
        } else {//no conflict, add to the object
            leftObj.add(rightKey, rightVal);
        }
    }
}
 
Example 8
public static boolean getCurrentNodeSubExist(int maparea, int mapno, int no) {
    String currentMapString = KcaUtils.format("%d-%d", maparea, mapno);
    if (helper != null) {
        JsonObject subEdgeInfo = helper.getJsonObjectValue(DB_KEY_MAPSUBDT);
        if (subEdgeInfo != null && subEdgeInfo.has(currentMapString)) {
            JsonArray sub_edges = subEdgeInfo.getAsJsonArray(currentMapString);
            return sub_edges.contains(new JsonPrimitive(no));
        }
    }
    return false;
}
 
Example 9
Source Project: streamsx.topology   File: GsonUtilities.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean intersect(JsonArray a1, JsonArray a2) {
    for (JsonElement e : a1) {
        if (a2.contains(e))
            return true;
    }
    return false;
}
 
Example 10
public JsonObject getEachSeekValue(JsonArray deckShipIdList, int id, int Cn, JsonObject exclude_flag) {
    JsonObject data = new JsonObject();
    double pureTotalSeek = 0.0;
    double totalEquipSeek = 0.0;
    double totalShipSeek = 0.0;
    int noShipCount = 6;

    boolean excludeflagexist = (exclude_flag != null);
    JsonArray excludeflagdata = null;
    if (excludeflagexist) {
        if (id == 0) excludeflagdata = exclude_flag.getAsJsonArray("escape");
        if (id == 1) excludeflagdata = exclude_flag.getAsJsonArray("escapecb");
    }

    for (int i = 0; i < deckShipIdList.size(); i++) {
        if (excludeflagdata != null && excludeflagdata.contains(new JsonPrimitive(i + 1)))
            continue;

        int shipId = deckShipIdList.get(i).getAsInt();
        if (shipId != -1) {
            noShipCount -= 1;
            JsonObject shipData = getUserShipDataById(shipId, "slot,sakuteki");
            int shipSeek = shipData.get("sakuteki").getAsJsonArray().get(0).getAsInt();
            pureTotalSeek += shipSeek;
            if (Cn != SEEK_PURE) {
                JsonArray shipItem = (JsonArray) shipData.get("slot");
                for (int j = 0; j < shipItem.size(); j++) {
                    int item_id = shipItem.get(j).getAsInt();
                    if (item_id != -1) {
                        JsonObject itemData = getUserItemStatusById(item_id, "level,alv", "name,type,saku");
                        if (itemData == null) continue;
                        String itemName = itemData.get("name").getAsString();
                        int itemLevel = itemData.get("level").getAsInt();
                        int itemType = itemData.get("type").getAsJsonArray().get(2).getAsInt();
                        int itemSeek = itemData.get("saku").getAsInt();
                        shipSeek -= itemSeek;

                        switch (itemType) {
                            case T2_TORPEDO_BOMBER:
                                totalEquipSeek += 0.8 * itemSeek;
                                break;
                            case T2_SCOUT:
                                totalEquipSeek += itemSeek + 1.2 * Math.sqrt(itemLevel);
                                break;
                            case T2_SCOUT_II:
                                totalEquipSeek += itemSeek + 1.2 * Math.sqrt(itemLevel);
                                break;
                            case T2_SEA_SCOUT:
                                totalEquipSeek += 1.2 * (itemSeek + 1.2 * Math.sqrt(itemLevel));
                                break;
                            case T2_SEA_BOMBER:
                                totalEquipSeek += 1.1 * (itemSeek + 1.15 * Math.sqrt(itemLevel));
                                break;
                            case T2_RADAR_LARGE:
                                totalEquipSeek += 0.6 * (itemSeek + 1.4 * Math.sqrt(itemLevel));
                                break;
                            case T2_RADAR_SMALL:
                                totalEquipSeek += 0.6 * (itemSeek + 1.25 * Math.sqrt(itemLevel));
                                break;
                            default:
                                totalEquipSeek += 0.6 * itemSeek;
                                break;
                        }
                    }
                }
                totalShipSeek += Math.sqrt(shipSeek);
            }
        }
    }
    data.addProperty("ship", totalShipSeek);
    data.addProperty("equip", totalEquipSeek);
    data.addProperty("pure", pureTotalSeek);
    data.addProperty("nscount", noShipCount);
    return data;
}
 
Example 11
public int[] getAirPowerRange(JsonArray deckPortData, int deckid, JsonObject exclude_flag) {
    int[] totalRangeAAC = {0, 0};
    boolean excludeflagexist = (exclude_flag != null);
    JsonArray excludeflagdata = null;
    if (excludeflagexist) {
        if (deckid == 0) excludeflagdata = exclude_flag.getAsJsonArray("escape");
        if (deckid == 1) excludeflagdata = exclude_flag.getAsJsonArray("escapecb");
    }

    JsonArray deckShipIdList = (JsonArray) ((JsonObject) deckPortData.get(deckid)).get("api_ship");
    for (int i = 0; i < deckShipIdList.size(); i++) {
            if (excludeflagdata != null && excludeflagdata.contains(new JsonPrimitive(i + 1)))
                continue;

        int shipId = deckShipIdList.get(i).getAsInt();
        if (shipId != -1) {
            JsonObject shipData = getUserShipDataById(shipId, "ship_id,lv,slot,onslot");
            int shipKcId = shipData.get("ship_id").getAsInt();
            int shipLv = shipData.get("lv").getAsInt();
            JsonArray shipItem = (JsonArray) shipData.get("slot");
            JsonArray shipSlotCount = (JsonArray) shipData.get("onslot");
            for (int j = 0; j < shipItem.size(); j++) {
                int item_id = shipItem.get(j).getAsInt();
                int slot = shipSlotCount.get(j).getAsInt();
                if (item_id != -1) {
                    JsonObject itemData = getUserItemStatusById(item_id, "level,alv", "id,name,type,tyku");
                    if (itemData == null) continue;
                    String itemName = itemData.get("name").getAsString();
                    int itemLevel = itemData.get("level").getAsInt();
                    int itemMastery = 0;
                    if (itemData.has("alv")) {
                        itemMastery = itemData.get("alv").getAsInt();
                    }
                    int itemType = itemData.get("type").getAsJsonArray().get(2).getAsInt();
                    int itemAAC = itemData.get("tyku").getAsInt();
                    double baseAAC = calcBasicAAC(itemType, calcReinforcedAAC(itemType, itemAAC, itemLevel), slot);

                    double[] masteryAAC = calcSlotAACFromMastery(itemType, itemMastery, 0);

                    totalRangeAAC[0] += (int) Math.floor(baseAAC + masteryAAC[0]);
                    totalRangeAAC[1] += (int) Math.floor(baseAAC + masteryAAC[1]);
                }
            }
        }
    }
    return totalRangeAAC;
}
 
Example 12
public int getSpeed(JsonArray deckPortData, String deckid_list, JsonObject exclude_flag) {
    boolean is_slow_flag = false;
    boolean is_fast_flag = false;
    boolean is_fastplus_flag = false;
    boolean is_superfast_flag = false;

    boolean excludeflagexist = (exclude_flag != null);
    String[] decklist = deckid_list.split(",");

    for (int n = 0; n < decklist.length; n++) {
        int deckid = Integer.parseInt(decklist[n]);
        JsonArray excludeflagdata = null;
        if (excludeflagexist) {
            if (deckid == 0) excludeflagdata = exclude_flag.getAsJsonArray("escape");
            if (deckid == 1) excludeflagdata = exclude_flag.getAsJsonArray("escapecb");
        }
        JsonArray deckShipIdList = deckPortData.get(deckid).getAsJsonObject().get("api_ship").getAsJsonArray();

        // Retrieve Speed (soku) Information
        for (int i = 0; i < deckShipIdList.size(); i++) {
            if (excludeflagdata != null && excludeflagdata.contains(new JsonPrimitive(i + 1)))
                continue;

            int shipId = deckShipIdList.get(i).getAsInt();
            if (shipId != -1) {
                JsonObject shipData = getUserShipDataById(shipId, "soku");
                int soku = shipData.get("soku").getAsInt();
                if (soku == SPEED_SLOW) {
                    is_slow_flag = true;
                } else if (soku == SPEED_FAST) {
                    is_fast_flag = true;
                } else if (soku == SPEED_FASTPLUS) {
                    is_fastplus_flag = true;
                } else if (soku == SPEED_SUPERFAST) {
                    is_superfast_flag = true;
                }
            }
        }
    }


    int flag = getSpeedFlagValue(is_slow_flag, is_fast_flag, is_fastplus_flag, is_superfast_flag);
    if (flag > SPEEDFLAG_SLOW) {
        return SPEED_MIXED_NORMAL;
    } else if (flag == SPEEDFLAG_SLOW) {
        return SPEED_SLOW;
    } else if (flag > SPEEDFLAG_FAST) {
        return SPEED_MIXED_FAST;
    } else if (flag == SPEEDFLAG_FAST) {
        return SPEED_FAST;
    } else if (flag > SPEEDFLAG_FASTPLUS) {
        return SPEED_MIXED_FASTPLUS;
    } else if (flag == SPEEDFLAG_FASTPLUS) {
        return SPEED_FASTPLUS;
    } else if (flag == SPEEDFLAG_SUPERFAST) {
        return SPEED_SUPERFAST;
    } else {
        return SPEED_NONE; // Unreachable
    }
}
 
Example 13
public int[] getAirPowerRange(JsonArray deckPortData, int deckid, JsonObject exclude_flag) {
    int[] totalRangeAAC = {0, 0};
    boolean excludeflagexist = (exclude_flag != null);
    JsonArray excludeflagdata = null;
    if (excludeflagexist) {
        if (deckid == 0) excludeflagdata = exclude_flag.getAsJsonArray("escape");
        if (deckid == 1) excludeflagdata = exclude_flag.getAsJsonArray("escapecb");
    }

    JsonArray deckShipIdList = (JsonArray) ((JsonObject) deckPortData.get(deckid)).get("api_ship");
    for (int i = 0; i < deckShipIdList.size(); i++) {
            if (excludeflagdata != null && excludeflagdata.contains(new JsonPrimitive(i + 1)))
                continue;

        int shipId = deckShipIdList.get(i).getAsInt();
        if (shipId != -1) {
            JsonObject shipData = getUserShipDataById(shipId, "ship_id,lv,slot,onslot");
            int shipKcId = shipData.get("ship_id").getAsInt();
            int shipLv = shipData.get("lv").getAsInt();
            JsonArray shipItem = (JsonArray) shipData.get("slot");
            JsonArray shipSlotCount = (JsonArray) shipData.get("onslot");
            for (int j = 0; j < shipItem.size(); j++) {
                int item_id = shipItem.get(j).getAsInt();
                int slot = shipSlotCount.get(j).getAsInt();
                if (item_id != -1) {
                    JsonObject itemData = getUserItemStatusById(item_id, "level,alv", "id,name,type,tyku");
                    if (itemData == null) continue;
                    String itemName = itemData.get("name").getAsString();
                    int itemLevel = itemData.get("level").getAsInt();
                    int itemMastery = 0;
                    if (itemData.has("alv")) {
                        itemMastery = itemData.get("alv").getAsInt();
                    }
                    int itemType = itemData.get("type").getAsJsonArray().get(2).getAsInt();
                    int itemAAC = itemData.get("tyku").getAsInt();
                    double baseAAC = calcBasicAAC(itemType, calcReinforcedAAC(itemType, itemAAC, itemLevel), slot);

                    double[] masteryAAC = calcSlotAACFromMastery(itemType, itemMastery, 0);

                    totalRangeAAC[0] += (int) Math.floor(baseAAC + masteryAAC[0]);
                    totalRangeAAC[1] += (int) Math.floor(baseAAC + masteryAAC[1]);
                }
            }
        }
    }
    return totalRangeAAC;
}
 
Example 14
public int getSpeed(JsonArray deckPortData, String deckid_list, JsonObject exclude_flag) {
    boolean is_slow_flag = false;
    boolean is_fast_flag = false;
    boolean is_fastplus_flag = false;
    boolean is_superfast_flag = false;

    boolean excludeflagexist = (exclude_flag != null);
    String[] decklist = deckid_list.split(",");

    for (int n = 0; n < decklist.length; n++) {
        int deckid = Integer.parseInt(decklist[n]);
        JsonArray excludeflagdata = null;
        if (excludeflagexist) {
            if (deckid == 0) excludeflagdata = exclude_flag.getAsJsonArray("escape");
            if (deckid == 1) excludeflagdata = exclude_flag.getAsJsonArray("escapecb");
        }
        JsonArray deckShipIdList = deckPortData.get(deckid).getAsJsonObject().get("api_ship").getAsJsonArray();

        // Retrieve Speed (soku) Information
        for (int i = 0; i < deckShipIdList.size(); i++) {
            if (excludeflagdata != null && excludeflagdata.contains(new JsonPrimitive(i + 1)))
                continue;

            int shipId = deckShipIdList.get(i).getAsInt();
            if (shipId != -1) {
                JsonObject shipData = getUserShipDataById(shipId, "soku");
                int soku = shipData.get("soku").getAsInt();
                if (soku == SPEED_SLOW) {
                    is_slow_flag = true;
                } else if (soku == SPEED_FAST) {
                    is_fast_flag = true;
                } else if (soku == SPEED_FASTPLUS) {
                    is_fastplus_flag = true;
                } else if (soku == SPEED_SUPERFAST) {
                    is_superfast_flag = true;
                }
            }
        }
    }


    int flag = getSpeedFlagValue(is_slow_flag, is_fast_flag, is_fastplus_flag, is_superfast_flag);
    if (flag > SPEEDFLAG_SLOW) {
        return SPEED_MIXED_NORMAL;
    } else if (flag == SPEEDFLAG_SLOW) {
        return SPEED_SLOW;
    } else if (flag > SPEEDFLAG_FAST) {
        return SPEED_MIXED_FAST;
    } else if (flag == SPEEDFLAG_FAST) {
        return SPEED_FAST;
    } else if (flag > SPEEDFLAG_FASTPLUS) {
        return SPEED_MIXED_FASTPLUS;
    } else if (flag == SPEEDFLAG_FASTPLUS) {
        return SPEED_FASTPLUS;
    } else if (flag == SPEEDFLAG_SUPERFAST) {
        return SPEED_SUPERFAST;
    } else {
        return SPEED_NONE; // Unreachable
    }
}