I wrote an Android application for my school that generates a HashMap that displays the course name in the ArrayList of the available sections for this course (string). The map is created using JSoup to connect to the school’s website and receive all current course information, analyze and format it, and create a HashMap> ().
It works. However, it literally takes about 5 minutes to create a HashMap on an Android device. I'm a relative newbie to programming, and I was wondering if there are other, more efficient ways to store and process such a large amount of data (HashMap cards comprise about 800 ArrayLists, which, in turn, contain several lines). Ideally, the data will be updated every time the application starts, so I'm not sure if writing to the internal memory will be effective.
Any suggestions?
thanks
Edit: Here is the method that creates the HashMap. This is a bit confusing, but the website I retrieve the data from was not easy to operate.
public HashMap<String, ArrayList<String>> generateCourseSectionMap()
{
ArrayList<String> store = new ArrayList<String>();
CourseLinks courses = new CourseLinks();
HashMap<String, String> courseLinks = courses.getCourseMap();
StringUtils util = new StringUtils();
HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
String sectionFormat = "((\\d){5};(\\d)+;(.*?) \\((.*?)\\);(.*?);(\\d)+ \\/ (\\d)+;(.*?);(TBA|Mo|Tu|We|Th|Fr|Sa|Su)+( (\\d){1,2}:(\\d){2}(AM|PM) - (\\d){1,2}:(\\d){2}(AM|PM))*?;(.*?));";
Document doc;
try
{
for (Map.Entry<String, String> entry : courseLinks.entrySet())
{
doc = Jsoup.connect(entry.getValue()).get();
Elements links = doc.select("*+tr>*:not(tr[class~=SectionTopic.*]>*):not(tr[class~=SectionTitle.*]>*)");
if (!links.isEmpty())
links.remove(0);
String build = "";
for (Element e : links)
{
String s = util.trim(e.text());
if (!s.isEmpty())
build = build + s + ";";
}
String rebuilt = rebuild(build);
store = util.toArrayList(rebuilt.split("BREAK"));
for (String d : store)
{
Pattern p = Pattern.compile(sectionFormat, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = p.matcher(d);
String[] array = d.split(";");
String firstKey = d.substring(0, d.indexOf(";"));
ArrayList<String> sectionList = new ArrayList<String>();
while (m.find())
sectionList.add(array[0] + ";" + array[1] + ";" + m.group());
map.put(firstKey, sectionList);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
return map;
}
dnUVA source
share