Package org.ec4j.core

Class ResourceProperties

java.lang.Object
org.ec4j.core.ResourceProperties

public class ResourceProperties extends Object
A collection of Propertys applicable to a Resource as returned by ResourcePropertiesService.queryProperties(Resource).

This is basically just a wrapper around a Map of Propertys that offers utility methods for getting entries from the underlying Map not only by name but also by PropertyType in a type safe manner.

  • Field Details

  • Constructor Details

  • Method Details

    • builder

      public static ResourceProperties.Builder builder()
      Returns:
      a new ResourceProperties.Builder
    • getProperties

      public Map<String,Property> getProperties()
      Returns:
      the underlying Map of Propertys
    • getValue

      public <T> T getValue(PropertyType<T> type, T defaultValue, boolean throwInvalid)
      Gets a Property from properties by the name of the given PropertyType and returns Property.getValueAs() or returns defaultValue if no such name is available in properties.
      Type Parameters:
      T - the type of the property value
      Parameters:
      type - the PropertyType whose name will be used to get the value fron properties
      defaultValue - the value to return if the name is not available in properties
      throwInvalid - if true and the underlying Property value is invalid, an RuntimeException will be thrown. Otherwise, in the same case the invalid value will be ignored and defaultValue will be returned instead
      Returns:
      the value associated with the given type's name or the defaultValue if the name is not available in properties
      Throws:
      RuntimeException - if throwInvalid is true and the underlying Property value is invalid.
    • getValue

      public <T> T getValue(String name, T defaultValue, boolean throwInvalid)
      Gets a Property from properties by the given name and returns Property.getValueAs() or returns defaultValue if no such name is available in properties.
      Type Parameters:
      T - the type of the property value
      Parameters:
      name - the name to use to get the value fron properties
      defaultValue - the value to return if the name is not available in properties
      throwInvalid - if true and the underlying Property value is invalid, an RuntimeException will be thrown. Otherwise, in the same case the invalid value will be ignored and defaultValue will be returned instead
      Returns:
      the value associated with the given name or the defaultValue if the name is not available in properties
      Throws:
      RuntimeException - if throwInvalid is true and the underlying Property value is invalid.
    • getEditorConfigFiles

      public List<Ec4jPath> getEditorConfigFiles()
      Returns:
      a List of Ec4jPaths pointing at .editorconfig files existing in the parent hierarchy of the queried Resource. The files are ordered from the .editorconfig file closest to the queried Resource to the root of the hierarchy. Only existing files are included. If some of the files in the hierarchy contains root = true, then any other files higher in the hierarchy won't be returned. Any user and/or system defaults passed via ResourcePropertiesService.Builder.defaultEditorConfig(org.ec4j.core.model.EditorConfig) or related methods will not be included in the returned list.