CPD Results

The following document contains the results of PMD's CPD 6.55.0.

Duplications

File Line
org/codehaus/plexus/interpolation/InterpolatorFilterReader.java 159
org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReader.java 171
}

    /**
     * Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of
     * the stream is reached.
     *
     * @param n The number of characters to skip
     * @return the number of characters actually skipped
     * @exception IllegalArgumentException If <code>n</code> is negative.
     * @exception IOException If an I/O error occurs
     */
    public long skip(long n) throws IOException {
        if (n < 0L) {
            throw new IllegalArgumentException("skip value is negative");
        }

        for (long i = 0; i < n; i++) {
            if (read() == -1) {
                return i;
            }
        }
        return n;
    }

    /**
     * Reads characters into a portion of an array. This method will block until some input is available, an I/O error
     * occurs, or the end of the stream is reached.
     *
     * @param cbuf Destination buffer to write characters to. Must not be <code>null</code>.
     * @param off Offset at which to start storing characters.
     * @param len Maximum number of characters to read.
     * @return the number of characters read, or -1 if the end of the stream has been reached
     * @exception IOException If an I/O error occurs
     */
    public int read(char cbuf[], int off, int len) throws IOException {
        for (int i = 0; i < len; i++) {
            int ch = read();
            if (ch == -1) {
                if (i == 0) {
                    return -1;
                } else {
                    return i;
                }
            }
            cbuf[off + i] = (char) ch;
        }
        return len;
    }

    /**
     * Returns the next character in the filtered stream, replacing tokens from the original stream.
     *
     * @return the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
     * @exception IOException if the underlying stream throws an IOException during reading
     */
    public int read() throws IOException {
        if (replaceIndex != -1 && replaceIndex < replaceData.length()) {
            int ch = replaceData.charAt(replaceIndex++);
            if (replaceIndex >= replaceData.length()) {
                replaceIndex = -1;
            }
            return ch;
        }

        int ch = -1;
        if (previousIndex != -1 && previousIndex < this.endToken.length()) {
            ch = this.endToken.charAt(previousIndex++);
        } else {
            ch = in.read();
        }
File Line
org/codehaus/plexus/interpolation/InterpolatorFilterReader.java 304
org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReader.java 339
if (key.toString().startsWith(escapeString + orginalBeginToken)) {
                        String keyStr = key.toString();
                        if (!preserveEscapeString) {
                            value = keyStr.substring(escapeString.length(), keyStr.length());
                        } else {
                            value = keyStr;
                        }
                        escapeFound = true;
                    }
                }
                if (!escapeFound) {
                    if (interpolateWithPrefixPattern) {
                        value = interpolator.interpolate(key.toString(), "", recursionInterceptor);
                    } else {
                        value = interpolator.interpolate(key.toString(), recursionInterceptor);
                    }
                }
            } catch (InterpolationException e) {
                IllegalArgumentException error = new IllegalArgumentException(e.getMessage());
                error.initCause(e);

                throw error;
            }

            if (value != null) {
                if (value.length() != 0) {
                    replaceData = value;
                    replaceIndex = 0;
                }
                return read();
            } else {
                previousIndex = 0;
                replaceData = key.substring(0, key.length() - this.endToken.length());
                replaceIndex = 0;
                return this.beginToken.charAt(0);
            }
        }

        return ch;
    }
File Line
org/codehaus/plexus/interpolation/InterpolatorFilterReader.java 264
org/codehaus/plexus/interpolation/multi/MultiDelimiterInterpolatorFilterReader.java 299
} while (ch != this.endToken.charAt(0));

            // now test endToken
            if (ch != -1 && this.endToken.length() > 1) {
                int endTokenMatchPos = 1;

                do {
                    if (previousIndex != -1 && previousIndex < this.endToken.length()) {
                        ch = this.endToken.charAt(previousIndex++);
                    } else {
                        ch = in.read();
                    }

                    if (ch != -1) {
                        key.append((char) ch);

                        if (ch != this.endToken.charAt(endTokenMatchPos++)) {
                            ch = -1; // not really EOF but to trigger code below
                            break;
                        }

                    } else {
                        break;
                    }
                } while (endTokenMatchPos < this.endToken.length());
            }

            // There is nothing left to read so we have the situation where the begin/end token
            // are in fact the same and as there is nothing left to read we have got ourselves
            // end of a token boundary so let it pass through.
            if (ch == -1) {
                replaceData = key.toString();
                replaceIndex = 1;
                return replaceData.charAt(0);
            }

            String value = null;
            try {
                boolean escapeFound = false;
                if (useEscape) {
                    if (key.toString().startsWith(escapeString + orginalBeginToken)) {
File Line
org/codehaus/plexus/interpolation/StringSearchInterpolator.java 124
org/codehaus/plexus/interpolation/fixed/FixedStringSearchInterpolator.java 181
do {
                result.append(input, endIdx + 1, startIdx);

                endIdx = input.indexOf(endExpr, startIdx + 1);
                if (endIdx < 0) {
                    break;
                }

                final String wholeExpr = input.substring(startIdx, endIdx + endExpr.length());
                String realExpr = wholeExpr.substring(startExpr.length(), wholeExpr.length() - endExpr.length());

                if (startIdx >= 0 && escapeString != null && escapeString.length() > 0) {
                    int startEscapeIdx = startIdx == 0 ? 0 : startIdx - escapeString.length();
                    if (startEscapeIdx >= 0) {
                        String escape = input.substring(startEscapeIdx, startIdx);
                        if (escapeString.equals(escape)) {
                            result.append(wholeExpr);
                            result.replace(startEscapeIdx, startEscapeIdx + escapeString.length(), "");
                            continue;
                        }
                    }
                }

                boolean resolved = false;
                if (!unresolvable.contains(wholeExpr)) {
File Line
org/codehaus/plexus/interpolation/StringSearchInterpolator.java 54
org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java 78
}

    /**
     * {@inheritDoc}
     */
    public void addValueSource(ValueSource valueSource) {
        valueSources.add(valueSource);
    }

    /**
     * {@inheritDoc}
     */
    public void removeValuesSource(ValueSource valueSource) {
        valueSources.remove(valueSource);
    }

    /**
     * {@inheritDoc}
     */
    public void addPostProcessor(InterpolationPostProcessor postProcessor) {
        postProcessors.add(postProcessor);
    }

    /**
     * {@inheritDoc}
     */
    public void removePostProcessor(InterpolationPostProcessor postProcessor) {
        postProcessors.remove(postProcessor);
    }

    public String interpolate(String input, String thisPrefixPattern) throws InterpolationException {
        return interpolate(input, new SimpleRecursionInterceptor());
    }

    public String interpolate(String input, String thisPrefixPattern, RecursionInterceptor recursionInterceptor)
            throws InterpolationException {
        return interpolate(input, recursionInterceptor);
    }

    public String interpolate(String input) throws InterpolationException {
        return interpolate(input, new SimpleRecursionInterceptor());
    }

    /**
     * Entry point for recursive resolution of an expression and all of its
     * nested expressions.
     *
     * TODO: Ensure unresolvable expressions don't trigger infinite recursion.
     */
    public String interpolate(String input, RecursionInterceptor recursionInterceptor) throws InterpolationException {
        try {
            return interpolate(input, recursionInterceptor, new HashSet<String>());
File Line
org/codehaus/plexus/interpolation/StringSearchInterpolator.java 239
org/codehaus/plexus/interpolation/multi/MultiDelimiterStringSearchInterpolator.java 291
List<?> messages = new ArrayList();
        for (ValueSource vs : valueSources) {
            List feedback = vs.getFeedback();
            if (feedback != null && !feedback.isEmpty()) {
                messages.addAll(feedback);
            }
        }

        return messages;
    }

    /**
     * Clear the feedback messages from previous interpolate(..) calls.
     */
    public void clearFeedback() {
        for (ValueSource vs : valueSources) {
            vs.clearFeedback();
        }
    }

    public boolean isCacheAnswers() {
        return cacheAnswers;
    }

    public void setCacheAnswers(boolean cacheAnswers) {
        this.cacheAnswers = cacheAnswers;
    }

    public void clearAnswers() {
        existingAnswers.clear();
    }

    public String getEscapeString() {
        return escapeString;
    }

    public void setEscapeString(String escapeString) {
        this.escapeString = escapeString;
    }