/** * Returns the current value, consisting of the {@code prefix}, the values * added so far separated by the {@code delimiter}, and the {@code suffix}, * unless no elements have been added in which case, the * {@code prefix + suffix} or the {@code emptyValue} characters are returned * * @return \PHPJ\Lang\String * the string representation of this {@code StringJoiner} */ public function toString() { if ($this->value == null) { return $this->emptyValue; } if ($this->suffix->equals(new String(""))) { return $this->value->toString(); } $initialLength = $this->value->length(); $result = $this->value->append($this->suffix)->toString(); // reset value to pre-append initialLength $this->value->setLength($initialLength); return $result; }
public function testReverse() { $sb = new StringBuilder(); $sb->append('This'); $sb->reverse(); $this->assertEquals("sihT", $sb->toString()); $sb->append(1); $sb->reverse(); $sb->append(1); $this->assertEquals("1This1", $sb->toString()); }