meh
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using java.lang;
|
||||
using java.util.concurrent;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class DelegateExtensions
|
||||
{
|
||||
public static Runnable ToRunnable(this Action action) => new DelegateRunnable(action);
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
// lets make it an overload for convenience
|
||||
public static void execute(this Executor executor, Action action) => executor.execute(action.ToRunnable());
|
||||
|
||||
private sealed class DelegateRunnable(Action action) : Runnable
|
||||
{
|
||||
public void run() => action();
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using java.util;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
public static Collection ToCollection<T>(this IEnumerable<T> enumerable)
|
||||
{
|
||||
var collection = enumerable is IReadOnlyCollection<T> readOnlyCollection ? new ArrayList(readOnlyCollection.Count) : new ArrayList(((IReadOnlyCollection<T>)(enumerable = enumerable.ToArray())).Count);
|
||||
|
||||
foreach (var t in enumerable)
|
||||
{
|
||||
collection.add(t);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using java.util;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class IteratorExtensions
|
||||
{
|
||||
public static IteratorEnumerator<object> GetEnumerator(this Iterator iterator) => new(iterator);
|
||||
|
||||
public static IteratorEnumerable<T> AsEnumerable<T>(this Iterator iterator) => new(iterator);
|
||||
|
||||
public struct IteratorEnumerator<T>(Iterator iterator) : IEnumerator<T>
|
||||
{
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (!iterator.hasNext()) return false;
|
||||
|
||||
Current = (T)iterator.next();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
object? IEnumerator.Current => Current;
|
||||
|
||||
public T Current { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public struct IteratorEnumerable<T>(Iterator iterator) : IEnumerable<T>
|
||||
{
|
||||
public IteratorEnumerator<T> GetEnumerator() => new(iterator);
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => null!;
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using java.util;
|
||||
using LuckPerms.Torch.Utils.Extensions;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
using Torch.Server.Managers;
|
||||
|
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using java.io;
|
||||
using Torch.Utils;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
internal static class StreamExtensions
|
||||
{
|
||||
public static InputStream GetInputStream(this Stream stream)
|
||||
{
|
||||
if (!stream.CanRead)
|
||||
throw new ArgumentException("Stream should be readable", nameof(stream));
|
||||
|
||||
var array = stream.ReadToEnd(); // TODO make it not allocate array for an entire stream content
|
||||
|
||||
return new ByteArrayInputStream(array);
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
using java.util;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class UuidExtensions
|
||||
{
|
||||
public static ulong GetSteamId(this UUID uuid) => (ulong)uuid.getLeastSignificantBits();
|
||||
|
||||
public static UUID GetUuid(this ulong steamId) => new(0, (long)steamId);
|
||||
}
|
Reference in New Issue
Block a user