Class Block

java.lang.Object
org.glassfish.pfl.basic.tools.file.Block

public class Block extends Object
Represents a range of Strings, typically read from a file, that are in some sense related and contiguous. Blocks may also be tagged as an aid in transforming a series of blocks.
  • Constructor Details

    • Block

      public Block(List<String> data)
      Create a new Block from a list of strings.
    • Block

      public Block(Block block)
      Create a new Block which is a copy of block.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • addTag

      public void addTag(String tag)
      Add a tag to the block. Useful for classifying blocks.
    • hasTag

      public boolean hasTag(String tag)
      Return whether or not a block has a particular tag.
    • hasTags

      public boolean hasTags(String... tags)
      Return whether or not a block has ALL of the listed tags.
    • contents

      public List<String> contents()
      Get the contents of the block.
    • addBeforeFirst

      public void addBeforeFirst(String str)
      Add String before the start of the block.
    • addAfterLast

      public void addAfterLast(String str)
      Add String after the end of the block.
    • addPrefixToAll

      public void addPrefixToAll(String prefix)
      Add the prefix to each string in the block.
    • find

      public String find(String search)
      Return the first string in the block that contains the search string.
    • write

      public void write(FileWrapper fw) throws IOException
      Write block to FileWrapper. FileWrapper must be open for writing.
      Throws:
      IOException
    • instantiateTemplate

      public Block instantiateTemplate(Map<String,String> parameters)
      replace all occurrences of @KEY@ with parameters.get( KEY ). This is very simple: only one scan is made, so @...@ patterns in the parameters values are ignored.
    • expandTabs

      public Block expandTabs()
      Replace tabs with spaces, assuming tab stops are located as usual at n*8 + 1
    • substitute

      public Block substitute(List<? extends Pair<String,String>> substitutions)
    • splitFirst

      public Pair<Block,Block> splitFirst()
      Split block into two blocks, with only the first line of the original Block in result.first().