Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Core/JVM/ConstantPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function __construct(ReaderInterface $reader, int $entries)
}
}

/**
* @return StructureInterface[]
*/
public function getEntries(): array
{
return $this->entries;
Expand Down Expand Up @@ -94,31 +97,49 @@ private function read($entryTag): ?StructureInterface
throw new ReadEntryException('Entry tag ' . sprintf('0x%04X', $entryTag) . ' is not defined.');
}

/**
* @return boolean
*/
public function offsetExists($offset)
{
return isset($this->entries[$offset]);
}

/**
* @return StructureInterface
*/
public function offsetGet($offset)
{
return $this->entries[$offset];
}

/**
* @return int
*/
public function count()
{
return count($this->entries);
}

/**
* @throws ReadOnlyException
*/
public function offsetSet($offset, $value)
{
throw new ReadOnlyException('You cannot rewrite datum. The Constant Pool is read-only.');
}

/**
* @throws ReadOnlyException
*/
public function offsetUnset($offset)
{
throw new ReadOnlyException('You cannot rewrite datum. The Constant Pool is read-only.');
}

/**
* @return \ArrayIterator<StructureInterface>
*/
public function getIterator()
{
return new \ArrayIterator($this->entries);
Expand Down
6 changes: 3 additions & 3 deletions src/Packages/java/lang/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use PHPJava\Exceptions\NotImplementedException;
use PHPJava\Packages\java\lang\_Object;
use PHPJava\Packages\PHPJava\Kernel\Behavior\System as SystemBehavior;

// use PHPJava\Packages\java\lang\System\Logger;
// use PHPJava\Packages\java\util\Map;
Expand Down Expand Up @@ -194,12 +195,11 @@ public static function static_getSecurityManager($a = null)
*
* @param mixed $a
* @return mixed
* @throws NotImplementedException
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/package-summary.html#identityHashCode
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html#identityHashCode(java.lang.Object)
*/
public static function static_identityHashCode($a = null)
{
throw new NotImplementedException(__METHOD__);
return SystemBehavior::identityHashCode($a);
}

/**
Expand Down
24 changes: 17 additions & 7 deletions src/Packages/java/lang/_String.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
class _String extends _Object implements CharSequence
{
private $hash = 0;
private $object = null;

/**
Expand Down Expand Up @@ -223,8 +224,7 @@ public function endsWith($a = null)
*
* @param mixed $a
* @return mixed
* @throws NotImplementedException
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/package-summary.html#equals
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#equals(java.lang.Object)
*/
public function equals($a = null)
{
Expand Down Expand Up @@ -304,14 +304,24 @@ public function getChars($a = null, $b = null, $c = null, $d = null)
/**
* Returns a hash code for this string.
*
* @param mixed $a
* @return mixed
* @throws NotImplementedException
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/package-summary.html#hashCode
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#hashCode()
*/
public function hashCode($a = null)
public function hashCode()
{
throw new NotImplementedException(__METHOD__);
$count = $this->length();

$h = $this->hash;
if ($h || !$count) {
return $h;
}

$str = $this->toString();
for ($i = 0; $i < $count; ++$i) {
$h = 31 * $h + ord($str[$i]);
}

return $this->hash = $h;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Packages/java/util/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ public static function static_hash($a = null)
*
* @param mixed $a
* @return mixed
* @throws NotImplementedException
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/package-summary.html#hashCode
* @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Objects.html#hashCode(java.lang.Object)
*/
public static function static_hashCode($a = null)
{
throw new NotImplementedException(__METHOD__);
if ($a === null) {
return 0;
}

return $a->hashCode();
}

/**
Expand Down