2020-11-28 15:05:28 +01:00
|
|
|
package speiger.src.collections.utils;
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Interface that allows to test for if a collection is trimmable.
|
|
|
|
* This also allows that synchronization-wrappers are trimmable without extracting the original collection.
|
|
|
|
*/
|
2020-11-28 15:05:28 +01:00
|
|
|
public interface ITrimmable
|
|
|
|
{
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Trims the original collection down to the size of the current elements
|
2021-04-22 23:02:04 +02:00
|
|
|
* @return if the internal array has been trimmed.
|
2020-12-06 09:32:22 +01:00
|
|
|
*/
|
2021-09-25 20:23:01 +02:00
|
|
|
default boolean trim() {
|
2020-12-13 20:14:22 +01:00
|
|
|
return trim(0);
|
2020-11-28 15:05:28 +01:00
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Trims the original collection down to the size of the current elements or the requested size depending which is bigger
|
|
|
|
* @param size the requested trim size.
|
2021-04-22 23:02:04 +02:00
|
|
|
* @return if the internal array has been trimmed.
|
2020-12-06 09:32:22 +01:00
|
|
|
*/
|
2021-09-25 20:23:01 +02:00
|
|
|
boolean trim(int size);
|
2021-05-26 13:06:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Trims the collection down to the original size and clears all present elements with it.
|
|
|
|
*/
|
2021-09-25 20:23:01 +02:00
|
|
|
default void clearAndTrim() {
|
2021-05-26 13:06:52 +02:00
|
|
|
clearAndTrim(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trims the collection down to the requested size and clears all elements while doing so
|
|
|
|
* @param size the amount of elements that should be allowed
|
|
|
|
* @note this will enforce minimum size of the collection itself
|
|
|
|
*/
|
2021-09-25 20:23:01 +02:00
|
|
|
void clearAndTrim(int size);
|
2020-11-28 15:05:28 +01:00
|
|
|
}
|