Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3780345
D2508.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D2508.diff
View Options
diff --git a/src/Collections/BaseCollection.php b/src/Collections/BaseCollection.php
--- a/src/Collections/BaseCollection.php
+++ b/src/Collections/BaseCollection.php
@@ -23,4 +23,6 @@
public function count () : int;
+ public function isEmpty () : bool;
+
}
diff --git a/src/Collections/HashMap.php b/src/Collections/HashMap.php
--- a/src/Collections/HashMap.php
+++ b/src/Collections/HashMap.php
@@ -79,6 +79,10 @@
return count($this->map);
}
+ public function isEmpty () : bool {
+ return $this->count() === 0;
+ }
+
public function clear () : self {
$this->map = [];
diff --git a/src/Collections/Vector.php b/src/Collections/Vector.php
--- a/src/Collections/Vector.php
+++ b/src/Collections/Vector.php
@@ -100,6 +100,10 @@
return count($this->items);
}
+ public function isEmpty () : bool {
+ return $this->count() === 0;
+ }
+
public function clear () : self {
$this->items = [];
diff --git a/tests/Collections/HashMapTest.php b/tests/Collections/HashMapTest.php
--- a/tests/Collections/HashMapTest.php
+++ b/tests/Collections/HashMapTest.php
@@ -127,6 +127,12 @@
$this->assertSame(0, $this->map->count());
}
+ public function testIsEmpty () : void {
+ $this->map->clear();
+
+ $this->assertTrue($this->map->isEmpty());
+ }
+
public function testMerge () {
$iterable = [
"The Culture" => "Iain M. Banks", // existing key
diff --git a/tests/Collections/VectorTest.php b/tests/Collections/VectorTest.php
--- a/tests/Collections/VectorTest.php
+++ b/tests/Collections/VectorTest.php
@@ -76,6 +76,12 @@
$this->assertEquals(0, $this->vector->count());
}
+ public function testIsEmpty () : void {
+ $this->vector->clear();
+
+ $this->assertTrue($this->vector->isEmpty());
+ }
+
public function testAppend () : void {
$this->vector->append([6, 7, 8]);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 13:21 (21 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264654
Default Alt Text
D2508.diff (1 KB)
Attached To
Mode
D2508: Allow to check if a vector or map is empty
Attached
Detach File
Event Timeline
Log In to Comment