Example usage for java.util ArrayList hashCode

List of usage examples for java.util ArrayList hashCode

Introduction

In this page you can find the example usage for java.util ArrayList hashCode.

Prototype

public int hashCode() 

Source Link

Usage

From source file:Main.java

public static int hashCode(List list) {
    if (list == null) {
        return 0;
    }//from  w  ww . j  ava 2s.co m
    if (list.isEmpty()) {
        return 1;
    }
    ArrayList<?> tmp = new ArrayList<>(list);
    Collections.sort(tmp, (o1, o2) -> Integer.compare(o1.hashCode(), o2.hashCode()));
    return tmp.hashCode();
}

From source file:de.hero.vertretungsplan.HtmlWork.java

public void extractTable(StringBuffer strHtml) throws IOException {
    SharedPreferences.Editor editor = mySharedPreferences.edit();

    ArrayList<HashMap<String, String>> lstEintraege = new ArrayList<HashMap<String, String>>();

    HashMap<String, String> hmEintrag = new HashMap<String, String>();

    int intIndex = strHtml.indexOf("<table");
    strHtml.delete(0, intIndex - 1);/*from   w w  w  . j  a v a2 s  . c  o m*/
    intIndex = strHtml.indexOf("</table");
    strHtml.delete(intIndex, strHtml.length() - 1);
    DateFormat dfm = new SimpleDateFormat("dd.MM.yyyy");
    DateFormat dfm2 = new SimpleDateFormat("dd.MM.yy");
    Date dat = new Date();
    try {
        dat = dfm.parse(strHtml.substring(strHtml.indexOf(":") + 2));
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //      int date = dat.getDate();
    //      int month = dat.getMonth() + 1;

    //String strAktualisierungsText =  ((date < 10) ? "0" + date : date)  + "." + ((month < 10) ? "0" + month : month) + "." + (dat.getYear() + 1900) + " - " + strHtml.substring(strHtml.indexOf("<td>") + 4,strHtml.indexOf("</td"));
    String datumVertretungsplan = dfm2.format(dat);
    String aOderBWoche = strHtml.substring(strHtml.indexOf("<td>") + 4, strHtml.indexOf("</td"));
    Log.d("HtmlWork", "strAktualisierungsText " + datumVertretungsplan);
    editor.putString(context.getString(R.string.datumVertretungsplan), datumVertretungsplan);
    editor.putString("aOderBWoche", aOderBWoche);
    editor.commit();

    intIndex = strHtml.indexOf("<tr>");
    int intIndex2 = strHtml.indexOf("</tr>");
    strHtml.delete(0, intIndex2 + 4);
    intIndex = strHtml.indexOf("<tr>");
    intIndex2 = strHtml.indexOf("</tr>");

    strHtml.delete(0, intIndex2 + 4);
    intIndex2 = strHtml.indexOf("</tr>");
    strHtml.delete(0, intIndex2 + 4);
    intIndex = strHtml.indexOf("<tr>");
    intIndex2 = strHtml.indexOf("</tr>");
    while (intIndex != -1) {
        StringBuffer strZeile = new StringBuffer(strHtml.substring(intIndex + 4, intIndex2));
        int intIndex4 = strZeile.indexOf("</t");
        strZeile.delete(0, intIndex4 + 5);
        int intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");

        String stunde = strZeile.substring(intIndex3 + 4, intIndex4);
        hmEintrag.put("stunde", stunde + ((stunde.endsWith(".")) ? " Stunde" : ". Stunde"));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("fach1", strZeile.substring(intIndex3 + 4, intIndex4));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("vertreter", strZeile.substring(intIndex3 + 4, intIndex4));

        /*strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("fach2", strZeile.substring(intIndex3 + 4, intIndex4));*/

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("klassen", strZeile.substring(intIndex3 + 4, intIndex4));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");
        hmEintrag.put("raum", strZeile.substring(intIndex3 + 4, intIndex4));

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");

        String strTemp = strZeile.substring(intIndex3 + 4, intIndex4);

        strZeile.delete(intIndex3, intIndex4 + 4);
        intIndex3 = strZeile.indexOf("<t");
        intIndex4 = strZeile.indexOf("</t");

        hmEintrag.put("text", strTemp + " " + strZeile.substring(intIndex3 + 4, intIndex4));

        lstEintraege.add(hmEintrag);

        hmEintrag = new HashMap<String, String>();

        strHtml.delete(0, intIndex2 + 2);
        intIndex = strHtml.indexOf("<tr>");
        intIndex2 = strHtml.indexOf("</tr>");
    }
    FileOutputStream fos = context.openFileOutput(context.getString(R.string.filename), Context.MODE_PRIVATE);
    ObjectOutputStream oos = new ObjectOutputStream(fos);

    int oldHash = mySharedPreferences.getInt(context.getString(R.string.v_plan_hash_value), 0);

    oos.writeObject(lstEintraege);
    oos.close();
    fos.close();
    int newHash = lstEintraege.hashCode();
    editor.putInt(context.getString(R.string.v_plan_hash_value), newHash);
    editor.commit();

    Log.d("HtmlWork", "oldHash: " + oldHash + "; newHash: " + newHash);
    if (oldHash != newHash) {
        onDataChange();
    }
}