Example usage for com.mongodb.client MongoCursor hasNext

List of usage examples for com.mongodb.client MongoCursor hasNext

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor hasNext.

Prototype

@Override
    boolean hasNext();

Source Link

Usage

From source file:data.ProjectMember.java

License:Open Source License

public static ArrayList<ProjectMember> getOwnedProject(String loginName, DBManagerMongo manager)
        throws Exception {
    ArrayList<ProjectMember> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_member");
    FindIterable<Document> doc = coll.find(and(eq("user_login_name", loginName), eq("role", "LEADER")));
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractMember(cursor.next(), manager));

    return list;// www  .java  2 s.  co  m
}

From source file:data.ProjectMember.java

License:Open Source License

public static List<ProjectMember> getAll(DBManagerMongo manager) throws Exception {
    ArrayList<ProjectMember> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_member");
    FindIterable<Document> doc = coll.find();
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractMember(cursor.next(), manager));

    return list;/*from   w w w  .j  ava2s.  co m*/
}

From source file:data.ProjectPhase.java

License:Open Source License

public static ProjectPhase getByPrimaryKey(int id, DBManagerMongo manager) throws Exception {
    MongoCollection<Document> coll = manager.getDb().getCollection("project_phase");
    FindIterable<Document> doc = coll.find(eq("id", id));
    MongoCursor<Document> cursor = doc.iterator();
    if (!cursor.hasNext())
        throw new Exception("no such record");

    return extractPhase(cursor.next(), manager);
}

From source file:data.ProjectPhase.java

License:Open Source License

public static ArrayList<ProjectPhase> getByProjectId(int projectId, DBManagerMongo manager) throws Exception {
    ArrayList<ProjectPhase> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_phase");
    FindIterable<Document> doc = coll.find(eq("project_id", projectId));
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractPhase(cursor.next(), manager));

    return list;/*from w ww.j a  v  a 2s .co  m*/
}

From source file:data.ProjectPhase.java

License:Open Source License

public static List<ProjectPhase> getAll(DBManagerMongo manager) throws Exception {
    ArrayList<ProjectPhase> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_phase");
    FindIterable<Document> doc = coll.find();
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractPhase(cursor.next(), manager));

    return list;/*  w  w w. ja v a  2  s  .  co  m*/
}

From source file:data.User.java

License:Open Source License

public static User getByPrimaryKey(String loginName, DBManagerMongo manager) throws Exception {
    MongoCollection<Document> coll = manager.getDb().getCollection("user");
    FindIterable<Document> doc = coll.find(eq("login_name", loginName));
    MongoCursor<Document> cursor = doc.iterator();
    if (!cursor.hasNext())
        throw new Exception("no such record");

    return extractUser(cursor.next());
}

From source file:data.User.java

License:Open Source License

public static List<User> getAll(DBManagerMongo manager) throws Exception {
    ArrayList<User> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("user");
    FindIterable<Document> doc = coll.find();
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractUser(cursor.next()));

    return list;/*from www  .  j a  v  a 2 s.com*/
}

From source file:de.jan.smartenergybackend.de.MongoDBClient.java

/**
 * //from   w ww  .j  a  v a 2s  .  c om
 * @param startTime
 * @param entTime
 * @return The avarage of the measured values in the given time slot
 */
public long getSmartMeterValueAvarage(int startTime, int entTime) {
    FindIterable<Document> findIt = collection.find();
    MongoCursor<Document> mongoCurser = findIt.iterator();
    int count = 0;
    long sum = 0;
    while (mongoCurser.hasNext()) {
        Document next = mongoCurser.next();
        sum += next.getLong("value");
        count++;
    }
    if (count > 0) {
        return sum / count;
    } else {
        return -1;
    }
}

From source file:DS.Model.java

public List<Restaurant> getRestaurants() {
    MongoCollection<Document> collection = db.getCollection("restaurants");
    MongoCursor<Document> cursor = collection.find().iterator();

    resList = new ArrayList<Restaurant>();
    try {/*from ww w.  ja  va 2s. c om*/
        //Iterate through all the returned restaurants and store the information into the resList list
        while (cursor.hasNext()) {
            String json = cursor.next().toJson();
            JsonParser parser = new JsonParser();
            JsonElement jsonTree = parser.parse(json);
            if (jsonTree.isJsonObject()) {
                Restaurant r = new Restaurant();
                JsonObject j = jsonTree.getAsJsonObject();
                r.setName(j.get("name").getAsString());
                r.setLocation(j.get("address").getAsString());
                r.setRating(Double.parseDouble(j.get("rating").getAsString()));
                resList.add(r);
            }
        }
    } finally {
        cursor.close();
    }

    return resList;
}

From source file:DS.Model.java

public List<Request> getRequests() {
    MongoCollection<Document> collection = db.getCollection("requests");
    MongoCursor<Document> cursor = collection.find().iterator();

    reqList = new ArrayList<Request>();
    try {//from  ww  w  .j  a v a  2s . c o m
        //Iterate through all the requests to retrieve the information and add to the reqList list
        while (cursor.hasNext()) {
            String json = cursor.next().toJson();
            JsonParser parser = new JsonParser();
            JsonElement jsonTree = parser.parse(json);
            if (jsonTree.isJsonObject()) {
                Request r = new Request();
                JsonObject j = jsonTree.getAsJsonObject();
                String term = j.get("term").getAsString();
                String location = j.get("location").getAsString();
                r.setLocation(location);
                r.setTerm(term);
                r.setTimestamp(j.get("time").getAsString());
                r.setPhone(j.get("phone").getAsString());
                r.setDelay(Double.parseDouble(j.get("delay").getAsString()));
                reqList.add(r);

                //Add the term to the termCount map, used to find which term is the most popular
                //Check if the term already exists.  IF yes, increment by one, else add as new term
                if (termCount.containsKey(term)) {
                    int count = termCount.get(term);
                    termCount.put(term, count + 1);
                } else {
                    termCount.put(term, 0);
                }

                //Add the location to the locCount map, used to find which term is the most popular
                //Check if the location already exists.  IF yes, increment by one, else add as new loc
                if (locCount.containsKey(location)) {
                    int count = locCount.get(location);
                    locCount.put(location, count + 1);
                } else {
                    locCount.put(location, 0);
                }
            }
        }
    } finally {
        cursor.close();
    }

    return reqList;
}