Example usage for java.lang String equals

List of usage examples for java.lang String equals

Introduction

In this page you can find the example usage for java.lang String equals.

Prototype

public boolean equals(Object anObject) 

Source Link

Document

Compares this string to the specified object.

Usage

From source file:CourserankConnector.java

public static void main(String[] args) throws Exception {
    ///////////////////////////////////////
    //Tagger init

    //MaxentTagger tagger = new MaxentTagger("models/english-left3words-distsim.tagger");
    /////  w w w .j  a  v  a 2 s .c  om
    //CLIENT INITIALIZATION
    ImportData importCourse = new ImportData();
    HttpClient httpclient = new DefaultHttpClient();
    httpclient = WebClientDevWrapper.wrapClient(httpclient);
    try {
        /*
         httpclient.getCredentialsProvider().setCredentials(
            new AuthScope(null, -1),
            new UsernamePasswordCredentials("eadrian", "eactresp1"));
        */
        //////////////////////////////////////////////////
        //Get Course Bulletin Departments page
        List<Course> courses = new ArrayList<Course>();

        HttpGet httpget = new HttpGet("http://explorecourses.stanford.edu");

        System.out.println("executing request" + httpget.getRequestLine());
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        String bulletinpage = "";

        //STORE RETURNED HTML TO BULLETINPAGE

        if (entity != null) {
            //System.out.println("Response content length: " + entity.getContentLength());
            InputStream i = entity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                bulletinpage += line;
                //System.out.println(line);
            }
            br.close();
            i.close();
        }
        EntityUtils.consume(entity);

        ///////////////////////////////////////////////////////////////////////////////
        //Login to Courserank

        httpget = new HttpGet("https://courserank.com/stanford/main");

        System.out.println("executing request" + httpget.getRequestLine());
        response = httpclient.execute(httpget);
        entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        String page = "";
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
            InputStream i = entity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                page += line;
                //System.out.println(line);
            }
            br.close();
            i.close();
        }
        EntityUtils.consume(entity);
        ////////////////////////////////////////////////////
        //POST REQUEST LOGIN

        HttpPost post = new HttpPost("https://www.courserank.com/stanford/main");

        List<NameValuePair> pairs = new ArrayList<NameValuePair>(2);

        pairs.add(new BasicNameValuePair("RT", ""));
        pairs.add(new BasicNameValuePair("action", "login"));
        pairs.add(new BasicNameValuePair("password", "trespass"));
        pairs.add(new BasicNameValuePair("username", "eaconte@stanford.edu"));
        post.setEntity(new UrlEncodedFormEntity(pairs));
        System.out.println("executing request" + post.getRequestLine());
        HttpResponse resp = httpclient.execute(post);
        HttpEntity ent = resp.getEntity();

        System.out.println("----------------------------------------");
        if (ent != null) {
            System.out.println("Response content length: " + ent.getContentLength());
            InputStream i = ent.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                //System.out.println(line);
            }
            br.close();
            i.close();
        }
        EntityUtils.consume(ent);
        ///////////////////////////////////////////////////
        //THIS STEP MAY NOT BE NEEDED BUT GETS MAIN PROFILE PAGE

        HttpGet gethome = new HttpGet("https://www.courserank.com/stanford/home");

        System.out.println("executing request" + gethome.getRequestLine());
        HttpResponse gresp = httpclient.execute(gethome);
        HttpEntity gent = gresp.getEntity();

        System.out.println("----------------------------------------");
        if (ent != null) {
            System.out.println("Response content length: " + gent.getContentLength());
            InputStream i = gent.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(i));
            String line;
            while ((line = br.readLine()) != null) {
                //System.out.println(line);
            }
            br.close();
            i.close();
        }

        /////////////////////////////////////////////////////////////////////////////////
        //Parse Bulletin

        String results = getToken(bulletinpage, "RESULTS HEADER", "Additional Searches");
        String[] depts = results.split("href");

        //SPLIT FOR EACH DEPARTMENT LINK, ITERATE
        boolean ready = false;
        for (int i = 1; i < depts.length; i++) {
            //EXTRACT LINK, DEPARTMENT NAME AND ABBREVIATION
            String dept = new String(depts[i]);
            String abbr = getToken(dept, "(", ")");
            String name = getToken(dept, ">", "(");
            name.trim();
            //System.out.println(tagger.tagString(name));
            String link = getToken(dept, "=\"", "\">");
            System.out.println(name + " : " + abbr + " : " + link);

            System.out.println("======================================================================");

            if (i <= 10 || i >= 127) //values to keep it to undergraduate courses. Excludes law, med, business, overseas
                continue;
            /*if (i<=46)
               continue; */ //Start at BIOHOP
            /*if (abbr.equals("INTNLREL"))
               ready = true;
            if (!ready)
               continue;*/
            //Construct department course search URL
            //Then request page
            String URL = "http://explorecourses.stanford.edu/" + link
                    + "&filter-term-Autumn=on&filter-term-Winter=on&filter-term-Spring=on";
            httpget = new HttpGet(URL);

            //System.out.println("executing request" + httpget.getRequestLine());
            response = httpclient.execute(httpget);
            entity = response.getEntity();

            //ystem.out.println("----------------------------------------");
            //System.out.println(response.getStatusLine());
            String rpage = "";
            if (entity != null) {
                //System.out.println("Response content length: " + entity.getContentLength());
                InputStream in = entity.getContent();
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String line;
                while ((line = br.readLine()) != null) {
                    rpage += line;
                    //System.out.println(line);
                }
                br.close();
                in.close();
            }
            EntityUtils.consume(entity);

            //Process results page
            List<Course> deptCourses = new ArrayList<Course>();
            List<Course> result = processResultPage(rpage);
            deptCourses.addAll(result);

            //While there are more result pages, keep going
            boolean more = (!(result.size() == 0) && (result.get((result.size() - 1)).courseNumber < 299));
            boolean morepages = anotherPage(rpage);
            while (morepages && more) {
                URL = nextURL(URL);
                httpget = new HttpGet(URL);

                //System.out.println("executing request" + httpget.getRequestLine());
                response = httpclient.execute(httpget);
                entity = response.getEntity();

                //System.out.println("----------------------------------------");
                //System.out.println(response.getStatusLine());
                rpage = "";
                if (entity != null) {
                    //System.out.println("Response content length: " + entity.getContentLength());
                    InputStream in = entity.getContent();
                    BufferedReader br = new BufferedReader(new InputStreamReader(in));
                    String line;
                    while ((line = br.readLine()) != null) {
                        rpage += line;
                        //System.out.println(line);
                    }
                    br.close();
                    in.close();
                }
                EntityUtils.consume(entity);
                morepages = anotherPage(rpage);
                result = processResultPage(rpage);
                deptCourses.addAll(result);
                more = (!(result.size() == 0) && (result.get((result.size() - 1)).courseNumber < 299));
                /*String mores = more? "yes": "no";
                String pagess = morepages?"yes":"no";
                System.out.println("more: "+mores+" morepages: "+pagess);
                System.out.println("more");*/
            }

            //Get course ratings for all department courses via courserank
            deptCourses = getRatings(httpclient, abbr, deptCourses);
            for (int j = 0; j < deptCourses.size(); j++) {
                Course c = deptCourses.get(j);
                System.out.println("" + c.title + " : " + c.rating);
                c.tags = name;
                c.code = c.code.trim();
                c.department = name;
                c.deptAB = abbr;
                c.writeToDatabase();
                //System.out.println(tagger.tagString(c.title));
            }

        }

        if (!page.equals(""))
            return;

        ///////////////////////////////////////////////////
        //Get Course Bulletin Department courses 

        /*
                
         httpget = new HttpGet("https://courserank.com/stanford/main");
                
         System.out.println("executing request" + httpget.getRequestLine());
         response = httpclient.execute(httpget);
         entity = response.getEntity();
                
         System.out.println("----------------------------------------");
         System.out.println(response.getStatusLine());
         page = "";
         if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
        InputStream i = entity.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           page +=line;
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(entity);
         ////////////////////////////////////////////////////
         //POST REQUEST LOGIN
                 
                 
         HttpPost post = new HttpPost("https://www.courserank.com/stanford/main");
                 
         List<NameValuePair> pairs = new ArrayList<NameValuePair>(2);
                 
                 
         pairs.add(new BasicNameValuePair("RT", ""));
         pairs.add(new BasicNameValuePair("action", "login"));
         pairs.add(new BasicNameValuePair("password", "trespass"));
         pairs.add(new BasicNameValuePair("username", "eaconte@stanford.edu"));
         post.setEntity(new UrlEncodedFormEntity(pairs));
         System.out.println("executing request" + post.getRequestLine());
         HttpResponse resp = httpclient.execute(post);
         HttpEntity ent = resp.getEntity();
                 
         System.out.println("----------------------------------------");
         if (ent != null) {
        System.out.println("Response content length: " + ent.getContentLength());
        InputStream i = ent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(ent);
         ///////////////////////////////////////////////////
         //THIS STEP MAY NOT BE NEEDED BUT GETS MAIN PROFILE PAGE
                 
         HttpGet gethome = new HttpGet("https://www.courserank.com/stanford/home");
                 
                 
         System.out.println("executing request" + gethome.getRequestLine());
         HttpResponse gresp = httpclient.execute(gethome);
         HttpEntity gent = gresp.getEntity();
                 
         System.out.println("----------------------------------------");
         if (ent != null) {
        System.out.println("Response content length: " + gent.getContentLength());
        InputStream i = gent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
                 
                 
         ////////////////////////////////////////
         //GETS FIRST PAGE OF RESULTS
         EntityUtils.consume(gent);
                 
         post = new HttpPost("https://www.courserank.com/stanford/search_results");
                 
         pairs = new ArrayList<NameValuePair>(2);
                 
                 
         pairs.add(new BasicNameValuePair("filter_term_currentYear", "on"));
         pairs.add(new BasicNameValuePair("query", ""));
         post.setEntity(new UrlEncodedFormEntity(pairs));
         System.out.println("executing request" + post.getRequestLine());
         resp = httpclient.execute(post);
         ent = resp.getEntity();
                 
         System.out.println("----------------------------------------");
                 
         String rpage = "";
         if (ent != null) {
        System.out.println("Response content length: " + ent.getContentLength());
        InputStream i = ent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           rpage += line;
           System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(ent);
                 
         ////////////////////////////////////////////////////
         //PARSE FIRST PAGE OF RESULTS
                 
         //int index = rpage.indexOf("div class=\"searchItem");
         String []classSplit = rpage.split("div class=\"searchItem");
         for (int i=1; i<classSplit.length; i++) {
            String str = classSplit[i];
                    
            //ID
            String CID = getToken(str, "course?id=","\">");
                    
            // CODE 
            String CODE = getToken(str,"class=\"code\">" ,":</");
                    
            //TITLE 
            String NAME = getToken(str, "class=\"title\">","</");
                    
            //DESCRIP
            String DES = getToken(str, "class=\"description\">","</");
                    
            //TERM
            String TERM = getToken(str, "Terms:", "|");
                    
            //UNITS
            String UNITS = getToken(str, "Units:", "<br/>");
                
            //WORKLOAD
                    
            String WLOAD = getToken(str, "Workload:", "|");
                    
            //GER
            String GER = getToken(str, "GERs:", "</d");
                    
            //RATING
            int searchIndex = 0;
            float rating = 0;
            while (true) {
          int ratingIndex = str.indexOf("large_Full", searchIndex);
          if (ratingIndex ==-1) {
             int halfratingIndex = str.indexOf("large_Half", searchIndex);
             if (halfratingIndex == -1)
                break;
             else
                rating += .5;
             break;
          }
          searchIndex = ratingIndex+1;
          rating++;
                     
            }
            String RATING = ""+rating;
                    
            //GRADE
            String GRADE = getToken(str, "div class=\"unofficialGrade\">", "</");
            if (GRADE.equals("NOT FOUND")) {
          GRADE = getToken(str, "div class=\"officialGrade\">", "</");
            }
                    
            //REVIEWS
            String REVIEWS = getToken(str, "class=\"ratings\">", " ratings");
                    
                    
            System.out.println(""+CODE+" : "+NAME + " : "+CID);
            System.out.println("----------------------------------------");
            System.out.println("Term: "+TERM+" Units: "+UNITS+ " Workload: "+WLOAD + " Grade: "+ GRADE);
            System.out.println("Rating: "+RATING+ " Reviews: "+REVIEWS);
            System.out.println("==========================================");
            System.out.println(DES);
            System.out.println("==========================================");
                    
                    
                    
         }
                 
                 
         ///////////////////////////////////////////////////
         //GETS SECOND PAGE OF RESULTS
         post = new HttpPost("https://www.courserank.com/stanford/search_results");
                 
         pairs = new ArrayList<NameValuePair>(2);
                 
                 
         pairs.add(new BasicNameValuePair("filter_term_currentYear", "on"));
         pairs.add(new BasicNameValuePair("page", "2"));
         pairs.add(new BasicNameValuePair("query", ""));
         post.setEntity(new UrlEncodedFormEntity(pairs));
         System.out.println("executing request" + post.getRequestLine());
         resp = httpclient.execute(post);
         ent = resp.getEntity();
                 
         System.out.println("----------------------------------------");
         if (ent != null) {
        System.out.println("Response content length: " + ent.getContentLength());
        InputStream i = ent.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           //System.out.println(line);
        }
        br.close();
        i.close();
         }
         EntityUtils.consume(ent);
                 
         /*
         httpget = new HttpGet("https://github.com/");
                
         System.out.println("executing request" + httpget.getRequestLine());
         response = httpclient.execute(httpget);
         entity = response.getEntity();
                
         System.out.println("----------------------------------------");
         System.out.println(response.getStatusLine());
         page = "";
         if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
        InputStream i = entity.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(i));
        String line;
        while ((line = br.readLine()) != null) {
           page +=line;
           System.out.println(line);
        }
        br.close();
        i.close();
         }*/
        EntityUtils.consume(entity);

    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:Main.java

public static int strBooleanToInt(String s) {
    if (s.equals("true"))
        return 1;
    return 0;//from  w w w  .ja v  a 2s .  c  o  m
}

From source file:Main.java

public static boolean checkIsLogOutDone(String url) {
    return url.equals("https://www.instagram.com/");
}

From source file:Main.java

public static boolean isPoGo(String name) {
    return name.equals("com.nianticlabs.pokemongo");
}

From source file:Main.java

static private boolean isNone(String name) {
    return name.equals("") || name.equals("255");
}

From source file:Main.java

public static boolean isHighPrecedence(String op) {
    if (op.equals("*") || op.equals("/")) {
        return true;
    }//w w  w . ja v a  2s . c om
    return false;
}

From source file:Main.java

public static boolean tagIsInt(String name) {
    if (name.equals("tiger:tlid"))
        return true;
    return false;
}

From source file:Main.java

public static boolean isToggleFullScreen(String event) {
    return event.equals("toggleFullscreen");
}

From source file:Main.java

public static boolean charSetImpliesAscii(String charset) {
    return charset.equals("ISO-8859-1") || charset.equals("US-ASCII"); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:Main.java

public static boolean ismOPEudfMinMax(String func) {
    return func.equals(UDF_MAX_FUNC_mOPE) || func.equals(UDF_MIN_FUNC_mOPE);
}