public function testSetLength() { $sb = new StringBuilder(); $sb->setLength(200); $this->assertEquals(200, $sb->capacity()); $this->assertEquals(200, $sb->length()); $sb = new StringBuilder(); $sb->setLength(20); $this->assertEquals(34, $sb->capacity()); $this->assertEquals(20, $sb->length()); }
/** * 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; }