ConfigCollection.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.gmail.nossr50.config;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. /**
  6. * Represents a config file that registers keys after its initialized
  7. */
  8. public abstract class ConfigCollection<T> extends Config implements Registers, GenericCollectionContainer {
  9. //The collection held by this class
  10. protected Collection<T> genericCollection;
  11. /**
  12. * @param pathToParentFolder Path to the "parent" folder on disk
  13. * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files
  14. * @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
  15. * @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
  16. * @param removeOldKeys if true, the users config file will have keys not found in the internal default resource file of the same name and path removed
  17. */
  18. public ConfigCollection(String fileName, File pathToParentFolder, String relativePath, boolean generateDefaults, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) {
  19. super(fileName, pathToParentFolder, relativePath, generateDefaults, mergeNewKeys, copyDefaults, removeOldKeys);
  20. //init
  21. initCollection();
  22. //DO NOT CALL THIS HERE
  23. //register();
  24. }
  25. /**
  26. * Initializes the generic collection held by this class
  27. */
  28. private void initCollection() {
  29. if (genericCollection == null)
  30. genericCollection = new ArrayList<>();
  31. }
  32. @Override
  33. public Collection<T> getLoadedCollection() {
  34. return this.genericCollection;
  35. }
  36. @Override
  37. public void unload() {
  38. genericCollection.clear();
  39. }
  40. }