Skip to content

Commit 043dd55

Browse files
committed
Make Package comparable
1 parent 43dc06d commit 043dd55

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/main/php/lang/reflection/Package.class.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php namespace lang\reflection;
22

3-
use lang\{ClassLoader, IClassLoader, Reflection, IllegalArgumentException};
3+
use lang\{ClassLoader, IClassLoader, Reflection, IllegalArgumentException, Value};
44

55
/**
66
* Represents a namespace, which may exist in various class loaders
77
*
88
* @test lang.reflection.unittest.PackageTest
99
*/
10-
class Package {
10+
class Package implements Value {
1111
private $name;
1212

1313
/**
@@ -106,4 +106,23 @@ public function type($name) {
106106

107107
throw new IllegalArgumentException('Given type '.$type.' is not in package '.$this->name);
108108
}
109+
110+
/** @return string */
111+
public function hashCode() { return md5($this->name); }
112+
113+
/** @return string */
114+
public function toString() { return nameof($this).'<'.$this->name().'>'; }
115+
116+
/**
117+
* Compares this member to another value
118+
*
119+
* @param var $value
120+
* @return int
121+
*/
122+
public function compareTo($value) {
123+
return $value instanceof self
124+
? $this->name <=> $value->name
125+
: 1
126+
;
127+
}
109128
}

0 commit comments

Comments
 (0)