Esempio n. 1
0
 public function testLength()
 {
     $sj = new StringJoiner("_");
     $this->assertEquals(0, $sj->length());
     $sj = new StringJoiner("_", ">", "<");
     $this->assertEquals(2, $sj->length());
     $sj = new StringJoiner("_");
     $sj->add("1");
     $sj->add("2");
     $this->assertEquals(3, $sj->length());
 }
Esempio n. 2
0
File: String.php Progetto: phpj/phpj
 /**
  * Returns a new String composed of copies of the
  * {@code CharSequence elements} joined together with a copy of
  * the specified {@code delimiter}.
  *
  * <blockquote>For example,
  * <pre>{@code
  *     String message = String.join("-", "Java", "is", "cool");
  *     // message returned is: "Java-is-cool"
  * }</pre></blockquote>
  *
  * Note that if an element is null, then {@code "null"} is added.
  *
  * @param  string|\PHPJ\Lang\String $delimiter
  *         the delimiter that separates each element
  *
  * @return \PHPJ\Lang\String
  *         a new {@code String} that is composed of the {@code elements}
  *         separated by the {@code delimiter}
  *
  * @throws NullPointerException If {@code delimiter} or {@code elements}
  *         is {@code null}
  *
  * @see java.util.StringJoiner
  * @since 1.8
  */
 public static function join($delimiter)
 {
     $sequence = self::joinGetSequence(func_get_args());
     $sj = new StringJoiner((string) $delimiter);
     foreach ($sequence as $cs) {
         $sj->add($cs);
     }
     return $sj->toString();
 }