GraphFragment (@Nullable GraphFragment startFragment, int bound) { if (startFragment == null) return null; GraphFragment shortFragment; int maxDown = startFragment.downNodeIndex; while ((shortFragment = getDownFragment(maxDown)) != null && !myPinnedNodes.contains(maxDown)) { maxDown = shortFragment.downNodeIndex; if (maxDown - startFragment.downNodeIndex > bound) break; } int maxUp = startFragment.upNodeIndex; while ((shortFragment = getUpFragment(maxUp)) != null && !myPinnedNodes.contains(maxUp)) { maxUp = shortFragment.upNodeIndex; if (startFragment.upNodeIndex - maxUp > bound) break; } if (maxUp != startFragment.upNodeIndex || maxDown != startFragment.downNodeIndex) { return new GraphFragment(maxUp, maxDown); } else { // start fragment is Simple if (myLinearGraph.getNodes(startFragment.upNodeIndex, DOWN).size() != 1) return startFragment; } return null; }