Class FormatMarker


  • public final class FormatMarker
    extends java.lang.Object
    The FormatMarker class provides facilities to identify markers within a format string. Currently, the following markers are supported: %b, %d, %x and %s.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FormatMarker.Kind
      The FormatMarker.Kind enumeration describes supported types of format markers.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<FormatMarker> extractMarkers​(java.lang.String text)
      Gets the list of format tokens for the specified format string.
      int getEnd()
      Returns the end position of the marker (first character after the marker) in the format string.
      FormatMarker.Kind getKind()
      Returns the marker kind.
      int getLength()
      Returns the length specified in the marker.
      java.lang.String getRegExpr()
      Gets the regular expression describing the given marker type.
      int getStart()
      Returns the start position of the marker (first character of the marker) in the format string.
      java.lang.String getTokenId()
      Returns the token identifier for the given marker type.
      boolean isKind​(FormatMarker.Kind kind)
      Check whether the marker of the specified kind.
      static java.util.List<ru.ispras.fortress.util.Pair<java.lang.String,​java.lang.Integer>> tokenize​(java.lang.String text, java.util.List<FormatMarker> markers)
      Tokenizes text using the specified list of markers previously extracted from it.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getKind

        public FormatMarker.Kind getKind()
        Returns the marker kind.
        Returns:
        Marker kind.
      • isKind

        public boolean isKind​(FormatMarker.Kind kind)
        Check whether the marker of the specified kind.
        Parameters:
        kind - Marker kind.
        Returns:
        true if the marker is of the specified kind or false otherwise.
      • getLength

        public int getLength()
        Returns the length specified in the marker.
        Returns:
        Length specified in the marker or 0 if no length is specified.
      • getStart

        public int getStart()
        Returns the start position of the marker (first character of the marker) in the format string.
        Returns:
        Start position of the marker in the format string.
      • getEnd

        public int getEnd()
        Returns the end position of the marker (first character after the marker) in the format string.
        Returns:
        End position of the marker in the format string.
      • getTokenId

        public java.lang.String getTokenId()
        Returns the token identifier for the given marker type.
        Returns:
        Token identifier.
      • getRegExpr

        public java.lang.String getRegExpr()
        Gets the regular expression describing the given marker type.
        Returns:
        Regular expression.
      • extractMarkers

        public static java.util.List<FormatMarker> extractMarkers​(java.lang.String text)
        Gets the list of format tokens for the specified format string.
        Parameters:
        text - Format string to be parsed.
        Returns:
        List of extracted tokens.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • tokenize

        public static java.util.List<ru.ispras.fortress.util.Pair<java.lang.String,​java.lang.Integer>> tokenize​(java.lang.String text,
                                                                                                                      java.util.List<FormatMarker> markers)
        Tokenizes text using the specified list of markers previously extracted from it. Tokens represent text of markers and text between them.
        Parameters:
        text - Text to be tokenized.
        markers - List of markers.
        Returns:
        List of tokens represented by pairs [text, marker index]. Marker index is -1 for tokens that does not correspond to any markers.
        Throws:
        java.lang.IllegalArgumentException - if the parameter is null.
      • toString

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