Projects >> jcommune >>62130ea4f281c3bdce9f80a1cf8e791a68251774

Chunk
Conflicting content
    List getPostsOfUser(User userCreated);

    /**
<<<<<<< HEAD
     * Returns the preview part of the original post. Size is defined in the interface implementation class.
     *
     * @param originalPost the original post
     * @return original post preview part as a String
     */
    String getPostPreviewContent(String originalPost);
=======
     * Calculates page number for post based on the current user
     * paging settings and total post amount in the topic
     * @param post post to find a page for
     * @return number of the page where the post will actually be
     */
    int getPageForPost(Post post);
>>>>>>> dfeb21a833562a3bfd6a657aa8ea01415723ac8c
}
Solution content
    List getPostsOfUser(User userCreated);

    /**
     * Calculates page number for post based on the current user
     * paging settings and total post amount in the topic
     * @param post post to find a page for
     * @return number of the page where the post will actually be
     */
    int getPageForPost(Post post);

    /**
     * Returns the preview part of the original post. Size is defined in the interface implementation class.
     *
     * @param originalPost the original post
     * @return original post preview part as a String
     */
    String getPostPreviewContent(String originalPost);
}
File
PostService.java
Developer's decision
Concatenation
Kind of conflict
Comment
Method interface
Chunk
Conflicting content
     * {@inheritDoc}
     */
    @Override
<<<<<<< HEAD
    public String getPostPreviewContent(String originalPost) {
        String result = deleteAllImages(originalPost);
        int absoluteIndex = getAbsoluteIndex(result);
        if (absoluteIndex <= ABBREVIATED_LENGTH)
            return originalPost;
        else
            return getPreview(originalPost, absoluteIndex);
    }

    private boolean[] locateAllCodes(String post) {
        boolean[] r = new boolean[post.length()];

        for (String code : codes) {
            Matcher m = getMatcherForBBCode(code, post);
            while (m.find()) {
                markAs(r, true, m.start(1), m.end(1));
                markAs(r, true, m.start(4), m.end(4));
            }
        }

        return r;
    }

    private void markAs(boolean[] a, boolean isCountable, int startIndex, int endIndex) {
        for (int i = startIndex; i < endIndex; i++) {
            a[i] = isCountable;
        }
    }

    private Matcher getMatcherForBBCode(String code, String text) {
        return Pattern.compile(String.format("(\\[%s.*?\\])((.|\\n)*?)(\\[\\/%s\\])", code, code)).matcher(text);
    }

    private String deleteAllImages(String post) {
        String r = post;
        Matcher m = getMatcherForBBCode("img", r);
        while (m.find()) {
            r = m.replaceAll("");
        }

        return r;
    }

    private int getAbsoluteIndex(String post) {
        boolean[] a = locateAllCodes(post);

        int absoluteIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if (!a[i])
                absoluteIndex++;
            if (absoluteIndex == ABBREVIATED_LENGTH) {
                absoluteIndex = i;
                break;
            }
        }
        return absoluteIndex;
    }

    private String getPreview(String post, int ai) {
        String longestCode = "";
        int index = 0;
        for (String code : codes) {
            Matcher m = getMatcherForBBCode(code, post);
            while (m.find()) {
                if (m.start() < ai && m.end() > ai & m.end() > index) {
                    index = m.end();
                    longestCode = m.group();
                }
            }
        }
        if (!"".equals(longestCode) && index > 0) {
            if (ai - (index - longestCode.length()) < Math.round(longestCode.length()/2)) {
                return post.substring(0, index - longestCode.length()) + ABBREVIATION_SIGN;
            } else {
                return post.substring(0, index) + ABBREVIATION_SIGN;
            }
        }
        return post;
=======
    public int getPageForPost(Post post) {
        Topic topic = post.getTopic();
        User user = securityService.getCurrentUser();
        int index = topic.getPosts().indexOf(post) + 1;
        int pageSize = (user == null) ? User.DEFAULT_PAGE_SIZE : user.getPageSize();
        int pageNum = index / pageSize;
        if (index % pageSize == 0) {
            return pageNum;
        } else {
            return pageNum + 1;
        }
>>>>>>> dfeb21a833562a3bfd6a657aa8ea01415723ac8c
    }
}
Solution content
     * {@inheritDoc}
     */
    @Override
    public String getPostPreviewContent(String originalPost) {
        String result = deleteAllImages(originalPost);
        int absoluteIndex = getAbsoluteIndex(result);
        if (absoluteIndex <= ABBREVIATED_LENGTH)
            return originalPost;
        else
            return getPreview(originalPost, absoluteIndex);
    }

    private boolean[] locateAllCodes(String post) {
        boolean[] r = new boolean[post.length()];

        for (String code : codes) {
            Matcher m = getMatcherForBBCode(code, post);
            while (m.find()) {
                markAs(r, true, m.start(1), m.end(1));
                markAs(r, true, m.start(4), m.end(4));
            }
        }

        return r;
    }

    private void markAs(boolean[] a, boolean isCountable, int startIndex, int endIndex) {
        for (int i = startIndex; i < endIndex; i++) {
            a[i] = isCountable;
        }
    }

    private Matcher getMatcherForBBCode(String code, String text) {
        return Pattern.compile(String.format("(\\[%s.*?\\])((.|\\n)*?)(\\[\\/%s\\])", code, code)).matcher(text);
    }

    private String deleteAllImages(String post) {
        String r = post;
        Matcher m = getMatcherForBBCode("img", r);
        while (m.find()) {
            r = m.replaceAll("");
        }

        return r;
    }

    private int getAbsoluteIndex(String post) {
        boolean[] a = locateAllCodes(post);

        int absoluteIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if (!a[i])
                absoluteIndex++;
            if (absoluteIndex == ABBREVIATED_LENGTH) {
                absoluteIndex = i;
                break;
            }
        }
        return absoluteIndex;
    }

    private String getPreview(String post, int ai) {
        String longestCode = "";
        int index = 0;
        for (String code : codes) {
            Matcher m = getMatcherForBBCode(code, post);
            while (m.find()) {
                if (m.start() < ai && m.end() > ai & m.end() > index) {
                    index = m.end();
                    longestCode = m.group();
                }
            }
        }
        if (!"".equals(longestCode) && index > 0) {
            if (ai - (index - longestCode.length()) < Math.round(longestCode.length()/2)) {
                return post.substring(0, index - longestCode.length()) + ABBREVIATION_SIGN;
            } else {
                return post.substring(0, index) + ABBREVIATION_SIGN;
            }
        }
        return post;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getPageForPost(Post post) {
        Topic topic = post.getTopic();
        User user = securityService.getCurrentUser();
        int index = topic.getPosts().indexOf(post) + 1;
        int pageSize = (user == null) ? User.DEFAULT_PAGE_SIZE : user.getPageSize();
        int pageNum = index / pageSize;
        if (index % pageSize == 0) {
            return pageNum;
        } else {
            return pageNum + 1;
        }
    }
}
File
TransactionalPostService.java
Developer's decision
Manual
Kind of conflict
For statement
If statement
Method declaration
Method invocation
Method signature
Return statement
Variable