Class SourceHabitats

java.lang.Object
eu.bandm.tools.util.files.SourceHabitats

public class SourceHabitats extends Object
Organizes a collection of places where to look for resources (=input files).

A sequence of SourceHabitats.SourceHabitat is maintained which will be searched for a file, ie. a data source with a certain file name. Currently this can be a SourceHabitats.SourceHabitat_file as a pointer into the file system, or a SourceHabitats.SourceHabitat_resource as a class which comes with "resources", eg. in a ".jar" file.

  • Field Details

  • Constructor Details

  • Method Details

    • allPlaces_toString

      public String allPlaces_toString()
      Return a human-readable representation of all places to search.
      Returns:
      a human-readable representation of all places to search.
    • searchAllPlaces

      @Opt public @Opt SourceHabitats.FoundSource searchAllPlaces(String name, @Opt @Opt BiConsumer<String,Object[]> verbose, String... suffices)
      Service access point for searching all habitats for the given name of the resource, tested with all given suffixes. The suffixes are tested faster, i.e. they all are tested in the sequential order of the method argument, for one particular habitat. The habitats are tested in the sequential order of the "add"-calls to this object. Each suffix must include a leading dot (="."), but can also be totally empty.
      Parameters:
      name - the file stem to look for
      verbose - the receiver for log messages
      suffices - to test for files, in this sequential order
      Returns:
      a found file description, or null if no is found
    • appendNewHabitat

      public void appendNewHabitat(String s, @Opt @Opt String additionalErrorText)
      Service access point for adding a habitat to the end of the search list. Does so only if consistency checks okay.
      Parameters:
      s - name of the habitat according to the defined prefices, see makeHabitat(java.lang.String, java.lang.String).
      additionalErrorText - describes the context of the habitat modification attempt
    • error

      protected void error(String txt, Object... args)
      Reports errors only during appendNewHabitat(String,String).
      Parameters:
      txt - the error text
      args - the arguments of the error text
    • makeHabitat

      @Opt protected @Opt SourceHabitats.SourceHabitat makeHabitat(String name, @Opt @Opt String additionalErrorText)
      Internal method to check whether the input to appendNewHabitat(String,String) is consistent.
      Parameters:
      name - the specification where this habitat is found. The prefix decides which subclass of SourceHabitats.SourceHabitat is constructed and how the rest of the name is used for searching (file system position or a Java resource). See the doucmentation SourceHabitats.SourceHabitat.
      additionalErrorText - describes the context of the habitat modification attempt.
      Returns:
      a new habitat, if the data is consistent