This commit is contained in:
Mandy Chung 2020-08-10 14:57:53 -07:00
commit 6cfe3fea08
420 changed files with 6757 additions and 3705 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -302,6 +302,8 @@ public class BufferedReader extends Reader {
* (EOF).
*
* @param ignoreLF If true, the next '\n' will be skipped
* @param term Output: Whether a line terminator was encountered
* while reading the line; may be {@code null}.
*
* @return A String containing the contents of the line, not including
* any line-termination characters, or null if the end of the
@ -311,13 +313,14 @@ public class BufferedReader extends Reader {
*
* @throws IOException If an I/O error occurs
*/
String readLine(boolean ignoreLF) throws IOException {
String readLine(boolean ignoreLF, boolean[] term) throws IOException {
StringBuilder s = null;
int startChar;
synchronized (lock) {
ensureOpen();
boolean omitLF = ignoreLF || skipLF;
if (term != null) term[0] = false;
bufferLoop:
for (;;) {
@ -344,6 +347,7 @@ public class BufferedReader extends Reader {
for (i = nextChar; i < nChars; i++) {
c = cb[i];
if ((c == '\n') || (c == '\r')) {
if (term != null) term[0] = true;
eol = true;
break charLoop;
}
@ -389,7 +393,7 @@ public class BufferedReader extends Reader {
* @see java.nio.file.Files#readAllLines
*/
public String readLine() throws IOException {
return readLine(false);
return readLine(false, null);
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,8 @@
package java.io;
import java.util.Objects;
/**
* A data input stream lets an application read primitive Java data
* types from an underlying input stream in a machine-independent
@ -192,8 +194,7 @@ public class DataInputStream extends FilterInputStream implements DataInput {
* @see java.io.FilterInputStream#in
*/
public final void readFully(byte b[], int off, int len) throws IOException {
if (len < 0)
throw new IndexOutOfBoundsException();
Objects.checkFromIndexSize(off, len, b.length);
int n = 0;
while (n < len) {
int count = in.read(b, off + n, len - n);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package java.io;
/**
* A buffered character-input stream that keeps track of line numbers. This
* class defines methods {@link #setLineNumber(int)} and {@link
@ -33,15 +32,17 @@ package java.io;
* respectively.
*
* <p> By default, line numbering begins at 0. This number increments at every
* <a href="#lt">line terminator</a> as the data is read, and can be changed
* with a call to {@code setLineNumber(int)}. Note however, that
* {@code setLineNumber(int)} does not actually change the current position in
* the stream; it only changes the value that will be returned by
* <a href="#lt">line terminator</a> as the data is read, and at the end of the
* stream if the last character in the stream is not a line terminator. This
* number can be changed with a call to {@code setLineNumber(int)}. Note
* however, that {@code setLineNumber(int)} does not actually change the current
* position in the stream; it only changes the value that will be returned by
* {@code getLineNumber()}.
*
* <p> A line is considered to be <a id="lt">terminated</a> by any one of a
* line feed ('\n'), a carriage return ('\r'), or a carriage return followed
* immediately by a linefeed.
* immediately by a linefeed, or any of the previous terminators followed by
* end of stream, or end of stream not preceded by another terminator.
*
* @author Mark Reinhold
* @since 1.1
@ -49,6 +50,15 @@ package java.io;
public class LineNumberReader extends BufferedReader {
/** Previous character types */
private static final int NONE = 0; // no previous character
private static final int CHAR = 1; // non-line terminator
private static final int EOL = 2; // line terminator
private static final int EOF = 3; // end-of-file
/** The previous character type */
private int prevChar = NONE;
/** The current line number */
private int lineNumber = 0;
@ -111,8 +121,10 @@ public class LineNumberReader extends BufferedReader {
/**
* Read a single character. <a href="#lt">Line terminators</a> are
* compressed into single newline ('\n') characters. Whenever a line
* terminator is read the current line number is incremented.
* compressed into single newline ('\n') characters. The current line
* number is incremented whenever a line terminator is read, or when the
* end of the stream is reached and the last character in the stream is
* not a line terminator.
*
* @return The character read, or -1 if the end of the stream has been
* reached
@ -134,16 +146,27 @@ public class LineNumberReader extends BufferedReader {
skipLF = true;
case '\n': /* Fall through */
lineNumber++;
prevChar = EOL;
return '\n';
case -1:
if (prevChar == CHAR)
lineNumber++;
prevChar = EOF;
break;
default:
prevChar = CHAR;
break;
}
return c;
}
}
/**
* Read characters into a portion of an array. Whenever a <a
* href="#lt">line terminator</a> is read the current line number is
* incremented.
* Read characters into a portion of an array.
* <a href="#lt">Line terminators</a> are compressed into single newline
* ('\n') characters. The current line number is incremented whenever a
* line terminator is read, or when the end of the stream is reached and
* the last character in the stream is not a line terminator.
*
* @param cbuf
* Destination buffer
@ -154,8 +177,8 @@ public class LineNumberReader extends BufferedReader {
* @param len
* Maximum number of characters to read
*
* @return The number of bytes read, or -1 if the end of the stream has
* already been reached
* @return The number of characters read, or -1 if the end of the stream
* has already been reached
*
* @throws IOException
* If an I/O error occurs
@ -167,6 +190,13 @@ public class LineNumberReader extends BufferedReader {
synchronized (lock) {
int n = super.read(cbuf, off, len);
if (n == -1) {
if (prevChar == CHAR)
lineNumber++;
prevChar = EOF;
return -1;
}
for (int i = off; i < off + n; i++) {
int c = cbuf[i];
if (skipLF) {
@ -183,13 +213,28 @@ public class LineNumberReader extends BufferedReader {
}
}
if (n > 0) {
switch ((int)cbuf[off + n - 1]) {
case '\r':
case '\n': /* Fall through */
prevChar = EOL;
break;
default:
prevChar = CHAR;
break;
}
}
return n;
}
}
/**
* Read a line of text. Whenever a <a href="#lt">line terminator</a> is
* read the current line number is incremented.
* Read a line of text. <a href="#lt">Line terminators</a> are compressed
* into single newline ('\n') characters. The current line number is
* incremented whenever a line terminator is read, or when the end of the
* stream is reached and the last character in the stream is not a line
* terminator.
*
* @return A String containing the contents of the line, not including
* any <a href="#lt">line termination characters</a>, or
@ -200,10 +245,17 @@ public class LineNumberReader extends BufferedReader {
*/
public String readLine() throws IOException {
synchronized (lock) {
String l = super.readLine(skipLF);
boolean[] term = new boolean[1];
String l = super.readLine(skipLF, term);
skipLF = false;
if (l != null)
if (l != null) {
lineNumber++;
prevChar = term[0] ? EOL : EOF;
} else { // l == null
if (prevChar == CHAR)
lineNumber++;
prevChar = EOF;
}
return l;
}
}
@ -242,6 +294,9 @@ public class LineNumberReader extends BufferedReader {
break;
r -= nc;
}
if (n - r > 0) {
prevChar = NONE;
}
return n - r;
}
}

View file

@ -40,6 +40,10 @@ public interface AnnotatedWildcardType extends AnnotatedType {
* If no lower bound is explicitly declared, the lower bound is the
* type of null. In this case, a zero length array is returned.
*
* @apiNote While to date a wildcard may have at most one lower
* bound, callers of this method should be written to accommodate
* multiple bounds.
*
* @return the potentially annotated lower bounds of this wildcard type or
* an empty array if no lower bound is explicitly declared.
* @see WildcardType#getLowerBounds()
@ -51,6 +55,10 @@ public interface AnnotatedWildcardType extends AnnotatedType {
* If no upper bound is explicitly declared, the upper bound is
* unannotated {@code Object}
*
* @apiNote While to date a wildcard may have at most one upper
* bound, callers of this method should be written to accommodate
* multiple bounds.
*
* @return the potentially annotated upper bounds of this wildcard type
* @see WildcardType#getUpperBounds()
*/

View file

@ -46,6 +46,10 @@ public interface WildcardType extends Type {
* <li>Otherwise, B is resolved.
* </ul>
*
* @apiNote While to date a wildcard may have at most one upper
* bound, callers of this method should be written to accommodate
* multiple bounds.
*
* @return an array of Types representing the upper bound(s) of this
* type variable
* @throws TypeNotPresentException if any of the
@ -70,6 +74,10 @@ public interface WildcardType extends Type {
* <li>Otherwise, B is resolved.
* </ul>
*
* @apiNote While to date a wildcard may have at most one lower
* bound, callers of this method should be written to accommodate
* multiple bounds.
*
* @return an array of Types representing the lower bound(s) of this
* type variable
* @throws TypeNotPresentException if any of the
@ -79,6 +87,4 @@ public interface WildcardType extends Type {
* for any reason
*/
Type[] getLowerBounds();
// one or many? Up to language spec; currently only one, but this API
// allows for generalization.
}

View file

@ -464,9 +464,10 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* specified radix into a BigInteger. The String representation
* consists of an optional minus or plus sign followed by a
* sequence of one or more digits in the specified radix. The
* character-to-digit mapping is provided by {@code
* Character.digit}. The String may not contain any extraneous
* characters (whitespace, for example).
* character-to-digit mapping is provided by {@link
* Character#digit(char, char) Character.digit}. The String may
* not contain any extraneous characters (whitespace, for
* example).
*
* @param val String representation of BigInteger.
* @param radix radix to be used in interpreting {@code val}.
@ -474,7 +475,6 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
* of a BigInteger in the specified radix, or {@code radix} is
* outside the range from {@link Character#MIN_RADIX} to
* {@link Character#MAX_RADIX}, inclusive.
* @see Character#digit
*/
public BigInteger(String val, int radix) {
int cursor = 0, numDigits;
@ -658,17 +658,17 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
}
/**
* Translates the decimal String representation of a BigInteger into a
* BigInteger. The String representation consists of an optional minus
* sign followed by a sequence of one or more decimal digits. The
* character-to-digit mapping is provided by {@code Character.digit}.
* The String may not contain any extraneous characters (whitespace, for
* example).
* Translates the decimal String representation of a BigInteger
* into a BigInteger. The String representation consists of an
* optional minus or plus sign followed by a sequence of one or
* more decimal digits. The character-to-digit mapping is
* provided by {@link Character#digit(char, char)
* Character.digit}. The String may not contain any extraneous
* characters (whitespace, for example).
*
* @param val decimal String representation of BigInteger.
* @throws NumberFormatException {@code val} is not a valid representation
* of a BigInteger.
* @see Character#digit
*/
public BigInteger(String val) {
this(val, 10);

View file

@ -277,7 +277,7 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter;
*
* </ol>
*
* <p> For category <i>General</i>, <i>Character</i>, <i>Numberic</i>,
* <p> For category <i>General</i>, <i>Character</i>, <i>Numeric</i>,
* <i>Integral</i> and <i>Date/Time</i> conversion, unless otherwise specified,
* if the argument <i>arg</i> is {@code null}, then the result is "{@code null}".
*
@ -703,7 +703,7 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter;
* methods such as {@link String#format(String,Object...) String.format} and
* {@link java.io.PrintStream#printf(String,Object...) PrintStream.printf}.
*
* <p> For category <i>General</i>, <i>Character</i>, <i>Numberic</i>,
* <p> For category <i>General</i>, <i>Character</i>, <i>Numeric</i>,
* <i>Integral</i> and <i>Date/Time</i> conversion, unless otherwise specified,
* if the argument <i>arg</i> is {@code null}, then the result is "{@code null}".
*

View file

@ -1790,6 +1790,42 @@ public class TreeMap<K,V>
return m.put(key, value);
}
public V putIfAbsent(K key, V value) {
if (!inRange(key))
throw new IllegalArgumentException("key out of range");
return m.putIfAbsent(key, value);
}
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
if (!inRange(key))
throw new IllegalArgumentException("key out of range");
return m.merge(key, value, remappingFunction);
}
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
if (!inRange(key)) {
// Do not throw if mapping function returns null
// to preserve compatibility with default computeIfAbsent implementation
if (mappingFunction.apply(key) == null) return null;
throw new IllegalArgumentException("key out of range");
}
return m.computeIfAbsent(key, mappingFunction);
}
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
if (!inRange(key)) {
// Do not throw if remapping function returns null
// to preserve compatibility with default computeIfAbsent implementation
if (remappingFunction.apply(key, null) == null) return null;
throw new IllegalArgumentException("key out of range");
}
return m.compute(key, remappingFunction);
}
public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
return !inRange(key) ? null : m.computeIfPresent(key, remappingFunction);
}
public final V get(Object key) {
return !inRange(key) ? null : m.get(key);
}