类 PositionTrackingStorage
java.lang.Object
cn.nukkit.positiontracking.PositionTrackingStorage
- 所有已实现的接口:
Closeable
,AutoCloseable
@PowerNukkitOnly
@Since("1.4.0.0-PN")
@ParametersAreNonnullByDefault
public class PositionTrackingStorage
extends Object
implements Closeable
Stores a sequential range of
PositionTracking
objects in a file. The read operation is cached.
This object holds a file handler and must be closed when it is no longer needed.
Once closed the instance cannot be reused.
- 作者:
- joserobjr
-
字段概要
-
构造器概要
构造器说明PositionTrackingStorage
(int startIndex, File persistenceFile) Opens or create the file and all directories in the path automatically.PositionTrackingStorage
(int startIndex, File persistenceFile, int maxStorage) Opens or create the file and all directories in the path automatically. -
方法概要
修饰符和类型方法说明addNewPosition
(NamedPosition position) Adds the given position as a new entry in this storage, even if the position is already registered and enabled.addNewPosition
(NamedPosition position, boolean enabled) Adds the given position as a new entry in this storage, even if the position is already registered and enabled.addOrReusePosition
(NamedPosition position) Attempts to reuse an existing and enabled trackingHandler for the given position, if none is found than a new handler is created if the limit was not exceeded.void
close()
protected void
finalize()
findTrackingHandler
(NamedPosition position) it.unimi.dsi.fastutil.ints.IntList
it.unimi.dsi.fastutil.ints.IntList
findTrackingHandlers
(NamedPosition pos, boolean onlyEnabled) it.unimi.dsi.fastutil.ints.IntList
findTrackingHandlers
(NamedPosition pos, boolean onlyEnabled, int limit) int
getPosition
(int trackingHandler) Retrieves thePositionTracking
object that is assigned to the given trackingHandler.getPosition
(int trackingHandler, boolean onlyEnabled) Retrieves thePositionTracking
object that is assigned to the given trackingHandler.int
boolean
hasPosition
(int trackingHandler) boolean
hasPosition
(int trackingHandler, boolean onlyEnabled) void
invalidateHandler
(int trackingHandler) boolean
isEnabled
(int trackingHandler) boolean
setEnabled
(int trackingHandler, boolean enabled)
-
字段详细资料
-
DEFAULT_MAX_STORAGE
- 另请参阅:
-
-
构造器详细资料
-
PositionTrackingStorage
@PowerNukkitOnly @Since("1.4.0.0-PN") public PositionTrackingStorage(int startIndex, File persistenceFile) throws IOException Opens or create the file and all directories in the path automatically. The given start index will be used in new files and will be checked when opening files. If the file being opened don't matches this value internally than anIllegalArgumentException
will be thrown.- 参数:
startIndex
- The number of the first handler. Must be higher than 0 and must match the number of the existing file.persistenceFile
- The file being opened or created. Parent directories will also be created if necessary.- 抛出:
IOException
- If an error has occurred while reading, parsing or creating the fileIllegalArgumentException
- If opening an existing file and the internal startIndex don't match the given startIndex
-
PositionTrackingStorage
@PowerNukkitOnly @Since("1.4.0.0-PN") public PositionTrackingStorage(int startIndex, File persistenceFile, int maxStorage) throws IOException Opens or create the file and all directories in the path automatically. The given start index will be used in new files and will be checked when opening files. If the file being opened don't matches this value internally than anIllegalArgumentException
will be thrown.- 参数:
startIndex
- The number of the first handler. Must be higher than 0 and must match the number of the existing file.persistenceFile
- The file being opened or created. Parent directories will also be created if necessary.maxStorage
- The maximum amount of positions that this storage may hold. It cannot be changed after creation. Ignored when loading an existing file. When zero or negative, a default value will be used.- 抛出:
IOException
- If an error has occurred while reading, parsing or creating the fileIllegalArgumentException
- If opening an existing file and the internal startIndex don't match the given startIndex
-
-
方法详细资料
-
getPosition
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nullable public PositionTracking getPosition(int trackingHandler) throws IOException Retrieves thePositionTracking
object that is assigned to the given trackingHandler. The handler must be valid for this storage.This call may return a cached result but the returned object can be modified freely.
- 参数:
trackingHandler
- A valid handler for this storage- 返回:
- A clone of the cached result.
- 抛出:
IOException
- If an error has occurred while accessing the fileIllegalArgumentException
- If the trackingHandler is not valid for this storage
-
getPosition
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nullable public PositionTracking getPosition(int trackingHandler, boolean onlyEnabled) throws IOException Retrieves thePositionTracking
object that is assigned to the given trackingHandler. The handler must be valid for this storage.This call may return a cached result but the returned object can be modified freely.
- 参数:
trackingHandler
- A valid handler for this storageonlyEnabled
- When false, disabled positions that wasn't invalidated may be returned. Caching only works when this is set to true- 返回:
- A clone of the cached result.
- 抛出:
IOException
- If an error has occurred while accessing the fileIllegalArgumentException
- If the trackingHandler is not valid for this storage
-
addOrReusePosition
@PowerNukkitOnly @Since("1.4.0.0-PN") public OptionalInt addOrReusePosition(NamedPosition position) throws IOException Attempts to reuse an existing and enabled trackingHandler for the given position, if none is found than a new handler is created if the limit was not exceeded.- 参数:
position
- The position that needs a handler- 返回:
- The trackingHandler assigned to the position or an empty OptionalInt if none was found and this storage is full
- 抛出:
IOException
- If an error occurred while reading or writing the file
-
addNewPosition
@PowerNukkitOnly @Since("1.4.0.0-PN") public OptionalInt addNewPosition(NamedPosition position) throws IOException Adds the given position as a new entry in this storage, even if the position is already registered and enabled.- 参数:
position
- The position that needs a handler- 返回:
- The trackingHandler assigned to the position or an empty OptionalInt if none was found and this storage is full
- 抛出:
IOException
- If an error occurred while reading or writing the file
-
addNewPosition
@PowerNukkitOnly @Since("1.4.0.0-PN") public OptionalInt addNewPosition(NamedPosition position, boolean enabled) throws IOException Adds the given position as a new entry in this storage, even if the position is already registered and enabled.- 参数:
position
- The position that needs a handlerenabled
- If the position will be added as enabled or disabled- 返回:
- The trackingHandler assigned to the position or an empty OptionalInt if none was found and this storage is full
- 抛出:
IOException
- If an error occurred while reading or writing the file
-
findTrackingHandler
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public OptionalInt findTrackingHandler(NamedPosition position) throws IOException - 抛出:
IOException
-
invalidateHandler
@PowerNukkitOnly @Since("1.4.0.0-PN") public void invalidateHandler(int trackingHandler) throws IOException - 抛出:
IOException
-
isEnabled
@PowerNukkitOnly @Since("1.4.0.0-PN") public boolean isEnabled(int trackingHandler) throws IOException - 抛出:
IOException
-
setEnabled
@PowerNukkitOnly @Since("1.4.0.0-PN") public boolean setEnabled(int trackingHandler, boolean enabled) throws IOException - 抛出:
IOException
-
hasPosition
@PowerNukkitOnly @Since("1.4.0.0-PN") public boolean hasPosition(int trackingHandler) throws IOException - 抛出:
IOException
-
hasPosition
@PowerNukkitOnly @Since("1.4.0.0-PN") public boolean hasPosition(int trackingHandler, boolean onlyEnabled) throws IOException - 抛出:
IOException
-
findTrackingHandlers
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public it.unimi.dsi.fastutil.ints.IntList findTrackingHandlers(NamedPosition pos) throws IOException - 抛出:
IOException
-
findTrackingHandlers
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public it.unimi.dsi.fastutil.ints.IntList findTrackingHandlers(NamedPosition pos, boolean onlyEnabled) throws IOException - 抛出:
IOException
-
findTrackingHandlers
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public it.unimi.dsi.fastutil.ints.IntList findTrackingHandlers(NamedPosition pos, boolean onlyEnabled, int limit) throws IOException - 抛出:
IOException
-
getStartingHandler
-
getMaxHandler
-
close
- 指定者:
close
在接口中AutoCloseable
- 指定者:
close
在接口中Closeable
- 抛出:
IOException
-
finalize
-