Class YamlFile

java.lang.Object
com.avrix.utils.YamlFile

public class YamlFile extends Object
This class represents a YAML file and provides methods to read, write, and manipulate its contents.
  • Constructor Details

    • YamlFile

      public YamlFile(String jarFilePath, String internalFilePath)
      Constructor to load a YAML file from a JAR file.
      Parameters:
      jarFilePath - the path to the JAR file
      internalFilePath - the internal path to the YAML file within the JAR
    • YamlFile

      public YamlFile(InputStream inputStream, Path filePath, String fileName)
      Constructor to load a YAML file from an InputStream.
      Parameters:
      inputStream - the InputStream to load the YAML file from
      filePath - the path to the YAML file
      fileName - the name of the YAML file
    • YamlFile

      public YamlFile(Path path) throws IOException
      Constructor to load a YAML file from a Path.
      Parameters:
      path - the Path to the YAML file
      Throws:
      IOException - if an I/O error occurs
    • YamlFile

      public YamlFile(URL filePath) throws IOException, URISyntaxException
      Constructor to load a YAML file from a URL.
      Parameters:
      filePath - the URL to the YAML file
      Throws:
      IOException - if an I/O error occurs
      URISyntaxException - if the URL is malformed
    • YamlFile

      public YamlFile(URI fileUri) throws IOException
      Constructor to load a YAML file from a URI.
      Parameters:
      fileUri - the URI to the YAML file
      Throws:
      IOException - if an I/O error occurs
    • YamlFile

      public YamlFile(File file) throws IOException
      Constructor to load a YAML file from a File.
      Parameters:
      file - the YAML file
      Throws:
      IOException - if an I/O error occurs
    • YamlFile

      public YamlFile(String filePath) throws IOException
      Constructor to load a YAML file from a file path.
      Parameters:
      filePath - the path to the YAML file
      Throws:
      IOException - if an I/O error occurs
  • Method Details

    • getFilePath

      public Path getFilePath()
      Returns the file path of the YAML file.
      Returns:
      the file path
    • getFileName

      public String getFileName()
      Returns the file name of the YAML file.
      Returns:
      the file name
    • save

      public void save(String path)
      Saves the YAML file to a specified file path.
      Parameters:
      path - the path to save the YAML file to
    • save

      public void save()
      Saves the YAML file to its original file path.
    • load

      public static YamlFile load(File filePath)
      Loads a YAML file from a File.
      Parameters:
      filePath - the YAML file
      Returns:
      the loaded YamlFile object, or null if the file does not exist
    • load

      public static YamlFile load(Path filePath)
      Loads a YAML file from a Path.
      Parameters:
      filePath - the path to the YAML file
      Returns:
      the loaded YamlFile object
    • load

      public static YamlFile load(String filePath)
      Loads a YAML file from a file path.
      Parameters:
      filePath - the path to the YAML file
      Returns:
      the loaded YamlFile object
    • create

      public static YamlFile create(File filePath)
      Creates a new YAML file.
      Parameters:
      filePath - the YAML file to create
      Returns:
      the created YamlFile object, or null if the file already exists or an error occurs
    • create

      public static YamlFile create(Path filePath)
      Creates a new YAML file from a Path.
      Parameters:
      filePath - the path to the YAML file to create
      Returns:
      the created YamlFile object
    • create

      public static YamlFile create(String filePath)
      Creates a new YAML file from a file path.
      Parameters:
      filePath - the path to the YAML file to create
      Returns:
      the created YamlFile object
    • remove

      public final void remove(String key)
      Removes a key from the YAML file.
      Parameters:
      key - the key to remove
    • setValue

      public void setValue(String key, Object value)
      Sets a value in the YAML file.
      Parameters:
      key - the key to set
      value - the value to set
    • getValue

      public Object getValue(String key)
      Gets a value from the YAML file.
      Parameters:
      key - the key to get
      Returns:
      the value associated with the key, or null if the key does not exist
    • getAll

      public final Map<String,Object> getAll()
      Returns all the data in the YAML file.
      Returns:
      a map containing all the data in the YAML file
    • contains

      public final boolean contains(String key)
      Checks if a key exists in the YAML file.
      Parameters:
      key - the key to check
      Returns:
      true if the key exists, false otherwise
    • clear

      public final void clear()
      Clears all the data in the YAML file.
    • isEmpty

      public final boolean isEmpty()
      Checks if the YAML file is empty.
      Returns:
      true if the YAML file is empty, false otherwise
    • merge

      public final void merge(Map<String,Object> data)
      Merges a map of data into the YAML file.
      Parameters:
      data - the data to merge
    • merge

      public final void merge(YamlFile yamlFile)
      Merges another YamlFile into this YAML file.
      Parameters:
      yamlFile - the YamlFile to merge
    • getInt

      public final int getInt(String key)
      Gets an integer value from the YAML file.
      Parameters:
      key - the key to get the integer value from
      Returns:
      the integer value associated with the key, or 0 if the key does not exist or is not a number
    • setInt

      public final void setInt(String key, int value)
      Sets an integer value in the YAML file.
      Parameters:
      key - the key to set the integer value for
      value - the integer value to set
    • getLong

      public final long getLong(String key)
      Gets a long value from the YAML file.
      Parameters:
      key - the key to get the long value from
      Returns:
      the long value associated with the key, or 0L if the key does not exist or is not a number
    • setLong

      public final void setLong(String key, long value)
      Sets a long value in the YAML file.
      Parameters:
      key - the key to set the long value for
      value - the long value to set
    • getShort

      public final short getShort(String key)
      Gets a short value from the YAML file.
      Parameters:
      key - the key to get the short value from
      Returns:
      the short value associated with the key, or 0 if the key does not exist or is not a number
    • setShort

      public final void setShort(String key, short value)
      Sets a short value in the YAML file.
      Parameters:
      key - the key to set the short value for
      value - the short value to set
    • getByte

      public final byte getByte(String key)
      Gets a byte value from the YAML file.
      Parameters:
      key - the key to get the byte value from
      Returns:
      the byte value associated with the key, or 0 if the key does not exist or is not a number
    • setByte

      public final void setByte(String key, byte value)
      Sets a byte value in the YAML file.
      Parameters:
      key - the key to set the byte value for
      value - the byte value to set
    • getBoolean

      public final boolean getBoolean(String key)
      Gets a boolean value from the YAML file.
      Parameters:
      key - the key to get the boolean value from
      Returns:
      the boolean value associated with the key, or false if the key does not exist or is not a boolean
    • setBoolean

      public final void setBoolean(String key, boolean value)
      Sets a boolean value in the YAML file.
      Parameters:
      key - the key to set the boolean value for
      value - the boolean value to set
    • getDouble

      public final double getDouble(String key)
      Gets a double value from the YAML file.
      Parameters:
      key - the key to get the double value from
      Returns:
      the double value associated with the key, or 0.0 if the key does not exist or is not a number
    • setDouble

      public final void setDouble(String key, double value)
      Sets a double value in the YAML file.
      Parameters:
      key - the key to set the double value for
      value - the double value to set
    • getString

      public final String getString(String key)
      Gets a string value from the YAML file.
      Parameters:
      key - the key to get the string value from
      Returns:
      the string value associated with the key, or null if the key does not exist or is not a string
    • setString

      public final void setString(String key, String value)
      Sets a string value in the YAML file.
      Parameters:
      key - the key to set the string value for
      value - the string value to set
    • getChar

      public final char getChar(String key)
      Gets a char value from the YAML file.
      Parameters:
      key - the key to get the char value from
      Returns:
      the char value associated with the key, or '' if the key does not exist or is not a string
    • setChar

      public final void setChar(String key, char value)
      Sets a char value in the YAML file.
      Parameters:
      key - the key to set the char value for
      value - the char value to set
    • getMapKeys

      public final Set<String> getMapKeys(String key)
      Retrieves the keys of the map stored under the specified key in the YAML file.
      Parameters:
      key - the key of the map in the YAML file
      Returns:
      a set containing the keys of the map, or null if the key does not exist or does not contain a map
    • getMapValues

      public final Collection<Object> getMapValues(String key)
      Retrieves the values of the map stored under the specified key in the YAML file.
      Parameters:
      key - the key of the map in the YAML file
      Returns:
      a collection containing the values of the map, or null if the key does not exist or does not contain a map
    • setMap

      public void setMap(String key, Map<String,Object> map)
      Sets a map in the YAML file under the specified key.
      Parameters:
      key - the key where the map should be set
      map - the map to set
    • getMap

      public Map<String,Object> getMap(String key)
      Gets a map from the YAML file stored under the specified key.
      Parameters:
      key - the key of the map to retrieve
      Returns:
      the map stored under the specified key, or null if the key does not exist or does not contain a map
    • setStringMap

      public void setStringMap(String key, Map<String,String> map)
      Sets a map of string values in the YAML file under the specified key.
      Parameters:
      key - the key where the map should be set
      map - the map of string values to set
    • getStringMap

      public Map<String,String> getStringMap(String key)
      Gets a map of string values from the YAML file stored under the specified key.
      Parameters:
      key - the key of the map to retrieve
      Returns:
      the map of string values stored under the specified key, or null if the key does not exist or does not contain a map
    • setDoubleMap

      public void setDoubleMap(String key, Map<String,Double> map)
      Sets a map of double values in the YAML file under the specified key.
      Parameters:
      key - the key where the map should be set
      map - the map of double values to set
    • getDoubleMap

      public Map<String,Double> getDoubleMap(String key)
      Gets a map of double values from the YAML file stored under the specified key.
      Parameters:
      key - the key of the map to retrieve
      Returns:
      the map of double values stored under the specified key, or null if the key does not exist or does not contain a map
    • setIntMap

      public void setIntMap(String key, Map<String,Integer> map)
      Sets a map of integer values in the YAML file under the specified key.
      Parameters:
      key - the key where the map should be set
      map - the map of integer values to set
    • getIntMap

      public Map<String,Integer> getIntMap(String key)
      Gets a map of integer values from the YAML file stored under the specified key.
      Parameters:
      key - the key of the map to retrieve
      Returns:
      the map of integer values stored under the specified key, or null if the key does not exist or does not contain a map
    • setBooleanMap

      public void setBooleanMap(String key, Map<String,Boolean> map)
      Sets a map of boolean values in the YAML file under the specified key.
      Parameters:
      key - the key where the map should be set
      map - the map of boolean values to set
    • getBooleanMap

      public Map<String,Boolean> getBooleanMap(String key)
      Gets a map of boolean values from the YAML file stored under the specified key.
      Parameters:
      key - the key of the map to retrieve
      Returns:
      the map of boolean values stored under the specified key, or null if the key does not exist or does not contain a map
    • getList

      public final List<Object> getList(String key)
      Gets a list of values from the YAML file.
      Parameters:
      key - the key to get the list of values from
      Returns:
      the list of values associated with the key, or an empty list if the key does not exist or is not a list
    • setList

      public final void setList(String key, List<Object> value)
      Sets a list of values in the YAML file.
      Parameters:
      key - the key to set the list of values for
      value - the list of values to set
    • getStringList

      public final List<String> getStringList(String key)
      Gets a list of strings from the YAML file.
      Parameters:
      key - the key to get the list of strings from
      Returns:
      the list of strings associated with the key, or an empty list if the key does not exist or is not a list
    • setStringList

      public final void setStringList(String key, List<String> value)
      Sets a list of strings in the YAML file.
      Parameters:
      key - the key to set the list of strings for
      value - the list of strings to set
    • getDoubleList

      public final List<Double> getDoubleList(String key)
      Gets a list of doubles from the YAML file.
      Parameters:
      key - the key to get the list of doubles from
      Returns:
      the list of doubles associated with the key, or an empty list if the key does not exist or is not a list
    • setDoubleList

      public final void setDoubleList(String key, List<Double> value)
      Sets a list of doubles in the YAML file.
      Parameters:
      key - the key to set the list of doubles for
      value - the list of doubles to set
    • getLongList

      public final List<Long> getLongList(String key)
      Gets a list of longs from the YAML file.
      Parameters:
      key - the key to get the list of longs from
      Returns:
      the list of longs associated with the key, or an empty list if the key does not exist or is not a list
    • setLongList

      public final void setLongList(String key, List<Long> value)
      Sets a list of longs in the YAML file.
      Parameters:
      key - the key to set the list of longs for
      value - the list of longs to set
    • getIntegerList

      public final List<Integer> getIntegerList(String key)
      Gets a list of integers from the YAML file.
      Parameters:
      key - the key to get the list of integers from
      Returns:
      the list of integers associated with the key, or an empty list if the key does not exist or is not a list
    • setIntegerList

      public final void setIntegerList(String key, List<Integer> value)
      Sets a list of integers in the YAML file.
      Parameters:
      key - the key to set the list of integers for
      value - the list of integers to set
    • getCharacterList

      public final List<Character> getCharacterList(String key)
      Gets a list of characters from the YAML file.
      Parameters:
      key - the key to get the list of characters from
      Returns:
      the list of characters associated with the key, or an empty list if the key does not exist or is not a list
    • setCharacterList

      public final void setCharacterList(String key, List<Character> value)
      Sets a list of characters in the YAML file.
      Parameters:
      key - the key to set the list of characters for
      value - the list of characters to set
    • getBooleanList

      public final List<Boolean> getBooleanList(String key)
      Gets a list of booleans from the YAML file.
      Parameters:
      key - the key to get the list of booleans from
      Returns:
      the list of booleans associated with the key, or an empty list if the key does not exist or is not a list
    • setBooleanList

      public final void setBooleanList(String key, List<Boolean> value)
      Sets a list of booleans in the YAML file.
      Parameters:
      key - the key to set the list of booleans for
      value - the list of booleans to set
    • getShortList

      public final List<Short> getShortList(String key)
      Gets a list of shorts from the YAML file.
      Parameters:
      key - the key to get the list of shorts from
      Returns:
      the list of shorts associated with the key, or an empty list if the key does not exist or is not a list
    • setShortList

      public final void setShortList(String key, List<Short> value)
      Sets a list of shorts in the YAML file.
      Parameters:
      key - the key to set the list of shorts for
      value - the list of shorts to set
    • getByteList

      public final List<Byte> getByteList(String key)
      Gets a list of bytes from the YAML file.
      Parameters:
      key - the key to get the list of bytes from
      Returns:
      the list of bytes associated with the key, or an empty list if the key does not exist or is not a list
    • setByteList

      public final void setByteList(String key, List<Byte> value)
      Sets a list of bytes in the YAML file.
      Parameters:
      key - the key to set the list of bytes for
      value - the list of bytes to set