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