void () { ArrayList<String[]> paths = new ArrayList<>(); for (int i = 0; i < myView.getItemsSize(); i++) { ItemWrapper item = myView.getItemByIndex(i); paths.add(ArrayUtilRt.toStringArray(FileUtil.splitPath(item.getPresentableUrl()))); } FragmentBuilder headBuilder = new FragmentBuilder(paths){ @Override protected void append(String fragment, StringBuffer buffer) { buffer.append(mySeparator); buffer.append(fragment); } @Override protected int getFragmentIndex(String[] path, int index) { return path.length > index ? index : -1; } }; String commonHead = headBuilder.execute(); final int headLimit = headBuilder.getIndex(); FragmentBuilder tailBuilder = new FragmentBuilder(paths) { @Override protected void append(String fragment, StringBuffer buffer) { buffer.insert(0, fragment + mySeparator); } @Override protected int getFragmentIndex(String[] path, int index) { int result = path.length - 1 - index; return result > headLimit ? result : -1; } }; String commonTail = tailBuilder.execute(); int tailLimit = tailBuilder.getIndex(); for (int i = 0; i < myView.getItemsSize(); i++) { ItemWrapper item = myView.getItemByIndex(i); String special = concat(paths.get(i), headLimit, tailLimit); item.setFragments(createFragments(commonHead, special, commonTail)); } }