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 committed Feb 29, 2016
1 parent 11f7d3f commit 11b8fa1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Wikibase DataModel release notes

## Version 5.1 (dev)
## Version 5.1.0 (dev)

* Deprecated `FingerprintHolder` and `StatementListHolder`
* Added `clear` to `TermList`, `AliasGroupList` and `StatementList`

## Version 5.0.2 (2016-02-23)

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

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

}
9 changes: 9 additions & 0 deletions src/Term/AliasGroupList.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,13 @@ public function toTextArray() {
return $array;
}

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

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

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

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

public function testClear() {
$statement1 = $this->getStatement( 1, null );
$statement2 = $this->getStatement( 2, 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 @@ -384,4 +384,14 @@ public function testToTextArray() {
$this->assertEquals( $expected, $list->toTextArray() );
}

public function testClear() {
$list = new AliasGroupList();
$list->setAliasesForLanguage( 'en', array( 'foo', 'baz' ) );
$list->setAliasesForLanguage( 'de', array( '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 @@ -398,4 +398,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 11b8fa1

Please sign in to comment.