refac: использованы generics

This commit is contained in:
2025-06-11 23:19:52 +03:00
parent 1f8ff98243
commit 96fcbd6aef

View File

@@ -3,74 +3,63 @@ package ru.di9.minecraft.shared.utils;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("ALL")
public class IntCache
{
@SuppressWarnings("GrazieInspection")
public class IntCache {
private static int intCacheSize = 256;
/**
* A list of pre-allocated int[256] arrays that are currently unused and can be returned by getIntCache()
*/
private static List freeSmallArrays = new ArrayList();
private static final List<int[]> freeSmallArrays = new ArrayList<>();
/**
* A list of pre-allocated int[256] arrays that were previously returned by getIntCache() and which will not be re-
* used again until resetIntCache() is called.
*/
private static List inUseSmallArrays = new ArrayList();
private static final List<int[]> inUseSmallArrays = new ArrayList<>();
/**
* A list of pre-allocated int[cacheSize] arrays that are currently unused and can be returned by getIntCache()
*/
private static List freeLargeArrays = new ArrayList();
private static final List<int[]> freeLargeArrays = new ArrayList<>();
/**
* A list of pre-allocated int[cacheSize] arrays that were previously returned by getIntCache() and which will not
* be re-used again until resetIntCache() is called.
*/
private static List inUseLargeArrays = new ArrayList();
private static final List<int[]> inUseLargeArrays = new ArrayList<>();
public IntCache()
{
private IntCache() {
}
public static int[] getIntCache(int par0)
{
if (par0 <= 256)
{
if (freeSmallArrays.size() == 0)
{
int ai[] = new int[256];
public static int[] getIntCache(int par0) {
if (par0 <= 256) {
if (freeSmallArrays.isEmpty()) {
int[] ai = new int[256];
inUseSmallArrays.add(ai);
return ai;
}
else
{
int ai1[] = (int[])freeSmallArrays.remove(freeSmallArrays.size() - 1);
} else {
int[] ai1 = freeSmallArrays.remove(freeSmallArrays.size() - 1);
inUseSmallArrays.add(ai1);
return ai1;
}
}
if (par0 > intCacheSize)
{
if (par0 > intCacheSize) {
intCacheSize = par0;
freeLargeArrays.clear();
inUseLargeArrays.clear();
int ai2[] = new int[intCacheSize];
int[] ai2 = new int[intCacheSize];
inUseLargeArrays.add(ai2);
return ai2;
}
if (freeLargeArrays.size() == 0)
{
int ai3[] = new int[intCacheSize];
if (freeLargeArrays.isEmpty()) {
int[] ai3 = new int[intCacheSize];
inUseLargeArrays.add(ai3);
return ai3;
}
else
{
int ai4[] = (int[])freeLargeArrays.remove(freeLargeArrays.size() - 1);
} else {
int[] ai4 = freeLargeArrays.remove(freeLargeArrays.size() - 1);
inUseLargeArrays.add(ai4);
return ai4;
}
@@ -79,15 +68,12 @@ public class IntCache
/**
* Mark all pre-allocated arrays as available for re-use by moving them to the appropriate free lists.
*/
public static void resetIntCache()
{
if (freeLargeArrays.size() > 0)
{
public static void resetIntCache() {
if (!freeLargeArrays.isEmpty()) {
freeLargeArrays.remove(freeLargeArrays.size() - 1);
}
if (freeSmallArrays.size() > 0)
{
if (!freeSmallArrays.isEmpty()) {
freeSmallArrays.remove(freeSmallArrays.size() - 1);
}