Class Block


  • public class Block
    extends java.lang.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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.String> data  
      private java.util.Set<java.lang.String> tags  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        Block​(java.util.List<java.lang.String> data)
      Create a new Block from a list of strings.
      private Block​(java.util.List<java.lang.String> data, java.util.Set<java.lang.String> tags)  
        Block​(Block block)
      Create a new Block which is a copy of block.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAfterLast​(java.lang.String str)
      Add String after the end of the block.
      void addBeforeFirst​(java.lang.String str)
      Add String before the start of the block.
      void addPrefixToAll​(java.lang.String prefix)
      Add the prefix to each string in the block.
      void addTag​(java.lang.String tag)
      Add a tag to the block.
      java.util.List<java.lang.String> contents()
      Get the contents of the block.
      boolean equals​(java.lang.Object obj)  
      Block expandTabs()
      Replace tabs with spaces, assuming tab stops are located as usual at n*8 + 1
      private java.lang.String expandTabs​(java.lang.String src)  
      java.lang.String find​(java.lang.String search)
      Return the first string in the block that contains the search string.
      int hashCode()  
      boolean hasTag​(java.lang.String tag)
      Return whether or not a block has a particular tag.
      boolean hasTags​(java.lang.String... tags)
      Return whether or not a block has ALL of the listed tags.
      Block instantiateTemplate​(java.util.Map<java.lang.String,​java.lang.String> parameters)
      replace all occurrences of @KEY@ with parameters.get( KEY ).
      Pair<Block,​Block> splitFirst()
      Split block into two blocks, with only the first line of the original Block in result.first().
      Block substitute​(java.util.List<? extends Pair<java.lang.String,​java.lang.String>> substitutions)  
      java.lang.String toString()  
      void write​(FileWrapper fw)
      Write block to FileWrapper.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • data

        private java.util.List<java.lang.String> data
      • tags

        private final java.util.Set<java.lang.String> tags
    • Constructor Detail

      • Block

        private Block​(java.util.List<java.lang.String> data,
                      java.util.Set<java.lang.String> tags)
      • Block

        public Block​(java.util.List<java.lang.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 Detail

      • toString

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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

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

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

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

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

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

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

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

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

        public Block instantiateTemplate​(java.util.Map<java.lang.String,​java.lang.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

        private java.lang.String expandTabs​(java.lang.String src)
      • expandTabs

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

        public Block substitute​(java.util.List<? extends Pair<java.lang.String,​java.lang.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().