Record Class WarnEntry
- All Implemented Interfaces:
IWarnEntry
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The IWarnEntryAdapter class is a TypeAdapter for serializing and deserializing IWarnEntry objects to and from JSON. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AtomicInteger
The idGenerator variable is an AtomicInteger that is used for generating unique IDs for warnings. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a warning to the warn entry.final boolean
Indicates whether some other object is "equal to" this one.static IWarnEntry
Finds the warning entry with the specified UUID.static @NotNull List<IWarnEntry>
Retrieves all the warning entries.final int
hashCode()
Returns a hash code value for this object.name()
Returns the value of thename
record component.static void
removeEntry
(@NotNull IWarnEntry entry) Removes the specified warning entry from the system.static void
removeFromJson
(UUID target) Removes the specified UUID from the JSON file.boolean
removeWarn
(int id) Removes a warning with the specified ID from the warn entry.static void
saveToJson
(IWarnEntry entry) Saves a WarnEntry to a JSON file.final String
toString()
Returns a string representation of this record class.uuid()
Returns the value of theuuid
record component.warns()
Returns the value of thewarns
record component.
-
Field Details
-
idGenerator
The idGenerator variable is an AtomicInteger that is used for generating unique IDs for warnings. It is declared as public, static, and final, which means that it is a constant variable and can be accessed without creating an instance of its containing class.idGenerator is an instance of the AtomicInteger class, which provides atomic operations for integers. This allows multiple threads to safely increment and retrieve the current value of the generator without conflicts or data races.
The initial value of the generator is 1.
Example usage:
int id = idGenerator.getAndIncrement();
This code snippet gets the current value of idGenerator and then increments it atomically. The returned value is stored in the "id" variable.
-
-
Constructor Details
-
WarnEntry
Checks if the specified file exists, and if it doesn't, creates a new file. If the file is created successfully, a log message will be logged indicating the creation of the file. Any IOException that occurs during the file creation process will be logged as an error.
-
-
Method Details
-
saveToJson
Saves a WarnEntry to a JSON file.- Parameters:
entry
- The WarnEntry to be saved.
-
removeEntry
Removes the specified warning entry from the system.- Parameters:
entry
- the warning entry to be removed
-
removeFromJson
Removes the specified UUID from the JSON file.- Parameters:
target
- The UUID to remove from the JSON file.
-
getAllEntries
Retrieves all the warning entries.- Returns:
- a list of IWarnEntry objects representing the warning entries
-
findEntry
Finds the warning entry with the specified UUID.- Parameters:
targetUUID
- the UUID of the warning entry to find- Returns:
- the warning entry with the specified UUID, or null if not found
-
addWarn
Adds a warning to the warn entry.- Specified by:
addWarn
in interfaceIWarnEntry
- Parameters:
warn
- the warning to be added
-
removeWarn
public boolean removeWarn(int id) Removes a warning with the specified ID from the warn entry.- Specified by:
removeWarn
in interfaceIWarnEntry
- Parameters:
id
- the ID of the warning to remove- Returns:
- true if the warning is successfully removed, false otherwise
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
uuid
Returns the value of theuuid
record component.- Specified by:
uuid
in interfaceIWarnEntry
- Returns:
- the value of the
uuid
record component
-
name
Returns the value of thename
record component.- Specified by:
name
in interfaceIWarnEntry
- Returns:
- the value of the
name
record component
-
warns
Returns the value of thewarns
record component.- Specified by:
warns
in interfaceIWarnEntry
- Returns:
- the value of the
warns
record component
-