Skip to content

Commit 11b8fa1

Browse files
committed
Add clear to list classes
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
1 parent 11f7d3f commit 11b8fa1

7 files changed

Lines changed: 59 additions & 1 deletion

File tree

RELEASE-NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Wikibase DataModel release notes
22

3-
## Version 5.1 (dev)
3+
## Version 5.1.0 (dev)
44

55
* Deprecated `FingerprintHolder` and `StatementListHolder`
6+
* Added `clear` to `TermList`, `AliasGroupList` and `StatementList`
67

78
## Version 5.0.2 (2016-02-23)
89

src/Statement/StatementList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,13 @@ public function filter( StatementFilter $filter ) {
325325
return $statementList;
326326
}
327327

328+
/**
329+
* Removes all statements from this list.
330+
*
331+
* @since 5.1
332+
*/
333+
public function clear() {
334+
$this->statements = array();
335+
}
336+
328337
}

src/Term/AliasGroupList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,13 @@ public function toTextArray() {
216216
return $array;
217217
}
218218

219+
/**
220+
* Removes all alias groups from this list.
221+
*
222+
* @since 5.1
223+
*/
224+
public function clear() {
225+
$this->groups = array();
226+
}
227+
219228
}

src/Term/TermList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@ public function hasTerm( Term $term ) {
190190
&& $this->terms[$term->getLanguageCode()]->equals( $term );
191191
}
192192

193+
/**
194+
* Removes all terms from this list.
195+
*
196+
* @since 5.1
197+
*/
198+
public function clear() {
199+
$this->terms = array();
200+
}
201+
193202
}

tests/unit/Statement/StatementListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,14 @@ public function testFilter() {
650650
);
651651
}
652652

653+
public function testClear() {
654+
$statement1 = $this->getStatement( 1, null );
655+
$statement2 = $this->getStatement( 2, null );
656+
$statements = new StatementList( $statement1, $statement2 );
657+
658+
$statements->clear();
659+
660+
$this->assertEquals( new StatementList(), $statements );
661+
}
662+
653663
}

tests/unit/Term/AliasGroupListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,14 @@ public function testToTextArray() {
384384
$this->assertEquals( $expected, $list->toTextArray() );
385385
}
386386

387+
public function testClear() {
388+
$list = new AliasGroupList();
389+
$list->setAliasesForLanguage( 'en', array( 'foo', 'baz' ) );
390+
$list->setAliasesForLanguage( 'de', array( 'bar' ) );
391+
392+
$list->clear();
393+
394+
$this->assertEquals( new AliasGroupList(), $list );
395+
}
396+
387397
}

tests/unit/Term/TermListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,14 @@ public function testGivenEmptyTerm_setTermRemovesExistingOne() {
398398
);
399399
}
400400

401+
public function testClear() {
402+
$list = new TermList();
403+
$list->setTextForLanguage( 'en', 'foo' );
404+
$list->setTextForLanguage( 'de', 'bar' );
405+
406+
$list->clear();
407+
408+
$this->assertEquals( new TermList(), $list );
409+
}
410+
401411
}

0 commit comments

Comments
 (0)