@Test public void testIsLicenseText() throws Exception { CopyrightHeader header1 = new CopyrightHeader(80, null, null, null, null); CopyrightHeader header2 = new CopyrightHeader(160, null, null, null, null); CopyrightHeader header3 = new CopyrightHeader(80, null, null, "#", null); StringWriter writer = new StringWriter(); header1.writeTo(writer); String headerString1 = writer.toString(); writer.getBuffer().setLength(0); header2.writeTo(writer); String headerString2 = writer.toString(); writer.getBuffer().setLength(0); header3.writeTo(writer); String headerString3 = writer.toString(); writer.getBuffer().setLength(0); assertTrue(header1.isLicenseText(headerString1)); assertTrue(header1.isLicenseText(headerString2)); assertFalse(header1.isLicenseText(headerString3)); assertTrue(header2.isLicenseText(headerString1)); assertTrue(header2.isLicenseText(headerString2)); assertFalse(header2.isLicenseText(headerString3)); assertFalse(header3.isLicenseText(headerString1)); assertFalse(header3.isLicenseText(headerString2)); assertTrue(header3.isLicenseText(headerString3)); }
public boolean isLicenseText(@Nonnull CharSequence text) { String[] textParts = LINE_BREAK_PATTERN.split(text); if (textParts.length == 0) { return false; } if ((commentIntro != null) && !textParts[0].equals(commentIntro)) { return false; } if ((commentOutro != null) && !textParts[textParts.length - 1].equals(commentOutro)) { return false; } int textStartIndex = (commentIntro == null) ? 0 : 1; int textEndIndex = (commentOutro == null) ? textParts.length : (textParts.length - 1); StringBuilder licenseText = new StringBuilder(); for (int i = textStartIndex; i < textEndIndex; i++) { String line = textParts[i]; int lineStartIndex = 0; int lineEndIndex = line.length(); if (commentLineStart != null) { if (!line.startsWith(commentLineStart.trim())) { return false; } lineStartIndex = commentLineStart.length(); } if (commentLineEnd != null) { if (!line.endsWith(commentLineEnd.trim())) { return false; } lineEndIndex = line.length() - commentLineEnd.length(); } if (lineStartIndex < lineEndIndex) { licenseText.append(line.substring(lineStartIndex, lineEndIndex).trim()); } licenseText.append(' '); } licenseText.setLength(licenseText.length() - 1); try { String licenseTemplate = getLicenseTextTemplate().replace('\n', ' '); return licenseTemplate.equals(licenseText.toString()); } catch (IOException e) { return false; } }
CopyrightHeader { public boolean isLicenseText(@Nonnull CharSequence text) { String[] textParts = LINE_BREAK_PATTERN.split(text); if (textParts.length == 0) { return false; } if ((commentIntro != null) && !textParts[0].equals(commentIntro)) { return false; } if ((commentOutro != null) && !textParts[textParts.length - 1].equals(commentOutro)) { return false; } int textStartIndex = (commentIntro == null) ? 0 : 1; int textEndIndex = (commentOutro == null) ? textParts.length : (textParts.length - 1); StringBuilder licenseText = new StringBuilder(); for (int i = textStartIndex; i < textEndIndex; i++) { String line = textParts[i]; int lineStartIndex = 0; int lineEndIndex = line.length(); if (commentLineStart != null) { if (!line.startsWith(commentLineStart.trim())) { return false; } lineStartIndex = commentLineStart.length(); } if (commentLineEnd != null) { if (!line.endsWith(commentLineEnd.trim())) { return false; } lineEndIndex = line.length() - commentLineEnd.length(); } if (lineStartIndex < lineEndIndex) { licenseText.append(line.substring(lineStartIndex, lineEndIndex).trim()); } licenseText.append(' '); } licenseText.setLength(licenseText.length() - 1); try { String licenseTemplate = getLicenseTextTemplate().replace('\n', ' '); return licenseTemplate.equals(licenseText.toString()); } catch (IOException e) { return false; } } }
CopyrightHeader { public boolean isLicenseText(@Nonnull CharSequence text) { String[] textParts = LINE_BREAK_PATTERN.split(text); if (textParts.length == 0) { return false; } if ((commentIntro != null) && !textParts[0].equals(commentIntro)) { return false; } if ((commentOutro != null) && !textParts[textParts.length - 1].equals(commentOutro)) { return false; } int textStartIndex = (commentIntro == null) ? 0 : 1; int textEndIndex = (commentOutro == null) ? textParts.length : (textParts.length - 1); StringBuilder licenseText = new StringBuilder(); for (int i = textStartIndex; i < textEndIndex; i++) { String line = textParts[i]; int lineStartIndex = 0; int lineEndIndex = line.length(); if (commentLineStart != null) { if (!line.startsWith(commentLineStart.trim())) { return false; } lineStartIndex = commentLineStart.length(); } if (commentLineEnd != null) { if (!line.endsWith(commentLineEnd.trim())) { return false; } lineEndIndex = line.length() - commentLineEnd.length(); } if (lineStartIndex < lineEndIndex) { licenseText.append(line.substring(lineStartIndex, lineEndIndex).trim()); } licenseText.append(' '); } licenseText.setLength(licenseText.length() - 1); try { String licenseTemplate = getLicenseTextTemplate().replace('\n', ' '); return licenseTemplate.equals(licenseText.toString()); } catch (IOException e) { return false; } } CopyrightHeader(
            int lineWidth,
            @Nullable String commentIntro,
            @Nullable String commentOutro,
            @Nullable String commentLineStart,
            @Nullable String commentLineEnd); }
CopyrightHeader { public boolean isLicenseText(@Nonnull CharSequence text) { String[] textParts = LINE_BREAK_PATTERN.split(text); if (textParts.length == 0) { return false; } if ((commentIntro != null) && !textParts[0].equals(commentIntro)) { return false; } if ((commentOutro != null) && !textParts[textParts.length - 1].equals(commentOutro)) { return false; } int textStartIndex = (commentIntro == null) ? 0 : 1; int textEndIndex = (commentOutro == null) ? textParts.length : (textParts.length - 1); StringBuilder licenseText = new StringBuilder(); for (int i = textStartIndex; i < textEndIndex; i++) { String line = textParts[i]; int lineStartIndex = 0; int lineEndIndex = line.length(); if (commentLineStart != null) { if (!line.startsWith(commentLineStart.trim())) { return false; } lineStartIndex = commentLineStart.length(); } if (commentLineEnd != null) { if (!line.endsWith(commentLineEnd.trim())) { return false; } lineEndIndex = line.length() - commentLineEnd.length(); } if (lineStartIndex < lineEndIndex) { licenseText.append(line.substring(lineStartIndex, lineEndIndex).trim()); } licenseText.append(' '); } licenseText.setLength(licenseText.length() - 1); try { String licenseTemplate = getLicenseTextTemplate().replace('\n', ' '); return licenseTemplate.equals(licenseText.toString()); } catch (IOException e) { return false; } } CopyrightHeader(
            int lineWidth,
            @Nullable String commentIntro,
            @Nullable String commentOutro,
            @Nullable String commentLineStart,
            @Nullable String commentLineEnd); void writeTo(@Nonnull Writer writer); boolean isLicenseText(@Nonnull CharSequence text); }
CopyrightHeader { public boolean isLicenseText(@Nonnull CharSequence text) { String[] textParts = LINE_BREAK_PATTERN.split(text); if (textParts.length == 0) { return false; } if ((commentIntro != null) && !textParts[0].equals(commentIntro)) { return false; } if ((commentOutro != null) && !textParts[textParts.length - 1].equals(commentOutro)) { return false; } int textStartIndex = (commentIntro == null) ? 0 : 1; int textEndIndex = (commentOutro == null) ? textParts.length : (textParts.length - 1); StringBuilder licenseText = new StringBuilder(); for (int i = textStartIndex; i < textEndIndex; i++) { String line = textParts[i]; int lineStartIndex = 0; int lineEndIndex = line.length(); if (commentLineStart != null) { if (!line.startsWith(commentLineStart.trim())) { return false; } lineStartIndex = commentLineStart.length(); } if (commentLineEnd != null) { if (!line.endsWith(commentLineEnd.trim())) { return false; } lineEndIndex = line.length() - commentLineEnd.length(); } if (lineStartIndex < lineEndIndex) { licenseText.append(line.substring(lineStartIndex, lineEndIndex).trim()); } licenseText.append(' '); } licenseText.setLength(licenseText.length() - 1); try { String licenseTemplate = getLicenseTextTemplate().replace('\n', ' '); return licenseTemplate.equals(licenseText.toString()); } catch (IOException e) { return false; } } CopyrightHeader(
            int lineWidth,
            @Nullable String commentIntro,
            @Nullable String commentOutro,
            @Nullable String commentLineStart,
            @Nullable String commentLineEnd); void writeTo(@Nonnull Writer writer); boolean isLicenseText(@Nonnull CharSequence text);  }