void (final String folderName) { if (myCurrentFolder == null) { return; } if (!folderName.equals(myCurrentFolder.getName())) { // if one of path components differs - no sense in checking others myCurrentFolder = null; return; } // common folder was found, let's increase proximity degree and move to parent folder myProximity ++; myCurrentFolder = myCurrentFolder.getParent(); }