@@ -54,4 +54,73 @@ class Fi {
5454 }
5555}
5656
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 (
73+ public interfaceAddresses : InterfaceAddress [ ] ,
74+ public loopback = false ,
75+ public up = true ,
76+ ) { }
77+ getInterfaceAddresses ( ) { return new ArrayList ( this . interfaceAddresses ) ; }
78+ static getNetworkInterfaces ( ) {
79+ return [
80+ new NetworkInterface ( [ new InterfaceAddress ( new Inet6Address ( "0:0:0:0:0:0:0:1" ) ) , new InterfaceAddress ( new Inet4Address ( "127.0.0.1" ) ) ] ) , //loopback
81+ new NetworkInterface ( [ new InterfaceAddress ( new Inet6Address ( "fe80:0:0:0:216:3eff:feaa:b35c" ) ) , new InterfaceAddress ( new Inet4Address ( "1.2.3.4" ) ) ] ) , //eth0
82+ ] ;
83+ }
84+ }
85+ class Stream < T > {
86+ iterator : IteratorObject < T , undefined > ;
87+ constructor ( items :T [ ] ) {
88+ this . iterator = items . values ( ) ;
89+ }
90+ map < U > ( operation :( item :T ) => U ) {
91+ ( this as never as Stream < U > ) . iterator = this . iterator . map ( operation ) ;
92+ return this as never as Stream < U > ;
93+ }
94+ filter ( operation :( item :T ) => boolean ) {
95+ this . iterator = this . iterator . filter ( operation ) ;
96+ return this ;
97+ }
98+ findFirst ( ) {
99+ return new Optional < T > ( this . iterator . next ( ) ?. value ?? null ) ;
100+ }
101+ }
102+ class Optional < T > {
103+ constructor ( public item :T | null ) { }
104+ orElse < U > ( value :U ) {
105+ return this . item ?? value ;
106+ }
107+ }
108+ class InterfaceAddress {
109+ constructor ( public address : InetAddress ) { }
110+ getAddress ( ) { return this . address ; }
111+ }
112+ class InetAddress {
113+ constructor ( public hostAddress : string ) { }
114+ getHostAddress ( ) { return this . hostAddress ; }
115+ }
116+ class Inet4Address extends InetAddress { }
117+ class Inet6Address extends InetAddress { }
118+
119+ const Packages = {
120+ java : {
121+ net : { NetworkInterface, Inet4Address } ,
122+ util : { Collections }
123+ }
124+ } ;
125+
126+ Object . assign ( globalThis , { Pattern, ObjectIntMap, Seq, Fi, Packages} ) ;
0 commit comments