Skip to content

Commit b0a0cce

Browse files
committed
Add a bunch more function wrappers.
Support publishing IKVM.Java.Extensions: this will be very useful, and I think it's mature enough now.
1 parent 06cc475 commit b0a0cce

File tree

9 files changed

+148
-3
lines changed

9 files changed

+148
-3
lines changed

src/IKVM.Java.Extensions/IKVM.Java.Extensions.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55

66
<PropertyGroup>
77
<TargetFrameworks>net472;net6.0;net8.0</TargetFrameworks>
8+
<Nullable>true</Nullable>
9+
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
10+
<PackageReadmeFile>README.md</PackageReadmeFile>
11+
<Description>Various extensions for working against Java types.</Description>
812
</PropertyGroup>
913

14+
<ItemGroup>
15+
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="." />
16+
<None Include="..\..\README.md" Pack="true" PackagePath="." />
17+
</ItemGroup>
18+
1019
<Import Project="$(MSBuildThisFileDirectory)..\..\IKVM.deps.targets" />
1120
<Import Project="$(MSBuildThisFileDirectory)..\..\IKVM.refs.targets" />
1221

src/IKVM.Java.Extensions/java/lang/IterableWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ IEnumerator IEnumerable.GetEnumerator()
4141

4242
}
4343

44-
}
44+
}

src/IKVM.Java.Extensions/java/util/function/BaseStreamExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace java.util.function
66
{
77

8-
public static class BaseStreamExtensions
8+
public static class BaseStreamExtensions
99
{
1010

1111
public static IEnumerable<T> AsEnumerable<T>(this Stream stream)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
3+
namespace java.util.function
4+
{
5+
6+
/// <summary>
7+
/// Implementation of <see cref="DoubleFunction"/> that forwards to a <see cref="Func{Double, TResult}"/>.
8+
/// </summary>
9+
/// <typeparam name="TResult"></typeparam>
10+
public class DelegateDoubleFunction<TResult> : DoubleFunction
11+
{
12+
13+
readonly Func<double, TResult> func;
14+
15+
/// <summary>
16+
/// Initializes a new instance.
17+
/// </summary>
18+
/// <param name="func"></param>
19+
/// <exception cref="ArgumentNullException"></exception>
20+
public DelegateDoubleFunction(Func<double, TResult> func)
21+
{
22+
this.func = func ?? throw new ArgumentNullException(nameof(func));
23+
}
24+
25+
public object apply(double t)
26+
{
27+
return func(t);
28+
}
29+
30+
}
31+
32+
}

src/IKVM.Java.Extensions/java/util/function/DelegateFunction.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
namespace java.util.function
44
{
55

6+
/// <summary>
7+
/// Implementation of <see cref="Function"/> that forwards to a <see cref="Func{T, TResult}"/>.
8+
/// </summary>
9+
/// <typeparam name="TArg"></typeparam>
10+
/// <typeparam name="TResult"></typeparam>
611
public class DelegateFunction<TArg, TResult> : Function
712
{
813

@@ -35,4 +40,36 @@ public object apply(object t)
3540

3641
}
3742

43+
/// <summary>
44+
/// Implementation of <see cref="Function"/> that forwards to a <see cref="Func{T, TResult}"/>.
45+
/// </summary>
46+
/// <typeparam name="TArg"></typeparam>
47+
/// <typeparam name="TResult"></typeparam>
48+
public class DelegateFunction<TArg1, TArg2, TResult> : BiFunction
49+
{
50+
51+
readonly Func<TArg1, TArg2, TResult> func;
52+
53+
/// <summary>
54+
/// Initializes a new instance.
55+
/// </summary>
56+
/// <param name="func"></param>
57+
/// <exception cref="ArgumentNullException"></exception>
58+
public DelegateFunction(Func<TArg1, TArg2, TResult> func)
59+
{
60+
this.func = func ?? throw new ArgumentNullException(nameof(func));
61+
}
62+
63+
public BiFunction andThen(Function after)
64+
{
65+
return BiFunction.__DefaultMethods.andThen(this, after);
66+
}
67+
68+
public object apply(object t1, object t2)
69+
{
70+
return func((TArg1)t1, (TArg2)t2);
71+
}
72+
73+
}
74+
3875
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
3+
namespace java.util.function
4+
{
5+
6+
/// <summary>
7+
/// Implementation of <see cref="IntFunction"/> that forwards to a <see cref="Func{Int32, TResult}"/>.
8+
/// </summary>
9+
/// <typeparam name="TResult"></typeparam>
10+
public class DelegateIntFunction<TResult> : IntFunction
11+
{
12+
13+
readonly Func<int, TResult> func;
14+
15+
/// <summary>
16+
/// Initializes a new instance.
17+
/// </summary>
18+
/// <param name="func"></param>
19+
/// <exception cref="ArgumentNullException"></exception>
20+
public DelegateIntFunction(Func<int, TResult> func)
21+
{
22+
this.func = func ?? throw new ArgumentNullException(nameof(func));
23+
}
24+
25+
public object apply(int t)
26+
{
27+
return func(t);
28+
}
29+
30+
}
31+
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
3+
namespace java.util.function
4+
{
5+
6+
/// <summary>
7+
/// Implementation of <see cref="LongFunction"/> that forwards to a <see cref="Func{Int64, TResult}"/>.
8+
/// </summary>
9+
/// <typeparam name="TResult"></typeparam>
10+
public class DelegateLongFunction<TResult> : LongFunction
11+
{
12+
13+
readonly Func<long, TResult> func;
14+
15+
/// <summary>
16+
/// Initializes a new instance.
17+
/// </summary>
18+
/// <param name="func"></param>
19+
/// <exception cref="ArgumentNullException"></exception>
20+
public DelegateLongFunction(Func<long, TResult> func)
21+
{
22+
this.func = func ?? throw new ArgumentNullException(nameof(func));
23+
}
24+
25+
public object apply(long t)
26+
{
27+
return func(t);
28+
}
29+
30+
}
31+
32+
}

src/IKVM.Java.Extensions/java/util/function/StreamWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ IEnumerator IEnumerable.GetEnumerator()
4646

4747
}
4848

49-
}
49+
}

src/dist-nuget/dist-nuget.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<PackageProjectReference Include="..\IKVM.Image.JDK.runtime.osx-arm64\IKVM.Image.JDK.runtime.osx-arm64.csproj" Condition="$(_EnabledImageRuntimes.Contains(';osx-arm64;'))">
157157
<PackageTargetPath>.</PackageTargetPath>
158158
</PackageProjectReference>
159+
<PackageProjectReference Include="..\IKVM.Java.Extensions\IKVM.Java.Extensions.csproj">
160+
<PackageTargetPath>.</PackageTargetPath>
161+
</PackageProjectReference>
159162
</ItemGroup>
160163

161164
</Project>

0 commit comments

Comments
 (0)