Skip to content

Commit

Permalink
Add clear to list classes
Browse files Browse the repository at this point in the history
This is needed as a replacement for users of the holder interfaces to
remove all elements from one of the given list classes.

Bug: T128363
  • Loading branch information
Benestar authored and thiemowmde committed Feb 28, 2017
1 parent d6a55f2 commit 99edc1f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Removed `HashArray::indicesAreUpToDate`
* Removed `HashArray::removeDuplicates`
* Removed `$acceptDuplicates` feature from `HashArray`
* Added `clear` to `TermList`, `AliasGroupList` and `StatementList`

## Version 6.3.1 (2016-11-30)

Expand Down
9 changes: 9 additions & 0 deletions src/Statement/StatementList.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ public function filter( StatementFilter $filter ) {
return $statementList;
}

/**
* Removes all statements from this list.
*
* @since 6.0
*/
public function clear() {
$this->statements = [];
}

/**
* @see http://php.net/manual/en/language.oop5.cloning.php
*
Expand Down
9 changes: 9 additions & 0 deletions src/Term/AliasGroupList.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,13 @@ public function toTextArray() {
return $array;
}

/**
* Removes all alias groups from this list.
*
* @since 6.0
*/
public function clear() {
$this->groups = [];
}

}
9 changes: 9 additions & 0 deletions src/Term/TermList.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,13 @@ public function hasTerm( Term $term ) {
&& $this->terms[$term->getLanguageCode()]->equals( $term );
}

/**
* Removes all terms from this list.
*
* @since 6.0
*/
public function clear() {
$this->terms = [];
}

}
10 changes: 10 additions & 0 deletions tests/unit/Statement/StatementListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,14 @@ public function testFilter() {
);
}

public function testClear() {
$statement1 = $this->getStatement( 'P1', null );
$statement2 = $this->getStatement( 'P2', null );
$statements = new StatementList( $statement1, $statement2 );

$statements->clear();

$this->assertEquals( new StatementList(), $statements );
}

}
10 changes: 10 additions & 0 deletions tests/unit/Term/AliasGroupListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,14 @@ public function testToTextArray() {
$this->assertEquals( $expected, $list->toTextArray() );
}

public function testClear() {
$list = new AliasGroupList();
$list->setAliasesForLanguage( 'en', [ 'foo', 'baz' ] );
$list->setAliasesForLanguage( 'de', [ 'bar' ] );

$list->clear();

$this->assertEquals( new AliasGroupList(), $list );
}

}
10 changes: 10 additions & 0 deletions tests/unit/Term/TermListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,14 @@ public function testGivenEmptyTerm_setTermRemovesExistingOne() {
);
}

public function testClear() {
$list = new TermList();
$list->setTextForLanguage( 'en', 'foo' );
$list->setTextForLanguage( 'de', 'bar' );

$list->clear();

$this->assertEquals( new TermList(), $list );
}

}

0 comments on commit 99edc1f

Please sign in to comment.