mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
Merge
This commit is contained in:
commit
3d9f35c4f5
99 changed files with 1717 additions and 5750 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2018, 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
|
||||
|
@ -30,7 +30,6 @@ import java.io.FilePermission;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Objects;
|
||||
|
@ -63,7 +62,7 @@ final class ProxyClassesDumper {
|
|||
}
|
||||
try {
|
||||
path = path.trim();
|
||||
final Path dir = Paths.get(path.length() == 0 ? "." : path);
|
||||
final Path dir = Path.of(path.length() == 0 ? "." : path);
|
||||
AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public Void run() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2018, 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
|
||||
|
@ -34,7 +34,6 @@ import java.lang.reflect.Array;
|
|||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
@ -346,11 +345,11 @@ class ProxyGenerator {
|
|||
int i = name.lastIndexOf('.');
|
||||
Path path;
|
||||
if (i > 0) {
|
||||
Path dir = Paths.get(name.substring(0, i).replace('.', File.separatorChar));
|
||||
Path dir = Path.of(name.substring(0, i).replace('.', File.separatorChar));
|
||||
Files.createDirectories(dir);
|
||||
path = dir.resolve(name.substring(i+1, name.length()) + ".class");
|
||||
} else {
|
||||
path = Paths.get(name + ".class");
|
||||
path = Path.of(name + ".class");
|
||||
}
|
||||
Files.write(path, classFile);
|
||||
return null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2018, 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
|
||||
|
@ -279,6 +279,9 @@ public abstract class DatagramChannel
|
|||
*
|
||||
* @return This datagram channel
|
||||
*
|
||||
* @throws AlreadyConnectedException
|
||||
* If this channel is already connected
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
|
@ -292,6 +295,12 @@ public abstract class DatagramChannel
|
|||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws UnresolvedAddressException
|
||||
* If the given remote address is not fully resolved
|
||||
*
|
||||
* @throws UnsupportedAddressTypeException
|
||||
* If the type of the given remote address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed
|
||||
* and it does not permit access to the given remote address
|
||||
|
@ -444,6 +453,10 @@ public abstract class DatagramChannel
|
|||
* zero if there was insufficient room for the datagram in the
|
||||
* underlying output buffer
|
||||
*
|
||||
* @throws AlreadyConnectedException
|
||||
* If this channel is connected to a different address
|
||||
* from that specified by {@code target}
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
|
@ -457,6 +470,12 @@ public abstract class DatagramChannel
|
|||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws UnresolvedAddressException
|
||||
* If the given remote address is not fully resolved
|
||||
*
|
||||
* @throws UnsupportedAddressTypeException
|
||||
* If the type of the given remote address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed
|
||||
* and it does not permit datagrams to be sent
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2018, 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
|
||||
|
@ -28,6 +28,7 @@ package java.nio.file;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
|
@ -93,12 +94,124 @@ import java.util.NoSuchElementException;
|
|||
* multiple concurrent threads.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see Paths
|
||||
*/
|
||||
|
||||
public interface Path
|
||||
extends Comparable<Path>, Iterable<Path>, Watchable
|
||||
{
|
||||
/**
|
||||
* Returns a {@code Path} by converting a path string, or a sequence of
|
||||
* strings that when joined form a path string. If {@code more} does not
|
||||
* specify any elements then the value of the {@code first} parameter is
|
||||
* the path string to convert. If {@code more} specifies one or more
|
||||
* elements then each non-empty string, including {@code first}, is
|
||||
* considered to be a sequence of name elements and is joined to form a
|
||||
* path string. The details as to how the Strings are joined is provider
|
||||
* specific but typically they will be joined using the
|
||||
* {@link FileSystem#getSeparator name-separator} as the separator.
|
||||
* For example, if the name separator is "{@code /}" and
|
||||
* {@code getPath("/foo","bar","gus")} is invoked, then the path string
|
||||
* {@code "/foo/bar/gus"} is converted to a {@code Path}. A {@code Path}
|
||||
* representing an empty path is returned if {@code first} is the empty
|
||||
* string and {@code more} does not contain any non-empty strings.
|
||||
*
|
||||
* <p> The {@code Path} is obtained by invoking the {@link FileSystem#getPath
|
||||
* getPath} method of the {@link FileSystems#getDefault default} {@link
|
||||
* FileSystem}.
|
||||
*
|
||||
* <p> Note that while this method is very convenient, using it will imply
|
||||
* an assumed reference to the default {@code FileSystem} and limit the
|
||||
* utility of the calling code. Hence it should not be used in library code
|
||||
* intended for flexible reuse. A more flexible alternative is to use an
|
||||
* existing {@code Path} instance as an anchor, such as:
|
||||
* <pre>{@code
|
||||
* Path dir = ...
|
||||
* Path path = dir.resolve("file");
|
||||
* }</pre>
|
||||
*
|
||||
* @param first
|
||||
* the path string or initial part of the path string
|
||||
* @param more
|
||||
* additional strings to be joined to form the path string
|
||||
*
|
||||
* @return the resulting {@code Path}
|
||||
*
|
||||
* @throws InvalidPathException
|
||||
* if the path string cannot be converted to a {@code Path}
|
||||
*
|
||||
* @see FileSystem#getPath
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
public static Path of(String first, String... more) {
|
||||
return FileSystems.getDefault().getPath(first, more);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@code Path} by converting a URI.
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers to locate the provider that is identified by the
|
||||
* URI {@link URI#getScheme scheme} of the given URI. URI schemes are
|
||||
* compared without regard to case. If the provider is found then its {@link
|
||||
* FileSystemProvider#getPath getPath} method is invoked to convert the
|
||||
* URI.
|
||||
*
|
||||
* <p> In the case of the default provider, identified by the URI scheme
|
||||
* "file", the given URI has a non-empty path component, and undefined query
|
||||
* and fragment components. Whether the authority component may be present
|
||||
* is platform specific. The returned {@code Path} is associated with the
|
||||
* {@link FileSystems#getDefault default} file system.
|
||||
*
|
||||
* <p> The default provider provides a similar <em>round-trip</em> guarantee
|
||||
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
|
||||
* is guaranteed that
|
||||
* <blockquote>{@code
|
||||
* Path.of(}<i>p</i>{@code .}{@link Path#toUri() toUri}{@code ()).equals(}
|
||||
* <i>p</i>{@code .}{@link Path#toAbsolutePath() toAbsolutePath}{@code ())}
|
||||
* </blockquote>
|
||||
* so long as the original {@code Path}, the {@code URI}, and the new {@code
|
||||
* Path} are all created in (possibly different invocations of) the same
|
||||
* Java virtual machine. Whether other providers make any guarantees is
|
||||
* provider specific and therefore unspecified.
|
||||
*
|
||||
* @param uri
|
||||
* the URI to convert
|
||||
*
|
||||
* @return the resulting {@code Path}
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if preconditions on the {@code uri} parameter do not hold. The
|
||||
* format of the URI is provider specific.
|
||||
* @throws FileSystemNotFoundException
|
||||
* The file system, identified by the URI, does not exist and
|
||||
* cannot be created automatically, or the provider identified by
|
||||
* the URI's scheme component is not installed
|
||||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission to access the file system
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
public static Path of(URI uri) {
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme == null)
|
||||
throw new IllegalArgumentException("Missing scheme");
|
||||
|
||||
// check for default provider to avoid loading of installed providers
|
||||
if (scheme.equalsIgnoreCase("file"))
|
||||
return FileSystems.getDefault().provider().getPath(uri);
|
||||
|
||||
// try to find provider
|
||||
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
|
||||
if (provider.getScheme().equalsIgnoreCase(scheme)) {
|
||||
return provider.getPath(uri);
|
||||
}
|
||||
}
|
||||
|
||||
throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file system that created this object.
|
||||
*
|
||||
|
@ -527,7 +640,7 @@ public interface Path
|
|||
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
|
||||
* is guaranteed that
|
||||
* <blockquote>
|
||||
* {@link Paths#get(URI) Paths.get}{@code (}<i>p</i>{@code .toUri()).equals(}<i>p</i>
|
||||
* {@link Path#of(URI) Path.of}{@code (}<i>p</i>{@code .toUri()).equals(}<i>p</i>
|
||||
* {@code .}{@link #toAbsolutePath() toAbsolutePath}{@code ())}
|
||||
* </blockquote>
|
||||
* so long as the original {@code Path}, the {@code URI}, and the new {@code
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2018, 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
|
||||
|
@ -32,7 +32,13 @@ import java.net.URI;
|
|||
* This class consists exclusively of static methods that return a {@link Path}
|
||||
* by converting a path string or {@link URI}.
|
||||
*
|
||||
* @apiNote
|
||||
* It is recommended to obtain a {@code Path} via the {@code Path.of} methods
|
||||
* instead of via the {@code get} methods defined in this class as this class
|
||||
* may be deprecated in a future release.
|
||||
*
|
||||
* @since 1.7
|
||||
* @see Path
|
||||
*/
|
||||
|
||||
public final class Paths {
|
||||
|
@ -40,33 +46,11 @@ public final class Paths {
|
|||
|
||||
/**
|
||||
* Converts a path string, or a sequence of strings that when joined form
|
||||
* a path string, to a {@code Path}. If {@code more} does not specify any
|
||||
* elements then the value of the {@code first} parameter is the path string
|
||||
* to convert. If {@code more} specifies one or more elements then each
|
||||
* non-empty string, including {@code first}, is considered to be a sequence
|
||||
* of name elements (see {@link Path}) and is joined to form a path string.
|
||||
* The details as to how the Strings are joined is provider specific but
|
||||
* typically they will be joined using the {@link FileSystem#getSeparator
|
||||
* name-separator} as the separator. For example, if the name separator is
|
||||
* "{@code /}" and {@code getPath("/foo","bar","gus")} is invoked, then the
|
||||
* path string {@code "/foo/bar/gus"} is converted to a {@code Path}.
|
||||
* A {@code Path} representing an empty path is returned if {@code first}
|
||||
* is the empty string and {@code more} does not contain any non-empty
|
||||
* strings.
|
||||
* a path string, to a {@code Path}.
|
||||
*
|
||||
* <p> The {@code Path} is obtained by invoking the {@link FileSystem#getPath
|
||||
* getPath} method of the {@link FileSystems#getDefault default} {@link
|
||||
* FileSystem}.
|
||||
*
|
||||
* <p> Note that while this method is very convenient, using it will imply
|
||||
* an assumed reference to the default {@code FileSystem} and limit the
|
||||
* utility of the calling code. Hence it should not be used in library code
|
||||
* intended for flexible reuse. A more flexible alternative is to use an
|
||||
* existing {@code Path} instance as an anchor, such as:
|
||||
* <pre>
|
||||
* Path dir = ...
|
||||
* Path path = dir.resolve("file");
|
||||
* </pre>
|
||||
* @implSpec
|
||||
* This method simply invokes {@link Path#of(String,String...)
|
||||
* Path.of(String, String...)} with the given parameters.
|
||||
*
|
||||
* @param first
|
||||
* the path string or initial part of the path string
|
||||
|
@ -79,38 +63,17 @@ public final class Paths {
|
|||
* if the path string cannot be converted to a {@code Path}
|
||||
*
|
||||
* @see FileSystem#getPath
|
||||
* @see Path#of(String,String...)
|
||||
*/
|
||||
public static Path get(String first, String... more) {
|
||||
return FileSystems.getDefault().getPath(first, more);
|
||||
return Path.of(first, more);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given URI to a {@link Path} object.
|
||||
*
|
||||
* <p> This method iterates over the {@link FileSystemProvider#installedProviders()
|
||||
* installed} providers to locate the provider that is identified by the
|
||||
* URI {@link URI#getScheme scheme} of the given URI. URI schemes are
|
||||
* compared without regard to case. If the provider is found then its {@link
|
||||
* FileSystemProvider#getPath getPath} method is invoked to convert the
|
||||
* URI.
|
||||
*
|
||||
* <p> In the case of the default provider, identified by the URI scheme
|
||||
* "file", the given URI has a non-empty path component, and undefined query
|
||||
* and fragment components. Whether the authority component may be present
|
||||
* is platform specific. The returned {@code Path} is associated with the
|
||||
* {@link FileSystems#getDefault default} file system.
|
||||
*
|
||||
* <p> The default provider provides a similar <em>round-trip</em> guarantee
|
||||
* to the {@link java.io.File} class. For a given {@code Path} <i>p</i> it
|
||||
* is guaranteed that
|
||||
* <blockquote>{@code
|
||||
* Paths.get(}<i>p</i>{@code .}{@link Path#toUri() toUri}{@code ()).equals(}
|
||||
* <i>p</i>{@code .}{@link Path#toAbsolutePath() toAbsolutePath}{@code ())}
|
||||
* </blockquote>
|
||||
* so long as the original {@code Path}, the {@code URI}, and the new {@code
|
||||
* Path} are all created in (possibly different invocations of) the same
|
||||
* Java virtual machine. Whether other providers make any guarantees is
|
||||
* provider specific and therefore unspecified.
|
||||
* @implSpec
|
||||
* This method simply invokes {@link Path#of(URI) * Path.of(URI)} with the given parameter.
|
||||
*
|
||||
* @param uri
|
||||
* the URI to convert
|
||||
|
@ -127,23 +90,10 @@ public final class Paths {
|
|||
* @throws SecurityException
|
||||
* if a security manager is installed and it denies an unspecified
|
||||
* permission to access the file system
|
||||
*
|
||||
* @see Path#of(URI)
|
||||
*/
|
||||
public static Path get(URI uri) {
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme == null)
|
||||
throw new IllegalArgumentException("Missing scheme");
|
||||
|
||||
// check for default provider to avoid loading of installed providers
|
||||
if (scheme.equalsIgnoreCase("file"))
|
||||
return FileSystems.getDefault().provider().getPath(uri);
|
||||
|
||||
// try to find provider
|
||||
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
|
||||
if (provider.getScheme().equalsIgnoreCase(scheme)) {
|
||||
return provider.getPath(uri);
|
||||
}
|
||||
}
|
||||
|
||||
throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed");
|
||||
return Path.of(uri);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2018, 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
|
||||
|
@ -46,7 +46,7 @@ class TempFileHelper {
|
|||
|
||||
// temporary directory location
|
||||
private static final Path tmpdir =
|
||||
Paths.get(GetPropertyAction.privilegedGetProperty("java.io.tmpdir"));
|
||||
Path.of(GetPropertyAction.privilegedGetProperty("java.io.tmpdir"));
|
||||
|
||||
private static final boolean isPosix =
|
||||
FileSystems.getDefault().supportedFileAttributeViews().contains("posix");
|
||||
|
|
|
@ -93,9 +93,7 @@ public abstract class AbstractSet<E> extends AbstractCollection<E> implements Se
|
|||
return false;
|
||||
try {
|
||||
return containsAll(c);
|
||||
} catch (ClassCastException unused) {
|
||||
return false;
|
||||
} catch (NullPointerException unused) {
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,146 +70,297 @@ class ImmutableCollections {
|
|||
|
||||
static UnsupportedOperationException uoe() { return new UnsupportedOperationException(); }
|
||||
|
||||
// ---------- List Implementations ----------
|
||||
|
||||
abstract static class AbstractImmutableList<E> extends AbstractList<E>
|
||||
implements RandomAccess, Serializable {
|
||||
static abstract class AbstractImmutableCollection<E> extends AbstractCollection<E> {
|
||||
// all mutating methods throw UnsupportedOperationException
|
||||
@Override public boolean add(E e) { throw uoe(); }
|
||||
@Override public boolean addAll(Collection<? extends E> c) { throw uoe(); }
|
||||
@Override public boolean addAll(int index, Collection<? extends E> c) { throw uoe(); }
|
||||
@Override public void clear() { throw uoe(); }
|
||||
@Override public boolean remove(Object o) { throw uoe(); }
|
||||
@Override public boolean removeAll(Collection<?> c) { throw uoe(); }
|
||||
@Override public boolean removeIf(Predicate<? super E> filter) { throw uoe(); }
|
||||
@Override public void replaceAll(UnaryOperator<E> operator) { throw uoe(); }
|
||||
@Override public boolean retainAll(Collection<?> c) { throw uoe(); }
|
||||
@Override public void sort(Comparator<? super E> c) { throw uoe(); }
|
||||
}
|
||||
|
||||
static final class List0<E> extends AbstractImmutableList<E> {
|
||||
private static final List0<?> INSTANCE = new List0<>();
|
||||
// ---------- List Implementations ----------
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> List0<T> instance() {
|
||||
return (List0<T>) INSTANCE;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E> List<E> emptyList() {
|
||||
return (List<E>) ListN.EMPTY_LIST;
|
||||
}
|
||||
|
||||
private List0() { }
|
||||
static abstract class AbstractImmutableList<E> extends AbstractImmutableCollection<E>
|
||||
implements List<E>, RandomAccess {
|
||||
|
||||
// all mutating methods throw UnsupportedOperationException
|
||||
@Override public void add(int index, E element) { throw uoe(); }
|
||||
@Override public boolean addAll(int index, Collection<? extends E> c) { throw uoe(); }
|
||||
@Override public E remove(int index) { throw uoe(); }
|
||||
@Override public void replaceAll(UnaryOperator<E> operator) { throw uoe(); }
|
||||
@Override public E set(int index, E element) { throw uoe(); }
|
||||
@Override public void sort(Comparator<? super E> c) { throw uoe(); }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
int size = size();
|
||||
subListRangeCheck(fromIndex, toIndex, size);
|
||||
return SubList.fromList(this, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
Objects.checkIndex(index, 0); // always throws IndexOutOfBoundsException
|
||||
return null; // but the compiler doesn't know this
|
||||
static void subListRangeCheck(int fromIndex, int toIndex, int size) {
|
||||
if (fromIndex < 0)
|
||||
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
|
||||
if (toIndex > size)
|
||||
throw new IndexOutOfBoundsException("toIndex = " + toIndex);
|
||||
if (fromIndex > toIndex)
|
||||
throw new IllegalArgumentException("fromIndex(" + fromIndex +
|
||||
") > toIndex(" + toIndex + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
throw new InvalidObjectException("not serial proxy");
|
||||
}
|
||||
|
||||
private Object writeReplace() {
|
||||
return new CollSer(CollSer.IMM_LIST);
|
||||
return new ListItr<E>(this, size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
public ListIterator<E> listIterator() {
|
||||
return listIterator(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator(final int index) {
|
||||
int size = size();
|
||||
if (index < 0 || index > size) {
|
||||
throw outOfBounds(index);
|
||||
}
|
||||
return new ListItr<E>(this, size, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof List)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Iterator<?> oit = ((List<?>) o).iterator();
|
||||
for (int i = 0, s = size(); i < s; i++) {
|
||||
if (!oit.hasNext() || !get(i).equals(oit.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !oit.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
Objects.requireNonNull(o);
|
||||
return false;
|
||||
for (int i = 0, s = size(); i < s; i++) {
|
||||
if (o.equals(get(i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> o) {
|
||||
return o.isEmpty(); // implicit nullcheck of o
|
||||
public int lastIndexOf(Object o) {
|
||||
Objects.requireNonNull(o);
|
||||
for (int i = size() - 1; i >= 0; i--) {
|
||||
if (o.equals(get(i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static final class List1<E> extends AbstractImmutableList<E> {
|
||||
@Stable
|
||||
private final E e0;
|
||||
|
||||
List1(E e0) {
|
||||
this.e0 = Objects.requireNonNull(e0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
Objects.checkIndex(index, 1);
|
||||
return e0;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
throw new InvalidObjectException("not serial proxy");
|
||||
}
|
||||
|
||||
private Object writeReplace() {
|
||||
return new CollSer(CollSer.IMM_LIST, e0);
|
||||
int hash = 1;
|
||||
for (int i = 0, s = size(); i < s; i++) {
|
||||
hash = 31 * hash + get(i).hashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return o.equals(e0); // implicit nullcheck of o
|
||||
return indexOf(o) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 + e0.hashCode();
|
||||
IndexOutOfBoundsException outOfBounds(int index) {
|
||||
return new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
|
||||
}
|
||||
}
|
||||
|
||||
static final class List2<E> extends AbstractImmutableList<E> {
|
||||
static final class ListItr<E> implements ListIterator<E> {
|
||||
|
||||
@Stable
|
||||
private final List<E> list;
|
||||
|
||||
@Stable
|
||||
private final int size;
|
||||
|
||||
private int cursor;
|
||||
|
||||
ListItr(List<E> list, int size) {
|
||||
this(list, size, 0);
|
||||
}
|
||||
|
||||
ListItr(List<E> list, int size, int index) {
|
||||
this.list = list;
|
||||
this.size = size;
|
||||
this.cursor = index;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return cursor != size;
|
||||
}
|
||||
|
||||
public E next() {
|
||||
try {
|
||||
int i = cursor;
|
||||
E next = list.get(i);
|
||||
cursor = i + 1;
|
||||
return next;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw uoe();
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return cursor != 0;
|
||||
}
|
||||
|
||||
public E previous() {
|
||||
try {
|
||||
int i = cursor - 1;
|
||||
E previous = list.get(i);
|
||||
cursor = i;
|
||||
return previous;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
return cursor;
|
||||
}
|
||||
|
||||
public int previousIndex() {
|
||||
return cursor - 1;
|
||||
}
|
||||
|
||||
public void set(E e) {
|
||||
throw uoe();
|
||||
}
|
||||
|
||||
public void add(E e) {
|
||||
throw uoe();
|
||||
}
|
||||
}
|
||||
|
||||
static final class SubList<E> extends AbstractImmutableList<E>
|
||||
implements RandomAccess {
|
||||
|
||||
@Stable
|
||||
private final List<E> root;
|
||||
|
||||
@Stable
|
||||
private final int offset;
|
||||
|
||||
@Stable
|
||||
private final int size;
|
||||
|
||||
private SubList(List<E> root, int offset, int size) {
|
||||
this.root = root;
|
||||
this.offset = offset;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sublist of another SubList.
|
||||
*/
|
||||
static <E> SubList<E> fromSubList(SubList<E> parent, int fromIndex, int toIndex) {
|
||||
return new SubList<E>(parent.root, parent.offset + fromIndex, toIndex - fromIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a sublist of an arbitrary AbstractImmutableList, which is
|
||||
* not a SubList itself.
|
||||
*/
|
||||
static <E> SubList<E> fromList(List<E> list, int fromIndex, int toIndex) {
|
||||
return new SubList<E>(list, fromIndex, toIndex - fromIndex);
|
||||
}
|
||||
|
||||
public E get(int index) {
|
||||
Objects.checkIndex(index, size);
|
||||
return root.get(offset + index);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
return new ListItr<E>(this, size());
|
||||
}
|
||||
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
rangeCheck(index);
|
||||
return new ListItr<E>(this, size(), index);
|
||||
}
|
||||
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
subListRangeCheck(fromIndex, toIndex, size);
|
||||
return SubList.fromSubList(this, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
private void rangeCheck(int index) {
|
||||
if (index < 0 || index > size) {
|
||||
throw outOfBounds(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final class List12<E> extends AbstractImmutableList<E>
|
||||
implements Serializable {
|
||||
|
||||
@Stable
|
||||
private final E e0;
|
||||
|
||||
@Stable
|
||||
private final E e1;
|
||||
|
||||
List2(E e0, E e1) {
|
||||
List12(E e0) {
|
||||
this.e0 = Objects.requireNonNull(e0);
|
||||
this.e1 = null;
|
||||
}
|
||||
|
||||
List12(E e0, E e1) {
|
||||
this.e0 = Objects.requireNonNull(e0);
|
||||
this.e1 = Objects.requireNonNull(e1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 2;
|
||||
return e1 != null ? 2 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
Objects.checkIndex(index, 2);
|
||||
if (index == 0) {
|
||||
return e0;
|
||||
} else { // index == 1
|
||||
} else if (index == 1 && e1 != null) {
|
||||
return e1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return o.equals(e0) || o.equals(e1); // implicit nullcheck of o
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 31 + e0.hashCode();
|
||||
return 31 * hash + e1.hashCode();
|
||||
throw outOfBounds(index);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
|
@ -217,11 +368,20 @@ class ImmutableCollections {
|
|||
}
|
||||
|
||||
private Object writeReplace() {
|
||||
return new CollSer(CollSer.IMM_LIST, e0, e1);
|
||||
if (e1 == null) {
|
||||
return new CollSer(CollSer.IMM_LIST, e0);
|
||||
} else {
|
||||
return new CollSer(CollSer.IMM_LIST, e0, e1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final class ListN<E> extends AbstractImmutableList<E> {
|
||||
static final class ListN<E> extends AbstractImmutableList<E>
|
||||
implements Serializable {
|
||||
|
||||
static final List<?> EMPTY_LIST = new ListN<>();
|
||||
|
||||
@Stable
|
||||
private final E[] elements;
|
||||
|
||||
|
@ -233,7 +393,12 @@ class ImmutableCollections {
|
|||
for (int i = 0; i < input.length; i++) {
|
||||
tmp[i] = Objects.requireNonNull(input[i]);
|
||||
}
|
||||
this.elements = tmp;
|
||||
elements = tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -243,29 +408,9 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
Objects.checkIndex(index, elements.length);
|
||||
return elements[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
for (E e : elements) {
|
||||
if (o.equals(e)) { // implicit nullcheck of o
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
for (E e : elements) {
|
||||
hash = 31 * hash + e.hashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
throw new InvalidObjectException("not serial proxy");
|
||||
}
|
||||
|
@ -277,105 +422,52 @@ class ImmutableCollections {
|
|||
|
||||
// ---------- Set Implementations ----------
|
||||
|
||||
abstract static class AbstractImmutableSet<E> extends AbstractSet<E> implements Serializable {
|
||||
@Override public boolean add(E e) { throw uoe(); }
|
||||
@Override public boolean addAll(Collection<? extends E> c) { throw uoe(); }
|
||||
@Override public void clear() { throw uoe(); }
|
||||
@Override public boolean remove(Object o) { throw uoe(); }
|
||||
@Override public boolean removeAll(Collection<?> c) { throw uoe(); }
|
||||
@Override public boolean removeIf(Predicate<? super E> filter) { throw uoe(); }
|
||||
@Override public boolean retainAll(Collection<?> c) { throw uoe(); }
|
||||
static abstract class AbstractImmutableSet<E> extends AbstractImmutableCollection<E>
|
||||
implements Set<E> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
} else if (!(o instanceof Set)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Collection<?> c = (Collection<?>) o;
|
||||
if (c.size() != size()) {
|
||||
return false;
|
||||
}
|
||||
for (Object e : c) {
|
||||
if (e == null || !contains(e)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
}
|
||||
|
||||
static final class Set0<E> extends AbstractImmutableSet<E> {
|
||||
private static final Set0<?> INSTANCE = new Set0<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> Set0<T> instance() {
|
||||
return (Set0<T>) INSTANCE;
|
||||
}
|
||||
|
||||
private Set0() { }
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
Objects.requireNonNull(o);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> o) {
|
||||
return o.isEmpty(); // implicit nullcheck of o
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
throw new InvalidObjectException("not serial proxy");
|
||||
}
|
||||
|
||||
private Object writeReplace() {
|
||||
return new CollSer(CollSer.IMM_SET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E> Set<E> emptySet() {
|
||||
return (Set<E>) SetN.EMPTY_SET;
|
||||
}
|
||||
|
||||
static final class Set1<E> extends AbstractImmutableSet<E> {
|
||||
@Stable
|
||||
private final E e0;
|
||||
static final class Set12<E> extends AbstractImmutableSet<E>
|
||||
implements Serializable {
|
||||
|
||||
Set1(E e0) {
|
||||
this.e0 = Objects.requireNonNull(e0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return o.equals(e0); // implicit nullcheck of o
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return Collections.singletonIterator(e0);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
throw new InvalidObjectException("not serial proxy");
|
||||
}
|
||||
|
||||
private Object writeReplace() {
|
||||
return new CollSer(CollSer.IMM_SET, e0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return e0.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
static final class Set2<E> extends AbstractImmutableSet<E> {
|
||||
@Stable
|
||||
final E e0;
|
||||
@Stable
|
||||
final E e1;
|
||||
|
||||
Set2(E e0, E e1) {
|
||||
Set12(E e0) {
|
||||
this.e0 = Objects.requireNonNull(e0);
|
||||
this.e1 = null;
|
||||
}
|
||||
|
||||
Set12(E e0, E e1) {
|
||||
if (e0.equals(Objects.requireNonNull(e1))) { // implicit nullcheck of e0
|
||||
throw new IllegalArgumentException("duplicate element: " + e0);
|
||||
}
|
||||
|
@ -391,7 +483,7 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public int size() {
|
||||
return 2;
|
||||
return (e1 == null) ? 1 : 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -401,26 +493,26 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return e0.hashCode() + e1.hashCode();
|
||||
return e0.hashCode() + (e1 == null ? 0 : e1.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return new Iterator<E>() {
|
||||
private int idx = 0;
|
||||
return new Iterator<>() {
|
||||
private int idx = size();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return idx < 2;
|
||||
return idx > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E next() {
|
||||
if (idx == 0) {
|
||||
idx = 1;
|
||||
if (idx == 1) {
|
||||
idx = 0;
|
||||
return e0;
|
||||
} else if (idx == 1) {
|
||||
idx = 2;
|
||||
} else if (idx == 2) {
|
||||
idx = 1;
|
||||
return e1;
|
||||
} else {
|
||||
throw new NoSuchElementException();
|
||||
|
@ -434,7 +526,11 @@ class ImmutableCollections {
|
|||
}
|
||||
|
||||
private Object writeReplace() {
|
||||
return new CollSer(CollSer.IMM_SET, e0, e1);
|
||||
if (e1 == null) {
|
||||
return new CollSer(CollSer.IMM_SET, e0);
|
||||
} else {
|
||||
return new CollSer(CollSer.IMM_SET, e0, e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,7 +540,11 @@ class ImmutableCollections {
|
|||
* least one null is always present.
|
||||
* @param <E> the element type
|
||||
*/
|
||||
static final class SetN<E> extends AbstractImmutableSet<E> {
|
||||
static final class SetN<E> extends AbstractImmutableSet<E>
|
||||
implements Serializable {
|
||||
|
||||
static final Set<?> EMPTY_SET = new SetN<>();
|
||||
|
||||
@Stable
|
||||
final E[] elements;
|
||||
@Stable
|
||||
|
@ -474,12 +574,13 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return probe(o) >= 0; // implicit nullcheck of o
|
||||
Objects.requireNonNull(o);
|
||||
return size > 0 && probe(o) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return new Iterator<E>() {
|
||||
return new Iterator<>() {
|
||||
private int idx = 0;
|
||||
|
||||
@Override
|
||||
|
@ -549,6 +650,11 @@ class ImmutableCollections {
|
|||
|
||||
// ---------- Map Implementations ----------
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <K,V> Map<K,V> emptyMap() {
|
||||
return (Map<K,V>) MapN.EMPTY_MAP;
|
||||
}
|
||||
|
||||
abstract static class AbstractImmutableMap<K,V> extends AbstractMap<K,V> implements Serializable {
|
||||
@Override public void clear() { throw uoe(); }
|
||||
@Override public V compute(K key, BiFunction<? super K,? super V,? extends V> rf) { throw uoe(); }
|
||||
|
@ -565,47 +671,6 @@ class ImmutableCollections {
|
|||
@Override public void replaceAll(BiFunction<? super K,? super V,? extends V> f) { throw uoe(); }
|
||||
}
|
||||
|
||||
static final class Map0<K,V> extends AbstractImmutableMap<K,V> {
|
||||
private static final Map0<?,?> INSTANCE = new Map0<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <K,V> Map0<K,V> instance() {
|
||||
return (Map0<K,V>) INSTANCE;
|
||||
}
|
||||
|
||||
private Map0() { }
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<K,V>> entrySet() {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object o) {
|
||||
Objects.requireNonNull(o);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object o) {
|
||||
Objects.requireNonNull(o);
|
||||
return false;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
throw new InvalidObjectException("not serial proxy");
|
||||
}
|
||||
|
||||
private Object writeReplace() {
|
||||
return new CollSer(CollSer.IMM_MAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static final class Map1<K,V> extends AbstractImmutableMap<K,V> {
|
||||
@Stable
|
||||
private final K k0;
|
||||
|
@ -656,8 +721,12 @@ class ImmutableCollections {
|
|||
* @param <V> the value type
|
||||
*/
|
||||
static final class MapN<K,V> extends AbstractImmutableMap<K,V> {
|
||||
|
||||
static final Map<?,?> EMPTY_MAP = new MapN<>();
|
||||
|
||||
@Stable
|
||||
final Object[] table; // pairs of key, value
|
||||
|
||||
@Stable
|
||||
final int size; // number of pairs
|
||||
|
||||
|
@ -689,14 +758,16 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public boolean containsKey(Object o) {
|
||||
return probe(o) >= 0; // implicit nullcheck of o
|
||||
Objects.requireNonNull(o);
|
||||
return size > 0 && probe(o) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object o) {
|
||||
Objects.requireNonNull(o);
|
||||
for (int i = 1; i < table.length; i += 2) {
|
||||
Object v = table[i];
|
||||
if (v != null && o.equals(v)) { // implicit nullcheck of o
|
||||
if (v != null && o.equals(v)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -718,6 +789,10 @@ class ImmutableCollections {
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public V get(Object o) {
|
||||
if (size == 0) {
|
||||
Objects.requireNonNull(o);
|
||||
return null;
|
||||
}
|
||||
int i = probe(o);
|
||||
if (i >= 0) {
|
||||
return (V)table[i+1];
|
||||
|
@ -733,7 +808,7 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public Set<Map.Entry<K,V>> entrySet() {
|
||||
return new AbstractSet<Map.Entry<K,V>>() {
|
||||
return new AbstractSet<>() {
|
||||
@Override
|
||||
public int size() {
|
||||
return MapN.this.size;
|
||||
|
@ -741,7 +816,7 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public Iterator<Map.Entry<K,V>> iterator() {
|
||||
return new Iterator<Map.Entry<K,V>>() {
|
||||
return new Iterator<>() {
|
||||
int idx = 0;
|
||||
|
||||
@Override
|
||||
|
@ -948,7 +1023,7 @@ final class CollSer implements Serializable {
|
|||
return Set.of(array);
|
||||
case IMM_MAP:
|
||||
if (array.length == 0) {
|
||||
return ImmutableCollections.Map0.instance();
|
||||
return ImmutableCollections.emptyMap();
|
||||
} else if (array.length == 2) {
|
||||
return new ImmutableCollections.Map1<>(array[0], array[1]);
|
||||
} else {
|
||||
|
|
|
@ -788,7 +788,7 @@ public interface List<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> List<E> of() {
|
||||
return ImmutableCollections.List0.instance();
|
||||
return ImmutableCollections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -804,7 +804,7 @@ public interface List<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> List<E> of(E e1) {
|
||||
return new ImmutableCollections.List1<>(e1);
|
||||
return new ImmutableCollections.List12<>(e1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -821,7 +821,7 @@ public interface List<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> List<E> of(E e1, E e2) {
|
||||
return new ImmutableCollections.List2<>(e1, e2);
|
||||
return new ImmutableCollections.List12<>(e1, e2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1031,11 +1031,11 @@ public interface List<E> extends Collection<E> {
|
|||
static <E> List<E> of(E... elements) {
|
||||
switch (elements.length) { // implicit null check of elements
|
||||
case 0:
|
||||
return ImmutableCollections.List0.instance();
|
||||
return ImmutableCollections.emptyList();
|
||||
case 1:
|
||||
return new ImmutableCollections.List1<>(elements[0]);
|
||||
return new ImmutableCollections.List12<>(elements[0]);
|
||||
case 2:
|
||||
return new ImmutableCollections.List2<>(elements[0], elements[1]);
|
||||
return new ImmutableCollections.List12<>(elements[0], elements[1]);
|
||||
default:
|
||||
return new ImmutableCollections.ListN<>(elements);
|
||||
}
|
||||
|
|
|
@ -1287,7 +1287,7 @@ public interface Map<K, V> {
|
|||
* @since 9
|
||||
*/
|
||||
static <K, V> Map<K, V> of() {
|
||||
return ImmutableCollections.Map0.instance();
|
||||
return ImmutableCollections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1604,11 +1604,11 @@ public interface Map<K, V> {
|
|||
@SuppressWarnings("varargs")
|
||||
static <K, V> Map<K, V> ofEntries(Entry<? extends K, ? extends V>... entries) {
|
||||
if (entries.length == 0) { // implicit null check of entries array
|
||||
return ImmutableCollections.Map0.instance();
|
||||
return ImmutableCollections.emptyMap();
|
||||
} else if (entries.length == 1) {
|
||||
// implicit null check of the array slot
|
||||
return new ImmutableCollections.Map1<>(entries[0].getKey(),
|
||||
entries[0].getValue());
|
||||
entries[0].getValue());
|
||||
} else {
|
||||
Object[] kva = new Object[entries.length << 1];
|
||||
int a = 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2018, 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
|
||||
|
@ -2897,7 +2897,7 @@ public final class Scanner implements Iterator<String>, Closeable {
|
|||
* letters:
|
||||
*
|
||||
* <pre>{@code
|
||||
* try (Scanner sc = new Scanner(Paths.get("input.txt"))) {
|
||||
* try (Scanner sc = new Scanner(Path.of("input.txt"))) {
|
||||
* Pattern pat = Pattern.compile("[A-Z]{7,}");
|
||||
* List<String> capWords = sc.findAll(pat)
|
||||
* .map(MatchResult::group)
|
||||
|
|
|
@ -449,7 +449,7 @@ public interface Set<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> Set<E> of() {
|
||||
return ImmutableCollections.Set0.instance();
|
||||
return ImmutableCollections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -464,7 +464,7 @@ public interface Set<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> Set<E> of(E e1) {
|
||||
return new ImmutableCollections.Set1<>(e1);
|
||||
return new ImmutableCollections.Set12<>(e1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -481,7 +481,7 @@ public interface Set<E> extends Collection<E> {
|
|||
* @since 9
|
||||
*/
|
||||
static <E> Set<E> of(E e1, E e2) {
|
||||
return new ImmutableCollections.Set2<>(e1, e2);
|
||||
return new ImmutableCollections.Set12<>(e1, e2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -692,11 +692,11 @@ public interface Set<E> extends Collection<E> {
|
|||
static <E> Set<E> of(E... elements) {
|
||||
switch (elements.length) { // implicit null check of elements
|
||||
case 0:
|
||||
return ImmutableCollections.Set0.instance();
|
||||
return ImmutableCollections.emptySet();
|
||||
case 1:
|
||||
return new ImmutableCollections.Set1<>(elements[0]);
|
||||
return new ImmutableCollections.Set12<>(elements[0]);
|
||||
case 2:
|
||||
return new ImmutableCollections.Set2<>(elements[0], elements[1]);
|
||||
return new ImmutableCollections.Set12<>(elements[0], elements[1]);
|
||||
default:
|
||||
return new ImmutableCollections.SetN<>(elements);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2018, 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
|
||||
|
@ -32,7 +32,6 @@ import java.net.URI;
|
|||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
|
@ -243,8 +242,8 @@ public class BootLoader {
|
|||
mn = location.substring(5, location.length());
|
||||
} else if (location.startsWith("file:/")) {
|
||||
// named module in exploded image
|
||||
Path path = Paths.get(URI.create(location));
|
||||
Path modulesDir = Paths.get(JAVA_HOME, "modules");
|
||||
Path path = Path.of(URI.create(location));
|
||||
Path modulesDir = Path.of(JAVA_HOME, "modules");
|
||||
if (path.startsWith(modulesDir)) {
|
||||
mn = path.getFileName().toString();
|
||||
}
|
||||
|
@ -267,7 +266,7 @@ public class BootLoader {
|
|||
private static URL toFileURL(String location) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
public URL run() {
|
||||
Path path = Paths.get(location);
|
||||
Path path = Path.of(location);
|
||||
if (Files.isRegularFile(path)) {
|
||||
try {
|
||||
return path.toUri().toURL();
|
||||
|
@ -285,7 +284,7 @@ public class BootLoader {
|
|||
private static Manifest getManifest(String location) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
public Manifest run() {
|
||||
Path jar = Paths.get(location);
|
||||
Path jar = Path.of(location);
|
||||
try (InputStream in = Files.newInputStream(jar);
|
||||
JarInputStream jis = new JarInputStream(in, false)) {
|
||||
return jis.getManifest();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2018, 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
|
||||
|
@ -28,7 +28,7 @@ package jdk.internal.loader;
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.security.CodeSource;
|
||||
import java.security.PermissionCollection;
|
||||
import java.util.jar.Manifest;
|
||||
|
@ -223,7 +223,7 @@ public class ClassLoaders {
|
|||
// Use an intermediate File object to construct a URI/URL without
|
||||
// authority component as URLClassPath can't handle URLs with a UNC
|
||||
// server name in the authority component.
|
||||
return Paths.get(s).toRealPath().toFile().toURI().toURL();
|
||||
return Path.of(s).toRealPath().toFile().toURI().toURL();
|
||||
} catch (InvalidPathException | IOException ignore) {
|
||||
// malformed path string or class path element does not exist
|
||||
return null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2018, 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
|
||||
|
@ -34,7 +34,6 @@ import java.lang.module.ModuleReference;
|
|||
import java.lang.module.ResolvedModule;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -539,7 +538,7 @@ public final class ModuleBootstrap {
|
|||
Path[] paths = new Path[dirs.length];
|
||||
int i = 0;
|
||||
for (String dir: dirs) {
|
||||
paths[i++] = Paths.get(dir);
|
||||
paths[i++] = Path.of(dir);
|
||||
}
|
||||
return ModulePath.of(patcher, paths);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2018, 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
|
||||
|
@ -30,7 +30,6 @@ import java.lang.module.Configuration;
|
|||
import java.lang.module.ResolvedModule;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
|
@ -129,7 +128,7 @@ public class ModuleHashesBuilder {
|
|||
() -> new InternalError("Selected module " + name + " not on module path"));
|
||||
|
||||
URI uri = rm.reference().location().get();
|
||||
Path path = Paths.get(uri);
|
||||
Path path = Path.of(uri);
|
||||
String fn = path.getFileName().toString();
|
||||
if (!fn.endsWith(".jar") && !fn.endsWith(".jmod")) {
|
||||
throw new UnsupportedOperationException(path + " is not a modular JAR or jmod file");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2018, 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
|
||||
|
@ -43,7 +43,6 @@ import java.nio.file.DirectoryStream;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -360,7 +359,7 @@ public class ModulePath implements ModuleFinder {
|
|||
URI uri = mref.location().orElse(null);
|
||||
if (uri != null) {
|
||||
if (uri.getScheme().equalsIgnoreCase("file")) {
|
||||
Path file = Paths.get(uri);
|
||||
Path file = Path.of(uri);
|
||||
return file.getFileName().toString();
|
||||
} else {
|
||||
return uri.toString();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2018, 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
|
||||
|
@ -38,7 +38,6 @@ import java.net.URLConnection;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayDeque;
|
||||
|
@ -185,7 +184,7 @@ public final class SystemModuleFinders {
|
|||
|
||||
// probe to see if this is an images build
|
||||
String home = System.getProperty("java.home");
|
||||
Path modules = Paths.get(home, "lib", "modules");
|
||||
Path modules = Path.of(home, "lib", "modules");
|
||||
if (Files.isRegularFile(modules)) {
|
||||
if (USE_FAST_PATH) {
|
||||
SystemModules systemModules = allSystemModules();
|
||||
|
@ -205,7 +204,7 @@ public final class SystemModuleFinders {
|
|||
}
|
||||
|
||||
// exploded build (do not cache module finder)
|
||||
Path dir = Paths.get(home, "modules");
|
||||
Path dir = Path.of(home, "modules");
|
||||
if (!Files.isDirectory(dir))
|
||||
throw new InternalError("Unable to detect the run-time image");
|
||||
ModuleFinder f = ModulePath.of(ModuleBootstrap.patcher(), dir);
|
||||
|
|
|
@ -508,8 +508,7 @@ class DatagramChannelImpl
|
|||
if (remote != null) {
|
||||
// connected
|
||||
if (!target.equals(remote)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Connected address not equal to target address");
|
||||
throw new AlreadyConnectedException();
|
||||
}
|
||||
do {
|
||||
n = IOUtil.write(fd, src, -1, nd);
|
||||
|
|
|
@ -397,7 +397,9 @@ public class IOUtil {
|
|||
* The read end of the pipe is returned in the high 32 bits,
|
||||
* while the write end is returned in the low 32 bits.
|
||||
*/
|
||||
static native long makePipe(boolean blocking);
|
||||
static native long makePipe(boolean blocking) throws IOException;
|
||||
|
||||
static native int write1(int fd, byte b) throws IOException;
|
||||
|
||||
static native boolean drain(int fd) throws IOException;
|
||||
|
||||
|
|
|
@ -33,10 +33,10 @@ import java.nio.channels.spi.AbstractSelectionKey;
|
|||
|
||||
|
||||
/**
|
||||
* An implementation of SelectionKey for Solaris.
|
||||
* An implementation of SelectionKey.
|
||||
*/
|
||||
|
||||
public class SelectionKeyImpl
|
||||
public final class SelectionKeyImpl
|
||||
extends AbstractSelectionKey
|
||||
{
|
||||
|
||||
|
@ -54,12 +54,14 @@ public class SelectionKeyImpl
|
|||
selector = sel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectableChannel channel() {
|
||||
return (SelectableChannel)channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Selector selector() {
|
||||
return selector;
|
||||
return (Selector)selector;
|
||||
}
|
||||
|
||||
int getIndex() { // package-private
|
||||
|
@ -75,16 +77,19 @@ public class SelectionKeyImpl
|
|||
throw new CancelledKeyException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int interestOps() {
|
||||
ensureValid();
|
||||
return interestOps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectionKey interestOps(int ops) {
|
||||
ensureValid();
|
||||
return nioInterestOps(ops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readyOps() {
|
||||
ensureValid();
|
||||
return readyOps;
|
||||
|
@ -131,4 +136,6 @@ public class SelectionKeyImpl
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
// used by Selector implementations to record when the key was selected
|
||||
int lastPolled;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,16 @@ public abstract class SelectorImpl
|
|||
return publicSelectedKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public view of the key sets
|
||||
*/
|
||||
protected final Set<SelectionKey> nioKeys() {
|
||||
return publicKeys;
|
||||
}
|
||||
protected final Set<SelectionKey> nioSelectedKeys() {
|
||||
return publicSelectedKeys;
|
||||
}
|
||||
|
||||
protected abstract int doSelect(long timeout) throws IOException;
|
||||
|
||||
private int lockAndDoSelect(long timeout) throws IOException {
|
||||
|
@ -125,8 +135,6 @@ public abstract class SelectorImpl
|
|||
|
||||
protected abstract void implClose() throws IOException;
|
||||
|
||||
public abstract void putEventOps(SelectionKeyImpl sk, int ops);
|
||||
|
||||
@Override
|
||||
protected final SelectionKey register(AbstractSelectableChannel ch,
|
||||
int ops,
|
||||
|
@ -166,4 +174,9 @@ public abstract class SelectorImpl
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked to change the key's interest set
|
||||
*/
|
||||
public abstract void putEventOps(SelectionKeyImpl ski, int ops);
|
||||
}
|
||||
|
|
|
@ -210,25 +210,20 @@ class ServerSocketChannelImpl
|
|||
|
||||
@Override
|
||||
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException {
|
||||
acceptLock.lock();
|
||||
try {
|
||||
synchronized (stateLock) {
|
||||
ensureOpen();
|
||||
if (localAddress != null)
|
||||
throw new AlreadyBoundException();
|
||||
InetSocketAddress isa = (local == null)
|
||||
? new InetSocketAddress(0)
|
||||
: Net.checkAddress(local);
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null)
|
||||
sm.checkListen(isa.getPort());
|
||||
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
|
||||
Net.bind(fd, isa.getAddress(), isa.getPort());
|
||||
Net.listen(fd, backlog < 1 ? 50 : backlog);
|
||||
localAddress = Net.localAddress(fd);
|
||||
}
|
||||
} finally {
|
||||
acceptLock.unlock();
|
||||
synchronized (stateLock) {
|
||||
ensureOpen();
|
||||
if (localAddress != null)
|
||||
throw new AlreadyBoundException();
|
||||
InetSocketAddress isa = (local == null)
|
||||
? new InetSocketAddress(0)
|
||||
: Net.checkAddress(local);
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null)
|
||||
sm.checkListen(isa.getPort());
|
||||
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
|
||||
Net.bind(fd, isa.getAddress(), isa.getPort());
|
||||
Net.listen(fd, backlog < 1 ? 50 : backlog);
|
||||
localAddress = Net.localAddress(fd);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.lang.reflect.*;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.Certificate;
|
||||
|
@ -278,7 +278,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
public URL run() {
|
||||
String sep = File.separator;
|
||||
try {
|
||||
return Paths.get(System.getProperty("java.home"),
|
||||
return Path.of(System.getProperty("java.home"),
|
||||
"lib", "security",
|
||||
"default.policy").toUri().toURL();
|
||||
} catch (MalformedURLException mue) {
|
||||
|
|
|
@ -27,7 +27,7 @@ package sun.security.tools.keytool;
|
|||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.security.CodeSigner;
|
||||
import java.security.CryptoPrimitive;
|
||||
import java.security.KeyStore;
|
||||
|
@ -2189,7 +2189,7 @@ public final class Main {
|
|||
inplaceBackupName = srcksfname + ".old" + (n == 1 ? "" : n);
|
||||
File bkFile = new File(inplaceBackupName);
|
||||
if (!bkFile.exists()) {
|
||||
Files.copy(Paths.get(srcksfname), bkFile.toPath());
|
||||
Files.copy(Path.of(srcksfname), bkFile.toPath());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue