Skip to content

Commit

Permalink
Use pattern singleton for class UniqueField
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Dec 3, 2024
1 parent e2872cc commit 405f4e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ public void preInit(FMLPreInitializationEvent fmlPreInitializationEvent) throws
{
globalDirectory = fmlPreInitializationEvent.getModConfigurationDirectory();

UniqueField uniqueField = new UniqueField();

Log.createLogFile(globalDirectory.getPath() + File.separator + DynamicSpawnControlStructure.STRUCT_FILES_DIRS.NAME_DIRECTORY, UniqueField.IDEA_RT);
Log.writeDataToLogFile(1, "Launching from Intellij Idea: " + (UniqueField.IDEA_RT ? "true" : "false"));
Log.writeDataToLogFile(0, "Object create [UniqueField]: " + uniqueField.hashCode());
Log.writeDataToLogFile(0, "Object create [UniqueField]: " + UniqueField.getInstance().hashCode());

MessageHandler.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,49 @@ public final class UniqueField
/**
*
*/
@UniqueObject
public static final Random RANDOM = new Random();
private static volatile UniqueField instance;

/**
*
*/
@UniqueObject
public static final Random RANDOM = new Random();

@UniqueObject
public static final Minecraft CLIENT = Minecraft.getMinecraft();

/**
*
*/
@UniqueObject
public static final Boolean IDEA_RT = System.getProperty("java.class.path").toLowerCase().contains("idea_rt.jar");

/**
*
*/
public UniqueField() throws IllegalAccessException
private UniqueField() throws IllegalAccessException
{
this.validateUniqueFields(this);
}

/**
*
* @param object
*/
public static UniqueField getInstance() throws IllegalAccessException
{
if (instance == null)
{
synchronized (UniqueField.class)
{
if (instance == null)
{
instance = new UniqueField();
}
}
}

return instance;
}

/**
*
*/
private void validateUniqueFields(Object object) throws IllegalAccessException
{
Expand All @@ -64,3 +81,4 @@ private void validateUniqueFields(Object object) throws IllegalAccessException
}
}
}

0 comments on commit 405f4e1

Please sign in to comment.