<?xml version="1.0"?>

<ruleset name="java.lang.String Rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../etc/ruleset_xml_schema.xml">
  <description>
These rules deal with different problems that can occur with manipulation of the class String or StringBuffer.
  </description>


    <rule name="AvoidDuplicateLiterals"
        message="The String literal {0} appears {1} times in this file; the first occurrence is on line {2}"
        class="net.sourceforge.pmd.rules.strings.AvoidDuplicateLiteralsRule"
        externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#AvoidDuplicateLiterals">
    <description>
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
    </description>
        <priority>3</priority>
   <properties>
    <property name="threshold" description="The number of duplicate literals reporting threshold" value="4"/>
   </properties>
    <example>
<![CDATA[
public class Foo {
 private void bar() {
    buz("Howdy");
    buz("Howdy");
    buz("Howdy");
    buz("Howdy");
 }
 private void buz(String x) {}
}
]]>
    </example>
  </rule>

    <rule name="StringInstantiation"
        message="Avoid instantiating String objects; this is usually unnecessary."
        class="net.sourceforge.pmd.rules.strings.StringInstantiation"
        externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#StringInstantiation">
    <description>
Avoid instantiating String objects; this is usually unnecessary.
    </description>
       <priority>2</priority>
    <example>
<![CDATA[
public class Foo {
 private String bar = new String("bar"); // just do a String bar = "bar";
}
]]>
    </example>
    </rule>

   <rule name="StringToString"
        message="Avoid calling toString() on String objects; this is unnecessary"
        class="net.sourceforge.pmd.rules.strings.StringToStringRule"
        externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#StringToString">
    <description>
    Avoid calling toString() on String objects; this is unnecessary
    </description>
       <priority>3</priority>
    <example>
<![CDATA[
public class Foo {
 private String baz() {
  String bar = "howdy";
  return bar.toString();
 }
}
]]>
    </example>
    </rule>

    <rule name="InefficientStringBuffering"
        message="Avoid concatenating nonliterals in a StringBuffer constructor or append()"
        class="net.sourceforge.pmd.rules.strings.InefficientStringBuffering"
        externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#InefficientStringBuffering">
    <description>
Avoid concatenating non literals in a StringBuffer constructor or append().
    </description>
       <priority>3</priority>
    <example>
<![CDATA[
public class Foo {
 void bar() {
  // Avoid this
  StringBuffer sb=new StringBuffer("tmp = "+System.getProperty("java.io.tmpdir"));
  // use instead something like this
  StringBuffer sb = new StringBuffer("tmp = ");
  sb.append(System.getProperty("java.io.tmpdir"));
 }
}
]]>
    </example>
    </rule>

    <rule name="UnnecessaryCaseChange"
          message="Using equalsIgnoreCase() is cleaner than using toUpperCase/toLowerCase().equals()"
           class="net.sourceforge.pmd.rules.strings.UnnecessaryCaseChange"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#UnnecessaryCaseChange">
       <description>
Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()
       </description>
       <priority>3</priority>
       <example>
                 <![CDATA[
 public class Foo {
  public boolean bar(String buz) {
    // should be buz.equalsIgnoreCase("baz")
    return buz.toUpperCase().equals("baz");
    // another unnecessary toUpperCase()
    // return buz.toUpperCase().equalsIgnoreCase("baz");
  }
 }
                 ]]>
       </example>
     </rule>

    <rule name="UseStringBufferLength"
          message="This is an inefficient use of StringBuffer.toString; just call StringBuffer.length instead"
          class="net.sourceforge.pmd.rules.strings.UseStringBufferLength"
          externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#UseStringBufferLength">
      <description>
 Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals("")
          or StringBuffer.toString().length() ==
      </description>
      <properties>
      </properties>
        <priority>3</priority>
      <example>
  <![CDATA[
public class Foo {
 void bar() {
  StringBuffer sb = new StringBuffer();
  // this is bad
  if(sb.toString().equals("")) {}
  // this is good
  if(sb.length() == 0) {}
 }
}

  ]]>
      </example>
    </rule>


    <rule name="AppendCharacterWithChar"
        message="Avoid appending characters as strings in StringBuffer.append"
        class="net.sourceforge.pmd.rules.strings.AppendCharacterWithChar"
        externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#AppendCharacterWithChar">
    <description>
Avoid concatenating characters as strings in StringBuffer.append
    </description>
       <priority>3</priority>
    <example>
<![CDATA[
public class Foo {
 void bar() {
  StringBuffer sb=new StringBuffer();
  // Avoid this
  sb.append("a");

  // use instead something like this
  StringBuffer sb=new StringBuffer();
  sb.append('a');
 }
}
]]>
    </example>
    </rule>

        <rule name="ConsecutiveLiteralAppends"
        message="StringBuffer.append is called {0} times consecutively, always using String literals"
        class="net.sourceforge.pmd.rules.strings.ConsecutiveLiteralAppends"
        externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#ConsecutiveLiteralAppends">
    <description>
Consecutively calling StringBuffer.append with String literals
    </description>
        <priority>3</priority>
   <properties>
    <property name="threshold" description="The report threshold" value="1"/>
   </properties>
    <example>
<![CDATA[
public class Foo {
 private void bar() {
   StringBuffer buf = new StringBuffer();
   buf.append("Hello").append(" ").append("World"); //bad
   buf.append("Hello World");//good
 }
}
]]>
    </example>
  </rule>


    <rule name="UseIndexOfChar"
        message="String.indexOf(char) is faster than String.indexOf(String)"
        class="net.sourceforge.pmd.rules.strings.UseIndexOfChar"
        externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#UseIndexOfChar">
    <description>
Use String.indexOf(char) when checking for the index of a single character; it's faster.
    </description>
       <priority>3</priority>
    <example>
<![CDATA[
public class Foo {
 void bar() {
  String s = "hello world";
  // avoid this
  if (s.indexOf("d") {}
  // instead do this
  if (s.indexOf('d') {}
 }
}
]]>
    </example>
    </rule>

</ruleset>

