src/java.base/share/classes/java/util/Scanner.java

Print this page
rev 10537 : 8055723[core]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>


1287      *
1288      * @return a match result for the last match operation
1289      * @throws IllegalStateException  If no match result is available
1290      */
1291     public MatchResult match() {
1292         if (!matchValid)
1293             throw new IllegalStateException("No match result available");
1294         return matcher.toMatchResult();
1295     }
1296 
1297     /**
1298      * <p>Returns the string representation of this <code>Scanner</code>. The
1299      * string representation of a <code>Scanner</code> contains information
1300      * that may be useful for debugging. The exact format is unspecified.
1301      *
1302      * @return  The string representation of this scanner
1303      */
1304     public String toString() {
1305         StringBuilder sb = new StringBuilder();
1306         sb.append("java.util.Scanner");
1307         sb.append("[delimiters=" + delimPattern + "]");
1308         sb.append("[position=" + position + "]");
1309         sb.append("[match valid=" + matchValid + "]");
1310         sb.append("[need input=" + needInput + "]");
1311         sb.append("[source closed=" + sourceClosed + "]");
1312         sb.append("[skipped=" + skipped + "]");
1313         sb.append("[group separator=" + groupSeparator + "]");
1314         sb.append("[decimal separator=" + decimalSeparator + "]");
1315         sb.append("[positive prefix=" + positivePrefix + "]");
1316         sb.append("[negative prefix=" + negativePrefix + "]");
1317         sb.append("[positive suffix=" + positiveSuffix + "]");
1318         sb.append("[negative suffix=" + negativeSuffix + "]");
1319         sb.append("[NaN string=" + nanString + "]");
1320         sb.append("[infinity string=" + infinityString + "]");
1321         return sb.toString();
1322     }
1323 
1324     /**
1325      * Returns true if this scanner has another token in its input.
1326      * This method may block while waiting for input to scan.
1327      * The scanner does not advance past any input.
1328      *
1329      * @return true if and only if this scanner has another token
1330      * @throws IllegalStateException if this scanner is closed
1331      * @see java.util.Iterator
1332      */
1333     public boolean hasNext() {
1334         ensureOpen();
1335         saveState();
1336         while (!sourceClosed) {
1337             if (hasTokenInBuffer())
1338                 return revertState(true);
1339             readInput();
1340         }




1287      *
1288      * @return a match result for the last match operation
1289      * @throws IllegalStateException  If no match result is available
1290      */
1291     public MatchResult match() {
1292         if (!matchValid)
1293             throw new IllegalStateException("No match result available");
1294         return matcher.toMatchResult();
1295     }
1296 
1297     /**
1298      * <p>Returns the string representation of this <code>Scanner</code>. The
1299      * string representation of a <code>Scanner</code> contains information
1300      * that may be useful for debugging. The exact format is unspecified.
1301      *
1302      * @return  The string representation of this scanner
1303      */
1304     public String toString() {
1305         StringBuilder sb = new StringBuilder();
1306         sb.append("java.util.Scanner");
1307         sb.append("[delimiters=").append(delimPattern).append(']');
1308         sb.append("[position=").append(position).append(']');
1309         sb.append("[match valid=").append(matchValid).append(']');
1310         sb.append("[need input=").append(needInput).append(']');
1311         sb.append("[source closed=").append(sourceClosed).append(']');
1312         sb.append("[skipped=").append(skipped).append(']');
1313         sb.append("[group separator=").append(groupSeparator).append(']');
1314         sb.append("[decimal separator=").append(decimalSeparator).append(']');
1315         sb.append("[positive prefix=").append(positivePrefix).append(']');
1316         sb.append("[negative prefix=").append(negativePrefix).append(']');
1317         sb.append("[positive suffix=").append(positiveSuffix).append(']');
1318         sb.append("[negative suffix=").append(negativeSuffix).append(']');
1319         sb.append("[NaN string=").append(nanString).append(']');
1320         sb.append("[infinity string=").append(infinityString).append(']');
1321         return sb.toString();
1322     }
1323 
1324     /**
1325      * Returns true if this scanner has another token in its input.
1326      * This method may block while waiting for input to scan.
1327      * The scanner does not advance past any input.
1328      *
1329      * @return true if and only if this scanner has another token
1330      * @throws IllegalStateException if this scanner is closed
1331      * @see java.util.Iterator
1332      */
1333     public boolean hasNext() {
1334         ensureOpen();
1335         saveState();
1336         while (!sourceClosed) {
1337             if (hasTokenInBuffer())
1338                 return revertState(true);
1339             readInput();
1340         }