java - Comparison of two-dimensional data structures - simplify and faster? -
how can following code simplified , made faster?
this comparison of two-dimensional data structures. several folders, each folder contains files, compared other folders.
arraylist<foldergroup> userfolders = commonfunctions.getuserfolders(); if (!userfolders.isempty()) { (foldergroup userfoldersgroup : userfolders) { (foldergroup publicfoldersgroup : publicgroupslist) { if (userfoldersgroup.getname().equals(publicfoldersgroup.getname())) { (file publicfile : publicfoldersgroup.getfiles()) { (file userfile : userfoldersgroup.getfiles()) { if (publicfile.contains(userfile)) { publicfile.setisdownloaded(true); userfoldersgroup.setdownloadedcount(); } } } } } } }
the out-most if
futile, out-most loop terminate without iterating when userfolders
empty, anyway.
other that, don't think overall complexity can reduced. can make code easier understand extracting methods meaningful names.
what can more speed use data structures allow use fewer nested loops. example, you'd need iterate on 1 of folder group collections if query other folder group collection folder group name. standard library comes collection classes allow such queries , implement the map
interface (documentation).
Comments
Post a Comment