@@ -54,4 +54,64 @@ class Fi {
54
54
}
55
55
}
56
56
57
- Object . assign ( globalThis , { Pattern, ObjectIntMap, Seq, Fi} ) ;
57
+ const Collections = {
58
+ list < T > ( e :Enumeration < T > ) {
59
+ return new ArrayList ( e . items ) ;
60
+ }
61
+ } ;
62
+ class Enumeration < T > {
63
+ constructor ( public items :T [ ] ) { }
64
+ }
65
+ class ArrayList < T > {
66
+ constructor ( public items :T [ ] ) { }
67
+ stream ( ) {
68
+ return new Stream ( this . items ) ;
69
+ }
70
+ }
71
+ class NetworkInterface {
72
+ constructor ( public interfaceAddresses : InterfaceAddress [ ] ) { }
73
+ getInterfaceAddresses ( ) { return new ArrayList ( this . interfaceAddresses ) ; }
74
+ }
75
+ class Stream < T > {
76
+ iterator : IteratorObject < T , undefined > ;
77
+ constructor ( items :T [ ] ) {
78
+ this . iterator = items . values ( ) ;
79
+ }
80
+ map < U > ( operation :( item :T ) => U ) {
81
+ ( this as never as Stream < U > ) . iterator = this . iterator . map ( operation ) ;
82
+ return this as never as Stream < U > ;
83
+ }
84
+ filter ( operation :( item :T ) => boolean ) {
85
+ this . iterator = this . iterator . filter ( operation ) ;
86
+ return this ;
87
+ }
88
+ findFirst ( ) {
89
+ return new Optional < T > ( this . iterator . next ( ) ?. value ?? null ) ;
90
+ }
91
+ }
92
+ class Optional < T > {
93
+ constructor ( public item :T | null ) { }
94
+ orElse < U > ( value :U ) {
95
+ return this . item ?? value ;
96
+ }
97
+ }
98
+ class InterfaceAddress {
99
+ constructor ( public address : InetAddress ) { }
100
+ getAddress ( ) { return this . address ; }
101
+ }
102
+ class InetAddress {
103
+ constructor ( public hostAddress : string ) { }
104
+ getHostAddress ( ) { return this . hostAddress ; }
105
+ }
106
+ class Inet4Address extends InetAddress {
107
+
108
+ }
109
+
110
+ const Packages = {
111
+ java : {
112
+ net : { NetworkInterface, Inet4Address } ,
113
+ util : { Collections }
114
+ }
115
+ } ;
116
+
117
+ Object . assign ( globalThis , { Pattern, ObjectIntMap, Seq, Fi, Packages} ) ;
0 commit comments