Skip to content

Commit cc45500

Browse files
committed
Add imitations
1 parent 066f212 commit cc45500

8 files changed

Lines changed: 84 additions & 49 deletions

File tree

src/.gitkeep

Whitespace-only changes.

src/imitation/java/lang/ArrayIndexOutOfBoundsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use PHPJava\Kernel\Structures\_Utf8;
55

6-
class ArrayIndexOutOfBoundsException extends \Exception
6+
class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException
77
{
88

99
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\lang;
3+
4+
class Exception extends Throwable
5+
{
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\lang;
3+
4+
class IndexOutOfBoundsException extends RuntimeException
5+
{
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\lang;
3+
4+
class RuntimeException extends Exception
5+
{
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace PHPJava\Imitation\java\lang;
3+
4+
class Throwable extends \Exception
5+
{
6+
use \PHPJava\Imitation\PHPJava\Extended\_Object;
7+
}

src/imitation/java/lang/_Object.php

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,5 @@
33

44
class _Object
55
{
6-
public function clone(): _Object
7-
{
8-
return clone $this;
9-
}
10-
11-
12-
public function equals($object): bool
13-
{
14-
return $this === $object;
15-
}
16-
17-
public function getClass(): self
18-
{
19-
return $this;
20-
}
21-
22-
public function hashCode(): int
23-
{
24-
if (version_compare(PHP_VERSION, '7.3', '<')) {
25-
return crc32(spl_object_hash($this));
26-
}
27-
return spl_object_id($this);
28-
}
29-
30-
public function notify(): void
31-
{
32-
// not implemented.
33-
}
34-
35-
public function notifyAll(): void
36-
{
37-
// not implemented.
38-
}
39-
40-
public function toString(): string
41-
{
42-
return 'java.lang.Object@PHPJava' . spl_object_hash($this);
43-
}
44-
45-
public function __toString(): string
46-
{
47-
return $this->toString();
48-
}
49-
50-
public function wait(int $timeout = null, int $nanos = null): void
51-
{
52-
// not implemented.
53-
}
6+
use \PHPJava\Imitation\PHPJava\Extended\_Object;
547
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
namespace PHPJava\Imitation\PHPJava\Extended;
3+
4+
trait _Object
5+
{
6+
public function clone(): _Object
7+
{
8+
return clone $this;
9+
}
10+
11+
12+
public function equals($object): bool
13+
{
14+
return $this === $object;
15+
}
16+
17+
public function getClass(): self
18+
{
19+
return $this;
20+
}
21+
22+
public function hashCode(): int
23+
{
24+
if (version_compare(PHP_VERSION, '7.2', '<')) {
25+
return crc32(spl_object_hash($this));
26+
}
27+
return spl_object_id($this);
28+
}
29+
30+
public function notify(): void
31+
{
32+
// not implemented.
33+
}
34+
35+
public function notifyAll(): void
36+
{
37+
// not implemented.
38+
}
39+
40+
public function toString(): string
41+
{
42+
return 'java.lang.Object@PHPJava' . spl_object_hash($this);
43+
}
44+
45+
public function __toString(): string
46+
{
47+
return $this->toString();
48+
}
49+
50+
public function wait(int $timeout = null, int $nanos = null): void
51+
{
52+
// not implemented.
53+
}
54+
}

0 commit comments

Comments
 (0)