class BookmarkableUrlHelper {

    public static String registerOpenedDock(String currentBookmarkableURLStatus,
                                            UberfireDock targetDock) {
        if (targetDock == null) {
            return currentBookmarkableURLStatus;
        }
        final String id = getDockId(targetDock);
        final String closed = CLOSED_DOCK_PREFIX.concat(id);

        if (currentBookmarkableURLStatus.contains(DOCK_CLOSE_SEP)) {
            String result = null;

            if (!currentBookmarkableURLStatus.contains(id)) {
                // the screen is not in the URL, insert in last position
                result = currentBookmarkableURLStatus.replace(DOCK_CLOSE_SEP,
                                                              (id + DOCK_CLOSE_SEP));
            } else if (currentBookmarkableURLStatus.contains(closed)) {
                // the screen is closed
                result = currentBookmarkableURLStatus.replace(closed,
                                                              id);
            } else {
                // screen already in URL
                result = currentBookmarkableURLStatus;
            }
            return result;
        } else {
            return currentBookmarkableURLStatus + DOCK_BEGIN_SEP + (getDockId(targetDock) + DOCK_CLOSE_SEP);
        }
    }

}