Example usage for com.mongodb DBCursor hasNext

List of usage examples for com.mongodb DBCursor hasNext

Introduction

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

Prototype

@Override
public boolean hasNext() 

Source Link

Document

Checks if there is another object available.

Usage

From source file:MashUp.java

public ArrayList<String> getMashUpbyYear(String year) {
    DBCursor cursor = table2.find();

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();/*from  w  w  w .  ja va2  s.  c o m*/

        if (temp.get("updated").toString().contains(year)) {

            api.add(temp.get("id").toString());
        }
    }
    return api;
}

From source file:MashUp.java

public ArrayList<String> getMashUpbyUsedApis(String Api) {
    DBCursor cursor = table2.find();

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();/*from  w  ww  .j  a v a 2  s .  c o  m*/

        if (temp.get("APIs").toString().contains(Api)) {

            api.add(temp.get("APIs").toString());
        }
    }
    return api;
}

From source file:MashUp.java

public ArrayList<String> getMashUpbasedonTags(String tags) {
    DBCursor cursor = table2.find();

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();// w ww  . j  a  v  a2s.c  o  m
        String tags_1[] = tags.split(" ");

        for (int i = 0; i < tags_1.length; i++) {
            if (temp.get("Tags").toString().contains(tags_1[i])) {

                api.add(temp.get("id").toString());
            }
        }
    }
    return api;
}

From source file:MashUp.java

public ArrayList<String> getMashUpVisual() {
    DBCursor cursor = table1.find();

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();/* www.  j a v a 2 s  .com*/

        if (temp.get("updated").toString().contains("2013")) {

            api.add(temp.get("name").toString());
        }

    }
    return api;
}

From source file:MashUp.java

public HashMap<String, String> getMashUpInformation(String keywords) {
    DBCursor cursor = table2.find();

    HashMap<String, String> api = new HashMap<String, String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();/*  w  ww. java2 s. c om*/
        String keywords_list[] = keywords.split(" ");
        for (int i = 0; i < keywords_list.length; i++) {
            if (temp.get("title").toString().contains(keywords_list[i])) {
                if (api.get("title") == null) {

                    api.put("title", "APINAME" + temp.get("id") + "$$" + temp.get("title").toString());
                } else {
                    if (!api.get("title")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("title").toString())) {
                        api.put("title", api.get("title") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("title").toString());
                    }
                }

            }
            if (temp.get("summary").toString().contains(keywords_list[i])) {
                if (api.get("summary") == null) {
                    System.out.println("Entering");
                    api.put("summary", "APINAME" + temp.get("id") + "$$" + temp.get("summary").toString());
                } else {
                    if (!api.get("summary")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("summary").toString())) {
                        api.put("summary", api.get("summary") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("summary").toString());
                    }
                }

            }
            if (temp.get("description").toString().contains(keywords_list[i])) {
                if (api.get("description") == null) {
                    System.out.println("Entering");
                    api.put("description",
                            "APINAME" + temp.get("id") + "$$" + temp.get("description").toString());
                } else {
                    if (!api.get("description")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("description").toString())) {
                        api.put("description", api.get("description") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("description").toString());
                    }
                }

            }
        }
    }
    return api;
}

From source file:MashUp.java

public String queryDatabaseApi(String Year, String Protocol, String Category, String Tags, String Keywords,
        Double Rating) {/*w w w .ja  v a  2  s  .  c  o  m*/

    String temp = "";
    BasicDBObject gtQuery = new BasicDBObject();
    BasicDBObject ltQuery = new BasicDBObject();
    BasicDBObject eqQuery = new BasicDBObject();

    if (!Rating.equals(0.0)) {

        /*
        greater than
        */

        temp = temp + "\n";
        temp = temp + "Greater than " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            gtQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            gtQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            gtQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            gtQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            gtQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        gtQuery.put("rating", new BasicDBObject("$gt", Rating));
        DBCursor cursor = table1.find(gtQuery);
        while (cursor.hasNext()) {
            DBObject temp1 = cursor.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

        /*
        lower than
        */

        temp = temp + "\n";
        temp = temp + "Lower than " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            ltQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            ltQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            ltQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            ltQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            ltQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        ltQuery.put("rating", new BasicDBObject("$lt", Rating));
        DBCursor cursor2 = table1.find(ltQuery);
        while (cursor2.hasNext()) {
            DBObject temp1 = cursor2.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

        /*
                
        equal to 
        */

        temp = temp + "\n";
        temp = temp + "Equal to " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            eqQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            eqQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            eqQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            eqQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            eqQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        eqQuery.put("rating", new BasicDBObject("$eq", Rating));
        DBCursor cursor3 = table1.find(eqQuery);
        while (cursor3.hasNext()) {
            DBObject temp1 = cursor3.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

    } else {

        BasicDBObject test = new BasicDBObject();
        if (!Year.equals("")) {
            test.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            test.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            test.put("category", Category);
        }
        if (!Tags.equals("")) {
            test.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            test.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        DBCursor cursor = table1.find(test);
        while (cursor.hasNext()) {
            DBObject temp1 = cursor.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }
    }

    /*
    if(!Year.equals("")){
    //gtQuery.put("rating", new BasicDBObject("$gt", "4"));
    gtQuery.put("updated",new BasicDBObject("$regex",".*"+Year+".*"));
    }
    if(!Protocol.equals("")){
    gtQuery.put("protocols",Protocol);
    }
            
    if(!Category.equals("")){
    gtQuery.put("category",Category);
    }
    if(!Tags.equals("")){
    gtQuery.put("Tags",new BasicDBObject("$regex",".*"+Tags+".*") );
    }
     if(!Keywords.equals("")){
    DBObject clause1 = new BasicDBObject("summary", new BasicDBObject("$regex",".*"+Keywords+".*"));  
    DBObject clause2 = new BasicDBObject("description", new BasicDBObject("$regex",".*"+Keywords+".*"));
    DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex",".*"+Keywords+".*")); 
    BasicDBList or = new BasicDBList();
    or.add(clause1);or.add(clause3);
    or.add(clause2);
    gtQuery.put("$or", or);
    //DBObject query = new BasicDBObject("$or", or);
    //System.out.println(query);
            
    }
             
            
            
    //gtQuery.put("rating", new BasicDBObject("$gt", "4").append("$lt", "5"));
    //  gtQuery.put("updated", "2012-12-17T09:51:40Z");
    DBCursor cursor = table1.find(gtQuery);
    String temp="";
            
    if(!Rating.equals(0.0)){
     gtQuery.put("rating",new BasicDBObject("$gt",Rating));
     temp="Greater than "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
      }
              
      gtQuery.remove("rating");
      temp=temp+"\n";
    gtQuery.put("rating",new BasicDBObject("$lt",Rating));
     temp= temp+"Lesser than "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
            
    gtQuery.remove("rating");
    temp=temp+"\n";
    gtQuery.put("rating",new BasicDBObject("$eq",Rating));
     temp=temp+"Equal to "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
            
    }else{
    while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
    }
            
    */

    return temp;
}

From source file:MashUp.java

public String queryDatabaseMashUp(String Year, String UsedApi, String Tags, String Keywords) {
    BasicDBObject gtQuery = new BasicDBObject();

    if (!Year.equals("")) {
        //gtQuery.put("rating", new BasicDBObject("$gt", "4"));
        gtQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
    }/*from www  .j a v a  2s .co  m*/
    if (!UsedApi.equals("")) {
        System.out.println("UsedApi " + UsedApi);
        // DBObject clause1 = new BasicDBObject("APIS", new BasicDBObject("$regex",".*"+UsedApi+".*"));  
        // gtQuery.put("APIs",new BasicDBObject("APIs", new BasicDBObject("$regex",".*"+UsedApi+".*")));
        gtQuery.put("APIs", new BasicDBObject("$regex", ".*" + UsedApi + ".*"));
    }

    if (!Tags.equals("")) {
        gtQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
    }
    if (!Keywords.equals("")) {
        DBObject clause1 = new BasicDBObject("summary", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
        DBObject clause2 = new BasicDBObject("description",
                new BasicDBObject("$regex", ".*" + Keywords + ".*"));
        DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
        BasicDBList or = new BasicDBList();
        or.add(clause1);
        or.add(clause3);
        or.add(clause2);
        gtQuery.put("$or", or);
        //DBObject query = new BasicDBObject("$or", or);
        //System.out.println(query);

    }

    //gtQuery.put("rating", new BasicDBObject("$gt", "4").append("$lt", "5"));
    //  gtQuery.put("updated", "2012-12-17T09:51:40Z");
    DBCursor cursor = table2.find(gtQuery);
    String temp = "";
    while (cursor.hasNext()) {
        DBObject temp1 = cursor.next();
        temp = temp + " " + temp1.get("name") + "\n";
    }
    return temp;
}

From source file:TeacherSection.java

private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
    // TODO add your handling code here:

    DBCollection coll = db.getCollection("user");
    BasicDBObject andQuery = new BasicDBObject();
    List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    String username = login.user;
    obj.add(new BasicDBObject("user", username));
    andQuery.put("$and", obj);

    DBCursor cursor = coll.find(andQuery);
    while (cursor.hasNext()) {
        lastname = cursor.next().get("lastname").toString();
    }/*from w  ww.  java 2  s .co  m*/

    DBCollection coll1 = db.getCollection("teacher");

    BasicDBObject andQuery1 = new BasicDBObject();
    List<BasicDBObject> obj1 = new ArrayList<BasicDBObject>();
    obj1.add(new BasicDBObject("firstname", firstname));
    obj1.add(new BasicDBObject("lastname", lastname));
    andQuery1.put("$and", obj1);
    cursor = coll1.find(andQuery1);

    while (cursor.hasNext()) {

        BasicDBList teache = (BasicDBList) cursor.next().get("teach");
        String data[] = new String[teache.size()];

        for (int j = 0; j < teache.size(); ++j) {
            BasicDBObject teach = (BasicDBObject) teache.get(j);
            String val = teach.getString("grade") + "-" + teach.getString("section");
            data[j] = val;

        }
        GradeList.setListData(data);
    }

}

From source file:TeacherSection.java

private void GradeListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_GradeListValueChanged
    // TODO add your handling code here:
    if (!evt.getValueIsAdjusting()) {
        String selected = GradeList.getSelectedValue();
        int grade = 0;
        int section = 0;
        for (int i = 0; i < selected.length(); ++i) {
            if (selected.charAt(i) == '-') {

                grade = (int) Double.parseDouble(selected.substring(0, i));
                section = (int) Double.parseDouble(selected.substring(i + 1));
            }/*from  www .ja  va  2 s . c o m*/
        }

        DBCollection coll = db.getCollection("student");
        BasicDBObject andQuery = new BasicDBObject();
        List<BasicDBObject> obj = new ArrayList<BasicDBObject>();

        obj.add(new BasicDBObject("grade", grade));
        obj.add(new BasicDBObject("section", section));

        andQuery.put("$and", obj);
        DBCursor cursor = coll.find(andQuery);
        while (cursor.hasNext()) {

            DBObject object = cursor.next();
            this.FirstnameField.setText(object.get("firstname").toString());
            this.MidnameField.setText(object.get("mid_name").toString());
            LastnameField.setText(object.get("lastname").toString());

            BasicDBList marks = (BasicDBList) object.get("marks");
            for (int i = 0; i < marks.size(); ++i) {
                BasicDBObject mark = (BasicDBObject) marks.get(i);
                if (mark.getString("teacher").equals(firstname)) {

                    if (mark.get("mid") == null) {

                        MidField.setText("-1");
                        FinalField.setText("-1");

                    } else if (mark.get("mid") != null && mark.get("final") == null) {

                        MidField.setText(mark.getString("mid"));
                        FinalField.setText("-1");
                    } else {

                        MidField.setText(mark.getString("mid"));
                        FinalField.setText(mark.getString("final"));

                    }

                    break;
                }

            }
            int reply = JOptionPane.showConfirmDialog(null, "if you want to update press yes", "Update or Skip",
                    JOptionPane.YES_NO_OPTION);
            if (reply == JOptionPane.YES_OPTION) {
                int midmark = Integer.parseInt(JOptionPane.showInputDialog("Please input mark for mid: "));
                int finalmark = Integer.parseInt(JOptionPane.showInputDialog("Please input mark for final: "));
                BasicDBObject andQuery1 = new BasicDBObject();
                List<BasicDBObject> obj1 = new ArrayList<BasicDBObject>();
                obj1.add(new BasicDBObject("firstname", FirstnameField.getText()));
                obj1.add(new BasicDBObject("mid_name", MidnameField.getText()));
                obj1.add(new BasicDBObject("lastname", LastnameField.getText()));
                obj1.add(new BasicDBObject("grade", grade));
                obj1.add(new BasicDBObject("section", section));
                obj1.add(new BasicDBObject("marks.teacher", firstname));
                andQuery1.put("$and", obj1);
                BasicDBObject data = new BasicDBObject();
                if (midmark == -1 && finalmark == -1) {
                    JOptionPane.showMessageDialog(null, "No data was updated!");
                } else if (midmark != -1 && finalmark != -1) {
                    data.put("marks.$.mid", midmark);
                    JOptionPane.showMessageDialog(null, "data was updated .");
                } else {
                    data.put("marks.$.mid", midmark);
                    data.put("marks.$.final", finalmark);
                    JOptionPane.showMessageDialog(null, "data was updated .");

                }
                BasicDBObject command = new BasicDBObject();
                command.put("$set", data);
                coll.update(andQuery1, command);

            }

        }

    }

}

From source file:Parent.java

private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
    // TODO add your handling code here:

    DBCollection coll = db.getCollection("parent");
    BasicDBObject andQuery = new BasicDBObject();
    List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    obj.add(new BasicDBObject("firstname", firstname));
    obj.add(new BasicDBObject("lastname", lastname));

    andQuery.put("$and", obj);
    DBCursor cursor = coll.find(andQuery);
    while (cursor.hasNext()) {
        BasicDBList sons = (BasicDBList) cursor.next().get("sons");
        String data[] = new String[sons.size()];
        for (int j = 0; j < sons.size(); ++j) {
            BasicDBObject son = (BasicDBObject) sons.get(j);
            data[j] = son.get("name").toString();

        }/* w w  w . ja  v a 2  s. c o  m*/

        SonList.setListData(data);

    }
}