Scanner Class Diagram

 

 

Ancestor class specifications:

java.lang.Object

Scanner Class Specification

            Invariant

                        A Scanner object...

-       is designed to extract tokens from a string

-       0 <= pos <= scanText.length

 

Constructor Methods

public Scanner( Strings )

post: scanText == s

 

public Scanner( InputStream is )

post: scanText == text from stream is

 

            Query Methods

public String next( )

pre:   hasNext()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following non-delimiter text

         and  result == the non-delimiter text

         and  pos is advanced to the index of the delimiter following the non-delimiter

                              text

 

public boolean nextBoolean( )

pre:   hasNextBoolean()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following the boolean literal (true or false)

         and  result == the scanned literal

         and  pos is advanced to the index of the delimiter following the literal

 

public byte nextByte( )

pre:   hasNextByte()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following the byte literal (integer)

         and  result == the scanned literal

         and  pos is advanced to the index of the delimiter following the literal

 

public double nextDouble( )

pre:   hasNextDouble()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following the double literal (real number)

         and  result == the scanned literal

         and  pos is advanced to the index of the delimiter following the literal

 

public float nextFloat( )

pre:   hasNextFloat()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following the float literal (real number)

         and  result == the scanned literal

         and  pos is advanced to the index of the delimiter following the literal

 

public int nextInt( )

pre:   hasNextInt()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following the int literal (integer)

         and  result == the scanned literal

         and  pos is advanced to the index of the delimiter following the literal

 

public String nextLine( )

pre:   hasNextDouble()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the first encountered Ò\nÓ (or end of string)

         and  result == the scanned line

         and  pos is advanced to the index of the delimiter following the line

 

public long nextLong )

pre:   hasNextLong()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following the long literal (integer)

         and  result == the scanned literal

         and  pos is advanced to the index of the delimiter following the literal

 

public short nextShort( )

pre:   hasNextShort()

post:  Scanning began with scanText[pos@pre].  All leading delimiters (white space) are skipped and scanning ends with the delimiter (or end of string) following the short literal (integer)

         and  result == the scanned literal

         and  pos is advanced to the index of the delimiter following the literal

 

            Predicate Methods

public boolean hasNextBoolean( )

post:  result == the text from scanText[pos] is a proper boolean literal (true or false), optionally preceded by delimiter (white space) characters and terminated with a delimiter or the end of scanText.

 

public boolean hasNextByte( )

post:  result == the text from scanText[pos] is a proper byte literal (integer), optionally preceded by delimiter (white space) characters and terminated with a delimiter or the end of scanText.

 

public boolean hasNextDouble( )

post:  result == the text from scanText[pos] is a proper double literal (real number), optionally preceded by delimiter (white space) characters and terminated with a delimiter or the end of scanText.

 

public boolean hasNextFloat( )

post:  result == the text from scanText[pos] is a proper float literal (real number), optionally preceded by delimiter (white space) characters and terminated with a delimiter or the end of scanText.

 

public boolean hasNextInt( )

post:  result == the text from scanText[pos] is a proper int literal (integer), optionally preceded by delimiter (white space) characters and terminated with a delimiter or the end of scanText.

 

public boolean hasNextLong( )

post:  result == the text from scanText[pos] is a proper long literal (integer), optionally preceded by delimiter (white space) characters and terminated with a delimiter or the end of scanText.

 

public boolean hasNextShort( )

post:  result == the text from scanText[pos] is a proper short literal (integer), optionally preceded by delimiter (white space) characters and terminated with a delimiter or the end of scanText.