Example usage for io.vertx.core.json JsonArray getInteger

List of usage examples for io.vertx.core.json JsonArray getInteger

Introduction

In this page you can find the example usage for io.vertx.core.json JsonArray getInteger.

Prototype

public Integer getInteger(int pos) 

Source Link

Document

Get the Integer at position pos in the array,

Usage

From source file:docoverride.json.Examples.java

License:Open Source License

public void example4(JsonArray array) {
    String val = array.getString(0);
    Integer intVal = array.getInteger(1);
    Boolean boolVal = array.getBoolean(2);
}

From source file:examples.ConfigExamples.java

License:Apache License

public void propsWitHierarchicalStructure() {
    ConfigStoreOptions propertyWitHierarchical = new ConfigStoreOptions().setFormat("properties")
            .setType("file")
            .setConfig(new JsonObject().put("path", "hierarchical.properties").put("hierarchical", true));
    ConfigRetrieverOptions options = new ConfigRetrieverOptions().addStore(propertyWitHierarchical);

    ConfigRetriever configRetriever = ConfigRetriever.create(Vertx.vertx(), options);

    configRetriever.configStream().handler(config -> {
        String host = config.getJsonObject("server").getString("host");
        Integer port = config.getJsonObject("server").getInteger("port");
        JsonArray multiple = config.getJsonObject("multiple").getJsonArray("values");
        for (int i = 0; i < multiple.size(); i++) {
            Integer value = multiple.getInteger(i);
        }//from ww w. j  a va2 s.  c o  m
    });
}

From source file:net.sf.sgsimulator.sgsrest.vertx.services.GridLabSimulatorService.java

License:Open Source License

private void onInit(Vertx vertx, JsonObject config) throws IOException {
    config = config.getJsonObject("gridlab");
    int cycleTimeInMillis = config.getInteger("cycleTimeInMillis");// 60000;
    boolean intelligence = config.getBoolean("intelligence");// true;
    int moments = config.getInteger("moments");// 30;
    Double minRange = config.getDouble("minRange", null);
    Double maxRange = config.getDouble("maxRange", null);
    millisperwebpoll = config.getDouble("millisperwebpoll", null);
    boolean activeClients = config.getBoolean("activeClients");// true;
    // TODO parametrize
    Tariff tariff = new TariffExample();

    JsonArray sdjson = config.getJsonArray("startDate");
    JsonArray edjson = config.getJsonArray("endDate");
    Calendar calendarStart = Calendar.getInstance();
    calendarStart.set(sdjson.getInteger(0), sdjson.getInteger(1), sdjson.getInteger(2), sdjson.getInteger(3),
            sdjson.getInteger(4), sdjson.getInteger(5));

    Calendar calendarEnd = Calendar.getInstance();
    calendarEnd.set(edjson.getInteger(0), edjson.getInteger(1), edjson.getInteger(2), edjson.getInteger(3),
            edjson.getInteger(4), edjson.getInteger(5));

    String configurationFile = config.getString("configurationFile");
    String gridFile = config.getString("gridFile");
    // definition
    String scenarioFile = config.getString("scenarioFile");
    String gridLabFolder = config.getString("gridLabFolder");
    PATHS paths = new PATHS(configurationFile, gridFile, scenarioFile, gridLabFolder);

    Date[] dates = readSimulationTime(paths.getNetXmlSrcFile());
    long diffInMillies = calendarEnd.getTimeInMillis() - calendarStart.getTimeInMillis();

    int hoursOfSimulation = (int) TimeUnit.HOURS.convert(diffInMillies, TimeUnit.MILLISECONDS);
    startDate = calendarStart.getTime();
    init(title, startDate, cycleTimeInMillis, paths, intelligence, hoursOfSimulation, tariff, moments, minRange,
            maxRange, activeClients);//from   w w w. j a v  a2  s. c o  m
}

From source file:org.entcore.feeder.csv.MappingFinder.java

License:Open Source License

private void findChildExternalIds(final String structureId, final String path, final String charset,
        final List<String> columns, final JsonArray errors, final Handler<JsonArray> handler) {
    final List<String[]> lines = new ArrayList<>();

    final JsonArray childLastNameIndex = new fr.wseduc.webutils.collections.JsonArray();
    final JsonArray childUsernameIndex = new fr.wseduc.webutils.collections.JsonArray();
    int idx = 0;//  w w  w.j  a v  a 2 s  . com
    for (String c : columns) {
        if ("childLastName".equals(c)) {
            childLastNameIndex.add(idx);
        } else if ("childUsername".equals(c)) {
            childUsernameIndex.add(idx);
        }
        idx++;
    }
    if (childLastNameIndex.size() == 0) {
        addError(errors, "missing.childLastName");
        handler.handle(errors);
        return;
    } else if (childUsernameIndex.size() != 0 && childLastNameIndex.size() != childUsernameIndex.size()) {
        addError(errors, "mismatch.childLastName.childUsername");
        handler.handle(errors);
        return;
    }

    final int maxNbChild = childLastNameIndex.size();
    final int appendIdx;
    if (childUsernameIndex.size() > 0) {
        appendIdx = childLastNameIndex.getInteger(0) > childUsernameIndex.getInteger(0)
                ? childUsernameIndex.getInteger(0)
                : childLastNameIndex.getInteger(0);
    } else {
        appendIdx = childLastNameIndex.getInteger(0);
    }
    final String query = "MATCH (s:Structure {externalId : {id}})<-[:DEPENDS]-(:ProfileGroup)<-[:IN]-(u:User) "
            + "WHERE u.firstNameSearchField = {firstName} AND u.lastNameSearchField = {lastName} AND head(u.profiles) = 'Student' "
            + "RETURN DISTINCT u.externalId as externalId, {rowIdx} as line, {itemIdx} as item ";
    final TransactionHelper tx;
    try {
        tx = TransactionManager.getTransaction();
    } catch (TransactionException e) {
        addError(errors, "transaction.error");
        handler.handle(errors);
        return;
    }
    try {
        CSVReader csvReader = getCsvReader(path, charset);
        String[] values;
        int rowIdx = 0;
        while ((values = csvReader.readNext()) != null) {
            if (emptyLine(values)) {
                continue;
            }

            final List<String> line = new LinkedList<>(Arrays.asList(values));
            for (int i = 0; i < maxNbChild; i++) {
                if (rowIdx == 0) {
                    line.add(appendIdx, "childExternalId");
                } else {
                    line.add(appendIdx, "");
                }
            }
            lines.add(line.toArray(new String[line.size()]));
            if (rowIdx == 0) {
                rowIdx++;
                continue;
            }

            final JsonArray firstNames = new fr.wseduc.webutils.collections.JsonArray();
            final JsonArray lastNames = new fr.wseduc.webutils.collections.JsonArray();
            try {
                int i = 0;
                for (String c : columns) {
                    if (i >= values.length)
                        break;
                    switch (c) {
                    case "childLastName":
                        lastNames.add(sanitize(values[i]));
                        break;
                    case "childFirstName":
                        firstNames.add(sanitize(values[i]));
                        break;
                    }
                    i++;
                }
            } catch (Exception e) {
                errors.add(new JsonObject().put("key", "parse.line.error").put("params",
                        new fr.wseduc.webutils.collections.JsonArray().add(Integer.toString(rowIdx))));
            }
            final int fns = firstNames.size();
            if (fns != lastNames.size()) {
                errors.add(new JsonObject().put("key", "child.lastName.firstName.mismatch").put("params",
                        new fr.wseduc.webutils.collections.JsonArray().add(Integer.toString(rowIdx))));
            } else if (fns > 0) {
                //               if (fns > maxNbChild) {
                //                  maxNbChild = fns;
                //               }
                for (int i = 0; i < fns; i++) {
                    JsonObject params = new JsonObject().put("id", structureId)
                            .put("firstName", firstNames.getString(i)).put("lastName", lastNames.getString(i))
                            .put("rowIdx", rowIdx).put("itemIdx", i);
                    tx.add(query, params);
                }
            }
            rowIdx++;
        }
    } catch (Exception e) {
        addError(errors, "error.read.file", path);
        handler.handle(errors);
    }
    tx.commit(new Handler<Message<JsonObject>>() {
        @Override
        public void handle(Message<JsonObject> event) {
            JsonArray results = event.body().getJsonArray("results");
            if ("ok".equals(event.body().getString("status")) && results != null) {
                for (int i = 0; i < results.size(); i++) {
                    JsonArray item = results.getJsonArray(i);
                    if (item.size() == 1) { // Si 0 ou plusieurs utilisateurs, on laisse la ligne d'origine
                        String eId = item.getJsonObject(0).getString("externalId", "");
                        int lineIdx = item.getJsonObject(0).getInteger("line", -1);
                        int itemIdx = item.getJsonObject(0).getInteger("item", -1);
                        if (lineIdx > 0 && itemIdx >= 0) {
                            String[] line = lines.get(lineIdx);
                            line[itemIdx + appendIdx] = eId;
                            line[childLastNameIndex.getInteger(itemIdx) + maxNbChild] = "";
                            if (childUsernameIndex.size() > 0) {
                                line[childUsernameIndex.getInteger(itemIdx) + maxNbChild] = "";
                            }
                        }
                    }
                }
                vertx.fileSystem().deleteBlocking(path);

                try {
                    CSVWriter writer = getCsvWriter(path, charset);
                    writer.writeAll(lines);
                    writer.close();
                } catch (IOException e) {
                    log.error("Error writing file.", e);
                    addError(errors, "error.write.file", path);
                }
                handler.handle(errors);
            } else {
                addError(errors, "error.find.ids");
                handler.handle(errors);
            }
        }
    });
}