--- a/jdk/src/share/classes/java/io/DataInput.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/io/DataInput.java Thu Jul 25 20:30:58 2013 -0400
@@ -48,132 +48,87 @@
* may be thrown if the input stream has been
* closed.
*
- * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
+ * <h3><a name="modified-utf-8">Modified UTF-8</a></h3>
* <p>
* Implementations of the DataInput and DataOutput interfaces represent
* Unicode strings in a format that is a slight modification of UTF-8.
* (For information regarding the standard UTF-8 format, see section
* <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
* 4.0</i>).
- * Note that in the following tables, the most significant bit appears in the
+ * Note that in the following table, the most significant bit appears in the
* far left-hand column.
- * <p>
- * All characters in the range {@code '\u005Cu0001'} to
- * {@code '\u005Cu007F'} are represented by a single byte:
*
* <blockquote>
- * <table border="1" cellspacing="0" cellpadding="8" width="50%"
+ * <table border="1" cellspacing="0" cellpadding="8"
* summary="Bit values and bytes">
* <tr>
+ * <th colspan="9"><span style="font-weight:normal">
+ * All characters in the range {@code '\u005Cu0001'} to
+ * {@code '\u005Cu007F'} are represented by a single byte:</span></th>
+ * </tr>
+ * <tr>
* <td></td>
- * <th id="bit_a">Bit Values</th>
+ * <th colspan="8" id="bit_a">Bit Values</th>
* </tr>
* <tr>
* <th id="byte1_a">Byte 1</th>
- * <td>
- * <table border="1" cellspacing="0" width="100%">
- * <tr>
- * <td width="12%"><center>0</center>
- * <td colspan="7"><center>bits 6-0</center>
- * </tr>
- * </table>
- * </td>
+ * <td><center>0</center>
+ * <td colspan="7"><center>bits 6-0</center>
* </tr>
- * </table>
- * </blockquote>
- *
- * <p>
- * The null character {@code '\u005Cu0000'} and characters in the
- * range {@code '\u005Cu0080'} to {@code '\u005Cu07FF'} are
- * represented by a pair of bytes:
- *
- * <blockquote>
- * <table border="1" cellspacing="0" cellpadding="8" width="50%"
- * summary="Bit values and bytes">
+ * <tr>
+ * <th colspan="9"><span style="font-weight:normal">
+ * The null character {@code '\u005Cu0000'} and characters
+ * in the range {@code '\u005Cu0080'} to {@code '\u005Cu07FF'} are
+ * represented by a pair of bytes:</span></th>
+ * </tr>
* <tr>
* <td></td>
- * <th id="bit_b">Bit Values</th>
+ * <th colspan="8" id="bit_b">Bit Values</th>
* </tr>
* <tr>
* <th id="byte1_b">Byte 1</th>
- * <td>
- * <table border="1" cellspacing="0" width="100%">
- * <tr>
- * <td width="12%"><center>1</center>
- * <td width="13%"><center>1</center>
- * <td width="12%"><center>0</center>
- * <td colspan="5"><center>bits 10-6</center>
- * </tr>
- * </table>
- * </td>
+ * <td><center>1</center>
+ * <td><center>1</center>
+ * <td><center>0</center>
+ * <td colspan="5"><center>bits 10-6</center>
* </tr>
* <tr>
* <th id="byte2_a">Byte 2</th>
- * <td>
- * <table border="1" cellspacing="0" width="100%">
- * <tr>
- * <td width="12%"><center>1</center>
- * <td width="13%"><center>0</center>
- * <td colspan="6"><center>bits 5-0</center>
- * </tr>
- * </table>
- * </td>
+ * <td><center>1</center>
+ * <td><center>0</center>
+ * <td colspan="6"><center>bits 5-0</center>
* </tr>
- * </table>
- * </blockquote>
- *
- * <br>
- * {@code char} values in the range {@code '\u005Cu0800'} to
- * {@code '\u005CuFFFF'} are represented by three bytes:
- *
- * <blockquote>
- * <table border="1" cellspacing="0" cellpadding="8" width="50%"
- * summary="Bit values and bytes">
+ * <tr>
+ * <th colspan="9"><span style="font-weight:normal">
+ * {@code char} values in the range {@code '\u005Cu0800'}
+ * to {@code '\u005CuFFFF'} are represented by three bytes:</span></th>
+ * </tr>
* <tr>
* <td></td>
- * <th id="bit_c">Bit Values</th>
+ * <th colspan="8"id="bit_c">Bit Values</th>
* </tr>
* <tr>
* <th id="byte1_c">Byte 1</th>
- * <td>
- * <table border="1" cellspacing="0" width="100%">
- * <tr>
- * <td width="12%"><center>1</center>
- * <td width="13%"><center>1</center>
- * <td width="12%"><center>1</center>
- * <td width="13%"><center>0</center>
- * <td colspan="4"><center>bits 15-12</center>
- * </tr>
- * </table>
- * </td>
+ * <td><center>1</center>
+ * <td><center>1</center>
+ * <td><center>1</center>
+ * <td><center>0</center>
+ * <td colspan="4"><center>bits 15-12</center>
* </tr>
* <tr>
* <th id="byte2_b">Byte 2</th>
- * <td>
- * <table border="1" cellspacing="0" width="100%">
- * <tr>
- * <td width="12%"><center>1</center>
- * <td width="13%"><center>0</center>
- * <td colspan="6"><center>bits 11-6</center>
- * </tr>
- * </table>
- * </td>
+ * <td><center>1</center>
+ * <td><center>0</center>
+ * <td colspan="6"><center>bits 11-6</center>
* </tr>
* <tr>
* <th id="byte3">Byte 3</th>
- * <td>
- * <table border="1" cellspacing="0" width="100%">
- * <tr>
- * <td width="12%"><center>1</center>
- * <td width="13%"><center>0</center>
- * <td colspan="6"><center>bits 5-0</center>
- * </tr>
- * </table>
- * </td>
+ * <td><center>1</center>
+ * <td><center>0</center>
+ * <td colspan="6"><center>bits 5-0</center>
* </tr>
* </table>
- * </blockquote>
- *
+ * </blockquote>
* <p>
* The differences between this format and the
* standard UTF-8 format are the following:
--- a/jdk/src/share/classes/java/io/File.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/io/File.java Thu Jul 25 20:30:58 2013 -0400
@@ -129,7 +129,7 @@
* created, the abstract pathname represented by a <code>File</code> object
* will never change.
*
- * <h4>Interoperability with {@code java.nio.file} package</h4>
+ * <h3>Interoperability with {@code java.nio.file} package</h3>
*
* <p> The <a href="../../java/nio/file/package-summary.html">{@code java.nio.file}</a>
* package defines interfaces and classes for the Java virtual machine to access
--- a/jdk/src/share/classes/java/io/ObjectInputStream.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/io/ObjectInputStream.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -313,6 +313,7 @@
* @throws SecurityException if a security manager exists and its
* <code>checkPermission</code> method denies enabling
* subclassing.
+ * @throws IOException if an I/O error occurs while creating this stream
* @see SecurityManager#checkPermission
* @see java.io.SerializablePermission
*/
--- a/jdk/src/share/classes/java/io/ObjectOutputStream.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/io/ObjectOutputStream.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -265,6 +265,7 @@
* @throws SecurityException if a security manager exists and its
* <code>checkPermission</code> method denies enabling
* subclassing.
+ * @throws IOException if an I/O error occurs while creating this stream
* @see SecurityManager#checkPermission
* @see java.io.SerializablePermission
*/
--- a/jdk/src/share/classes/java/io/ObjectStreamField.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/io/ObjectStreamField.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -240,6 +240,8 @@
* Returns boolean value indicating whether or not the serializable field
* represented by this ObjectStreamField instance is unshared.
*
+ * @return {@code true} if this field is unshared
+ *
* @since 1.4
*/
public boolean isUnshared() {
--- a/jdk/src/share/classes/java/io/RandomAccessFile.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/io/RandomAccessFile.java Thu Jul 25 20:30:58 2013 -0400
@@ -128,7 +128,7 @@
* meanings are:
*
* <table summary="Access mode permitted values and meanings">
- * <tr><th><p align="left">Value</p></th><th><p align="left">Meaning</p></th></tr>
+ * <tr><th align="left">Value</th><th align="left">Meaning</th></tr>
* <tr><td valign="top"><tt>"r"</tt></td>
* <td> Open for reading only. Invoking any of the <tt>write</tt>
* methods of the resulting object will cause an {@link
--- a/jdk/src/share/classes/java/lang/Class.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/lang/Class.java Thu Jul 25 20:30:58 2013 -0400
@@ -157,10 +157,10 @@
*
* The string is formatted as a list of type modifiers, if any,
* followed by the kind of type (empty string for primitive types
- * and {@code class}, {@code enum}, {@code interface}, or {@code
- * @interface}, as appropriate), followed by the type's name,
- * followed by an angle-bracketed comma-separated list of the
- * type's type parameters, if any.
+ * and {@code class}, {@code enum}, {@code interface}, or
+ * <code>@</code>{@code interface}, as appropriate), followed
+ * by the type's name, followed by an angle-bracketed
+ * comma-separated list of the type's type parameters, if any.
*
* A space is used to separate modifiers from one another and to
* separate any modifiers from the kind of type. The modifiers
--- a/jdk/src/share/classes/java/lang/invoke/LambdaConversionException.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/lang/invoke/LambdaConversionException.java Thu Jul 25 20:30:58 2013 -0400
@@ -29,6 +29,8 @@
* LambdaConversionException
*/
public class LambdaConversionException extends Exception {
+ private static final long serialVersionUID = 292L + 8L;
+
/**
* Constructs a {@code LambdaConversionException}.
*/
--- a/jdk/src/share/classes/java/lang/reflect/Parameter.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/lang/reflect/Parameter.java Thu Jul 25 20:30:58 2013 -0400
@@ -162,7 +162,7 @@
/**
* Returns the name of the parameter. If the parameter's name is
- * {@linkplain isNamePresent() present}, then this method returns
+ * {@linkplain #isNamePresent() present}, then this method returns
* the name provided by the class file. Otherwise, this method
* synthesizes a name of the form argN, where N is the index of
* the parameter in the descriptor of the method which declares
--- a/jdk/src/share/classes/java/net/URI.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/net/URI.java Thu Jul 25 20:30:58 2013 -0400
@@ -530,7 +530,7 @@
* href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>,
* Appendix A, <b><i>except for the following deviations:</i></b> </p>
*
- * <ul type=disc>
+ * <ul>
*
* <li><p> An empty authority component is permitted as long as it is
* followed by a non-empty path, a query component, or a fragment
@@ -993,7 +993,7 @@
* <li><p> Otherwise the new URI's authority component is copied from
* this URI, and its path is computed as follows: </p>
*
- * <ol type=a>
+ * <ol>
*
* <li><p> If the given URI's path is absolute then the new URI's path
* is taken from the given URI. </p></li>
@@ -1241,7 +1241,7 @@
* <p> The host component of a URI, if defined, will have one of the
* following forms: </p>
*
- * <ul type=disc>
+ * <ul>
*
* <li><p> A domain name consisting of one or more <i>labels</i>
* separated by period characters (<tt>'.'</tt>), optionally followed by
@@ -1495,7 +1495,7 @@
*
* <p> The ordering of URIs is defined as follows: </p>
*
- * <ul type=disc>
+ * <ul>
*
* <li><p> Two URIs with different schemes are ordered according the
* ordering of their schemes, without regard to case. </p></li>
@@ -1513,7 +1513,7 @@
* <li><p> Two hierarchical URIs with identical schemes are ordered
* according to the ordering of their authority components: </p>
*
- * <ul type=disc>
+ * <ul>
*
* <li><p> If both authority components are server-based then the URIs
* are ordered according to their user-information components; if these
--- a/jdk/src/share/classes/java/nio/channels/package-info.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/nio/channels/package-info.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2013, 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
@@ -31,7 +31,7 @@
* <a name="channels"></a>
*
* <blockquote><table cellspacing=1 cellpadding=0 summary="Lists channels and their descriptions">
- * <tr><th><p align="left">Channels</p></th><th><p align="left">Description</p></th></tr>
+ * <tr><th align="left">Channels</th><th align="left">Description</th></tr>
* <tr><td valign=top><tt><i>{@link java.nio.channels.Channel}</i></tt></td>
* <td>A nexus for I/O operations</td></tr>
* <tr><td valign=top><tt> <i>{@link java.nio.channels.ReadableByteChannel}</i></tt></td>
@@ -110,7 +110,7 @@
* write them to a given writable byte channel.
*
* <blockquote><table cellspacing=1 cellpadding=0 summary="Lists file channels and their descriptions">
- * <tr><th><p align="left">File channels</p></th><th><p align="left">Description</p></th></tr>
+ * <tr><th align="left">File channels</th><th align="left">Description</th></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.FileChannel}</tt></td>
* <td>Reads, writes, maps, and manipulates files</td></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.FileLock}</tt></td>
@@ -138,7 +138,7 @@
*
* <a name="multiplex"></a>
* <blockquote><table cellspacing=1 cellpadding=0 summary="Lists multiplexed, non-blocking channels and their descriptions">
- * <tr><th><p align="left">Multiplexed, non-blocking I/O</p></th><th><p align="left">Description</p></th></tr>
+ * <tr><th align="left">Multiplexed, non-blocking I/O</th><th align="left"><p>Description</th></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.SelectableChannel}</tt></td>
* <td>A channel that can be multiplexed</td></tr>
* <tr><td valign=top><tt> {@link java.nio.channels.DatagramChannel}</tt></td>
@@ -225,7 +225,7 @@
* <a name="async"></a>
*
* <blockquote><table cellspacing=1 cellpadding=0 summary="Lists asynchronous channels and their descriptions">
- * <tr><th><p align="left">Asynchronous I/O</p></th><th><p align="left">Description</p></th></tr>
+ * <tr><th align="left">Asynchronous I/O</th><th align="left">Description</th></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousFileChannel}</tt></td>
* <td>An asynchronous channel for reading, writing, and manipulating a file</td></tr>
* <tr><td valign=top><tt>{@link java.nio.channels.AsynchronousSocketChannel}</tt></td>
--- a/jdk/src/share/classes/java/nio/charset/Charset.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/nio/charset/Charset.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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
@@ -65,7 +65,7 @@
* concurrent threads.
*
*
- * <a name="names"><a name="charenc">
+ * <a name="names"></a><a name="charenc"></a>
* <h2>Charset names</h2>
*
* <p> Charsets are named by strings composed of the following characters:
@@ -111,21 +111,17 @@
* The aliases of a charset are returned by the {@link #aliases() aliases}
* method.
*
- * <a name="hn">
- *
- * <p> Some charsets have an <i>historical name</i> that is defined for
- * compatibility with previous versions of the Java platform. A charset's
+ * <p><a name="hn">Some charsets have an <i>historical name</i> that is defined for
+ * compatibility with previous versions of the Java platform.</a> A charset's
* historical name is either its canonical name or one of its aliases. The
* historical name is returned by the <tt>getEncoding()</tt> methods of the
* {@link java.io.InputStreamReader#getEncoding InputStreamReader} and {@link
* java.io.OutputStreamWriter#getEncoding OutputStreamWriter} classes.
*
- * <a name="iana">
- *
- * <p> If a charset listed in the <a
+ * <p><a name="iana">If a charset listed in the <a
* href="http://www.iana.org/assignments/character-sets"><i>IANA Charset
* Registry</i></a> is supported by an implementation of the Java platform then
- * its canonical name must be the name listed in the registry. Many charsets
+ * its canonical name must be the name listed in the registry.</a> Many charsets
* are given more than one name in the registry, in which case the registry
* identifies one of the names as <i>MIME-preferred</i>. If a charset has more
* than one registry name then its canonical name must be the MIME-preferred
@@ -142,15 +138,15 @@
*
* <h2>Standard charsets</h2>
*
- * <a name="standard">
+ *
*
- * <p> Every implementation of the Java platform is required to support the
- * following standard charsets. Consult the release documentation for your
+ * <p><a name="standard">Every implementation of the Java platform is required to support the
+ * following standard charsets.</a> Consult the release documentation for your
* implementation to see if any other charsets are supported. The behavior
* of such optional charsets may differ between implementations.
*
* <blockquote><table width="80%" summary="Description of standard charsets">
- * <tr><th><p align="left">Charset</p></th><th><p align="left">Description</p></th></tr>
+ * <tr><th align="left">Charset</th><th align="left">Description</th></tr>
* <tr><td valign=top><tt>US-ASCII</tt></td>
* <td>Seven-bit ASCII, a.k.a. <tt>ISO646-US</tt>,
* a.k.a. the Basic Latin block of the Unicode character set</td></tr>
--- a/jdk/src/share/classes/java/nio/charset/MalformedInputException.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/nio/charset/MalformedInputException.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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
@@ -42,14 +42,27 @@
private int inputLength;
+ /**
+ * Constructs an {@code MalformedInputException} with the given
+ * length.
+ * @param inputLength the length of the input
+ */
public MalformedInputException(int inputLength) {
this.inputLength = inputLength;
}
+ /**
+ * Returns the length of the input.
+ * @return the length of the input
+ */
public int getInputLength() {
return inputLength;
}
+ /**
+ * Returns the message.
+ * @return the message
+ */
public String getMessage() {
return "Input length = " + inputLength;
}
--- a/jdk/src/share/classes/java/nio/charset/UnmappableCharacterException.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/nio/charset/UnmappableCharacterException.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2013, 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
@@ -42,14 +42,27 @@
private int inputLength;
+ /**
+ * Constructs an {@code UnmappableCharacterException} with the
+ * given length.
+ * @param inputLength the length of the input
+ */
public UnmappableCharacterException(int inputLength) {
this.inputLength = inputLength;
}
+ /**
+ * Returns the length of the input.
+ * @return the length of the input
+ */
public int getInputLength() {
return inputLength;
}
+ /**
+ * Returns the message.
+ * @return the message
+ */
public String getMessage() {
return "Input length = " + inputLength;
}
--- a/jdk/src/share/classes/java/nio/file/attribute/package-info.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/nio/file/attribute/package-info.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2013, 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
@@ -27,7 +27,7 @@
* Interfaces and classes providing access to file and file system attributes.
*
* <blockquote><table cellspacing=1 cellpadding=0 summary="Attribute views">
- * <tr><th><p align="left">Attribute views</p></th><th><p align="left">Description</p></th></tr>
+ * <tr><th align="left">Attribute views</th><th align="left">Description</th></tr>
* <tr><td valign=top><tt><i>{@link java.nio.file.attribute.AttributeView}</i></tt></td>
* <td>Can read or update non-opaque values associated with objects in a file system</td></tr>
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.FileAttributeView}</i></tt></td>
@@ -38,7 +38,7 @@
* <td>Can read or update POSIX defined file attributes</td></tr>
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.DosFileAttributeView} </i></tt></td>
* <td>Can read or update FAT file attributes</td></tr>
- * <tr><td valign=top><tt>  <i>{@link java.nio.file.attribute.FileOwnerAttributeView} </i></tt></td>
+ * <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.FileOwnerAttributeView} </i></tt></td>
* <td>Can read or update the owner of a file</td></tr>
* <tr><td valign=top><tt> <i>{@link java.nio.file.attribute.AclFileAttributeView} </i></tt></td>
* <td>Can read or update Access Control Lists</td></tr>
@@ -86,14 +86,14 @@
*
* <ul>
*
- * <p><li> The {@link java.nio.file.attribute.UserPrincipal} and
+ * <li> The {@link java.nio.file.attribute.UserPrincipal} and
* {@link java.nio.file.attribute.GroupPrincipal} interfaces represent an
* identity or group identity. </li>
*
- * <p><li> The {@link java.nio.file.attribute.UserPrincipalLookupService}
+ * <li> The {@link java.nio.file.attribute.UserPrincipalLookupService}
* interface defines methods to lookup user or group principals. </li>
*
- * <p><li> The {@link java.nio.file.attribute.FileAttribute} interface
+ * <li> The {@link java.nio.file.attribute.FileAttribute} interface
* represents the value of an attribute for cases where the attribute value is
* required to be set atomically when creating an object in the file system. </li>
*
--- a/jdk/src/share/classes/java/nio/file/package-info.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/nio/file/package-info.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2013, 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
@@ -33,8 +33,8 @@
* package is used by service provider implementors wishing to extend the
* platform default provider, or to construct other provider implementations. </p>
*
- * <a name="links"><h3>Symbolic Links</h3></a>
- * Many operating systems and file systems support for <em>symbolic links</em>.
+ * <h3><a name="links">Symbolic Links</a></h3>
+ * <p> Many operating systems and file systems support for <em>symbolic links</em>.
* A symbolic link is a special file that serves as a reference to another file.
* For the most part, symbolic links are transparent to applications and
* operations on symbolic links are automatically redirected to the <em>target</em>
@@ -45,8 +45,8 @@
* that are semantically close but support for these other types of links is
* not included in this package. </p>
*
- * <a name="interop"><h3>Interoperability</h3></a>
- * The {@link java.io.File} class defines the {@link java.io.File#toPath
+ * <h3><a name="interop">Interoperability</a></h3>
+ * <p> The {@link java.io.File} class defines the {@link java.io.File#toPath
* toPath} method to construct a {@link java.nio.file.Path} by converting
* the abstract path represented by the {@code java.io.File} object. The resulting
* {@code Path} can be used to operate on the same file as the {@code File}
@@ -55,7 +55,7 @@
* and {@code java.io.File} objects. </p>
*
* <h3>Visibility</h3>
- * The view of the files and file system provided by classes in this package are
+ * <p> The view of the files and file system provided by classes in this package are
* guaranteed to be consistent with other views provided by other instances in the
* same Java virtual machine. The view may or may not, however, be consistent with
* the view of the file system as seen by other concurrently running programs due
@@ -65,8 +65,8 @@
* or on some other machine. The exact nature of any such inconsistencies are
* system-dependent and are therefore unspecified. </p>
*
- * <a name="integrity"><h3>Synchronized I/O File Integrity</h3></a>
- * The {@link java.nio.file.StandardOpenOption#SYNC SYNC} and {@link
+ * <h3><a name="integrity">Synchronized I/O File Integrity</a></h3>
+ * <p> The {@link java.nio.file.StandardOpenOption#SYNC SYNC} and {@link
* java.nio.file.StandardOpenOption#DSYNC DSYNC} options are used when opening a file
* to require that updates to the file are written synchronously to the underlying
* storage device. In the case of the default provider, and the file resides on
@@ -83,7 +83,7 @@
* specific. </p>
*
* <h3>General Exceptions</h3>
- * Unless otherwise noted, passing a {@code null} argument to a constructor
+ * <p> Unless otherwise noted, passing a {@code null} argument to a constructor
* or method of any class or interface in this package will cause a {@link
* java.lang.NullPointerException NullPointerException} to be thrown. Additionally,
* invoking a method with a collection containing a {@code null} element will
--- a/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/security/cert/PKIXRevocationChecker.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, 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
@@ -50,21 +50,26 @@
* status of certificates with OCSP and CRLs. By default, OCSP is the
* preferred mechanism for checking revocation status, with CRLs as the
* fallback mechanism. However, this preference can be switched to CRLs with
- * the {@link Option#PREFER_CRLS PREFER_CRLS} option.
+ * the {@link Option#PREFER_CRLS PREFER_CRLS} option. In addition, the fallback
+ * mechanism can be disabled with the {@link Option#NO_FALLBACK NO_FALLBACK}
+ * option.
*
* <p>A {@code PKIXRevocationChecker} is obtained by calling the
* {@link CertPathValidator#getRevocationChecker getRevocationChecker} method
* of a PKIX {@code CertPathValidator}. Additional parameters and options
- * specific to revocation can be set (by calling {@link #setOCSPResponder}
- * method for instance). The {@code PKIXRevocationChecker} is added to
- * a {@code PKIXParameters} object using the
- * {@link PKIXParameters#addCertPathChecker addCertPathChecker}
+ * specific to revocation can be set (by calling the
+ * {@link #setOcspResponder setOcspResponder} method for instance). The
+ * {@code PKIXRevocationChecker} is added to a {@code PKIXParameters} object
+ * using the {@link PKIXParameters#addCertPathChecker addCertPathChecker}
* or {@link PKIXParameters#setCertPathCheckers setCertPathCheckers} method,
* and then the {@code PKIXParameters} is passed along with the {@code CertPath}
* to be validated to the {@link CertPathValidator#validate validate} method
* of a PKIX {@code CertPathValidator}. When supplying a revocation checker in
* this manner, it will be used to check revocation irrespective of the setting
* of the {@link PKIXParameters#isRevocationEnabled RevocationEnabled} flag.
+ * Similarly, a {@code PKIXRevocationChecker} may be added to a
+ * {@code PKIXBuilderParameters} object for use with a PKIX
+ * {@code CertPathBuilder}.
*
* <p>Note that when a {@code PKIXRevocationChecker} is added to
* {@code PKIXParameters}, it clones the {@code PKIXRevocationChecker};
@@ -83,6 +88,13 @@
* need not synchronize.
*
* @since 1.8
+ *
+ * @see <a href="http://www.ietf.org/rfc/rfc2560.txt"><i>RFC 2560: X.509
+ * Internet Public Key Infrastructure Online Certificate Status Protocol -
+ * OCSP</i></a>, <br><a
+ * href="http://www.ietf.org/rfc/rfc5280.txt"><i>RFC 5280: Internet X.509
+ * Public Key Infrastructure Certificate and Certificate Revocation List (CRL)
+ * Profile</i></a>
*/
public abstract class PKIXRevocationChecker extends PKIXCertPathChecker {
private URI ocspResponder;
@@ -101,7 +113,7 @@
*
* @param uri the responder URI
*/
- public void setOCSPResponder(URI uri) {
+ public void setOcspResponder(URI uri) {
this.ocspResponder = uri;
}
@@ -114,7 +126,7 @@
*
* @return the responder URI, or {@code null} if not set
*/
- public URI getOCSPResponder() {
+ public URI getOcspResponder() {
return ocspResponder;
}
@@ -126,7 +138,7 @@
*
* @param cert the responder's certificate
*/
- public void setOCSPResponderCert(X509Certificate cert) {
+ public void setOcspResponderCert(X509Certificate cert) {
this.ocspResponderCert = cert;
}
@@ -140,7 +152,7 @@
*
* @return the responder's certificate, or {@code null} if not set
*/
- public X509Certificate getOCSPResponderCert() {
+ public X509Certificate getOcspResponderCert() {
return ocspResponderCert;
}
@@ -151,7 +163,7 @@
* @param extensions a list of extensions. The list is copied to protect
* against subsequent modification.
*/
- public void setOCSPExtensions(List<Extension> extensions)
+ public void setOcspExtensions(List<Extension> extensions)
{
this.ocspExtensions = (extensions == null)
? Collections.<Extension>emptyList()
@@ -161,10 +173,10 @@
/**
* Gets the optional OCSP request extensions.
*
- * @return an unmodifiable list of extensions. Returns an empty list if no
+ * @return an unmodifiable list of extensions. The list is empty if no
* extensions have been specified.
*/
- public List<Extension> getOCSPExtensions() {
+ public List<Extension> getOcspExtensions() {
return Collections.unmodifiableList(ocspExtensions);
}
@@ -177,7 +189,7 @@
* DER-encoded OCSP response for that certificate. A deep copy of
* the map is performed to protect against subsequent modification.
*/
- public void setOCSPResponses(Map<X509Certificate, byte[]> responses)
+ public void setOcspResponses(Map<X509Certificate, byte[]> responses)
{
if (responses == null) {
this.ocspResponses = Collections.<X509Certificate, byte[]>emptyMap();
@@ -200,7 +212,7 @@
* the map is returned to protect against subsequent modification.
* Returns an empty map if no responses have been specified.
*/
- public Map<X509Certificate, byte[]> getOCSPResponses() {
+ public Map<X509Certificate, byte[]> getOcspResponses() {
Map<X509Certificate, byte[]> copy = new HashMap<>(ocspResponses.size());
for (Map.Entry<X509Certificate, byte[]> e : ocspResponses.entrySet()) {
copy.put(e.getKey(), e.getValue().clone());
@@ -223,15 +235,31 @@
/**
* Gets the revocation options.
*
- * @return an unmodifiable set of revocation options, or an empty set if
- * none are specified
+ * @return an unmodifiable set of revocation options. The set is empty if
+ * no options have been specified.
*/
public Set<Option> getOptions() {
return Collections.unmodifiableSet(options);
}
+ /**
+ * Returns a list containing the exceptions that are ignored by the
+ * revocation checker when the {@link Option#SOFT_FAIL SOFT_FAIL} option
+ * is set. The list is cleared each time {@link #init init} is called.
+ * The list is ordered in ascending order according to the certificate
+ * index returned by {@link CertPathValidatorException#getIndex getIndex}
+ * method of each entry.
+ * <p>
+ * An implementation of {@code PKIXRevocationChecker} is responsible for
+ * adding the ignored exceptions to the list.
+ *
+ * @return an unmodifiable list containing the ignored exceptions. The list
+ * is empty if no exceptions have been ignored.
+ */
+ public abstract List<CertPathValidatorException> getSoftFailExceptions();
+
@Override
- public Object clone() {
+ public PKIXRevocationChecker clone() {
PKIXRevocationChecker copy = (PKIXRevocationChecker)super.clone();
copy.ocspExtensions = new ArrayList<>(ocspExtensions);
copy.ocspResponses = new HashMap<>(ocspResponses);
@@ -262,9 +290,26 @@
*/
PREFER_CRLS,
/**
- * Ignore network failures. The default behavior is to consider it a
- * failure if the revocation status of a certificate cannot be obtained
- * due to a network error. This option applies to both OCSP and CRLs.
+ * Disable the fallback mechanism.
+ */
+ NO_FALLBACK,
+ /**
+ * Allow revocation check to succeed if the revocation status cannot be
+ * determined for one of the following reasons:
+ * <p><ul>
+ * <li>The CRL or OCSP response cannot be obtained because of a
+ * network error.
+ * <li>The OCSP responder returns one of the following errors
+ * specified in section 2.3 of RFC 2560: internalError, tryLater,
+ * or unauthorized.
+ * </ul><br>
+ * Note that these conditions apply to both OCSP and CRLs, and unless
+ * the {@code NO_FALLBACK} option is set, the revocation check is
+ * allowed to succeed only if both mechanisms fail under one of the
+ * conditions as stated above.
+ * Exceptions that cause the network errors are ignored but can be
+ * later retrieved by calling the
+ * {@link #getSoftFailExceptions getSoftFailExceptions} method.
*/
SOFT_FAIL
}
--- a/jdk/src/share/classes/java/time/DayOfWeek.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/DayOfWeek.java Thu Jul 25 20:30:58 2013 -0400
@@ -61,7 +61,6 @@
*/
package java.time;
-import java.time.temporal.UnsupportedTemporalTypeException;
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
import static java.time.temporal.ChronoUnit.DAYS;
@@ -73,6 +72,7 @@
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
+import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import java.time.temporal.WeekFields;
import java.util.Locale;
@@ -339,7 +339,7 @@
if (field == DAY_OF_WEEK) {
return getValue();
} else if (field instanceof ChronoField) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
--- a/jdk/src/share/classes/java/time/Duration.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/Duration.java Thu Jul 25 20:30:58 2013 -0400
@@ -459,9 +459,9 @@
*/
public static Duration between(Temporal startInclusive, Temporal endExclusive) {
try {
- return ofNanos(startInclusive.periodUntil(endExclusive, NANOS));
+ return ofNanos(startInclusive.until(endExclusive, NANOS));
} catch (DateTimeException | ArithmeticException ex) {
- long secs = startInclusive.periodUntil(endExclusive, SECONDS);
+ long secs = startInclusive.until(endExclusive, SECONDS);
long nanos;
try {
nanos = endExclusive.getLong(NANO_OF_SECOND) - startInclusive.getLong(NANO_OF_SECOND);
@@ -523,7 +523,7 @@
} else if (unit == NANOS) {
return nanos;
} else {
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
}
--- a/jdk/src/share/classes/java/time/Instant.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/Instant.java Thu Jul 25 20:30:58 2013 -0400
@@ -69,6 +69,7 @@
import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
+import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.NANOS;
import java.io.DataInput;
@@ -418,8 +419,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this instant can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -448,6 +450,44 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isTimeBased() || unit == DAYS;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -511,7 +551,7 @@
case MILLI_OF_SECOND: return nanos / 1000_000;
case INSTANT_SECONDS: INSTANT_SECONDS.checkValidIntValue(seconds);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return range(field).checkValidIntValue(field.getFrom(this), field);
}
@@ -548,7 +588,7 @@
case MILLI_OF_SECOND: return nanos / 1000_000;
case INSTANT_SECONDS: return seconds;
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
@@ -665,7 +705,7 @@
case NANO_OF_SECOND: return (newValue != nanos ? create(seconds, (int) newValue) : this);
case INSTANT_SECONDS: return (newValue != seconds ? create(newValue, nanos) : this);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
@@ -807,7 +847,7 @@
case HALF_DAYS: return plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_DAY / 2));
case DAYS: return plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_DAY));
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.addTo(this, amountToAdd);
}
@@ -1053,14 +1093,14 @@
* complete units between the two instants.
* The {@code Temporal} passed to this method must be an {@code Instant}.
* For example, the amount in days between two dates can be calculated
- * using {@code startInstant.periodUntil(endInstant, SECONDS)}.
+ * using {@code startInstant.until(endInstant, SECONDS)}.
* <p>
* There are two equivalent ways of using this method.
* The first is to invoke this method.
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, SECONDS);
+ * amount = start.until(end, SECONDS);
* amount = SECONDS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -1085,7 +1125,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endInstant, TemporalUnit unit) {
+ public long until(Temporal endInstant, TemporalUnit unit) {
if (endInstant instanceof Instant == false) {
Objects.requireNonNull(endInstant, "endInstant");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
@@ -1103,7 +1143,7 @@
case HALF_DAYS: return secondsUntil(end) / (12 * SECONDS_PER_HOUR);
case DAYS: return secondsUntil(end) / (SECONDS_PER_DAY);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.between(this, endInstant);
}
--- a/jdk/src/share/classes/java/time/LocalDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/LocalDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -127,7 +127,7 @@
* @since 1.8
*/
public final class LocalDate
- implements Temporal, TemporalAdjuster, ChronoLocalDate<LocalDate>, Serializable {
+ implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable {
/**
* The minimum supported {@code LocalDate}, '-999999999-01-01'.
@@ -466,8 +466,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -502,6 +503,41 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ return ChronoLocalDate.super.isSupported(unit);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -538,7 +574,7 @@
}
return field.range();
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
@@ -631,7 +667,7 @@
case YEAR: return year;
case ERA: return (year >= 1 ? 1 : 0);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
private long getProlepticMonth() {
@@ -988,7 +1024,7 @@
case YEAR: return withYear((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
@@ -1187,7 +1223,7 @@
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.addTo(this, amountToAdd);
}
@@ -1497,7 +1533,7 @@
* The result will be negative if the end is before the start.
* The {@code Temporal} passed to this method must be a {@code LocalDate}.
* For example, the amount in days between two dates can be calculated
- * using {@code startDate.periodUntil(endDate, DAYS)}.
+ * using {@code startDate.until(endDate, DAYS)}.
* <p>
* The calculation returns a whole number, representing the number of
* complete units between the two dates.
@@ -1509,7 +1545,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MONTHS);
+ * amount = start.until(end, MONTHS);
* amount = MONTHS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -1534,7 +1570,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endDate, TemporalUnit unit) {
+ public long until(Temporal endDate, TemporalUnit unit) {
Objects.requireNonNull(unit, "unit");
if (endDate instanceof LocalDate == false) {
Objects.requireNonNull(endDate, "endDate");
@@ -1552,7 +1588,7 @@
case MILLENNIA: return monthsUntil(end) / 12000;
case ERAS: return end.getLong(ERA) - getLong(ERA);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.between(this, endDate);
}
@@ -1591,7 +1627,7 @@
* The second is to use {@link Period#between(LocalDate, LocalDate)}:
* <pre>
* // these two lines are equivalent
- * period = start.periodUntil(end);
+ * period = start.until(end);
* period = Period.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -1600,7 +1636,7 @@
* @return the period between this date and the end date, not null
*/
@Override
- public Period periodUntil(ChronoLocalDate<?> endDate) {
+ public Period until(ChronoLocalDate endDate) {
LocalDate end = LocalDate.from(endDate);
long totalMonths = end.getProlepticMonth() - this.getProlepticMonth(); // safe
int days = end.day - this.day;
@@ -1803,7 +1839,7 @@
* @return the comparator value, negative if less, positive if greater
*/
@Override // override for Javadoc and performance
- public int compareTo(ChronoLocalDate<?> other) {
+ public int compareTo(ChronoLocalDate other) {
if (other instanceof LocalDate) {
return compareTo0((LocalDate) other);
}
@@ -1843,7 +1879,7 @@
* @return true if this date is after the specified date
*/
@Override // override for Javadoc and performance
- public boolean isAfter(ChronoLocalDate<?> other) {
+ public boolean isAfter(ChronoLocalDate other) {
if (other instanceof LocalDate) {
return compareTo0((LocalDate) other) > 0;
}
@@ -1872,7 +1908,7 @@
* @return true if this date is before the specified date
*/
@Override // override for Javadoc and performance
- public boolean isBefore(ChronoLocalDate<?> other) {
+ public boolean isBefore(ChronoLocalDate other) {
if (other instanceof LocalDate) {
return compareTo0((LocalDate) other) < 0;
}
@@ -1901,7 +1937,7 @@
* @return true if this date is equal to the specified date
*/
@Override // override for Javadoc and performance
- public boolean isEqual(ChronoLocalDate<?> other) {
+ public boolean isEqual(ChronoLocalDate other) {
if (other instanceof LocalDate) {
return compareTo0((LocalDate) other) == 0;
}
--- a/jdk/src/share/classes/java/time/LocalDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/LocalDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -515,8 +515,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date-time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -570,6 +571,48 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ return ChronoLocalDateTime.super.isSupported(unit);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -1570,7 +1613,7 @@
* The result will be negative if the end is before the start.
* The {@code Temporal} passed to this method must be a {@code LocalDateTime}.
* For example, the amount in days between two date-times can be calculated
- * using {@code startDateTime.periodUntil(endDateTime, DAYS)}.
+ * using {@code startDateTime.until(endDateTime, DAYS)}.
* <p>
* The calculation returns a whole number, representing the number of
* complete units between the two date-times.
@@ -1582,7 +1625,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MONTHS);
+ * amount = start.until(end, MONTHS);
* amount = MONTHS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -1609,18 +1652,17 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
+ public long until(Temporal endDateTime, TemporalUnit unit) {
if (endDateTime instanceof LocalDateTime == false) {
Objects.requireNonNull(endDateTime, "endDateTime");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
}
LocalDateTime end = (LocalDateTime) endDateTime;
if (unit instanceof ChronoUnit) {
- ChronoUnit f = (ChronoUnit) unit;
- if (f.isTimeUnit()) {
+ if (unit.isTimeBased()) {
long amount = date.daysUntil(end.date);
if (amount == 0) {
- return time.periodUntil(end.time, unit);
+ return time.until(end.time, unit);
}
long timePart = end.time.toNanoOfDay() - time.toNanoOfDay();
if (amount > 0) {
@@ -1630,7 +1672,7 @@
amount++; // safe
timePart -= NANOS_PER_DAY; // safe
}
- switch (f) {
+ switch ((ChronoUnit) unit) {
case NANOS:
amount = Math.multiplyExact(amount, NANOS_PER_DAY);
break;
@@ -1667,7 +1709,7 @@
} else if (endDate.isBefore(date) && end.time.isAfter(time)) {
endDate = endDate.plusDays(1);
}
- return date.periodUntil(endDate, unit);
+ return date.until(endDate, unit);
}
return unit.between(this, endDateTime);
}
--- a/jdk/src/share/classes/java/time/LocalTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/LocalTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -470,8 +470,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -511,6 +512,43 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isTimeBased();
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -628,7 +666,7 @@
case CLOCK_HOUR_OF_DAY: return (hour == 0 ? 24 : hour);
case AMPM_OF_DAY: return hour / 12;
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
//-----------------------------------------------------------------------
@@ -803,7 +841,7 @@
case CLOCK_HOUR_OF_DAY: return withHour((int) (newValue == 24 ? 0 : newValue));
case AMPM_OF_DAY: return plusHours((newValue - (hour / 12)) * 12);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
@@ -995,8 +1033,7 @@
@Override
public LocalTime plus(long amountToAdd, TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
- ChronoUnit f = (ChronoUnit) unit;
- switch (f) {
+ switch ((ChronoUnit) unit) {
case NANOS: return plusNanos(amountToAdd);
case MICROS: return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
case MILLIS: return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000_000);
@@ -1005,7 +1042,7 @@
case HOURS: return plusHours(amountToAdd);
case HALF_DAYS: return plusHours((amountToAdd % 2) * 12);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.addTo(this, amountToAdd);
}
@@ -1295,7 +1332,7 @@
* The result will be negative if the end is before the start.
* The {@code Temporal} passed to this method must be a {@code LocalTime}.
* For example, the amount in hours between two times can be calculated
- * using {@code startTime.periodUntil(endTime, HOURS)}.
+ * using {@code startTime.until(endTime, HOURS)}.
* <p>
* The calculation returns a whole number, representing the number of
* complete units between the two times.
@@ -1307,7 +1344,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MINUTES);
+ * amount = start.until(end, MINUTES);
* amount = MINUTES.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -1332,7 +1369,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endTime, TemporalUnit unit) {
+ public long until(Temporal endTime, TemporalUnit unit) {
if (endTime instanceof LocalTime == false) {
Objects.requireNonNull(endTime, "endTime");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
@@ -1349,7 +1386,7 @@
case HOURS: return nanosUntil / NANOS_PER_HOUR;
case HALF_DAYS: return nanosUntil / (12 * NANOS_PER_HOUR);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.between(this, endTime);
}
--- a/jdk/src/share/classes/java/time/Month.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/Month.java Thu Jul 25 20:30:58 2013 -0400
@@ -61,7 +61,6 @@
*/
package java.time;
-import java.time.temporal.UnsupportedTemporalTypeException;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoUnit.MONTHS;
@@ -75,6 +74,7 @@
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
+import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import java.util.Locale;
@@ -370,7 +370,7 @@
if (field == MONTH_OF_YEAR) {
return getValue();
} else if (field instanceof ChronoField) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
--- a/jdk/src/share/classes/java/time/MonthDay.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/MonthDay.java Thu Jul 25 20:30:58 2013 -0400
@@ -438,7 +438,7 @@
case DAY_OF_MONTH: return day;
case MONTH_OF_YEAR: return month;
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
--- a/jdk/src/share/classes/java/time/OffsetDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/OffsetDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -65,6 +65,7 @@
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.NANO_OF_DAY;
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
+import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
import java.io.IOException;
@@ -137,25 +138,40 @@
public static final OffsetDateTime MAX = LocalDateTime.MAX.atOffset(ZoneOffset.MIN);
/**
- * Comparator for two {@code OffsetDateTime} instances based solely on the instant.
+ * Gets a comparator that compares two {@code OffsetDateTime} instances
+ * based solely on the instant.
* <p>
* This method differs from the comparison in {@link #compareTo} in that it
* only compares the underlying instant.
*
+ * @return a comparator that compares in time-line order
+ *
* @see #isAfter
* @see #isBefore
* @see #isEqual
*/
- public static final Comparator<OffsetDateTime> INSTANT_COMPARATOR = new Comparator<OffsetDateTime>() {
- @Override
- public int compare(OffsetDateTime datetime1, OffsetDateTime datetime2) {
- int cmp = Long.compare(datetime1.toEpochSecond(), datetime2.toEpochSecond());
- if (cmp == 0) {
- cmp = Long.compare(datetime1.toLocalTime().toNanoOfDay(), datetime2.toLocalTime().toNanoOfDay());
- }
- return cmp;
+ public static Comparator<OffsetDateTime> timeLineOrder() {
+ return OffsetDateTime::compareInstant;
+ }
+
+ /**
+ * Compares this {@code OffsetDateTime} to another date-time.
+ * The comparison is based on the instant.
+ *
+ * @param datetime1 the first date-time to compare, not null
+ * @param datetime2 the other date-time to compare to, not null
+ * @return the comparator value, negative if less, positive if greater
+ */
+ private static int compareInstant(OffsetDateTime datetime1, OffsetDateTime datetime2) {
+ if (datetime1.getOffset().equals(datetime2.getOffset())) {
+ return datetime1.toLocalDateTime().compareTo(datetime2.toLocalDateTime());
}
- };
+ int cmp = Long.compare(datetime1.toEpochSecond(), datetime2.toEpochSecond());
+ if (cmp == 0) {
+ cmp = datetime1.toLocalTime().getNano() - datetime2.toLocalTime().getNano();
+ }
+ return cmp;
+ }
/**
* Serialization version.
@@ -406,8 +422,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date-time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -459,6 +476,51 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit != FOREVER;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -1528,7 +1590,7 @@
* The start and end points are {@code this} and the specified date-time.
* The result will be negative if the end is before the start.
* For example, the period in days between two date-times can be calculated
- * using {@code startDateTime.periodUntil(endDateTime, DAYS)}.
+ * using {@code startDateTime.until(endDateTime, DAYS)}.
* <p>
* The {@code Temporal} passed to this method must be an {@code OffsetDateTime}.
* If the offset differs between the two date-times, the specified
@@ -1544,7 +1606,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MONTHS);
+ * amount = start.until(end, MONTHS);
* amount = MONTHS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -1571,7 +1633,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
+ public long until(Temporal endDateTime, TemporalUnit unit) {
if (endDateTime instanceof OffsetDateTime == false) {
Objects.requireNonNull(endDateTime, "endDateTime");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
@@ -1579,7 +1641,7 @@
if (unit instanceof ChronoUnit) {
OffsetDateTime end = (OffsetDateTime) endDateTime;
end = end.withOffsetSameInstant(offset);
- return dateTime.periodUntil(end.dateTime, unit);
+ return dateTime.until(end.dateTime, unit);
}
return unit.between(this, endDateTime);
}
@@ -1724,15 +1786,9 @@
*/
@Override
public int compareTo(OffsetDateTime other) {
- if (getOffset().equals(other.getOffset())) {
- return toLocalDateTime().compareTo(other.toLocalDateTime());
- }
- int cmp = Long.compare(toEpochSecond(), other.toEpochSecond());
+ int cmp = compareInstant(this, other);
if (cmp == 0) {
- cmp = toLocalTime().getNano() - other.toLocalTime().getNano();
- if (cmp == 0) {
- cmp = toLocalDateTime().compareTo(other.toLocalDateTime());
- }
+ cmp = toLocalDateTime().compareTo(other.toLocalDateTime());
}
return cmp;
}
--- a/jdk/src/share/classes/java/time/OffsetTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/OffsetTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -348,8 +348,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -390,6 +391,43 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isTimeBased();
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -1084,7 +1122,7 @@
* The start and end points are {@code this} and the specified time.
* The result will be negative if the end is before the start.
* For example, the period in hours between two times can be calculated
- * using {@code startTime.periodUntil(endTime, HOURS)}.
+ * using {@code startTime.until(endTime, HOURS)}.
* <p>
* The {@code Temporal} passed to this method must be an {@code OffsetTime}.
* If the offset differs between the two times, then the specified
@@ -1100,7 +1138,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MINUTES);
+ * amount = start.until(end, MINUTES);
* amount = MINUTES.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -1125,7 +1163,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endTime, TemporalUnit unit) {
+ public long until(Temporal endTime, TemporalUnit unit) {
if (endTime instanceof OffsetTime == false) {
Objects.requireNonNull(endTime, "endTime");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
@@ -1142,7 +1180,7 @@
case HOURS: return nanosUntil / NANOS_PER_HOUR;
case HALF_DAYS: return nanosUntil / (12 * NANOS_PER_HOUR);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.between(this, endTime);
}
--- a/jdk/src/share/classes/java/time/Period.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/Period.java Thu Jul 25 20:30:58 2013 -0400
@@ -139,7 +139,7 @@
* The pattern for parsing.
*/
private final static Pattern PATTERN =
- Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)D)?", Pattern.CASE_INSENSITIVE);
+ Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)W)?(?:([-+]?[0-9]+)D)?", Pattern.CASE_INSENSITIVE);
/**
* The set of supported units.
*/
@@ -187,6 +187,20 @@
}
/**
+ * Obtains a {@code Period} representing a number of weeks.
+ * <p>
+ * The resulting period will be day-based, with the amount of days
+ * equal to the number of weeks multiplied by 7.
+ * The years and months units will be zero.
+ *
+ * @param weeks the number of weeks, positive or negative
+ * @return the period, with the input weeks converted to days, not null
+ */
+ public static Period ofWeeks(int weeks) {
+ return create(0, 0, Math.multiplyExact(weeks, 7));
+ }
+
+ /**
* Obtains a {@code Period} representing a number of days.
* <p>
* The resulting period will have the specified days.
@@ -257,22 +271,36 @@
* Obtains a {@code Period} from a text string such as {@code PnYnMnD}.
* <p>
* This will parse the string produced by {@code toString()} which is
- * based on the ISO-8601 period format {@code PnYnMnD}.
+ * based on the ISO-8601 period formats {@code PnYnMnD} and {@code PnW}.
* <p>
* The string starts with an optional sign, denoted by the ASCII negative
* or positive symbol. If negative, the whole period is negated.
* The ASCII letter "P" is next in upper or lower case.
- * There are then three sections, each consisting of a number and a suffix.
- * At least one of the three sections must be present.
- * The sections have suffixes in ASCII of "Y", "M" and "D" for
- * years, months and days, accepted in upper or lower case.
+ * There are then four sections, each consisting of a number and a suffix.
+ * At least one of the four sections must be present.
+ * The sections have suffixes in ASCII of "Y", "M", "W" and "D" for
+ * years, months, weeks and days, accepted in upper or lower case.
* The suffixes must occur in order.
* The number part of each section must consist of ASCII digits.
* The number may be prefixed by the ASCII negative or positive symbol.
* The number must parse to an {@code int}.
* <p>
* The leading plus/minus sign, and negative values for other units are
- * not part of the ISO-8601 standard.
+ * not part of the ISO-8601 standard. In addition, ISO-8601 does not
+ * permit mixing between the {@code PnYnMnD} and {@code PnW} formats.
+ * Any week-based input is multiplied by 7 and treated as a number of days.
+ * <p>
+ * For example, the following are valid inputs:
+ * <pre>
+ * "P2Y" -- Period.ofYears(2)
+ * "P3M" -- Period.ofMonths(3)
+ * "P4W" -- Period.ofWeeks(4)
+ * "P5D" -- Period.ofDays(5)
+ * "P1Y2M3D" -- Period.of(1, 2, 3)
+ * "P1Y2M3W4D" -- Period.of(1, 2, 25)
+ * "P-1Y2M" -- Period.of(-1, 2, 0)
+ * "-P1Y2M" -- Period.of(-1, -2, 0)
+ * </pre>
*
* @param text the text to parse, not null
* @return the parsed period, not null
@@ -285,14 +313,18 @@
int negate = ("-".equals(matcher.group(1)) ? -1 : 1);
String yearMatch = matcher.group(2);
String monthMatch = matcher.group(3);
- String dayMatch = matcher.group(4);
- if (yearMatch != null || monthMatch != null || dayMatch != null) {
+ String weekMatch = matcher.group(4);
+ String dayMatch = matcher.group(5);
+ if (yearMatch != null || monthMatch != null || dayMatch != null || weekMatch != null) {
try {
- return create(parseNumber(text, yearMatch, negate),
- parseNumber(text, monthMatch, negate),
- parseNumber(text, dayMatch, negate));
+ int years = parseNumber(text, yearMatch, negate);
+ int months = parseNumber(text, monthMatch, negate);
+ int weeks = parseNumber(text, weekMatch, negate);
+ int days = parseNumber(text, dayMatch, negate);
+ days = Math.addExact(days, Math.multiplyExact(weeks, 7));
+ return create(years, months, days);
} catch (NumberFormatException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Period", text, 0).initCause(ex);
+ throw new DateTimeParseException("Text cannot be parsed to a Period", text, 0, ex);
}
}
}
@@ -307,7 +339,7 @@
try {
return Math.multiplyExact(val, negate);
} catch (ArithmeticException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Period", text, 0).initCause(ex);
+ throw new DateTimeParseException("Text cannot be parsed to a Period", text, 0, ex);
}
}
@@ -329,10 +361,10 @@
* @param startDate the start date, inclusive, not null
* @param endDate the end date, exclusive, not null
* @return the period between this date and the end date, not null
- * @see ChronoLocalDate#periodUntil(ChronoLocalDate)
+ * @see ChronoLocalDate#until(ChronoLocalDate)
*/
public static Period between(LocalDate startDate, LocalDate endDate) {
- return startDate.periodUntil(endDate);
+ return startDate.until(endDate);
}
//-----------------------------------------------------------------------
@@ -386,7 +418,7 @@
} else if (unit == ChronoUnit.DAYS) {
return getDays();
} else {
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
}
--- a/jdk/src/share/classes/java/time/Year.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/Year.java Thu Jul 25 20:30:58 2013 -0400
@@ -64,6 +64,10 @@
import static java.time.temporal.ChronoField.ERA;
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
+import static java.time.temporal.ChronoUnit.CENTURIES;
+import static java.time.temporal.ChronoUnit.DECADES;
+import static java.time.temporal.ChronoUnit.ERAS;
+import static java.time.temporal.ChronoUnit.MILLENNIA;
import static java.time.temporal.ChronoUnit.YEARS;
import java.io.DataInput;
@@ -329,8 +333,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this year can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -358,6 +363,41 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA || unit == ERAS;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -450,7 +490,7 @@
case YEAR: return year;
case ERA: return (year < 1 ? 0 : 1);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
@@ -575,7 +615,7 @@
case YEAR: return Year.of((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
@@ -664,7 +704,7 @@
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.addTo(this, amountToAdd);
}
@@ -821,7 +861,7 @@
* The result will be negative if the end is before the start.
* The {@code Temporal} passed to this method must be a {@code Year}.
* For example, the period in decades between two year can be calculated
- * using {@code startYear.periodUntil(endYear, DECADES)}.
+ * using {@code startYear.until(endYear, DECADES)}.
* <p>
* The calculation returns a whole number, representing the number of
* complete units between the two years.
@@ -833,7 +873,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, YEARS);
+ * amount = start.until(end, YEARS);
* amount = YEARS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -858,7 +898,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endYear, TemporalUnit unit) {
+ public long until(Temporal endYear, TemporalUnit unit) {
if (endYear instanceof Year == false) {
Objects.requireNonNull(endYear, "endYear");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
@@ -873,7 +913,7 @@
case MILLENNIA: return yearsUntil / 1000;
case ERAS: return end.getLong(ERA) - getLong(ERA);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.between(this, endYear);
}
--- a/jdk/src/share/classes/java/time/YearMonth.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/YearMonth.java Thu Jul 25 20:30:58 2013 -0400
@@ -66,7 +66,12 @@
import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
+import static java.time.temporal.ChronoUnit.CENTURIES;
+import static java.time.temporal.ChronoUnit.DECADES;
+import static java.time.temporal.ChronoUnit.ERAS;
+import static java.time.temporal.ChronoUnit.MILLENNIA;
import static java.time.temporal.ChronoUnit.MONTHS;
+import static java.time.temporal.ChronoUnit.YEARS;
import java.io.DataInput;
import java.io.DataOutput;
@@ -313,8 +318,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this year-month can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -345,6 +351,42 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ public boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit == MONTHS || unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA || unit == ERAS;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -440,7 +482,7 @@
case YEAR: return year;
case ERA: return (year < 1 ? 0 : 1);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
@@ -639,7 +681,7 @@
case YEAR: return withYear((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
@@ -761,7 +803,7 @@
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.addTo(this, amountToAdd);
}
@@ -952,7 +994,7 @@
* The result will be negative if the end is before the start.
* The {@code Temporal} passed to this method must be a {@code YearMonth}.
* For example, the period in years between two year-months can be calculated
- * using {@code startYearMonth.periodUntil(endYearMonth, YEARS)}.
+ * using {@code startYearMonth.until(endYearMonth, YEARS)}.
* <p>
* The calculation returns a whole number, representing the number of
* complete units between the two year-months.
@@ -964,7 +1006,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MONTHS);
+ * amount = start.until(end, MONTHS);
* amount = MONTHS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -989,7 +1031,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endYearMonth, TemporalUnit unit) {
+ public long until(Temporal endYearMonth, TemporalUnit unit) {
if (endYearMonth instanceof YearMonth == false) {
Objects.requireNonNull(endYearMonth, "endYearMonth");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
@@ -1005,7 +1047,7 @@
case MILLENNIA: return monthsUntil / 12000;
case ERAS: return end.getLong(ERA) - getLong(ERA);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.between(this, endYearMonth);
}
--- a/jdk/src/share/classes/java/time/ZoneId.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/ZoneId.java Thu Jul 25 20:30:58 2013 -0400
@@ -401,6 +401,36 @@
}
/**
+ * Obtains an instance of {@code ZoneId} wrapping an offset.
+ * <p>
+ * If the prefix is "GMT", "UTC", or "UT" a {@code ZoneId}
+ * with the prefix and the non-zero offset is returned.
+ * If the prefix is empty {@code ""} the {@code ZoneOffset} is returned.
+ *
+ * @param prefix the time-zone ID, not null
+ * @param offset the offset, not null
+ * @return the zone ID, not null
+ * @throws IllegalArgumentException if the prefix is not one of
+ * "GMT", "UTC", or "UT", or ""
+ */
+ public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
+ Objects.requireNonNull(prefix, "prefix");
+ Objects.requireNonNull(offset, "offset");
+ if (prefix.length() == 0) {
+ return offset;
+ }
+
+ if (!prefix.equals("GMT") && !prefix.equals("UTC") && !prefix.equals("UT")) {
+ throw new IllegalArgumentException("prefix should be GMT, UTC or UT, is: " + prefix);
+ }
+
+ if (offset.getTotalSeconds() != 0) {
+ prefix = prefix.concat(offset.getId());
+ }
+ return new ZoneRegion(prefix, offset.getRules());
+ }
+
+ /**
* Parses the ID, taking a flag to indicate whether {@code ZoneRulesException}
* should be thrown or not, used in deserialization.
*
@@ -433,7 +463,7 @@
private static ZoneId ofWithPrefix(String zoneId, int prefixLength, boolean checkAvailable) {
String prefix = zoneId.substring(0, prefixLength);
if (zoneId.length() == prefixLength) {
- return ZoneRegion.ofPrefixedOffset(prefix, ZoneOffset.UTC);
+ return ofOffset(prefix, ZoneOffset.UTC);
}
if (zoneId.charAt(prefixLength) != '+' && zoneId.charAt(prefixLength) != '-') {
return ZoneRegion.ofId(zoneId, checkAvailable); // drop through to ZoneRulesProvider
@@ -441,9 +471,9 @@
try {
ZoneOffset offset = ZoneOffset.of(zoneId.substring(prefixLength));
if (offset == ZoneOffset.UTC) {
- return ZoneRegion.ofPrefixedOffset(prefix, offset);
+ return ofOffset(prefix, offset);
}
- return ZoneRegion.ofPrefixedOffset(prefix + offset.toString(), offset);
+ return ofOffset(prefix, offset);
} catch (DateTimeException ex) {
throw new DateTimeException("Invalid ID for offset-based ZoneId: " + zoneId, ex);
}
--- a/jdk/src/share/classes/java/time/ZoneOffset.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/ZoneOffset.java Thu Jul 25 20:30:58 2013 -0400
@@ -61,7 +61,6 @@
*/
package java.time;
-import java.time.temporal.UnsupportedTemporalTypeException;
import static java.time.LocalTime.MINUTES_PER_HOUR;
import static java.time.LocalTime.SECONDS_PER_HOUR;
import static java.time.LocalTime.SECONDS_PER_MINUTE;
@@ -79,6 +78,7 @@
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
+import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import java.time.zone.ZoneRules;
import java.util.Objects;
@@ -581,7 +581,7 @@
if (field == OFFSET_SECONDS) {
return totalSeconds;
} else if (field instanceof ChronoField) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return range(field).checkValidIntValue(getLong(field), field);
}
@@ -613,7 +613,7 @@
if (field == OFFSET_SECONDS) {
return totalSeconds;
} else if (field instanceof ChronoField) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
--- a/jdk/src/share/classes/java/time/ZoneRegion.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/ZoneRegion.java Thu Jul 25 20:30:58 2013 -0400
@@ -66,7 +66,6 @@
import java.time.zone.ZoneRulesException;
import java.time.zone.ZoneRulesProvider;
import java.util.Objects;
-import java.util.regex.Pattern;
/**
* A geographical region where the same time-zone rules apply.
@@ -153,19 +152,6 @@
}
}
- /**
- * Obtains an instance of {@code ZoneId} wrapping an offset.
- * <p>
- * For example, zone IDs like 'UTC', 'GMT', 'UT' and 'UTC+01:30' will be setup here.
- *
- * @param zoneId the time-zone ID, not null
- * @param offset the offset, not null
- * @return the zone ID, not null
- */
- static ZoneRegion ofPrefixedOffset(String zoneId, ZoneOffset offset) {
- return new ZoneRegion(zoneId, offset.getRules());
- }
-
//-------------------------------------------------------------------------
/**
* Constructor.
--- a/jdk/src/share/classes/java/time/ZonedDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/ZonedDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -642,8 +642,9 @@
* Checks if the specified field is supported.
* <p>
* This checks if this date-time can be queried for the specified field.
- * If false, then calling the {@link #range(TemporalField) range} and
- * {@link #get(TemporalField) get} methods will throw an exception.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The supported fields are:
@@ -695,6 +696,48 @@
}
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * If the unit is a {@link ChronoUnit} then the query is implemented here.
+ * The supported units are:
+ * <ul>
+ * <li>{@code NANOS}
+ * <li>{@code MICROS}
+ * <li>{@code MILLIS}
+ * <li>{@code SECONDS}
+ * <li>{@code MINUTES}
+ * <li>{@code HOURS}
+ * <li>{@code HALF_DAYS}
+ * <li>{@code DAYS}
+ * <li>{@code WEEKS}
+ * <li>{@code MONTHS}
+ * <li>{@code YEARS}
+ * <li>{@code DECADES}
+ * <li>{@code CENTURIES}
+ * <li>{@code MILLENNIA}
+ * <li>{@code ERAS}
+ * </ul>
+ * All other {@code ChronoUnit} instances will return false.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override // override for Javadoc
+ public boolean isSupported(TemporalUnit unit) {
+ return ChronoZonedDateTime.super.isSupported(unit);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Gets the range of valid values for the specified field.
* <p>
* The range object expresses the minimum and maximum valid values for a field.
@@ -1540,8 +1583,7 @@
@Override
public ZonedDateTime plus(long amountToAdd, TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
- ChronoUnit u = (ChronoUnit) unit;
- if (u.isDateUnit()) {
+ if (unit.isDateBased()) {
return resolveLocal(dateTime.plus(amountToAdd, unit));
} else {
return resolveInstant(dateTime.plus(amountToAdd, unit));
@@ -1990,7 +2032,7 @@
* The start and end points are {@code this} and the specified date-time.
* The result will be negative if the end is before the start.
* For example, the period in days between two date-times can be calculated
- * using {@code startDateTime.periodUntil(endDateTime, DAYS)}.
+ * using {@code startDateTime.until(endDateTime, DAYS)}.
* <p>
* The {@code Temporal} passed to this method must be a {@code ZonedDateTime}.
* If the time-zone differs between the two zoned date-times, the specified
@@ -2006,7 +2048,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MONTHS);
+ * amount = start.until(end, MONTHS);
* amount = MONTHS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -2047,7 +2089,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
- public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
+ public long until(Temporal endDateTime, TemporalUnit unit) {
if (endDateTime instanceof ZonedDateTime == false) {
Objects.requireNonNull(endDateTime, "endDateTime");
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
@@ -2055,11 +2097,10 @@
if (unit instanceof ChronoUnit) {
ZonedDateTime end = (ZonedDateTime) endDateTime;
end = end.withZoneSameInstant(zone);
- ChronoUnit u = (ChronoUnit) unit;
- if (u.isDateUnit()) {
- return dateTime.periodUntil(end.dateTime, unit);
+ if (unit.isDateBased()) {
+ return dateTime.until(end.dateTime, unit);
} else {
- return toOffsetDateTime().periodUntil(end.toOffsetDateTime(), unit);
+ return toOffsetDateTime().until(end.toOffsetDateTime(), unit);
}
}
return unit.between(this, endDateTime);
--- a/jdk/src/share/classes/java/time/chrono/ChronoDateImpl.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ChronoDateImpl.java Thu Jul 25 20:30:58 2013 -0400
@@ -67,6 +67,8 @@
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalAmount;
+import java.time.temporal.TemporalField;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
@@ -96,12 +98,12 @@
* // Enumerate the list of available calendars and print today for each
* Set<Chronology> chronos = Chronology.getAvailableChronologies();
* for (Chronology chrono : chronos) {
- * ChronoLocalDate<?> date = chrono.dateNow();
+ * ChronoLocalDate date = chrono.dateNow();
* System.out.printf(" %20s: %s%n", chrono.getID(), date.toString());
* }
*
* // Print the Hijrah date and calendar
- * ChronoLocalDate<?> date = Chronology.of("Hijrah").dateNow();
+ * ChronoLocalDate date = Chronology.of("Hijrah").dateNow();
* int day = date.get(ChronoField.DAY_OF_MONTH);
* int dow = date.get(ChronoField.DAY_OF_WEEK);
* int month = date.get(ChronoField.MONTH_OF_YEAR);
@@ -110,10 +112,10 @@
* dow, day, month, year);
* // Print today's date and the last day of the year
- * ChronoLocalDate<?> now1 = Chronology.of("Hijrah").dateNow();
- * ChronoLocalDate<?> first = now1.with(ChronoField.DAY_OF_MONTH, 1)
+ * ChronoLocalDate now1 = Chronology.of("Hijrah").dateNow();
+ * ChronoLocalDate first = now1.with(ChronoField.DAY_OF_MONTH, 1)
* .with(ChronoField.MONTH_OF_YEAR, 1);
- * ChronoLocalDate<?> last = first.plus(1, ChronoUnit.YEARS)
+ * ChronoLocalDate last = first.plus(1, ChronoUnit.YEARS)
* .minus(1, ChronoUnit.DAYS);
* System.out.printf(" Today is %s: start: %s; end: %s%n", last.getChronology().getID(),
* first, last);
@@ -138,8 +140,8 @@
* @param <D> the ChronoLocalDate of this date-time
* @since 1.8
*/
-abstract class ChronoDateImpl<D extends ChronoLocalDate<D>>
- implements ChronoLocalDate<D>, Temporal, TemporalAdjuster, Serializable {
+abstract class ChronoDateImpl<D extends ChronoLocalDate>
+ implements ChronoLocalDate, Temporal, TemporalAdjuster, Serializable {
/**
* Serialization version.
@@ -147,13 +149,52 @@
private static final long serialVersionUID = 6282433883239719096L;
/**
+ * Casts the {@code Temporal} to {@code ChronoLocalDate} ensuring it bas the specified chronology.
+ *
+ * @param chrono the chronology to check for, not null
+ * @param temporal a date-time to cast, not null
+ * @return the date-time checked and cast to {@code ChronoLocalDate}, not null
+ * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDate
+ * or the chronology is not equal this Chronology
+ */
+ static <D extends ChronoLocalDate> D ensureValid(Chronology chrono, Temporal temporal) {
+ @SuppressWarnings("unchecked")
+ D other = (D) temporal;
+ if (chrono.equals(other.getChronology()) == false) {
+ throw new ClassCastException("Chronology mismatch, expected: " + chrono.getId() + ", actual: " + other.getChronology().getId());
+ }
+ return other;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
* Creates an instance.
*/
ChronoDateImpl() {
}
+ @Override
+ @SuppressWarnings("unchecked")
+ public D with(TemporalAdjuster adjuster) {
+ return (D) ChronoLocalDate.super.with(adjuster);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public D with(TemporalField field, long value) {
+ return (D) ChronoLocalDate.super.with(field, value);
+ }
+
//-----------------------------------------------------------------------
@Override
+ @SuppressWarnings("unchecked")
+ public D plus(TemporalAmount amount) {
+ return (D) ChronoLocalDate.super.plus(amount);
+ }
+
+ //-----------------------------------------------------------------------
+ @Override
+ @SuppressWarnings("unchecked")
public D plus(long amountToAdd, TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
ChronoUnit f = (ChronoUnit) unit;
@@ -167,9 +208,21 @@
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
- return ChronoLocalDate.super.plus(amountToAdd, unit);
+ return (D) ChronoLocalDate.super.plus(amountToAdd, unit);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public D minus(TemporalAmount amount) {
+ return (D) ChronoLocalDate.super.minus(amount);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public D minus(long amountToSubtract, TemporalUnit unit) {
+ return (D) ChronoLocalDate.super.minus(amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -254,6 +307,7 @@
* @return a date based on this one with the years subtracted, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
+ @SuppressWarnings("unchecked")
D minusYears(long yearsToSubtract) {
return (yearsToSubtract == Long.MIN_VALUE ? ((ChronoDateImpl<D>)plusYears(Long.MAX_VALUE)).plusYears(1) : plusYears(-yearsToSubtract));
}
@@ -274,6 +328,7 @@
* @return a date based on this one with the months subtracted, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
+ @SuppressWarnings("unchecked")
D minusMonths(long monthsToSubtract) {
return (monthsToSubtract == Long.MIN_VALUE ? ((ChronoDateImpl<D>)plusMonths(Long.MAX_VALUE)).plusMonths(1) : plusMonths(-monthsToSubtract));
}
@@ -293,6 +348,7 @@
* @return a date based on this one with the weeks subtracted, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
+ @SuppressWarnings("unchecked")
D minusWeeks(long weeksToSubtract) {
return (weeksToSubtract == Long.MIN_VALUE ? ((ChronoDateImpl<D>)plusWeeks(Long.MAX_VALUE)).plusWeeks(1) : plusWeeks(-weeksToSubtract));
}
@@ -310,6 +366,7 @@
* @return a date based on this one with the days subtracted, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
+ @SuppressWarnings("unchecked")
D minusDays(long daysToSubtract) {
return (daysToSubtract == Long.MIN_VALUE ? ((ChronoDateImpl<D>)plusDays(Long.MAX_VALUE)).plusDays(1) : plusDays(-daysToSubtract));
}
@@ -321,13 +378,13 @@
* @throws ArithmeticException {@inheritDoc}
*/
@Override
- public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
+ public long until(Temporal endDateTime, TemporalUnit unit) {
Objects.requireNonNull(endDateTime, "endDateTime");
Objects.requireNonNull(unit, "unit");
if (endDateTime instanceof ChronoLocalDate == false) {
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
}
- ChronoLocalDate<?> end = (ChronoLocalDate<?>) endDateTime;
+ ChronoLocalDate end = (ChronoLocalDate) endDateTime;
if (getChronology().equals(end.getChronology()) == false) {
throw new DateTimeException("Unable to calculate amount as objects have different chronologies");
}
@@ -342,16 +399,16 @@
case MILLENNIA: return monthsUntil(end) / 12000;
case ERAS: return end.getLong(ERA) - getLong(ERA);
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.between(this, endDateTime);
}
- private long daysUntil(ChronoLocalDate<?> end) {
+ private long daysUntil(ChronoLocalDate end) {
return end.toEpochDay() - toEpochDay(); // no overflow
}
- private long monthsUntil(ChronoLocalDate<?> end) {
+ private long monthsUntil(ChronoLocalDate end) {
ValueRange range = getChronology().range(MONTH_OF_YEAR);
if (range.getMaximum() != 12) {
throw new IllegalStateException("ChronoDateImpl only supports Chronologies with 12 months per year");
@@ -367,7 +424,7 @@
return true;
}
if (obj instanceof ChronoLocalDate) {
- return compareTo((ChronoLocalDate<?>) obj) == 0;
+ return compareTo((ChronoLocalDate) obj) == 0;
}
return false;
}
--- a/jdk/src/share/classes/java/time/chrono/ChronoLocalDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ChronoLocalDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -242,11 +242,10 @@
* Additional calendar systems may be added to the system.
* See {@link Chronology} for more details.
*
- * @param <D> the concrete type for the date
* @since 1.8
*/
-public interface ChronoLocalDate<D extends ChronoLocalDate<D>>
- extends Temporal, TemporalAdjuster, Comparable<ChronoLocalDate<?>> {
+public interface ChronoLocalDate
+ extends Temporal, TemporalAdjuster, Comparable<ChronoLocalDate> {
/**
* Gets a comparator that compares {@code ChronoLocalDate} in
@@ -263,7 +262,7 @@
* @see #isBefore
* @see #isEqual
*/
- static Comparator<ChronoLocalDate<?>> timeLineOrder() {
+ static Comparator<ChronoLocalDate> timeLineOrder() {
return Chronology.DATE_ORDER;
}
@@ -289,9 +288,9 @@
* @throws DateTimeException if unable to convert to a {@code ChronoLocalDate}
* @see Chronology#date(TemporalAccessor)
*/
- static ChronoLocalDate<?> from(TemporalAccessor temporal) {
+ static ChronoLocalDate from(TemporalAccessor temporal) {
if (temporal instanceof ChronoLocalDate) {
- return (ChronoLocalDate<?>) temporal;
+ return (ChronoLocalDate) temporal;
}
Chronology chrono = temporal.query(TemporalQuery.chronology());
if (chrono == null) {
@@ -367,6 +366,25 @@
return (isLeapYear() ? 366 : 365);
}
+ /**
+ * Checks if the specified field is supported.
+ * <p>
+ * This checks if the specified field can be queried on this date.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
+ * <p>
+ * The set of supported fields is defined by the chronology and normally includes
+ * all {@code ChronoField} date fields.
+ * <p>
+ * If the field is not a {@code ChronoField}, then the result of this method
+ * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
+ * passing {@code this} as the argument.
+ * Whether the field is supported is determined by the field.
+ *
+ * @param field the field to check, null returns false
+ * @return true if the field can be queried, false if not
+ */
@Override
default boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
@@ -375,6 +393,32 @@
return field != null && field.isSupportedBy(this);
}
+ /**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to or subtracted from this date.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * The set of supported units is defined by the chronology and normally includes
+ * all {@code ChronoUnit} date units except {@code FOREVER}.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ default boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit.isDateBased();
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
//-----------------------------------------------------------------------
// override for covariant return type
/**
@@ -383,8 +427,8 @@
* @throws ArithmeticException {@inheritDoc}
*/
@Override
- default D with(TemporalAdjuster adjuster) {
- return (D) getChronology().ensureChronoLocalDate(Temporal.super.with(adjuster));
+ default ChronoLocalDate with(TemporalAdjuster adjuster) {
+ return ChronoDateImpl.ensureValid(getChronology(), Temporal.super.with(adjuster));
}
/**
@@ -394,11 +438,11 @@
* @throws ArithmeticException {@inheritDoc}
*/
@Override
- default D with(TemporalField field, long newValue) {
+ default ChronoLocalDate with(TemporalField field, long newValue) {
if (field instanceof ChronoField) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
- return (D) getChronology().ensureChronoLocalDate(field.adjustInto(this, newValue));
+ return ChronoDateImpl.ensureValid(getChronology(), field.adjustInto(this, newValue));
}
/**
@@ -407,8 +451,8 @@
* @throws ArithmeticException {@inheritDoc}
*/
@Override
- default D plus(TemporalAmount amount) {
- return (D) getChronology().ensureChronoLocalDate(Temporal.super.plus(amount));
+ default ChronoLocalDate plus(TemporalAmount amount) {
+ return ChronoDateImpl.ensureValid(getChronology(), Temporal.super.plus(amount));
}
/**
@@ -417,11 +461,11 @@
* @throws ArithmeticException {@inheritDoc}
*/
@Override
- default D plus(long amountToAdd, TemporalUnit unit) {
+ default ChronoLocalDate plus(long amountToAdd, TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
- return (D) getChronology().ensureChronoLocalDate(unit.addTo(this, amountToAdd));
+ return ChronoDateImpl.ensureValid(getChronology(), unit.addTo(this, amountToAdd));
}
/**
@@ -430,8 +474,8 @@
* @throws ArithmeticException {@inheritDoc}
*/
@Override
- default D minus(TemporalAmount amount) {
- return (D) getChronology().ensureChronoLocalDate(Temporal.super.minus(amount));
+ default ChronoLocalDate minus(TemporalAmount amount) {
+ return ChronoDateImpl.ensureValid(getChronology(), Temporal.super.minus(amount));
}
/**
@@ -441,8 +485,8 @@
* @throws ArithmeticException {@inheritDoc}
*/
@Override
- default D minus(long amountToSubtract, TemporalUnit unit) {
- return (D) getChronology().ensureChronoLocalDate(Temporal.super.minus(amountToSubtract, unit));
+ default ChronoLocalDate minus(long amountToSubtract, TemporalUnit unit) {
+ return ChronoDateImpl.ensureValid(getChronology(), Temporal.super.minus(amountToSubtract, unit));
}
//-----------------------------------------------------------------------
@@ -522,14 +566,14 @@
* The calculation returns a whole number, representing the number of
* complete units between the two dates.
* For example, the amount in days between two dates can be calculated
- * using {@code startDate.periodUntil(endDate, DAYS)}.
+ * using {@code startDate.until(endDate, DAYS)}.
* <p>
* There are two equivalent ways of using this method.
* The first is to invoke this method.
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * amount = start.periodUntil(end, MONTHS);
+ * amount = start.until(end, MONTHS);
* amount = MONTHS.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -555,7 +599,7 @@
* @throws ArithmeticException if numeric overflow occurs
*/
@Override // override for Javadoc
- long periodUntil(Temporal endDate, TemporalUnit unit);
+ long until(Temporal endDate, TemporalUnit unit);
/**
* Calculates the period between this date and another date as a {@code Period}.
@@ -575,7 +619,7 @@
* @throws DateTimeException if the period cannot be calculated
* @throws ArithmeticException if numeric overflow occurs
*/
- Period periodUntil(ChronoLocalDate<?> endDate);
+ Period until(ChronoLocalDate endDate);
/**
* Formats this date using the specified formatter.
@@ -606,8 +650,9 @@
* @param localTime the local time to use, not null
* @return the local date-time formed from this date and the specified time, not null
*/
- default ChronoLocalDateTime<D> atTime(LocalTime localTime) {
- return (ChronoLocalDateTime<D>)ChronoLocalDateTimeImpl.of(this, localTime);
+ @SuppressWarnings("unchecked")
+ default ChronoLocalDateTime<?> atTime(LocalTime localTime) {
+ return ChronoLocalDateTimeImpl.of(this, localTime);
}
//-----------------------------------------------------------------------
@@ -656,7 +701,7 @@
* @return the comparator value, negative if less, positive if greater
*/
@Override
- default int compareTo(ChronoLocalDate<?> other) {
+ default int compareTo(ChronoLocalDate other) {
int cmp = Long.compare(toEpochDay(), other.toEpochDay());
if (cmp == 0) {
cmp = getChronology().compareTo(other.getChronology());
@@ -678,7 +723,7 @@
* @param other the other date to compare to, not null
* @return true if this is after the specified date
*/
- default boolean isAfter(ChronoLocalDate<?> other) {
+ default boolean isAfter(ChronoLocalDate other) {
return this.toEpochDay() > other.toEpochDay();
}
@@ -696,7 +741,7 @@
* @param other the other date to compare to, not null
* @return true if this is before the specified date
*/
- default boolean isBefore(ChronoLocalDate<?> other) {
+ default boolean isBefore(ChronoLocalDate other) {
return this.toEpochDay() < other.toEpochDay();
}
@@ -714,7 +759,7 @@
* @param other the other date to compare to, not null
* @return true if the underlying date is equal to the specified date
*/
- default boolean isEqual(ChronoLocalDate<?> other) {
+ default boolean isEqual(ChronoLocalDate other) {
return this.toEpochDay() == other.toEpochDay();
}
--- a/jdk/src/share/classes/java/time/chrono/ChronoLocalDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ChronoLocalDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -63,6 +63,7 @@
import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.NANO_OF_DAY;
+import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
import java.time.DateTimeException;
@@ -73,6 +74,7 @@
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
+import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
@@ -114,7 +116,7 @@
* @param <D> the concrete type for the date of this date-time
* @since 1.8
*/
-public interface ChronoLocalDateTime<D extends ChronoLocalDate<D>>
+public interface ChronoLocalDateTime<D extends ChronoLocalDate>
extends Temporal, TemporalAdjuster, Comparable<ChronoLocalDateTime<?>> {
/**
@@ -191,9 +193,54 @@
*/
LocalTime toLocalTime();
- @Override // Override to provide javadoc
+ /**
+ * Checks if the specified field is supported.
+ * <p>
+ * This checks if the specified field can be queried on this date-time.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
+ * <p>
+ * The set of supported fields is defined by the chronology and normally includes
+ * all {@code ChronoField} date and time fields.
+ * <p>
+ * If the field is not a {@code ChronoField}, then the result of this method
+ * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
+ * passing {@code this} as the argument.
+ * Whether the field is supported is determined by the field.
+ *
+ * @param field the field to check, null returns false
+ * @return true if the field can be queried, false if not
+ */
+ @Override
boolean isSupported(TemporalField field);
+ /**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to or subtracted from this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * The set of supported units is defined by the chronology and normally includes
+ * all {@code ChronoUnit} units except {@code FOREVER}.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ default boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit != FOREVER;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
//-----------------------------------------------------------------------
// override for covariant return type
/**
@@ -203,7 +250,7 @@
*/
@Override
default ChronoLocalDateTime<D> with(TemporalAdjuster adjuster) {
- return (ChronoLocalDateTime<D>)(toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.with(adjuster)));
+ return ChronoLocalDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.with(adjuster));
}
/**
@@ -221,7 +268,7 @@
*/
@Override
default ChronoLocalDateTime<D> plus(TemporalAmount amount) {
- return (ChronoLocalDateTime<D>)(toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.plus(amount)));
+ return ChronoLocalDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.plus(amount));
}
/**
@@ -239,7 +286,7 @@
*/
@Override
default ChronoLocalDateTime<D> minus(TemporalAmount amount) {
- return (ChronoLocalDateTime<D>)(toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.minus(amount)));
+ return ChronoLocalDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.minus(amount));
}
/**
@@ -249,7 +296,7 @@
*/
@Override
default ChronoLocalDateTime<D> minus(long amountToSubtract, TemporalUnit unit) {
- return (ChronoLocalDateTime<D>)(toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.minus(amountToSubtract, unit)));
+ return ChronoLocalDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.minus(amountToSubtract, unit));
}
//-----------------------------------------------------------------------
--- a/jdk/src/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ChronoLocalDateTimeImpl.java Thu Jul 25 20:30:58 2013 -0400
@@ -98,7 +98,7 @@
* @param <D> the concrete type for the date of this date-time
* @since 1.8
*/
-final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate<D>>
+final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>
implements ChronoLocalDateTime<D>, Temporal, TemporalAdjuster, Serializable {
/**
@@ -171,9 +171,27 @@
* @param time the local time, not null
* @return the local date-time, not null
*/
- @SuppressWarnings("rawtypes")
- static ChronoLocalDateTimeImpl<?> of(ChronoLocalDate<?> date, LocalTime time) {
- return new ChronoLocalDateTimeImpl(date, time);
+ static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl<R> of(R date, LocalTime time) {
+ return new ChronoLocalDateTimeImpl<>(date, time);
+ }
+
+ /**
+ * Casts the {@code Temporal} to {@code ChronoLocalDateTime} ensuring it bas the specified chronology.
+ *
+ * @param chrono the chronology to check for, not null
+ * @param temporal a date-time to cast, not null
+ * @return the date-time checked and cast to {@code ChronoLocalDateTime}, not null
+ * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDateTimeImpl
+ * or the chronology is not equal this Chronology
+ */
+ static <R extends ChronoLocalDate> ChronoLocalDateTimeImpl<R> ensureValid(Chronology chrono, Temporal temporal) {
+ @SuppressWarnings("unchecked")
+ ChronoLocalDateTimeImpl<R> other = (ChronoLocalDateTimeImpl<R>) temporal;
+ if (chrono.equals(other.toLocalDate().getChronology()) == false) {
+ throw new ClassCastException("Chronology mismatch, required: " + chrono.getId()
+ + ", actual: " + other.toLocalDate().getChronology().getId());
+ }
+ return other;
}
/**
@@ -202,7 +220,7 @@
return this;
}
// Validate that the new Temporal is a ChronoLocalDate (and not something else)
- D cd = (D) date.getChronology().ensureChronoLocalDate(newDate);
+ D cd = ChronoDateImpl.ensureValid(date.getChronology(), newDate);
return new ChronoLocalDateTimeImpl<>(cd, newTime);
}
@@ -260,13 +278,13 @@
public ChronoLocalDateTimeImpl<D> with(TemporalAdjuster adjuster) {
if (adjuster instanceof ChronoLocalDate) {
// The Chronology is checked in with(date,time)
- return with((ChronoLocalDate<D>) adjuster, time);
+ return with((ChronoLocalDate) adjuster, time);
} else if (adjuster instanceof LocalTime) {
return with(date, (LocalTime) adjuster);
} else if (adjuster instanceof ChronoLocalDateTimeImpl) {
- return (ChronoLocalDateTimeImpl<D>)(date.getChronology().ensureChronoLocalDateTime((ChronoLocalDateTimeImpl<?>) adjuster));
+ return ChronoLocalDateTimeImpl.ensureValid(date.getChronology(), (ChronoLocalDateTimeImpl<?>) adjuster);
}
- return (ChronoLocalDateTimeImpl<D>)(date.getChronology().ensureChronoLocalDateTime((ChronoLocalDateTimeImpl<?>) adjuster.adjustInto(this)));
+ return ChronoLocalDateTimeImpl.ensureValid(date.getChronology(), (ChronoLocalDateTimeImpl<?>) adjuster.adjustInto(this));
}
@Override
@@ -279,7 +297,7 @@
return with(date.with(field, newValue), time);
}
}
- return (ChronoLocalDateTimeImpl<D>)(date.getChronology().ensureChronoLocalDateTime(field.adjustInto(this, newValue)));
+ return ChronoLocalDateTimeImpl.ensureValid(date.getChronology(), field.adjustInto(this, newValue));
}
//-----------------------------------------------------------------------
@@ -298,7 +316,7 @@
}
return with(date.plus(amountToAdd, unit), time);
}
- return (ChronoLocalDateTimeImpl<D>)(date.getChronology().ensureChronoLocalDateTime(unit.addTo(this, amountToAdd)));
+ return ChronoLocalDateTimeImpl.ensureValid(date.getChronology(), unit.addTo(this, amountToAdd));
}
private ChronoLocalDateTimeImpl<D> plusDays(long days) {
@@ -322,7 +340,7 @@
}
//-----------------------------------------------------------------------
- private ChronoLocalDateTimeImpl<D> plusWithOverflow(ChronoLocalDate<?> newDate, long hours, long minutes, long seconds, long nanos) {
+ private ChronoLocalDateTimeImpl<D> plusWithOverflow(D newDate, long hours, long minutes, long seconds, long nanos) {
// 9223372036854775808 long, 2147483648 int
if ((hours | minutes | seconds | nanos) == 0) {
return with(newDate, time);
@@ -351,7 +369,7 @@
//-----------------------------------------------------------------------
@Override
- public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
+ public long until(Temporal endDateTime, TemporalUnit unit) {
if (endDateTime instanceof ChronoLocalDateTime == false) {
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
}
@@ -361,10 +379,9 @@
throw new DateTimeException("Unable to calculate amount as objects have different chronologies");
}
if (unit instanceof ChronoUnit) {
- ChronoUnit f = (ChronoUnit) unit;
- if (f.isTimeUnit()) {
+ if (unit.isTimeBased()) {
long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY);
- switch (f) {
+ switch ((ChronoUnit) unit) {
case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break;
case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break;
case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break;
@@ -373,13 +390,13 @@
case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break;
case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break;
}
- return Math.addExact(amount, time.periodUntil(end.toLocalTime(), unit));
+ return Math.addExact(amount, time.until(end.toLocalTime(), unit));
}
- D endDate = end.toLocalDate();
+ ChronoLocalDate endDate = end.toLocalDate();
if (end.toLocalTime().isBefore(time)) {
endDate = endDate.minus(1, ChronoUnit.DAYS);
}
- return date.periodUntil(endDate, unit);
+ return date.until(endDate, unit);
}
return unit.between(this, endDateTime);
}
@@ -404,7 +421,7 @@
}
static ChronoLocalDateTime<?> readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- ChronoLocalDate<?> date = (ChronoLocalDate<?>) in.readObject();
+ ChronoLocalDate date = (ChronoLocalDate) in.readObject();
LocalTime time = (LocalTime) in.readObject();
return date.atTime(time);
}
--- a/jdk/src/share/classes/java/time/chrono/ChronoZonedDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ChronoZonedDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -63,6 +63,7 @@
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
+import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
import java.time.DateTimeException;
@@ -73,6 +74,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
+import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
@@ -115,7 +117,7 @@
* @param <D> the concrete type for the date of this date-time
* @since 1.8
*/
-public interface ChronoZonedDateTime<D extends ChronoLocalDate<D>>
+public interface ChronoZonedDateTime<D extends ChronoLocalDate>
extends Temporal, Comparable<ChronoZonedDateTime<?>> {
/**
@@ -338,9 +340,54 @@
*/
ChronoZonedDateTime<D> withZoneSameInstant(ZoneId zone);
- @Override // Override to provide javadoc
+ /**
+ * Checks if the specified field is supported.
+ * <p>
+ * This checks if the specified field can be queried on this date-time.
+ * If false, then calling the {@link #range(TemporalField) range},
+ * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)}
+ * methods will throw an exception.
+ * <p>
+ * The set of supported fields is defined by the chronology and normally includes
+ * all {@code ChronoField} fields.
+ * <p>
+ * If the field is not a {@code ChronoField}, then the result of this method
+ * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
+ * passing {@code this} as the argument.
+ * Whether the field is supported is determined by the field.
+ *
+ * @param field the field to check, null returns false
+ * @return true if the field can be queried, false if not
+ */
+ @Override
boolean isSupported(TemporalField field);
+ /**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to or subtracted from this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ * <p>
+ * The set of supported units is defined by the chronology and normally includes
+ * all {@code ChronoUnit} units except {@code FOREVER}.
+ * <p>
+ * If the unit is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * Whether the unit is supported is determined by the unit.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ @Override
+ default boolean isSupported(TemporalUnit unit) {
+ if (unit instanceof ChronoUnit) {
+ return unit != FOREVER;
+ }
+ return unit != null && unit.isSupportedBy(this);
+ }
+
//-----------------------------------------------------------------------
// override for covariant return type
/**
@@ -350,7 +397,7 @@
*/
@Override
default ChronoZonedDateTime<D> with(TemporalAdjuster adjuster) {
- return (ChronoZonedDateTime<D>)(toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.with(adjuster)));
+ return ChronoZonedDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.with(adjuster));
}
/**
@@ -368,7 +415,7 @@
*/
@Override
default ChronoZonedDateTime<D> plus(TemporalAmount amount) {
- return (ChronoZonedDateTime<D>)(toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.plus(amount)));
+ return ChronoZonedDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.plus(amount));
}
/**
@@ -386,7 +433,7 @@
*/
@Override
default ChronoZonedDateTime<D> minus(TemporalAmount amount) {
- return (ChronoZonedDateTime<D>)(toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.minus(amount)));
+ return ChronoZonedDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.minus(amount));
}
/**
@@ -396,7 +443,7 @@
*/
@Override
default ChronoZonedDateTime<D> minus(long amountToSubtract, TemporalUnit unit) {
- return (ChronoZonedDateTime<D>)(toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.minus(amountToSubtract, unit)));
+ return ChronoZonedDateTimeImpl.ensureValid(toLocalDate().getChronology(), Temporal.super.minus(amountToSubtract, unit));
}
//-----------------------------------------------------------------------
--- a/jdk/src/share/classes/java/time/chrono/ChronoZonedDateTimeImpl.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ChronoZonedDateTimeImpl.java Thu Jul 25 20:30:58 2013 -0400
@@ -101,7 +101,7 @@
* @param <D> the concrete type for the date of this date-time
* @since 1.8
*/
-final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate<D>>
+final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>
implements ChronoZonedDateTime<D>, Serializable {
/**
@@ -131,7 +131,7 @@
* @param preferredOffset the zone offset, null if no preference
* @return the zoned date-time, not null
*/
- static <R extends ChronoLocalDate<R>> ChronoZonedDateTime<R> ofBest(
+ static <R extends ChronoLocalDate> ChronoZonedDateTime<R> ofBest(
ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
Objects.requireNonNull(localDateTime, "localDateTime");
Objects.requireNonNull(zone, "zone");
@@ -167,14 +167,13 @@
* @param zone the zone identifier, not null
* @return the zoned date-time, not null
*/
- @SuppressWarnings("rawtypes")
static ChronoZonedDateTimeImpl<?> ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
- ChronoLocalDateTimeImpl<?> cldt = (ChronoLocalDateTimeImpl<?>) chrono.localDateTime(ldt);
- return new ChronoZonedDateTimeImpl(cldt, offset, zone);
+ ChronoLocalDateTimeImpl<?> cldt = (ChronoLocalDateTimeImpl<?>)chrono.localDateTime(ldt);
+ return new ChronoZonedDateTimeImpl<>(cldt, offset, zone);
}
/**
@@ -184,10 +183,30 @@
* @param zone the time-zone to use, validated not null
* @return the zoned date-time, validated not null
*/
+ @SuppressWarnings("unchecked")
private ChronoZonedDateTimeImpl<D> create(Instant instant, ZoneId zone) {
return (ChronoZonedDateTimeImpl<D>)ofInstant(toLocalDate().getChronology(), instant, zone);
}
+ /**
+ * Casts the {@code Temporal} to {@code ChronoZonedDateTimeImpl} ensuring it bas the specified chronology.
+ *
+ * @param chrono the chronology to check for, not null
+ * @param temporal a date-time to cast, not null
+ * @return the date-time checked and cast to {@code ChronoZonedDateTimeImpl}, not null
+ * @throws ClassCastException if the date-time cannot be cast to ChronoZonedDateTimeImpl
+ * or the chronology is not equal this Chronology
+ */
+ static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R> ensureValid(Chronology chrono, Temporal temporal) {
+ @SuppressWarnings("unchecked")
+ ChronoZonedDateTimeImpl<R> other = (ChronoZonedDateTimeImpl<R>) temporal;
+ if (chrono.equals(other.toLocalDate().getChronology()) == false) {
+ throw new ClassCastException("Chronology mismatch, required: " + chrono.getId()
+ + ", actual: " + other.toLocalDate().getChronology().getId());
+ }
+ return other;
+ }
+
//-----------------------------------------------------------------------
/**
* Constructor.
@@ -271,7 +290,7 @@
}
return ofBest(dateTime.with(field, newValue), zone, offset);
}
- return (ChronoZonedDateTime<D>)(toLocalDate().getChronology().ensureChronoZonedDateTime(field.adjustInto(this, newValue)));
+ return ChronoZonedDateTimeImpl.ensureValid(toLocalDate().getChronology(), field.adjustInto(this, newValue));
}
//-----------------------------------------------------------------------
@@ -280,12 +299,12 @@
if (unit instanceof ChronoUnit) {
return with(dateTime.plus(amountToAdd, unit));
}
- return (ChronoZonedDateTime<D>)(toLocalDate().getChronology().ensureChronoZonedDateTime(unit.addTo(this, amountToAdd))); /// TODO: Generics replacement Risk!
+ return ChronoZonedDateTimeImpl.ensureValid(toLocalDate().getChronology(), unit.addTo(this, amountToAdd)); /// TODO: Generics replacement Risk!
}
//-----------------------------------------------------------------------
@Override
- public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
+ public long until(Temporal endDateTime, TemporalUnit unit) {
if (endDateTime instanceof ChronoZonedDateTime == false) {
throw new DateTimeException("Unable to calculate amount as objects are of two different types");
}
@@ -296,7 +315,7 @@
}
if (unit instanceof ChronoUnit) {
end = end.withZoneSameInstant(offset);
- return dateTime.periodUntil(end.toLocalDateTime(), unit);
+ return dateTime.until(end.toLocalDateTime(), unit);
}
return unit.between(this, endDateTime);
}
--- a/jdk/src/share/classes/java/time/chrono/Chronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/Chronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -74,6 +74,9 @@
import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
+import static java.time.temporal.ChronoUnit.DAYS;
+import static java.time.temporal.ChronoUnit.MONTHS;
+import static java.time.temporal.ChronoUnit.WEEKS;
import static java.time.temporal.TemporalAdjuster.nextOrSame;
import java.io.DataInput;
@@ -88,14 +91,16 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
+import java.time.Month;
+import java.time.Year;
import java.time.ZoneId;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.ResolverStyle;
import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
-import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
import java.time.temporal.UnsupportedTemporalTypeException;
@@ -188,8 +193,8 @@
/**
* ChronoLocalDate order constant.
*/
- static final Comparator<ChronoLocalDate<?>> DATE_ORDER =
- (Comparator<ChronoLocalDate<?>> & Serializable) (date1, date2) -> {
+ static final Comparator<ChronoLocalDate> DATE_ORDER =
+ (Comparator<ChronoLocalDate> & Serializable) (date1, date2) -> {
return Long.compare(date1.toEpochDay(), date2.toEpochDay());
};
/**
@@ -482,60 +487,6 @@
//-----------------------------------------------------------------------
/**
- * Casts the {@code Temporal} to {@code ChronoLocalDate} with the same chronology.
- *
- * @param temporal a date-time to cast, not null
- * @return the date-time checked and cast to {@code ChronoLocalDate}, not null
- * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDate
- * or the chronology is not equal this Chronology
- */
- ChronoLocalDate<?> ensureChronoLocalDate(Temporal temporal) {
- @SuppressWarnings("unchecked")
- ChronoLocalDate<?> other = (ChronoLocalDate<?>) temporal;
- if (this.equals(other.getChronology()) == false) {
- throw new ClassCastException("Chronology mismatch, expected: " + getId() + ", actual: " + other.getChronology().getId());
- }
- return other;
- }
-
- /**
- * Casts the {@code Temporal} to {@code ChronoLocalDateTime} with the same chronology.
- *
- * @param temporal a date-time to cast, not null
- * @return the date-time checked and cast to {@code ChronoLocalDateTime}, not null
- * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDateTimeImpl
- * or the chronology is not equal this Chronology
- */
- ChronoLocalDateTimeImpl<?> ensureChronoLocalDateTime(Temporal temporal) {
- @SuppressWarnings("unchecked")
- ChronoLocalDateTimeImpl<?> other = (ChronoLocalDateTimeImpl<?>) temporal;
- if (this.equals(other.toLocalDate().getChronology()) == false) {
- throw new ClassCastException("Chronology mismatch, required: " + getId()
- + ", supplied: " + other.toLocalDate().getChronology().getId());
- }
- return other;
- }
-
- /**
- * Casts the {@code Temporal} to {@code ChronoZonedDateTimeImpl} with the same chronology.
- *
- * @param temporal a date-time to cast, not null
- * @return the date-time checked and cast to {@code ChronoZonedDateTimeImpl}, not null
- * @throws ClassCastException if the date-time cannot be cast to ChronoZonedDateTimeImpl
- * or the chronology is not equal this Chronology
- */
- ChronoZonedDateTimeImpl<?> ensureChronoZonedDateTime(Temporal temporal) {
- @SuppressWarnings("unchecked")
- ChronoZonedDateTimeImpl<?> other = (ChronoZonedDateTimeImpl<?>) temporal;
- if (this.equals(other.toLocalDate().getChronology()) == false) {
- throw new ClassCastException("Chronology mismatch, required: " + getId()
- + ", supplied: " + other.toLocalDate().getChronology().getId());
- }
- return other;
- }
-
- //-----------------------------------------------------------------------
- /**
* Gets the ID of the chronology.
* <p>
* The ID uniquely identifies the {@code Chronology}.
@@ -574,7 +525,7 @@
* @throws DateTimeException if unable to create the date
* @throws ClassCastException if the {@code era} is not of the correct type for the chronology
*/
- public ChronoLocalDate<?> date(Era era, int yearOfEra, int month, int dayOfMonth) {
+ public ChronoLocalDate date(Era era, int yearOfEra, int month, int dayOfMonth) {
return date(prolepticYear(era, yearOfEra), month, dayOfMonth);
}
@@ -588,7 +539,7 @@
* @return the local date in this chronology, not null
* @throws DateTimeException if unable to create the date
*/
- public abstract ChronoLocalDate<?> date(int prolepticYear, int month, int dayOfMonth);
+ public abstract ChronoLocalDate date(int prolepticYear, int month, int dayOfMonth);
/**
* Obtains a local date in this chronology from the era, year-of-era and
@@ -601,7 +552,7 @@
* @throws DateTimeException if unable to create the date
* @throws ClassCastException if the {@code era} is not of the correct type for the chronology
*/
- public ChronoLocalDate<?> dateYearDay(Era era, int yearOfEra, int dayOfYear) {
+ public ChronoLocalDate dateYearDay(Era era, int yearOfEra, int dayOfYear) {
return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear);
}
@@ -614,7 +565,7 @@
* @return the local date in this chronology, not null
* @throws DateTimeException if unable to create the date
*/
- public abstract ChronoLocalDate<?> dateYearDay(int prolepticYear, int dayOfYear);
+ public abstract ChronoLocalDate dateYearDay(int prolepticYear, int dayOfYear);
/**
* Obtains a local date in this chronology from the epoch-day.
@@ -626,7 +577,7 @@
* @return the local date in this chronology, not null
* @throws DateTimeException if unable to create the date
*/
- public abstract ChronoLocalDate<?> dateEpochDay(long epochDay);
+ public abstract ChronoLocalDate dateEpochDay(long epochDay);
//-----------------------------------------------------------------------
/**
@@ -643,7 +594,7 @@
* @return the current local date using the system clock and default time-zone, not null
* @throws DateTimeException if unable to create the date
*/
- public ChronoLocalDate<?> dateNow() {
+ public ChronoLocalDate dateNow() {
return dateNow(Clock.systemDefaultZone());
}
@@ -660,7 +611,7 @@
* @return the current local date using the system clock, not null
* @throws DateTimeException if unable to create the date
*/
- public ChronoLocalDate<?> dateNow(ZoneId zone) {
+ public ChronoLocalDate dateNow(ZoneId zone) {
return dateNow(Clock.system(zone));
}
@@ -675,7 +626,7 @@
* @return the current local date, not null
* @throws DateTimeException if unable to create the date
*/
- public ChronoLocalDate<?> dateNow(Clock clock) {
+ public ChronoLocalDate dateNow(Clock clock) {
Objects.requireNonNull(clock, "clock");
return date(LocalDate.now(clock));
}
@@ -699,7 +650,7 @@
* @throws DateTimeException if unable to create the date
* @see ChronoLocalDate#from(TemporalAccessor)
*/
- public abstract ChronoLocalDate<?> date(TemporalAccessor temporal);
+ public abstract ChronoLocalDate date(TemporalAccessor temporal);
/**
* Obtains a local date-time in this chronology from another temporal object.
@@ -722,7 +673,7 @@
* @throws DateTimeException if unable to create the date-time
* @see ChronoLocalDateTime#from(TemporalAccessor)
*/
- public ChronoLocalDateTime<?> localDateTime(TemporalAccessor temporal) {
+ public ChronoLocalDateTime<? extends ChronoLocalDate> localDateTime(TemporalAccessor temporal) {
try {
return date(temporal).atTime(LocalTime.from(temporal));
} catch (DateTimeException ex) {
@@ -754,7 +705,7 @@
* @throws DateTimeException if unable to create the date-time
* @see ChronoZonedDateTime#from(TemporalAccessor)
*/
- public ChronoZonedDateTime<?> zonedDateTime(TemporalAccessor temporal) {
+ public ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(TemporalAccessor temporal) {
try {
ZoneId zone = ZoneId.from(temporal);
try {
@@ -762,8 +713,7 @@
return zonedDateTime(instant, zone);
} catch (DateTimeException ex1) {
- @SuppressWarnings("rawtypes")
- ChronoLocalDateTimeImpl cldt = ensureChronoLocalDateTime(localDateTime(temporal));
+ ChronoLocalDateTimeImpl<?> cldt = ChronoLocalDateTimeImpl.ensureValid(this, localDateTime(temporal));
return ChronoZonedDateTimeImpl.ofBest(cldt, zone, null);
}
} catch (DateTimeException ex) {
@@ -781,7 +731,7 @@
* @return the zoned date-time, not null
* @throws DateTimeException if the result exceeds the supported range
*/
- public ChronoZonedDateTime<?> zonedDateTime(Instant instant, ZoneId zone) {
+ public ChronoZonedDateTime<? extends ChronoLocalDate> zonedDateTime(Instant instant, ZoneId zone) {
return ChronoZonedDateTimeImpl.ofInstant(this, instant, zone);
}
@@ -929,11 +879,82 @@
* As such, {@code ChronoField} date fields are resolved here in the
* context of a specific chronology.
* <p>
+ * {@code ChronoField} instances are resolved by this method, which may
+ * be overridden in subclasses.
+ * <ul>
+ * <li>{@code EPOCH_DAY} - If present, this is converted to a date and
+ * all other date fields are then cross-checked against the date.
+ * <li>{@code PROLEPTIC_MONTH} - If present, then it is split into the
+ * {@code YEAR} and {@code MONTH_OF_YEAR}. If the mode is strict or smart
+ * then the field is validated.
+ * <li>{@code YEAR_OF_ERA} and {@code ERA} - If both are present, then they
+ * are combined to form a {@code YEAR}. In lenient mode, the {@code YEAR_OF_ERA}
+ * range is not validated, in smart and strict mode it is. The {@code ERA} is
+ * validated for range in all three modes. If only the {@code YEAR_OF_ERA} is
+ * present, and the mode is smart or lenient, then the last available era
+ * is assumed. In strict mode, no era is assumed and the {@code YEAR_OF_ERA} is
+ * left untouched. If only the {@code ERA} is present, then it is left untouched.
+ * <li>{@code YEAR}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} -
+ * If all three are present, then they are combined to form a date.
+ * In all three modes, the {@code YEAR} is validated.
+ * If the mode is smart or strict, then the month and day are validated.
+ * If the mode is lenient, then the date is combined in a manner equivalent to
+ * creating a date on the first day of the first month in the requested year,
+ * then adding the difference in months, then the difference in days.
+ * If the mode is smart, and the day-of-month is greater than the maximum for
+ * the year-month, then the day-of-month is adjusted to the last day-of-month.
+ * If the mode is strict, then the three fields must form a valid date.
+ * <li>{@code YEAR} and {@code DAY_OF_YEAR} -
+ * If both are present, then they are combined to form a date.
+ * In all three modes, the {@code YEAR} is validated.
+ * If the mode is lenient, then the date is combined in a manner equivalent to
+ * creating a date on the first day of the requested year, then adding
+ * the difference in days.
+ * If the mode is smart or strict, then the two fields must form a valid date.
+ * <li>{@code YEAR}, {@code MONTH_OF_YEAR}, {@code ALIGNED_WEEK_OF_MONTH} and
+ * {@code ALIGNED_DAY_OF_WEEK_IN_MONTH} -
+ * If all four are present, then they are combined to form a date.
+ * In all three modes, the {@code YEAR} is validated.
+ * If the mode is lenient, then the date is combined in a manner equivalent to
+ * creating a date on the first day of the first month in the requested year, then adding
+ * the difference in months, then the difference in weeks, then in days.
+ * If the mode is smart or strict, then the all four fields are validated to
+ * their outer ranges. The date is then combined in a manner equivalent to
+ * creating a date on the first day of the requested year and month, then adding
+ * the amount in weeks and days to reach their values. If the mode is strict,
+ * the date is additionally validated to check that the day and week adjustment
+ * did not change the month.
+ * <li>{@code YEAR}, {@code MONTH_OF_YEAR}, {@code ALIGNED_WEEK_OF_MONTH} and
+ * {@code DAY_OF_WEEK} - If all four are present, then they are combined to
+ * form a date. The approach is the same as described above for
+ * years, months and weeks in {@code ALIGNED_DAY_OF_WEEK_IN_MONTH}.
+ * The day-of-week is adjusted as the next or same matching day-of-week once
+ * the years, months and weeks have been handled.
+ * <li>{@code YEAR}, {@code ALIGNED_WEEK_OF_YEAR} and {@code ALIGNED_DAY_OF_WEEK_IN_YEAR} -
+ * If all three are present, then they are combined to form a date.
+ * In all three modes, the {@code YEAR} is validated.
+ * If the mode is lenient, then the date is combined in a manner equivalent to
+ * creating a date on the first day of the requested year, then adding
+ * the difference in weeks, then in days.
+ * If the mode is smart or strict, then the all three fields are validated to
+ * their outer ranges. The date is then combined in a manner equivalent to
+ * creating a date on the first day of the requested year, then adding
+ * the amount in weeks and days to reach their values. If the mode is strict,
+ * the date is additionally validated to check that the day and week adjustment
+ * did not change the year.
+ * <li>{@code YEAR}, {@code ALIGNED_WEEK_OF_YEAR} and {@code DAY_OF_WEEK} -
+ * If all three are present, then they are combined to form a date.
+ * The approach is the same as described above for years and weeks in
+ * {@code ALIGNED_DAY_OF_WEEK_IN_YEAR}. The day-of-week is adjusted as the
+ * next or same matching day-of-week once the years and weeks have been handled.
+ * </ul>
+ * <p>
* The default implementation is suitable for most calendar systems.
* If {@link ChronoField#YEAR_OF_ERA} is found without an {@link ChronoField#ERA}
* then the last era in {@link #eras()} is used.
* The implementation assumes a 7 day week, that the first day-of-month
- * has the value 1, and that first day-of-year has the value 1.
+ * has the value 1, that first day-of-year has the value 1, and that the
+ * first of the month and year always exists.
*
* @param fieldValues the map of fields to values, which can be updated, not null
* @param resolverStyle the requested type of resolve, not null
@@ -941,99 +962,214 @@
* @throws DateTimeException if the date cannot be resolved, typically
* because of a conflict in the input data
*/
- public ChronoLocalDate<?> resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ public ChronoLocalDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
// check epoch-day before inventing era
if (fieldValues.containsKey(EPOCH_DAY)) {
return dateEpochDay(fieldValues.remove(EPOCH_DAY));
}
// fix proleptic month before inventing era
- Long pMonth = fieldValues.remove(PROLEPTIC_MONTH);
- if (pMonth != null) {
- // first day-of-month is likely to be safest for setting proleptic-month
- // cannot add to year zero, as not all chronologies have a year zero
- ChronoLocalDate<?> chronoDate = dateNow()
- .with(DAY_OF_MONTH, 1).with(PROLEPTIC_MONTH, pMonth);
- addFieldValue(fieldValues, MONTH_OF_YEAR, chronoDate.get(MONTH_OF_YEAR));
- addFieldValue(fieldValues, YEAR, chronoDate.get(YEAR));
- }
+ resolveProlepticMonth(fieldValues, resolverStyle);
// invent era if necessary to resolve year-of-era
- Long yoeLong = fieldValues.remove(YEAR_OF_ERA);
- if (yoeLong != null) {
- Long eraLong = fieldValues.remove(ERA);
- int yoe = range(YEAR_OF_ERA).checkValidIntValue(yoeLong, YEAR_OF_ERA);
- if (eraLong != null) {
- Era eraObj = eraOf(Math.toIntExact(eraLong));
- addFieldValue(fieldValues, YEAR, prolepticYear(eraObj, yoe));
- } else if (fieldValues.containsKey(YEAR)) {
- int year = range(YEAR).checkValidIntValue(fieldValues.get(YEAR), YEAR);
- ChronoLocalDate<?> chronoDate = dateYearDay(year, 1);
- addFieldValue(fieldValues, YEAR, prolepticYear(chronoDate.getEra(), yoe));
- } else {
- List<Era> eras = eras();
- if (eras.isEmpty()) {
- addFieldValue(fieldValues, YEAR, yoe);
- } else {
- Era eraObj = eras.get(eras.size() - 1);
- addFieldValue(fieldValues, YEAR, prolepticYear(eraObj, yoe));
- }
- }
+ ChronoLocalDate resolved = resolveYearOfEra(fieldValues, resolverStyle);
+ if (resolved != null) {
+ return resolved;
}
// build date
if (fieldValues.containsKey(YEAR)) {
if (fieldValues.containsKey(MONTH_OF_YEAR)) {
if (fieldValues.containsKey(DAY_OF_MONTH)) {
- int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
- int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
- int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
- return date(y, moy, dom);
+ return resolveYMD(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(ALIGNED_WEEK_OF_MONTH)) {
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
- int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
- int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
- int aw = range(ALIGNED_WEEK_OF_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), ALIGNED_WEEK_OF_MONTH);
- int ad = range(ALIGNED_DAY_OF_WEEK_IN_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), ALIGNED_DAY_OF_WEEK_IN_MONTH);
- ChronoLocalDate<?> chronoDate = date(y, moy, 1);
- return chronoDate.plus((aw - 1) * 7 + (ad - 1), ChronoUnit.DAYS);
+ return resolveYMAA(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(DAY_OF_WEEK)) {
- int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
- int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
- int aw = range(ALIGNED_WEEK_OF_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), ALIGNED_WEEK_OF_MONTH);
- int dow = range(DAY_OF_WEEK).checkValidIntValue(fieldValues.remove(DAY_OF_WEEK), DAY_OF_WEEK);
- ChronoLocalDate<?> chronoDate = date(y, moy, 1);
- return chronoDate.plus((aw - 1) * 7, ChronoUnit.DAYS).with(nextOrSame(DayOfWeek.of(dow)));
+ return resolveYMAD(fieldValues, resolverStyle);
}
}
}
if (fieldValues.containsKey(DAY_OF_YEAR)) {
- int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
- int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
- return dateYearDay(y, doy);
+ return resolveYD(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(ALIGNED_WEEK_OF_YEAR)) {
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
- int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
- int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR);
- int ad = range(ALIGNED_DAY_OF_WEEK_IN_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), ALIGNED_DAY_OF_WEEK_IN_YEAR);
- ChronoLocalDate<?> chronoDate = dateYearDay(y, 1);
- return chronoDate.plus((aw - 1) * 7 + (ad - 1), ChronoUnit.DAYS);
+ return resolveYAA(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(DAY_OF_WEEK)) {
- int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
- int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR);
- int dow = range(DAY_OF_WEEK).checkValidIntValue(fieldValues.remove(DAY_OF_WEEK), DAY_OF_WEEK);
- ChronoLocalDate<?> chronoDate = dateYearDay(y, 1);
- return chronoDate.plus((aw - 1) * 7, ChronoUnit.DAYS).with(nextOrSame(DayOfWeek.of(dow)));
+ return resolveYAD(fieldValues, resolverStyle);
}
}
}
return null;
}
+ void resolveProlepticMonth(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ Long pMonth = fieldValues.remove(PROLEPTIC_MONTH);
+ if (pMonth != null) {
+ if (resolverStyle != ResolverStyle.LENIENT) {
+ PROLEPTIC_MONTH.checkValidValue(pMonth);
+ }
+ // first day-of-month is likely to be safest for setting proleptic-month
+ // cannot add to year zero, as not all chronologies have a year zero
+ ChronoLocalDate chronoDate = dateNow()
+ .with(DAY_OF_MONTH, 1).with(PROLEPTIC_MONTH, pMonth);
+ addFieldValue(fieldValues, MONTH_OF_YEAR, chronoDate.get(MONTH_OF_YEAR));
+ addFieldValue(fieldValues, YEAR, chronoDate.get(YEAR));
+ }
+ }
+
+ ChronoLocalDate resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ Long yoeLong = fieldValues.remove(YEAR_OF_ERA);
+ if (yoeLong != null) {
+ Long eraLong = fieldValues.remove(ERA);
+ int yoe;
+ if (resolverStyle != ResolverStyle.LENIENT) {
+ yoe = range(YEAR_OF_ERA).checkValidIntValue(yoeLong, YEAR_OF_ERA);
+ } else {
+ yoe = Math.toIntExact(yoeLong);
+ }
+ if (eraLong != null) {
+ Era eraObj = eraOf(range(ERA).checkValidIntValue(eraLong, ERA));
+ addFieldValue(fieldValues, YEAR, prolepticYear(eraObj, yoe));
+ } else {
+ if (fieldValues.containsKey(YEAR)) {
+ int year = range(YEAR).checkValidIntValue(fieldValues.get(YEAR), YEAR);
+ ChronoLocalDate chronoDate = dateYearDay(year, 1);
+ addFieldValue(fieldValues, YEAR, prolepticYear(chronoDate.getEra(), yoe));
+ } else if (resolverStyle == ResolverStyle.STRICT) {
+ // do not invent era if strict
+ // reinstate the field removed earlier, no cross-check issues
+ fieldValues.put(YEAR_OF_ERA, yoeLong);
+ } else {
+ List<Era> eras = eras();
+ if (eras.isEmpty()) {
+ addFieldValue(fieldValues, YEAR, yoe);
+ } else {
+ Era eraObj = eras.get(eras.size() - 1);
+ addFieldValue(fieldValues, YEAR, prolepticYear(eraObj, yoe));
+ }
+ }
+ }
+ } else if (fieldValues.containsKey(ERA)) {
+ range(ERA).checkValidValue(fieldValues.get(ERA), ERA); // always validated
+ }
+ return null;
+ }
+
+ ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
+ long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
+ return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
+ }
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
+ ValueRange domRange = range(DAY_OF_MONTH);
+ int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
+ if (resolverStyle == ResolverStyle.SMART) { // previous valid
+ try {
+ return date(y, moy, dom);
+ } catch (DateTimeException ex) {
+ return date(y, moy, 1).with(TemporalAdjuster.lastDayOfMonth());
+ }
+ }
+ return date(y, moy, dom);
+ }
+
+ ChronoLocalDate resolveYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
+ return dateYearDay(y, 1).plus(days, DAYS);
+ }
+ int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
+ return dateYearDay(y, doy); // smart is same as strict
+ }
+
+ ChronoLocalDate resolveYMAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
+ long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
+ long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
+ return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
+ }
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
+ int aw = range(ALIGNED_WEEK_OF_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), ALIGNED_WEEK_OF_MONTH);
+ int ad = range(ALIGNED_DAY_OF_WEEK_IN_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), ALIGNED_DAY_OF_WEEK_IN_MONTH);
+ ChronoLocalDate date = date(y, moy, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
+ if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
+ throw new DateTimeException("Strict mode rejected resolved date as it is in a different month");
+ }
+ return date;
+ }
+
+ ChronoLocalDate resolveYMAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
+ long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
+ long dow = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
+ return resolveAligned(date(y, 1, 1), months, weeks, dow);
+ }
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
+ int aw = range(ALIGNED_WEEK_OF_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), ALIGNED_WEEK_OF_MONTH);
+ int dow = range(DAY_OF_WEEK).checkValidIntValue(fieldValues.remove(DAY_OF_WEEK), DAY_OF_WEEK);
+ ChronoLocalDate date = date(y, moy, 1).plus((aw - 1) * 7, DAYS).with(nextOrSame(DayOfWeek.of(dow)));
+ if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
+ throw new DateTimeException("Strict mode rejected resolved date as it is in a different month");
+ }
+ return date;
+ }
+
+ ChronoLocalDate resolveYAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
+ long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
+ return dateYearDay(y, 1).plus(weeks, WEEKS).plus(days, DAYS);
+ }
+ int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR);
+ int ad = range(ALIGNED_DAY_OF_WEEK_IN_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), ALIGNED_DAY_OF_WEEK_IN_YEAR);
+ ChronoLocalDate date = dateYearDay(y, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
+ if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
+ throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
+ }
+ return date;
+ }
+
+ ChronoLocalDate resolveYAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
+ long dow = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
+ return resolveAligned(dateYearDay(y, 1), 0, weeks, dow);
+ }
+ int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR);
+ int dow = range(DAY_OF_WEEK).checkValidIntValue(fieldValues.remove(DAY_OF_WEEK), DAY_OF_WEEK);
+ ChronoLocalDate date = dateYearDay(y, 1).plus((aw - 1) * 7, DAYS).with(nextOrSame(DayOfWeek.of(dow)));
+ if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
+ throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
+ }
+ return date;
+ }
+
+ ChronoLocalDate resolveAligned(ChronoLocalDate base, long months, long weeks, long dow) {
+ ChronoLocalDate date = base.plus(months, MONTHS).plus(weeks, WEEKS);
+ if (dow > 7) {
+ date = date.plus((dow - 1) / 7, WEEKS);
+ dow = ((dow - 1) % 7) + 1;
+ } else if (dow < 1) {
+ date = date.plus(Math.subtractExact(dow, 7) / 7, WEEKS);
+ dow = ((dow + 6) % 7) + 1;
+ }
+ return date.with(nextOrSame(DayOfWeek.of((int) dow)));
+ }
+
/**
* Adds a field-value pair to the map, checking for conflicts.
* <p>
--- a/jdk/src/share/classes/java/time/chrono/Era.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/Era.java Thu Jul 25 20:30:58 2013 -0400
@@ -238,7 +238,7 @@
if (field == ERA) {
return getValue();
} else if (field instanceof ChronoField) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
--- a/jdk/src/share/classes/java/time/chrono/HijrahChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/HijrahChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -71,8 +71,10 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
+import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
import java.util.Arrays;
import java.util.HashMap;
@@ -115,7 +117,7 @@
* <tr class="altColor">
* <td>Hijrah-umalqura</td>
* <td>islamic-umalqura</td>
- * <td>ca-islamic-cv-umalqura</td>
+ * <td>ca-islamic-umalqura</td>
* <td>Islamic - Umm Al-Qura calendar of Saudi Arabia</td>
* </tr>
* </tbody>
@@ -126,10 +128,10 @@
* <p>
* Selecting the chronology from the locale uses {@link Chronology#ofLocale}
* to find the Chronology based on Locale supported BCP 47 extension mechanism
- * to request a specific calendar ("ca") and variant ("cv"). For example,
+ * to request a specific calendar ("ca"). For example,
* </p>
* <pre>
- * Locale locale = Locale.forLanguageTag("en-US-u-ca-islamic-cv-umalqura");
+ * Locale locale = Locale.forLanguageTag("en-US-u-ca-islamic-umalqura");
* Chronology chrono = Chronology.ofLocale(locale);
* </pre>
*
@@ -472,11 +474,16 @@
* @param prolepticYear the proleptic-year
* @param dayOfYear the day-of-year
* @return the Hijrah local date, not null
- * @throws DateTimeException if unable to create the date
+ * @throws DateTimeException if the value of the year is out of range,
+ * or if the day-of-year is invalid for the year
*/
@Override
public HijrahDate dateYearDay(int prolepticYear, int dayOfYear) {
- return HijrahDate.of(this, prolepticYear, 1, 1).plusDays(dayOfYear - 1); // TODO better
+ HijrahDate date = HijrahDate.of(this, prolepticYear, 1, 1);
+ if (dayOfYear > date.lengthOfYear()) {
+ throw new DateTimeException("Invalid dayOfYear: " + dayOfYear);
+ }
+ return date.plusDays(dayOfYear - 1);
}
/**
@@ -515,16 +522,19 @@
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoLocalDateTime<HijrahDate> localDateTime(TemporalAccessor temporal) {
return (ChronoLocalDateTime<HijrahDate>) super.localDateTime(temporal);
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoZonedDateTime<HijrahDate> zonedDateTime(TemporalAccessor temporal) {
return (ChronoZonedDateTime<HijrahDate>) super.zonedDateTime(temporal);
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoZonedDateTime<HijrahDate> zonedDateTime(Instant instant, ZoneId zone) {
return (ChronoZonedDateTime<HijrahDate>) super.zonedDateTime(instant, zone);
}
@@ -550,7 +560,7 @@
}
@Override
- public Era eraOf(int eraValue) {
+ public HijrahEra eraOf(int eraValue) {
switch (eraValue) {
case 1:
return HijrahEra.AH;
@@ -580,6 +590,8 @@
case YEAR:
case YEAR_OF_ERA:
return ValueRange.of(getMinimumYear(), getMaximumYear());
+ case ERA:
+ return ValueRange.of(1, 1);
default:
return field.range();
}
@@ -587,6 +599,13 @@
return field.range();
}
+ //-----------------------------------------------------------------------
+ @Override // override for return type
+ public HijrahDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ return (HijrahDate) super.resolveDate(fieldValues, resolverStyle);
+ }
+
+ //-----------------------------------------------------------------------
/**
* Check the validity of a year.
*
--- a/jdk/src/share/classes/java/time/chrono/HijrahDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/HijrahDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -109,7 +109,7 @@
*/
public final class HijrahDate
extends ChronoDateImpl<HijrahDate>
- implements ChronoLocalDate<HijrahDate>, Serializable {
+ implements ChronoLocalDate, Serializable {
/**
* Serialization version.
@@ -204,7 +204,7 @@
* @throws DateTimeException if the current date cannot be obtained
*/
public static HijrahDate now(Clock clock) {
- return HijrahChronology.INSTANCE.date(LocalDate.now(clock));
+ return HijrahDate.ofEpochDay(HijrahChronology.INSTANCE, LocalDate.now(clock).toEpochDay());
}
/**
@@ -349,7 +349,7 @@
}
return getChronology().range(f);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
@@ -372,7 +372,7 @@
case YEAR: return prolepticYear;
case ERA: return getEraValue();
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
@@ -393,7 +393,7 @@
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
case DAY_OF_MONTH: return resolvePreviousValid(prolepticYear, monthOfYear, nvalue);
- case DAY_OF_YEAR: return resolvePreviousValid(prolepticYear, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
+ case DAY_OF_YEAR: return plusDays(Math.min(nvalue, lengthOfYear()) - getDayOfYear());
case EPOCH_DAY: return new HijrahDate(chrono, newValue);
case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
@@ -403,9 +403,9 @@
case YEAR: return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth);
case ERA: return resolvePreviousValid(1 - prolepticYear, monthOfYear, dayOfMonth);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
- return ChronoLocalDate.super.with(field, newValue);
+ return super.with(field, newValue);
}
private HijrahDate resolvePreviousValid(int prolepticYear, int month, int day) {
@@ -479,7 +479,7 @@
* @return the day-of-year
*/
private int getDayOfYear() {
- return chrono.getDayOfYear(prolepticYear, monthOfYear);
+ return chrono.getDayOfYear(prolepticYear, monthOfYear) + dayOfMonth;
}
/**
@@ -575,12 +575,13 @@
}
@Override // for javadoc and covariant return type
+ @SuppressWarnings("unchecked")
public final ChronoLocalDateTime<HijrahDate> atTime(LocalTime localTime) {
- return super.atTime(localTime);
+ return (ChronoLocalDateTime<HijrahDate>)super.atTime(localTime);
}
@Override
- public Period periodUntil(ChronoLocalDate<?> endDate) {
+ public Period until(ChronoLocalDate endDate) {
// TODO: untested
HijrahDate end = getChronology().date(endDate);
long totalMonths = (end.prolepticYear - this.prolepticYear) * 12 + (end.monthOfYear - this.monthOfYear); // safe
@@ -622,7 +623,7 @@
return this;
}
- static ChronoLocalDate<HijrahDate> readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ static HijrahDate readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
HijrahChronology chrono = (HijrahChronology) in.readObject();
int year = in.readInt();
int month = in.readByte();
--- a/jdk/src/share/classes/java/time/chrono/IsoChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/IsoChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -61,25 +61,16 @@
*/
package java.time.chrono;
-import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
-import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
-import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
-import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
-import static java.time.temporal.ChronoField.DAY_OF_WEEK;
-import static java.time.temporal.ChronoField.DAY_OF_YEAR;
-import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.ERA;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
-import static java.time.temporal.TemporalAdjuster.nextOrSame;
import java.io.Serializable;
import java.time.Clock;
import java.time.DateTimeException;
-import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -398,7 +389,7 @@
}
@Override
- public Era eraOf(int eraValue) {
+ public IsoEra eraOf(int eraValue) {
return IsoEra.of(eraValue);
}
@@ -421,7 +412,7 @@
* as follows.
* <ul>
* <li>{@code EPOCH_DAY} - If present, this is converted to a {@code LocalDate}
- * all other date fields are then cross-checked against the date
+ * and all other date fields are then cross-checked against the date.
* <li>{@code PROLEPTIC_MONTH} - If present, then it is split into the
* {@code YEAR} and {@code MONTH_OF_YEAR}. If the mode is strict or smart
* then the field is validated.
@@ -430,7 +421,7 @@
* range is not validated, in smart and strict mode it is. The {@code ERA} is
* validated for range in all three modes. If only the {@code YEAR_OF_ERA} is
* present, and the mode is smart or lenient, then the current era (CE/AD)
- * is assumed. In strict mode, no ers is assumed and the {@code YEAR_OF_ERA} is
+ * is assumed. In strict mode, no era is assumed and the {@code YEAR_OF_ERA} is
* left untouched. If only the {@code ERA} is present, then it is left untouched.
* <li>{@code YEAR}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} -
* If all three are present, then they are combined to form a {@code LocalDate}.
@@ -495,48 +486,11 @@
*/
@Override // override for performance
public LocalDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
- // check epoch-day before inventing era
- if (fieldValues.containsKey(EPOCH_DAY)) {
- return LocalDate.ofEpochDay(fieldValues.remove(EPOCH_DAY));
- }
-
- // fix proleptic month before inventing era
- resolveProlepticMonth(fieldValues, resolverStyle);
-
- // invent era if necessary to resolve year-of-era
- resolveYearOfEra(fieldValues, resolverStyle);
-
- // build date
- if (fieldValues.containsKey(YEAR)) {
- if (fieldValues.containsKey(MONTH_OF_YEAR)) {
- if (fieldValues.containsKey(DAY_OF_MONTH)) {
- return resolveYMD(fieldValues, resolverStyle);
- }
- if (fieldValues.containsKey(ALIGNED_WEEK_OF_MONTH)) {
- if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
- return resolveYMAA(fieldValues, resolverStyle);
- }
- if (fieldValues.containsKey(DAY_OF_WEEK)) {
- return resolveYMAD(fieldValues, resolverStyle);
- }
- }
- }
- if (fieldValues.containsKey(DAY_OF_YEAR)) {
- return resolveYD(fieldValues, resolverStyle);
- }
- if (fieldValues.containsKey(ALIGNED_WEEK_OF_YEAR)) {
- if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
- return resolveYAA(fieldValues, resolverStyle);
- }
- if (fieldValues.containsKey(DAY_OF_WEEK)) {
- return resolveYAD(fieldValues, resolverStyle);
- }
- }
- }
- return null;
+ return (LocalDate) super.resolveDate(fieldValues, resolverStyle);
}
- private void resolveProlepticMonth(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ @Override // override for better proleptic algorithm
+ void resolveProlepticMonth(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
Long pMonth = fieldValues.remove(PROLEPTIC_MONTH);
if (pMonth != null) {
if (resolverStyle != ResolverStyle.LENIENT) {
@@ -547,7 +501,8 @@
}
}
- private void resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ @Override // override for enhanced behaviour
+ LocalDate resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
Long yoeLong = fieldValues.remove(YEAR_OF_ERA);
if (yoeLong != null) {
if (resolverStyle != ResolverStyle.LENIENT) {
@@ -575,10 +530,14 @@
} else {
throw new DateTimeException("Invalid value for era: " + era);
}
+ } else if (fieldValues.containsKey(ERA)) {
+ ERA.checkValidValue(fieldValues.get(ERA)); // always validated
}
+ return null;
}
- private LocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ @Override // override for performance
+ LocalDate resolveYMD(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
if (resolverStyle == ResolverStyle.LENIENT) {
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
@@ -598,96 +557,6 @@
return LocalDate.of(y, moy, dom);
}
- private LocalDate resolveYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
- int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
- if (resolverStyle == ResolverStyle.LENIENT) {
- long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
- return LocalDate.of(y, 1, 1).plusDays(days);
- }
- int doy = DAY_OF_YEAR.checkValidIntValue(fieldValues.remove(DAY_OF_YEAR));
- return LocalDate.ofYearDay(y, doy); // smart is same as strict
- }
-
- private LocalDate resolveYMAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
- int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
- if (resolverStyle == ResolverStyle.LENIENT) {
- long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
- long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
- long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
- return LocalDate.of(y, 1, 1).plusMonths(months).plusWeeks(weeks).plusDays(days);
- }
- int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
- int aw = ALIGNED_WEEK_OF_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH));
- int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
- LocalDate date = LocalDate.of(y, moy, 1).plusDays((aw - 1) * 7 + (ad - 1));
- if (resolverStyle == ResolverStyle.STRICT && date.getMonthValue() != moy) {
- throw new DateTimeException("Strict mode rejected resolved date as it is in a different month");
- }
- return date;
- }
-
- private LocalDate resolveYMAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
- int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
- if (resolverStyle == ResolverStyle.LENIENT) {
- long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
- long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
- long dow = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
- return resolveAligned(y, months, weeks, dow);
- }
- int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
- int aw = ALIGNED_WEEK_OF_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH));
- int dow = DAY_OF_WEEK.checkValidIntValue(fieldValues.remove(DAY_OF_WEEK));
- LocalDate date = LocalDate.of(y, moy, 1).plusDays((aw - 1) * 7).with(nextOrSame(DayOfWeek.of(dow)));
- if (resolverStyle == ResolverStyle.STRICT && date.getMonthValue() != moy) {
- throw new DateTimeException("Strict mode rejected resolved date as it is in a different month");
- }
- return date;
- }
-
- private LocalDate resolveYAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
- int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
- if (resolverStyle == ResolverStyle.LENIENT) {
- long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
- long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
- return LocalDate.of(y, 1, 1).plusWeeks(weeks).plusDays(days);
- }
- int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
- int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
- LocalDate date = LocalDate.of(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
- if (resolverStyle == ResolverStyle.STRICT && date.getYear() != y) {
- throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
- }
- return date;
- }
-
- private LocalDate resolveYAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
- int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
- if (resolverStyle == ResolverStyle.LENIENT) {
- long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
- long dow = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
- return resolveAligned(y, 0, weeks, dow);
- }
- int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
- int dow = DAY_OF_WEEK.checkValidIntValue(fieldValues.remove(DAY_OF_WEEK));
- LocalDate date = LocalDate.of(y, 1, 1).plusDays((aw - 1) * 7).with(nextOrSame(DayOfWeek.of(dow)));
- if (resolverStyle == ResolverStyle.STRICT && date.getYear() != y) {
- throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
- }
- return date;
- }
-
- private LocalDate resolveAligned(int y, long months, long weeks, long dow) {
- LocalDate date = LocalDate.of(y, 1, 1).plusMonths(months).plusWeeks(weeks);
- if (dow > 7) {
- date = date.plusWeeks((dow - 1) / 7);
- dow = ((dow - 1) % 7) + 1;
- } else if (dow < 1) {
- date = date.plusWeeks(Math.subtractExact(dow, 7) / 7);
- dow = ((dow + 6) % 7) + 1;
- }
- return date.with(nextOrSame(DayOfWeek.of((int) dow)));
- }
-
//-----------------------------------------------------------------------
@Override
public ValueRange range(ChronoField field) {
--- a/jdk/src/share/classes/java/time/chrono/JapaneseChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/JapaneseChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -56,6 +56,15 @@
*/
package java.time.chrono;
+import static java.time.temporal.ChronoField.DAY_OF_MONTH;
+import static java.time.temporal.ChronoField.DAY_OF_YEAR;
+import static java.time.temporal.ChronoField.ERA;
+import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
+import static java.time.temporal.ChronoField.YEAR;
+import static java.time.temporal.ChronoField.YEAR_OF_ERA;
+import static java.time.temporal.ChronoUnit.DAYS;
+import static java.time.temporal.ChronoUnit.MONTHS;
+
import java.io.Serializable;
import java.time.Clock;
import java.time.DateTimeException;
@@ -63,13 +72,18 @@
import java.time.LocalDate;
import java.time.Year;
import java.time.ZoneId;
+import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalField;
+import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import sun.util.calendar.CalendarSystem;
import sun.util.calendar.LocalGregorianCalendar;
@@ -82,8 +96,22 @@
* The Japanese Imperial calendar system is the same as the ISO calendar system
* apart from the era-based year numbering.
* <p>
- * Only Meiji (1865-04-07 - 1868-09-07) and later eras are supported.
- * Older eras are handled as an unknown era where the year-of-era is the ISO year.
+ * Japan introduced the Gregorian calendar starting with Meiji 6.
+ * Only Meiji and later eras are supported;
+ * dates before Meiji 6, January 1 are not supported.
+ * <p>
+ * The supported {@code ChronoField} instances are:
+ * <ul>
+ * <li>{@code DAY_OF_WEEK}
+ * <li>{@code DAY_OF_MONTH}
+ * <li>{@code DAY_OF_YEAR}
+ * <li>{@code EPOCH_DAY}
+ * <li>{@code MONTH_OF_YEAR}
+ * <li>{@code PROLEPTIC_MONTH}
+ * <li>{@code YEAR_OF_ERA}
+ * <li>{@code YEAR}
+ * <li>{@code ERA}
+ * </ul>
*
* @implSpec
* This class is immutable and thread-safe.
@@ -91,7 +119,6 @@
* @since 1.8
*/
public final class JapaneseChronology extends Chronology implements Serializable {
- // TODO: definition for unknown era may break requirement that year-of-era >= 1
static final LocalGregorianCalendar JCAL =
(LocalGregorianCalendar) CalendarSystem.forName("japanese");
@@ -152,6 +179,16 @@
/**
* Obtains a local date in Japanese calendar system from the
* era, year-of-era, month-of-year and day-of-month fields.
+ * <p>
+ * The Japanese month and day-of-month are the same as those in the
+ * ISO calendar system. They are not reset when the era changes.
+ * For example:
+ * <pre>
+ * 6th Jan Showa 64 = ISO 1989-01-06
+ * 7th Jan Showa 64 = ISO 1989-01-07
+ * 8th Jan Heisei 1 = ISO 1989-01-08
+ * 9th Jan Heisei 1 = ISO 1989-01-09
+ * </pre>
*
* @param era the Japanese era, not null
* @param yearOfEra the year-of-era
@@ -172,6 +209,9 @@
/**
* Obtains a local date in Japanese calendar system from the
* proleptic-year, month-of-year and day-of-month fields.
+ * <p>
+ * The Japanese proleptic year, month and day-of-month are the same as those
+ * in the ISO calendar system. They are not reset when the era changes.
*
* @param prolepticYear the proleptic-year
* @param month the month-of-year
@@ -187,6 +227,17 @@
/**
* Obtains a local date in Japanese calendar system from the
* era, year-of-era and day-of-year fields.
+ * <p>
+ * The day-of-year in this factory is expressed relative to the start of the year-of-era.
+ * This definition changes the normal meaning of day-of-year only in those years
+ * where the year-of-era is reset to one due to a change in the era.
+ * For example:
+ * <pre>
+ * 6th Jan Showa 64 = day-of-year 6
+ * 7th Jan Showa 64 = day-of-year 7
+ * 8th Jan Heisei 1 = day-of-year 1
+ * 9th Jan Heisei 1 = day-of-year 2
+ * </pre>
*
* @param era the Japanese era, not null
* @param yearOfEra the year-of-era
@@ -203,6 +254,10 @@
/**
* Obtains a local date in Japanese calendar system from the
* proleptic-year and day-of-year fields.
+ * <p>
+ * The day-of-year in this factory is expressed relative to the start of the proleptic year.
+ * The Japanese proleptic year and day-of-year are the same as those in the ISO calendar system.
+ * They are not reset when the era changes.
*
* @param prolepticYear the proleptic-year
* @param dayOfYear the day-of-year
@@ -211,8 +266,7 @@
*/
@Override
public JapaneseDate dateYearDay(int prolepticYear, int dayOfYear) {
- LocalDate date = LocalDate.ofYearDay(prolepticYear, dayOfYear);
- return date(prolepticYear, date.getMonthValue(), date.getDayOfMonth());
+ return new JapaneseDate(LocalDate.ofYearDay(prolepticYear, dayOfYear));
}
/**
@@ -290,15 +344,6 @@
throw new ClassCastException("Era must be JapaneseEra");
}
- if (era == JapaneseEra.SEIREKI) {
- JapaneseEra nextEra = JapaneseEra.values()[1];
- int nextEraYear = nextEra.getPrivateEra().getSinceDate().getYear();
- if (yearOfEra >= nextEraYear || yearOfEra < Year.MIN_VALUE) {
- throw new DateTimeException("Invalid yearOfEra value");
- }
- return yearOfEra;
- }
-
JapaneseEra jera = (JapaneseEra) era;
int gregorianYear = jera.getPrivateEra().getSinceDate().getYear() + yearOfEra - 1;
if (yearOfEra == 1) {
@@ -320,14 +365,13 @@
* See the description of each Era for the numeric values of:
* {@link JapaneseEra#HEISEI}, {@link JapaneseEra#SHOWA},{@link JapaneseEra#TAISHO},
* {@link JapaneseEra#MEIJI}), only Meiji and later eras are supported.
- * Prior to Meiji {@link JapaneseEra#SEIREKI} is used.
*
* @param eraValue the era value
* @return the Japanese {@code Era} for the given numeric era value
* @throws DateTimeException if {@code eraValue} is invalid
*/
@Override
- public Era eraOf(int eraValue) {
+ public JapaneseEra eraOf(int eraValue) {
return JapaneseEra.of(eraValue);
}
@@ -346,49 +390,117 @@
@Override
public ValueRange range(ChronoField field) {
switch (field) {
- case YEAR:
- case DAY_OF_MONTH:
- case DAY_OF_WEEK:
- case MICRO_OF_DAY:
- case MICRO_OF_SECOND:
- case HOUR_OF_DAY:
- case HOUR_OF_AMPM:
- case MINUTE_OF_DAY:
- case MINUTE_OF_HOUR:
- case SECOND_OF_DAY:
- case SECOND_OF_MINUTE:
- case MILLI_OF_DAY:
- case MILLI_OF_SECOND:
- case NANO_OF_DAY:
- case NANO_OF_SECOND:
- case CLOCK_HOUR_OF_DAY:
- case CLOCK_HOUR_OF_AMPM:
- case EPOCH_DAY:
- case PROLEPTIC_MONTH:
- case MONTH_OF_YEAR:
- return field.range();
- case ERA:
- return ValueRange.of(JapaneseEra.SEIREKI.getValue(),
- getCurrentEra().getValue());
- }
- Calendar jcal = Calendar.getInstance(LOCALE);
- int fieldIndex;
- switch (field) {
+ case ALIGNED_DAY_OF_WEEK_IN_MONTH:
+ case ALIGNED_DAY_OF_WEEK_IN_YEAR:
+ case ALIGNED_WEEK_OF_MONTH:
+ case ALIGNED_WEEK_OF_YEAR:
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
case YEAR_OF_ERA: {
+ Calendar jcal = Calendar.getInstance(LOCALE);
int startYear = getCurrentEra().getPrivateEra().getSinceDate().getYear();
- return ValueRange.of(Year.MIN_VALUE, jcal.getGreatestMinimum(Calendar.YEAR),
+ return ValueRange.of(1, jcal.getGreatestMinimum(Calendar.YEAR),
jcal.getLeastMaximum(Calendar.YEAR) + 1, // +1 due to the different definitions
Year.MAX_VALUE - startYear);
}
- case DAY_OF_YEAR:
- fieldIndex = Calendar.DAY_OF_YEAR;
- break;
+ case DAY_OF_YEAR: {
+ Calendar jcal = Calendar.getInstance(LOCALE);
+ int fieldIndex = Calendar.DAY_OF_YEAR;
+ return ValueRange.of(jcal.getMinimum(fieldIndex), jcal.getGreatestMinimum(fieldIndex),
+ jcal.getLeastMaximum(fieldIndex), jcal.getMaximum(fieldIndex));
+ }
+ case YEAR:
+ return ValueRange.of(JapaneseDate.MEIJI_6_ISODATE.getYear(), Year.MAX_VALUE);
+ case ERA:
+ return ValueRange.of(JapaneseEra.MEIJI.getValue(), getCurrentEra().getValue());
default:
- // TODO: review the remaining fields
- throw new UnsupportedOperationException("Unimplementable field: " + field);
+ return field.range();
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Override // override for return type
+ public JapaneseDate resolveDate(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ return (JapaneseDate) super.resolveDate(fieldValues, resolverStyle);
+ }
+
+ @Override // override for special Japanese behavior
+ ChronoLocalDate resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ // validate era and year-of-era
+ Long eraLong = fieldValues.get(ERA);
+ JapaneseEra era = null;
+ if (eraLong != null) {
+ era = eraOf(range(ERA).checkValidIntValue(eraLong, ERA)); // always validated
+ }
+ Long yoeLong = fieldValues.get(YEAR_OF_ERA);
+ int yoe = 0;
+ if (yoeLong != null) {
+ yoe = range(YEAR_OF_ERA).checkValidIntValue(yoeLong, YEAR_OF_ERA); // always validated
+ }
+ // if only year-of-era and no year then invent era unless strict
+ if (era == null && yoeLong != null && fieldValues.containsKey(YEAR) == false && resolverStyle != ResolverStyle.STRICT) {
+ era = JapaneseEra.values()[JapaneseEra.values().length - 1];
+ }
+ // if both present, then try to create date
+ if (yoeLong != null && era != null) {
+ if (fieldValues.containsKey(MONTH_OF_YEAR)) {
+ if (fieldValues.containsKey(DAY_OF_MONTH)) {
+ return resolveYMD(era, yoe, fieldValues, resolverStyle);
+ }
+ }
+ if (fieldValues.containsKey(DAY_OF_YEAR)) {
+ return resolveYD(era, yoe, fieldValues, resolverStyle);
+ }
}
- return ValueRange.of(jcal.getMinimum(fieldIndex), jcal.getGreatestMinimum(fieldIndex),
- jcal.getLeastMaximum(fieldIndex), jcal.getMaximum(fieldIndex));
+ return null;
+ }
+
+ private int prolepticYearLenient(JapaneseEra era, int yearOfEra) {
+ return era.getPrivateEra().getSinceDate().getYear() + yearOfEra - 1;
+ }
+
+ private ChronoLocalDate resolveYMD(JapaneseEra era, int yoe, Map<TemporalField,Long> fieldValues, ResolverStyle resolverStyle) {
+ fieldValues.remove(ERA);
+ fieldValues.remove(YEAR_OF_ERA);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ int y = prolepticYearLenient(era, yoe);
+ long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
+ long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
+ return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
+ }
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
+ int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
+ if (resolverStyle == ResolverStyle.SMART) { // previous valid
+ if (yoe < 1) {
+ throw new DateTimeException("Invalid YearOfEra: " + yoe);
+ }
+ int y = prolepticYearLenient(era, yoe);
+ JapaneseDate result;
+ try {
+ result = date(y, moy, dom);
+ } catch (DateTimeException ex) {
+ result = date(y, moy, 1).with(TemporalAdjuster.lastDayOfMonth());
+ }
+ // handle the era being changed
+ // only allow if the new date is in the same Jan-Dec as the era change
+ // determine by ensuring either original yoe or result yoe is 1
+ if (result.getEra() != era && result.get(YEAR_OF_ERA) > 1 && yoe > 1) {
+ throw new DateTimeException("Invalid YearOfEra for Era: " + era + " " + yoe);
+ }
+ return result;
+ }
+ return date(era, yoe, moy, dom);
+ }
+
+ private ChronoLocalDate resolveYD(JapaneseEra era, int yoe, Map <TemporalField,Long> fieldValues, ResolverStyle resolverStyle) {
+ fieldValues.remove(ERA);
+ fieldValues.remove(YEAR_OF_ERA);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ int y = prolepticYearLenient(era, yoe);
+ long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
+ return dateYearDay(y, 1).plus(days, DAYS);
+ }
+ int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
+ return dateYearDay(era, yoe, doy); // smart is same as strict
}
}
--- a/jdk/src/share/classes/java/time/chrono/JapaneseDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/JapaneseDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -56,9 +56,15 @@
*/
package java.time.chrono;
+import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
+import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
+import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
+import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
+import static java.time.temporal.ChronoField.DAY_OF_YEAR;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.YEAR;
+import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import java.io.DataInput;
import java.io.DataOutput;
@@ -96,6 +102,10 @@
* apart from the era-based year numbering. The proleptic-year is defined to be
* equal to the ISO proleptic-year.
* <p>
+ * Japan introduced the Gregorian calendar starting with Meiji 6.
+ * Only Meiji and later eras are supported;
+ * dates before Meiji 6, January 1 are not supported.
+ * <p>
* For example, the Japanese year "Heisei 24" corresponds to ISO year "2012".<br>
* Calling {@code japaneseDate.get(YEAR_OF_ERA)} will return 24.<br>
* Calling {@code japaneseDate.get(YEAR)} will return 2012.<br>
@@ -109,7 +119,7 @@
*/
public final class JapaneseDate
extends ChronoDateImpl<JapaneseDate>
- implements ChronoLocalDate<JapaneseDate>, Serializable {
+ implements ChronoLocalDate, Serializable {
/**
* Serialization version.
@@ -129,6 +139,11 @@
*/
private transient int yearOfEra;
+ /**
+ * The first day supported by the JapaneseChronology is Meiji 6, January 1st.
+ */
+ final static LocalDate MEIJI_6_ISODATE = LocalDate.of(1873, 1, 1);
+
//-----------------------------------------------------------------------
/**
* Obtains the current {@code JapaneseDate} from the system clock in the default time-zone.
@@ -173,7 +188,7 @@
* @throws DateTimeException if the current date cannot be obtained
*/
public static JapaneseDate now(Clock clock) {
- return JapaneseChronology.INSTANCE.date(LocalDate.now(clock));
+ return new JapaneseDate(LocalDate.now(clock));
}
/**
@@ -182,6 +197,16 @@
* <p>
* This returns a {@code JapaneseDate} with the specified fields.
* The day must be valid for the year and month, otherwise an exception will be thrown.
+ * <p>
+ * The Japanese month and day-of-month are the same as those in the
+ * ISO calendar system. They are not reset when the era changes.
+ * For example:
+ * <pre>
+ * 6th Jan Showa 64 = ISO 1989-01-06
+ * 7th Jan Showa 64 = ISO 1989-01-07
+ * 8th Jan Heisei 1 = ISO 1989-01-08
+ * 9th Jan Heisei 1 = ISO 1989-01-09
+ * </pre>
*
* @param era the Japanese era, not null
* @param yearOfEra the Japanese year-of-era
@@ -192,11 +217,15 @@
* or if the day-of-month is invalid for the month-year,
* or if the date is not a Japanese era
*/
- public static JapaneseDate of(Era era, int yearOfEra, int month, int dayOfMonth) {
- if (era instanceof JapaneseEra == false) {
- throw new ClassCastException("Era must be JapaneseEra");
+ public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) {
+ Objects.requireNonNull(era, "era");
+ LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null);
+ jdate.setEra(era.getPrivateEra()).setDate(yearOfEra, month, dayOfMonth);
+ if (!JapaneseChronology.JCAL.validate(jdate)) {
+ throw new DateTimeException("year, month, and day not valid for Era");
}
- return JapaneseDate.of((JapaneseEra) era, yearOfEra, month, dayOfMonth);
+ LocalDate date = LocalDate.of(jdate.getNormalizedYear(), month, dayOfMonth);
+ return new JapaneseDate(era, yearOfEra, date);
}
/**
@@ -205,6 +234,9 @@
* <p>
* This returns a {@code JapaneseDate} with the specified fields.
* The day must be valid for the year and month, otherwise an exception will be thrown.
+ * <p>
+ * The Japanese proleptic year, month and day-of-month are the same as those
+ * in the ISO calendar system. They are not reset when the era changes.
*
* @param prolepticYear the Japanese proleptic-year
* @param month the Japanese month-of-year, from 1 to 12
@@ -219,23 +251,31 @@
/**
* Obtains a {@code JapaneseDate} representing a date in the Japanese calendar
- * system from the proleptic-year and day-of-year fields.
+ * system from the era, year-of-era and day-of-year fields.
* <p>
* This returns a {@code JapaneseDate} with the specified fields.
* The day must be valid for the year, otherwise an exception will be thrown.
+ * <p>
+ * The day-of-year in this factory is expressed relative to the start of the year-of-era.
+ * This definition changes the normal meaning of day-of-year only in those years
+ * where the year-of-era is reset to one due to a change in the era.
+ * For example:
+ * <pre>
+ * 6th Jan Showa 64 = day-of-year 6
+ * 7th Jan Showa 64 = day-of-year 7
+ * 8th Jan Heisei 1 = day-of-year 1
+ * 9th Jan Heisei 1 = day-of-year 2
+ * </pre>
*
- * @param prolepticYear the chronology proleptic-year
+ * @param era the Japanese era, not null
+ * @param yearOfEra the Japanese year-of-era
* @param dayOfYear the chronology day-of-year, from 1 to 366
* @return the date in Japanese calendar system, not null
* @throws DateTimeException if the value of any field is out of range,
* or if the day-of-year is invalid for the year
*/
- public static JapaneseDate ofYearDay(int prolepticYear, int dayOfYear) {
- LocalDate date = LocalDate.ofYearDay(prolepticYear, dayOfYear);
- return of(prolepticYear, date.getMonthValue(), date.getDayOfMonth());
- }
-
static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) {
+ Objects.requireNonNull(era, "era");
CalendarDate firstDay = era.getPrivateEra().getSinceDate();
LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null);
jdate.setEra(era.getPrivateEra());
@@ -254,32 +294,6 @@
}
/**
- * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar
- * system from the era, year-of-era, month-of-year and day-of-month fields.
- * <p>
- * This returns a {@code JapaneseDate} with the specified fields.
- * The day must be valid for the year and month, otherwise an exception will be thrown.
- *
- * @param era the Japanese era, not null
- * @param yearOfEra the Japanese year-of-era
- * @param month the Japanese month-of-year, from 1 to 12
- * @param dayOfMonth the Japanese day-of-month, from 1 to 31
- * @return the date in Japanese calendar system, not null
- * @throws DateTimeException if the value of any field is out of range,
- * or if the day-of-month is invalid for the month-year
- */
- static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) {
- Objects.requireNonNull(era, "era");
- LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null);
- jdate.setEra(era.getPrivateEra()).setDate(yearOfEra, month, dayOfMonth);
- if (!JapaneseChronology.JCAL.validate(jdate)) {
- throw new DateTimeException("year, month, and day not valid for Era");
- }
- LocalDate date = LocalDate.of(jdate.getNormalizedYear(), month, dayOfMonth);
- return new JapaneseDate(era, yearOfEra, date);
- }
-
- /**
* Obtains a {@code JapaneseDate} from a temporal object.
* <p>
* This obtains a date in the Japanese calendar system based on the specified temporal.
@@ -307,6 +321,9 @@
* @param isoDate the standard local date, validated not null
*/
JapaneseDate(LocalDate isoDate) {
+ if (isoDate.isBefore(MEIJI_6_ISODATE)) {
+ throw new DateTimeException("JapaneseDate before Meiji 6 is not supported");
+ }
LocalGregorianCalendar.Date jdate = toPrivateJapaneseDate(isoDate);
this.era = JapaneseEra.toJapaneseEra(jdate.getEra());
this.yearOfEra = jdate.getYear();
@@ -322,6 +339,9 @@
* @param isoDate the standard local date, validated not null
*/
JapaneseDate(JapaneseEra era, int year, LocalDate isoDate) {
+ if (isoDate.isBefore(MEIJI_6_ISODATE)) {
+ throw new DateTimeException("JapaneseDate before Meiji 6 is not supported");
+ }
this.era = era;
this.yearOfEra = year;
this.isoDate = isoDate;
@@ -366,55 +386,99 @@
return isoDate.lengthOfMonth();
}
+ @Override
+ public int lengthOfYear() {
+ Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
+ jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET);
+ jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
+ return jcal.getActualMaximum(Calendar.DAY_OF_YEAR);
+ }
+
//-----------------------------------------------------------------------
+ /**
+ * Checks if the specified field is supported.
+ * <p>
+ * This checks if this date can be queried for the specified field.
+ * If false, then calling the {@link #range(TemporalField) range} and
+ * {@link #get(TemporalField) get} methods will throw an exception.
+ * <p>
+ * If the field is a {@link ChronoField} then the query is implemented here.
+ * The supported fields are:
+ * <ul>
+ * <li>{@code DAY_OF_WEEK}
+ * <li>{@code DAY_OF_MONTH}
+ * <li>{@code DAY_OF_YEAR}
+ * <li>{@code EPOCH_DAY}
+ * <li>{@code MONTH_OF_YEAR}
+ * <li>{@code PROLEPTIC_MONTH}
+ * <li>{@code YEAR_OF_ERA}
+ * <li>{@code YEAR}
+ * <li>{@code ERA}
+ * </ul>
+ * All other {@code ChronoField} instances will return false.
+ * <p>
+ * If the field is not a {@code ChronoField}, then the result of this method
+ * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
+ * passing {@code this} as the argument.
+ * Whether the field is supported is determined by the field.
+ *
+ * @param field the field to check, null returns false
+ * @return true if the field is supported on this date, false if not
+ */
+ @Override
+ public boolean isSupported(TemporalField field) {
+ if (field == ALIGNED_DAY_OF_WEEK_IN_MONTH || field == ALIGNED_DAY_OF_WEEK_IN_YEAR ||
+ field == ALIGNED_WEEK_OF_MONTH || field == ALIGNED_WEEK_OF_YEAR) {
+ return false;
+ }
+ return ChronoLocalDate.super.isSupported(field);
+ }
+
@Override
public ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
if (isSupported(field)) {
ChronoField f = (ChronoField) field;
switch (f) {
- case DAY_OF_MONTH:
- case ALIGNED_WEEK_OF_MONTH:
- return isoDate.range(field);
- case DAY_OF_YEAR:
- return actualRange(Calendar.DAY_OF_YEAR);
- case YEAR_OF_ERA:
- return actualRange(Calendar.YEAR);
+ case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());
+ case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());
+ case YEAR_OF_ERA: {
+ Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
+ jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET);
+ jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
+ return ValueRange.of(1, jcal.getActualMaximum(Calendar.YEAR));
+ }
}
return getChronology().range(f);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
- private ValueRange actualRange(int calendarField) {
- Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
- jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET); // TODO: cannot calculate this way for SEIREKI
- jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
- return ValueRange.of(jcal.getActualMinimum(calendarField),
- jcal.getActualMaximum(calendarField));
- }
-
@Override
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
// same as ISO:
- // DAY_OF_WEEK, ALIGNED_DAY_OF_WEEK_IN_MONTH, DAY_OF_MONTH, EPOCH_DAY,
- // ALIGNED_WEEK_OF_MONTH, MONTH_OF_YEAR, PROLEPTIC_MONTH, YEAR
+ // DAY_OF_WEEK, DAY_OF_MONTH, EPOCH_DAY, MONTH_OF_YEAR, PROLEPTIC_MONTH, YEAR
//
// calendar specific fields
- // ALIGNED_DAY_OF_WEEK_IN_YEAR, DAY_OF_YEAR, ALIGNED_WEEK_OF_YEAR, YEAR_OF_ERA, ERA
+ // DAY_OF_YEAR, YEAR_OF_ERA, ERA
switch ((ChronoField) field) {
+ case ALIGNED_DAY_OF_WEEK_IN_MONTH:
+ case ALIGNED_DAY_OF_WEEK_IN_YEAR:
+ case ALIGNED_WEEK_OF_MONTH:
+ case ALIGNED_WEEK_OF_YEAR:
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
case YEAR_OF_ERA:
return yearOfEra;
case ERA:
return era.getValue();
- case DAY_OF_YEAR: {
- LocalGregorianCalendar.Date jdate = toPrivateJapaneseDate(isoDate);
- return JapaneseChronology.JCAL.getDayOfYear(jdate);
- }
- // TODO: ALIGNED_DAY_OF_WEEK_IN_YEAR and ALIGNED_WEEK_OF_YEAR ???
+ case DAY_OF_YEAR:
+ Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
+ jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET);
+ jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
+ return jcal.get(Calendar.DAY_OF_YEAR);
}
return isoDate.getLong(field);
}
@@ -444,7 +508,7 @@
public JapaneseDate with(TemporalField field, long newValue) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
- if (getLong(f) == newValue) {
+ if (getLong(f) == newValue) { // getLong() validates for supported fields
return this;
}
switch (f) {
@@ -464,10 +528,9 @@
}
}
// YEAR, PROLEPTIC_MONTH and others are same as ISO
- // TODO: review other fields, such as WEEK_OF_YEAR
return with(isoDate.with(field, newValue));
}
- return ChronoLocalDate.super.with(field, newValue);
+ return super.with(field, newValue);
}
/**
@@ -592,13 +655,14 @@
}
@Override // for javadoc and covariant return type
+ @SuppressWarnings("unchecked")
public final ChronoLocalDateTime<JapaneseDate> atTime(LocalTime localTime) {
- return super.atTime(localTime);
+ return (ChronoLocalDateTime<JapaneseDate>)super.atTime(localTime);
}
@Override
- public Period periodUntil(ChronoLocalDate<?> endDate) {
- return isoDate.periodUntil(endDate);
+ public Period until(ChronoLocalDate endDate) {
+ return isoDate.until(endDate);
}
@Override // override for performance
@@ -624,14 +688,6 @@
return getChronology().getId().hashCode() ^ isoDate.hashCode();
}
- @Override
- public String toString() {
- if (era == JapaneseEra.SEIREKI) {
- return getChronology().getId() + " " + isoDate.toString();
- }
- return super.toString();
- }
-
//-----------------------------------------------------------------------
private Object writeReplace() {
return new Ser(Ser.JAPANESE_DATE_TYPE, this);
--- a/jdk/src/share/classes/java/time/chrono/JapaneseEra.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/JapaneseEra.java Thu Jul 25 20:30:58 2013 -0400
@@ -61,6 +61,7 @@
*/
package java.time.chrono;
+import static java.time.chrono.JapaneseDate.MEIJI_6_ISODATE;
import static java.time.temporal.ChronoField.ERA;
import java.io.DataInput;
@@ -84,12 +85,9 @@
* An era in the Japanese Imperial calendar system.
* <p>
* This class defines the valid eras for the Japanese chronology.
- * Only Meiji (1868-09-08 - 1912-07-29) and later eras are supported.
- * Japan introduced the Gregorian calendar since Meiji 6. The dates
- * between Meiji 1 - 5 are not historically correct.
- * The older eras are recognized as Seireki (Western calendar) era,
- * and the year of era of Seireki is proleptic Gregorian year.
- * (The Julian to Gregorian transition is not supported.)
+ * Japan introduced the Gregorian calendar starting with Meiji 6.
+ * Only Meiji and later eras are supported;
+ * dates before Meiji 6, January 1 are not supported.
*
* @implSpec
* This class is immutable and thread-safe.
@@ -100,17 +98,12 @@
implements Era, Serializable {
// The offset value to 0-based index from the era value.
- // i.e., getValue() + ERA_OFFSET == 0-based index; except that -999 is mapped to zero
+ // i.e., getValue() + ERA_OFFSET == 0-based index
static final int ERA_OFFSET = 2;
static final sun.util.calendar.Era[] ERA_CONFIG;
/**
- * The singleton instance for the before Meiji era ( - 1868-09-07)
- * which has the value -999.
- */
- public static final JapaneseEra SEIREKI = new JapaneseEra(-999, LocalDate.MIN);
- /**
* The singleton instance for the 'Meiji' era (1868-09-08 - 1912-07-29)
* which has the value -1.
*/
@@ -144,17 +137,13 @@
private static final JapaneseEra[] KNOWN_ERAS;
static {
- sun.util.calendar.Era[] sunEras = JapaneseChronology.JCAL.getEras();
- ERA_CONFIG = new sun.util.calendar.Era[sunEras.length + 1];
- for (int i = 1; i < ERA_CONFIG.length; i++) {
- ERA_CONFIG[i] = sunEras[i - 1];
- }
+ ERA_CONFIG = JapaneseChronology.JCAL.getEras();
+
KNOWN_ERAS = new JapaneseEra[ERA_CONFIG.length];
- KNOWN_ERAS[0] = SEIREKI;
- KNOWN_ERAS[1] = MEIJI;
- KNOWN_ERAS[2] = TAISHO;
- KNOWN_ERAS[3] = SHOWA;
- KNOWN_ERAS[4] = HEISEI;
+ KNOWN_ERAS[0] = MEIJI;
+ KNOWN_ERAS[1] = TAISHO;
+ KNOWN_ERAS[2] = SHOWA;
+ KNOWN_ERAS[3] = HEISEI;
for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) {
CalendarDate date = ERA_CONFIG[i].getSinceDate();
LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());
@@ -203,10 +192,8 @@
//-----------------------------------------------------------------------
/**
* Returns the Sun private Era instance corresponding to this {@code JapaneseEra}.
- * SEIREKI doesn't have its corresponding one.
*
- * @return the Sun private Era instance for this {@code JapaneseEra},
- * or null for SEIREKI.
+ * @return the Sun private Era instance for this {@code JapaneseEra}.
*/
sun.util.calendar.Era getPrivateEra() {
return ERA_CONFIG[ordinal(eraValue)];
@@ -218,16 +205,14 @@
* <p>
* The {@link #SHOWA} era that contains 1970-01-01 (ISO calendar system) has the value 1
* Later era is numbered 2 ({@link #HEISEI}). Earlier eras are numbered 0 ({@link #TAISHO}),
- * -1 ({@link #MEIJI}), only Meiji and later eras are supported. The prior to Meiji,
- * {@link #SEIREKI} is used.
+ * -1 ({@link #MEIJI}), only Meiji and later eras are supported.
*
* @param japaneseEra the era to represent
* @return the {@code JapaneseEra} singleton, not null
* @throws DateTimeException if the value is invalid
*/
public static JapaneseEra of(int japaneseEra) {
- if (japaneseEra != SEIREKI.eraValue &&
- (japaneseEra < MEIJI.eraValue || japaneseEra > HEISEI.eraValue)) {
+ if (japaneseEra < MEIJI.eraValue || japaneseEra > HEISEI.eraValue) {
throw new DateTimeException("Invalid era: " + japaneseEra);
}
return KNOWN_ERAS[ordinal(japaneseEra)];
@@ -276,22 +261,25 @@
* @return the Era singleton, never null
*/
static JapaneseEra from(LocalDate date) {
+ if (date.isBefore(MEIJI_6_ISODATE)) {
+ throw new DateTimeException("JapaneseDate before Meiji 6 are not supported");
+ }
for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
JapaneseEra era = KNOWN_ERAS[i];
if (date.compareTo(era.since) >= 0) {
return era;
}
}
- return SEIREKI;
+ return null;
}
static JapaneseEra toJapaneseEra(sun.util.calendar.Era privateEra) {
- for (int i = ERA_CONFIG.length - 1; i > 0; i--) {
+ for (int i = ERA_CONFIG.length - 1; i >= 0; i--) {
if (ERA_CONFIG[i].equals(privateEra)) {
return KNOWN_ERAS[i];
}
}
- return SEIREKI;
+ return null;
}
static sun.util.calendar.Era privateEraFrom(LocalDate isoDate) {
@@ -306,13 +294,13 @@
/**
* Returns the index into the arrays from the Era value.
- * the eraValue is a valid Era number, -999, -1..2.
+ * the eraValue is a valid Era number, -1..2.
*
* @param eraValue the era value to convert to the index
* @return the index of the current Era
*/
private static int ordinal(int eraValue) {
- return (eraValue == SEIREKI.eraValue) ? 0 : eraValue + ERA_OFFSET;
+ return eraValue + ERA_OFFSET - 1;
}
//-----------------------------------------------------------------------
@@ -321,7 +309,7 @@
* <p>
* The {@link #SHOWA} era that contains 1970-01-01 (ISO calendar system) has the value 1.
* Later eras are numbered from 2 ({@link #HEISEI}).
- * Earlier eras are numbered 0 ({@link #TAISHO}), -1 ({@link #MEIJI}), and -999 ({@link #SEIREKI}).
+ * Earlier eras are numbered 0 ({@link #TAISHO}), -1 ({@link #MEIJI})).
*
* @return the era value
*/
@@ -374,11 +362,7 @@
}
String getName() {
- int index = ordinal(getValue());
- if (index == 0) {
- return "Seireki";
- }
- return ERA_CONFIG[index].getName();
+ return ERA_CONFIG[ordinal(getValue())].getName();
}
@Override
--- a/jdk/src/share/classes/java/time/chrono/MinguoChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/MinguoChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -65,12 +65,15 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
+import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
/**
* The Minguo calendar system.
@@ -253,16 +256,19 @@
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoLocalDateTime<MinguoDate> localDateTime(TemporalAccessor temporal) {
return (ChronoLocalDateTime<MinguoDate>)super.localDateTime(temporal);
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoZonedDateTime<MinguoDate> zonedDateTime(TemporalAccessor temporal) {
return (ChronoZonedDateTime<MinguoDate>)super.zonedDateTime(temporal);
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoZonedDateTime<MinguoDate> zonedDateTime(Instant instant, ZoneId zone) {
return (ChronoZonedDateTime<MinguoDate>)super.zonedDateTime(instant, zone);
}
@@ -292,7 +298,7 @@
}
@Override
- public Era eraOf(int eraValue) {
+ public MinguoEra eraOf(int eraValue) {
return MinguoEra.of(eraValue);
}
@@ -321,4 +327,10 @@
return field.range();
}
+ //-----------------------------------------------------------------------
+ @Override // override for return type
+ public MinguoDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ return (MinguoDate) super.resolveDate(fieldValues, resolverStyle);
+ }
+
}
--- a/jdk/src/share/classes/java/time/chrono/MinguoDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/MinguoDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -96,7 +96,7 @@
*/
public final class MinguoDate
extends ChronoDateImpl<MinguoDate>
- implements ChronoLocalDate<MinguoDate>, Serializable {
+ implements ChronoLocalDate, Serializable {
/**
* Serialization version.
@@ -152,7 +152,7 @@
* @throws DateTimeException if the current date cannot be obtained
*/
public static MinguoDate now(Clock clock) {
- return MinguoChronology.INSTANCE.date(LocalDate.now(clock));
+ return new MinguoDate(LocalDate.now(clock));
}
/**
@@ -264,7 +264,7 @@
}
return getChronology().range(f);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
@@ -325,7 +325,7 @@
}
return with(isoDate.with(field, newValue));
}
- return ChronoLocalDate.super.with(field, newValue);
+ return super.with(field, newValue);
}
/**
@@ -370,6 +370,11 @@
}
@Override
+ MinguoDate plusWeeks(long weeksToAdd) {
+ return super.plusWeeks(weeksToAdd);
+ }
+
+ @Override
MinguoDate plusDays(long days) {
return with(isoDate.plusDays(days));
}
@@ -385,11 +390,6 @@
}
@Override
- MinguoDate plusWeeks(long weeksToAdd) {
- return super.plusWeeks(weeksToAdd);
- }
-
- @Override
MinguoDate minusYears(long yearsToSubtract) {
return super.minusYears(yearsToSubtract);
}
@@ -414,13 +414,14 @@
}
@Override // for javadoc and covariant return type
+ @SuppressWarnings("unchecked")
public final ChronoLocalDateTime<MinguoDate> atTime(LocalTime localTime) {
- return super.atTime(localTime);
+ return (ChronoLocalDateTime<MinguoDate>)super.atTime(localTime);
}
@Override
- public Period periodUntil(ChronoLocalDate<?> endDate) {
- return isoDate.periodUntil(endDate);
+ public Period until(ChronoLocalDate endDate) {
+ return isoDate.until(endDate);
}
@Override // override for performance
@@ -458,7 +459,7 @@
out.writeByte(get(DAY_OF_MONTH));
}
- static ChronoLocalDate<?> readExternal(DataInput in) throws IOException {
+ static MinguoDate readExternal(DataInput in) throws IOException {
int year = in.readInt();
int month = in.readByte();
int dayOfMonth = in.readByte();
--- a/jdk/src/share/classes/java/time/chrono/ThaiBuddhistChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ThaiBuddhistChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -65,13 +65,16 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
+import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
/**
* The Thai Buddhist calendar system.
@@ -289,16 +292,19 @@
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoLocalDateTime<ThaiBuddhistDate> localDateTime(TemporalAccessor temporal) {
return (ChronoLocalDateTime<ThaiBuddhistDate>)super.localDateTime(temporal);
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoZonedDateTime<ThaiBuddhistDate> zonedDateTime(TemporalAccessor temporal) {
return (ChronoZonedDateTime<ThaiBuddhistDate>)super.zonedDateTime(temporal);
}
@Override
+ @SuppressWarnings("unchecked")
public ChronoZonedDateTime<ThaiBuddhistDate> zonedDateTime(Instant instant, ZoneId zone) {
return (ChronoZonedDateTime<ThaiBuddhistDate>)super.zonedDateTime(instant, zone);
}
@@ -328,7 +334,7 @@
}
@Override
- public Era eraOf(int eraValue) {
+ public ThaiBuddhistEra eraOf(int eraValue) {
return ThaiBuddhistEra.of(eraValue);
}
@@ -357,4 +363,10 @@
return field.range();
}
+ //-----------------------------------------------------------------------
+ @Override // override for return type
+ public ThaiBuddhistDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ return (ThaiBuddhistDate) super.resolveDate(fieldValues, resolverStyle);
+ }
+
}
--- a/jdk/src/share/classes/java/time/chrono/ThaiBuddhistDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/ThaiBuddhistDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -96,7 +96,7 @@
*/
public final class ThaiBuddhistDate
extends ChronoDateImpl<ThaiBuddhistDate>
- implements ChronoLocalDate<ThaiBuddhistDate>, Serializable {
+ implements ChronoLocalDate, Serializable {
/**
* Serialization version.
@@ -152,7 +152,7 @@
* @throws DateTimeException if the current date cannot be obtained
*/
public static ThaiBuddhistDate now(Clock clock) {
- return ThaiBuddhistChronology.INSTANCE.date(LocalDate.now(clock));
+ return new ThaiBuddhistDate(LocalDate.now(clock));
}
/**
@@ -264,7 +264,7 @@
}
return getChronology().range(f);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
@@ -325,7 +325,7 @@
}
return with(isoDate.with(field, newValue));
}
- return ChronoLocalDate.super.with(field, newValue);
+ return super.with(field, newValue);
}
/**
@@ -414,13 +414,14 @@
}
@Override // for javadoc and covariant return type
+ @SuppressWarnings("unchecked")
public final ChronoLocalDateTime<ThaiBuddhistDate> atTime(LocalTime localTime) {
- return super.atTime(localTime);
+ return (ChronoLocalDateTime<ThaiBuddhistDate>) super.atTime(localTime);
}
@Override
- public Period periodUntil(ChronoLocalDate<?> endDate) {
- return isoDate.periodUntil(endDate);
+ public Period until(ChronoLocalDate endDate) {
+ return isoDate.until(endDate);
}
@Override // override for performance
--- a/jdk/src/share/classes/java/time/chrono/package-info.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/chrono/package-info.java Thu Jul 25 20:30:58 2013 -0400
@@ -103,7 +103,7 @@
* // Enumerate the list of available calendars and print todays date for each.
* Set<Chronology> chronos = Chronology.getAvailableChronologies();
* for (Chronology chrono : chronos) {
- * ChronoLocalDate<?> date = chrono.dateNow();
+ * ChronoLocalDate date = chrono.dateNow();
* System.out.printf(" %20s: %s%n", chrono.getId(), date.toString());
* }
* </pre>
@@ -113,7 +113,7 @@
* </p>
* <pre>
* // Print the Thai Buddhist date
- * ChronoLocalDate<?> now1 = Chronology.of("ThaiBuddhist").dateNow();
+ * ChronoLocalDate now1 = Chronology.of("ThaiBuddhist").dateNow();
* int day = now1.get(ChronoField.DAY_OF_MONTH);
* int dow = now1.get(ChronoField.DAY_OF_WEEK);
* int month = now1.get(ChronoField.MONTH_OF_YEAR);
@@ -121,10 +121,10 @@
* System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChronology().getId(),
* dow, day, month, year);
* // Print today's date and the last day of the year for the Thai Buddhist Calendar.
- * ChronoLocalDate<?> first = now1
+ * ChronoLocalDate first = now1
* .with(ChronoField.DAY_OF_MONTH, 1)
* .with(ChronoField.MONTH_OF_YEAR, 1);
- * ChronoLocalDate<?> last = first
+ * ChronoLocalDate last = first
* .plus(1, ChronoUnit.YEARS)
* .minus(1, ChronoUnit.DAYS);
* System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(),
--- a/jdk/src/share/classes/java/time/format/DateTimeFormatter.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/format/DateTimeFormatter.java Thu Jul 25 20:30:58 2013 -0400
@@ -265,7 +265,7 @@
* <p>
* For example:
* <blockquote><pre>
- * DateTimeFormatter formatter = DateTimeFormatter.pattern("yyyy MM dd");
+ * DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd");
* String text = date.toString(formatter);
* LocalDate date = LocalDate.parse(text, formatter);
* </pre></blockquote>
@@ -460,7 +460,7 @@
* <li>The {@code ChronoField} time fields are resolved.
* This is documented on {@link ChronoField} and is the same for all chronologies.
* <li>Any fields that are not {@code ChronoField} are processed.
- * This is achieved using {@link TemporalField#resolve(TemporalAccessor, long, ResolverStyle)}.
+ * This is achieved using {@link TemporalField#resolve(Map, Chronology, ZoneId, ResolverStyle)}.
* Documentation about field resolution is located in the implementation
* of {@code TemporalField}.
* <li>The {@code ChronoField} date and time fields are re-resolved.
--- a/jdk/src/share/classes/java/time/format/DateTimeFormatterBuilder.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/format/DateTimeFormatterBuilder.java Thu Jul 25 20:30:58 2013 -0400
@@ -77,7 +77,6 @@
import java.math.RoundingMode;
import java.text.ParsePosition;
import java.time.DateTimeException;
-import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -962,12 +961,9 @@
* <pre>
* "Europe/London" -- ZoneId.of("Europe/London")
* "Z" -- ZoneOffset.UTC
- * "UT" -- ZoneOffset.UTC
- * "UTC" -- ZoneOffset.UTC
- * "GMT" -- ZoneOffset.UTC
- * "UT0" -- ZoneOffset.UTC
- * "UTC0" -- ZoneOffset.UTC
- * "GMT0" -- ZoneOffset.UTC
+ * "UT" -- ZoneId.of("UT")
+ * "UTC" -- ZoneId.of("UTC")
+ * "GMT" -- ZoneId.of("GMT")
* "+01:30" -- ZoneOffset.of("+01:30")
* "UT+01:30" -- ZoneOffset.of("+01:30")
* "UTC+01:30" -- ZoneOffset.of("+01:30")
@@ -1016,12 +1012,9 @@
* <pre>
* "Europe/London" -- ZoneId.of("Europe/London")
* "Z" -- ZoneOffset.UTC
- * "UT" -- ZoneOffset.UTC
- * "UTC" -- ZoneOffset.UTC
- * "GMT" -- ZoneOffset.UTC
- * "UT0" -- ZoneOffset.UTC
- * "UTC0" -- ZoneOffset.UTC
- * "GMT0" -- ZoneOffset.UTC
+ * "UT" -- ZoneId.of("UT")
+ * "UTC" -- ZoneId.of("UTC")
+ * "GMT" -- ZoneId.of("GMT")
* "+01:30" -- ZoneOffset.of("+01:30")
* "UT+01:30" -- ZoneOffset.of("+01:30")
* "UTC+01:30" -- ZoneOffset.of("+01:30")
@@ -1077,16 +1070,13 @@
* <pre>
* "Europe/London" -- ZoneId.of("Europe/London")
* "Z" -- ZoneOffset.UTC
- * "UT" -- ZoneOffset.UTC
- * "UTC" -- ZoneOffset.UTC
- * "GMT" -- ZoneOffset.UTC
- * "UT0" -- ZoneOffset.UTC
- * "UTC0" -- ZoneOffset.UTC
- * "GMT0" -- ZoneOffset.UTC
+ * "UT" -- ZoneId.of("UT")
+ * "UTC" -- ZoneId.of("UTC")
+ * "GMT" -- ZoneId.of("GMT")
* "+01:30" -- ZoneOffset.of("+01:30")
- * "UT+01:30" -- ZoneOffset.of("+01:30")
- * "UTC+01:30" -- ZoneOffset.of("+01:30")
- * "GMT+01:30" -- ZoneOffset.of("+01:30")
+ * "UT+01:30" -- ZoneOffset.of("UT+01:30")
+ * "UTC+01:30" -- ZoneOffset.of("UTC+01:30")
+ * "GMT+01:30" -- ZoneOffset.of("GMT+01:30")
* </pre>
* <p>
* Note that this method is is identical to {@code appendZoneId()} except
@@ -2530,7 +2520,7 @@
DecimalStyle decimalStyle = context.getDecimalStyle();
String str = (value == Long.MIN_VALUE ? "9223372036854775808" : Long.toString(Math.abs(value)));
if (str.length() > maxWidth) {
- throw new DateTimeException("Field " + field.getName() +
+ throw new DateTimeException("Field " + field +
" cannot be printed as the value " + value +
" exceeds the maximum print width of " + maxWidth);
}
@@ -2555,7 +2545,7 @@
buf.append(decimalStyle.getNegativeSign());
break;
case NOT_NEGATIVE:
- throw new DateTimeException("Field " + field.getName() +
+ throw new DateTimeException("Field " + field +
" cannot be printed as the value " + value +
" cannot be negative according to the SignStyle");
}
@@ -2699,12 +2689,12 @@
@Override
public String toString() {
if (minWidth == 1 && maxWidth == 19 && signStyle == SignStyle.NORMAL) {
- return "Value(" + field.getName() + ")";
+ return "Value(" + field + ")";
}
if (minWidth == maxWidth && signStyle == SignStyle.NOT_NEGATIVE) {
- return "Value(" + field.getName() + "," + minWidth + ")";
+ return "Value(" + field + "," + minWidth + ")";
}
- return "Value(" + field.getName() + "," + minWidth + "," + maxWidth + "," + signStyle + ")";
+ return "Value(" + field + "," + minWidth + "," + maxWidth + "," + signStyle + ")";
}
}
@@ -2817,7 +2807,7 @@
@Override
public String toString() {
- return "ReducedValue(" + field.getName() + "," + minWidth + "," + maxWidth + "," + baseValue + ")";
+ return "ReducedValue(" + field + "," + minWidth + "," + maxWidth + "," + baseValue + ")";
}
}
@@ -2842,7 +2832,7 @@
FractionPrinterParser(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
Objects.requireNonNull(field, "field");
if (field.range().isFixed() == false) {
- throw new IllegalArgumentException("Field must have a fixed set of values: " + field.getName());
+ throw new IllegalArgumentException("Field must have a fixed set of values: " + field);
}
if (minWidth < 0 || minWidth > 9) {
throw new IllegalArgumentException("Minimum width must be from 0 to 9 inclusive but was " + minWidth);
@@ -2984,7 +2974,7 @@
@Override
public String toString() {
String decimal = (decimalPoint ? ",DecimalPoint" : "");
- return "Fraction(" + field.getName() + "," + minWidth + "," + maxWidth + decimal + ")";
+ return "Fraction(" + field + "," + minWidth + "," + maxWidth + decimal + ")";
}
}
@@ -3079,9 +3069,9 @@
@Override
public String toString() {
if (textStyle == TextStyle.FULL) {
- return "Text(" + field.getName() + ")";
+ return "Text(" + field + ")";
}
- return "Text(" + field.getName() + "," + textStyle + ")";
+ return "Text(" + field + "," + textStyle + ")";
}
}
@@ -3756,17 +3746,17 @@
// handle fixed time-zone IDs
char nextChar = text.charAt(position);
if (nextChar == '+' || nextChar == '-') {
- return parseOffsetBased(context, text, position, OffsetIdPrinterParser.INSTANCE_ID_Z);
+ return parseOffsetBased(context, text, position, position, OffsetIdPrinterParser.INSTANCE_ID_Z);
} else if (length >= position + 2) {
char nextNextChar = text.charAt(position + 1);
if (context.charEquals(nextChar, 'U') && context.charEquals(nextNextChar, 'T')) {
if (length >= position + 3 && context.charEquals(text.charAt(position + 2), 'C')) {
- return parseOffsetBased(context, text, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
+ return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
}
- return parseOffsetBased(context, text, position + 2, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
+ return parseOffsetBased(context, text, position, position + 2, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
} else if (context.charEquals(nextChar, 'G') && length >= position + 3 &&
context.charEquals(nextNextChar, 'M') && context.charEquals(text.charAt(position + 2), 'T')) {
- return parseOffsetBased(context, text, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
+ return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
}
}
@@ -3785,20 +3775,49 @@
return ppos.getIndex();
}
- private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int position, OffsetIdPrinterParser parser) {
+ /**
+ * Parse an offset following a prefix and set the ZoneId if it is valid.
+ * To matching the parsing of ZoneId.of the values are not normalized
+ * to ZoneOffsets.
+ *
+ * @param context the parse context
+ * @param text the input text
+ * @param prefixPos start of the prefix
+ * @param position start of text after the prefix
+ * @param parser parser for the value after the prefix
+ * @return the position after the parse
+ */
+ private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int prefixPos, int position, OffsetIdPrinterParser parser) {
+ String prefix = text.toString().substring(prefixPos, position).toUpperCase();
+ if (position >= text.length()) {
+ context.setParsed(ZoneId.of(prefix));
+ return position;
+ }
+
+ // '0' or 'Z' after prefix is not part of a valid ZoneId; use bare prefix
+ if (text.charAt(position) == '0' ||
+ context.charEquals(text.charAt(position), 'Z')) {
+ context.setParsed(ZoneId.of(prefix));
+ return position;
+ }
+
DateTimeParseContext newContext = context.copy();
int endPos = parser.parse(newContext, text, position);
- if (endPos < 0) {
- if (parser == OffsetIdPrinterParser.INSTANCE_ID_Z) {
- return ~position;
+ try {
+ if (endPos < 0) {
+ if (parser == OffsetIdPrinterParser.INSTANCE_ID_Z) {
+ return ~prefixPos;
+ }
+ context.setParsed(ZoneId.of(prefix));
+ return position;
}
- context.setParsed(ZoneOffset.UTC);
- return position;
+ int offset = (int) newContext.getParsed(OFFSET_SECONDS).longValue();
+ ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(offset);
+ context.setParsed(ZoneId.ofOffset(prefix, zoneOffset));
+ return endPos;
+ } catch (DateTimeException dte) {
+ return ~prefixPos;
}
- int offset = (int) newContext.getParsed(OFFSET_SECONDS).longValue();
- ZoneId zone = ZoneOffset.ofTotalSeconds(offset);
- context.setParsed(zone);
- return endPos;
}
@Override
--- a/jdk/src/share/classes/java/time/format/DateTimePrintContext.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/format/DateTimePrintContext.java Thu Jul 25 20:30:58 2013 -0400
@@ -157,7 +157,7 @@
}
}
final ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone);
- final ChronoLocalDate<?> effectiveDate;
+ final ChronoLocalDate effectiveDate;
if (overrideChrono != null) {
if (temporal.isSupported(EPOCH_DAY)) {
effectiveDate = effectiveChrono.date(temporal);
--- a/jdk/src/share/classes/java/time/format/Parsed.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/format/Parsed.java Thu Jul 25 20:30:58 2013 -0400
@@ -143,7 +143,7 @@
/**
* The resolved date.
*/
- private ChronoLocalDate<?> date;
+ private ChronoLocalDate date;
/**
* The resolved time.
*/
@@ -197,7 +197,7 @@
return time.getLong(field);
}
if (field instanceof ChronoField) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
@@ -255,42 +255,34 @@
// if any other fields, handle them
// any lenient date resolution should return epoch-day
if (fieldValues.size() > 0) {
- boolean changed = false;
+ int changedCount = 0;
outer:
- while (true) {
+ while (changedCount < 50) {
for (Map.Entry<TemporalField, Long> entry : fieldValues.entrySet()) {
TemporalField targetField = entry.getKey();
- Map<TemporalField, Long> changes = targetField.resolve(this, entry.getValue(), resolverStyle);
- if (changes != null) {
- changed = true;
- resolveFieldsMakeChanges(targetField, changes);
- fieldValues.remove(targetField); // helps avoid infinite loops
+ ChronoLocalDate resolvedDate = targetField.resolve(fieldValues, chrono, zone, resolverStyle);
+ if (resolvedDate != null) {
+ updateCheckConflict(resolvedDate);
+ changedCount++;
+ continue outer; // have to restart to avoid concurrent modification
+ } else if (fieldValues.containsKey(targetField) == false) {
+ changedCount++;
continue outer; // have to restart to avoid concurrent modification
}
}
break;
}
+ if (changedCount == 50) { // catch infinite loops
+ throw new DateTimeException("One of the parsed fields has an incorrectly implemented resolve method");
+ }
// if something changed then have to redo ChronoField resolve
- if (changed) {
+ if (changedCount > 0) {
resolveDateFields();
resolveTimeFields();
}
}
}
- private void resolveFieldsMakeChanges(TemporalField targetField, Map<TemporalField, Long> changes) {
- for (Map.Entry<TemporalField, Long> change : changes.entrySet()) {
- TemporalField changeField = change.getKey();
- Long changeValue = change.getValue();
- Objects.requireNonNull(changeField, "changeField");
- if (changeValue != null) {
- updateCheckConflict(targetField, changeField, changeValue);
- } else {
- fieldValues.remove(changeField);
- }
- }
- }
-
private void updateCheckConflict(TemporalField targetField, TemporalField changeField, Long changeValue) {
Long old = fieldValues.put(changeField, changeValue);
if (old != null && old.longValue() != changeValue.longValue()) {
@@ -305,7 +297,7 @@
updateCheckConflict(chrono.resolveDate(fieldValues, resolverStyle));
}
- private void updateCheckConflict(ChronoLocalDate<?> cld) {
+ private void updateCheckConflict(ChronoLocalDate cld) {
if (date != null) {
if (cld != null && date.equals(cld) == false) {
throw new DateTimeException("Conflict found: Fields resolved to two different dates: " + date + " " + cld);
--- a/jdk/src/share/classes/java/time/temporal/ChronoField.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/ChronoField.java Thu Jul 25 20:30:58 2013 -0400
@@ -403,6 +403,12 @@
* Non-ISO calendar systems should implement this field using the most recognized
* day-of-year values for users of the calendar system.
* Normally, this is a count of days from 1 to the length of the year.
+ * <p>
+ * Note that a non-ISO calendar system may have year numbering system that changes
+ * at a different point to the natural reset in the month numbering. An example
+ * of this is the Japanese calendar system where a change of era, which resets
+ * the year number to 1, can happen on any date. The era and year reset also cause
+ * the day-of-year to be reset to 1, but not the month-of-year or day-of-month.
*/
DAY_OF_YEAR("DayOfYear", DAYS, YEARS, ValueRange.of(1, 365, 366)),
/**
@@ -559,12 +565,11 @@
* <p>
* This represents the concept of the sequential count of seconds where
* 1970-01-01T00:00Z (ISO) is zero.
- * This field may be used with {@link #NANO_OF_DAY} to represent the fraction of the day.
+ * This field may be used with {@link #NANO_OF_SECOND} to represent the fraction of the second.
* <p>
* An {@link Instant} represents an instantaneous point on the time-line.
- * On their own they have no elements which allow a local date-time to be obtained.
- * Only when paired with an offset or time-zone can the local date or time be found.
- * This field allows the seconds part of the instant to be queried.
+ * On their own, an instant has insufficient information to allow a local date-time to be obtained.
+ * Only when paired with an offset or time-zone can the local date or time be calculated.
* <p>
* This field is strictly defined to have the same meaning in all calendar systems.
* This is necessary to ensure interoperation between calendars.
@@ -608,24 +613,18 @@
this.displayNameKey = displayNameKey;
}
- //-----------------------------------------------------------------------
- @Override
- public String getName() {
- return name;
- }
-
@Override
public String getDisplayName(Locale locale) {
Objects.requireNonNull(locale, "locale");
if (displayNameKey == null) {
- return getName();
+ return name;
}
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
String key = "field." + displayNameKey;
- return rb.containsKey(key) ? rb.getString(key) : getName();
+ return rb.containsKey(key) ? rb.getString(key) : name;
}
@Override
@@ -748,7 +747,7 @@
//-----------------------------------------------------------------------
@Override
public String toString() {
- return getName();
+ return name;
}
}
--- a/jdk/src/share/classes/java/time/temporal/ChronoUnit.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/ChronoUnit.java Thu Jul 25 20:30:58 2013 -0400
@@ -57,9 +57,6 @@
package java.time.temporal;
import java.time.Duration;
-import java.time.chrono.ChronoLocalDate;
-import java.time.chrono.ChronoLocalDateTime;
-import java.time.chrono.ChronoZonedDateTime;
/**
* A standard set of date periods units.
@@ -201,12 +198,6 @@
}
//-----------------------------------------------------------------------
- @Override
- public String getName() {
- return name;
- }
-
- //-----------------------------------------------------------------------
/**
* Gets the estimated duration of this unit in the ISO calendar system.
* <p>
@@ -233,41 +224,40 @@
*/
@Override
public boolean isDurationEstimated() {
- return isDateUnit();
+ return this.compareTo(DAYS) >= 0;
}
//-----------------------------------------------------------------------
/**
* Checks if this unit is a date unit.
+ * <p>
+ * All units from days to eras inclusive are date-based.
+ * Time-based units and {@code FOREVER} return false.
*
* @return true if a date unit, false if a time unit
*/
- public boolean isDateUnit() {
- return this.compareTo(DAYS) >= 0;
+ @Override
+ public boolean isDateBased() {
+ return this.compareTo(DAYS) >= 0 && this != FOREVER;
}
/**
* Checks if this unit is a time unit.
+ * <p>
+ * All units from nanos to half-days inclusive are time-based.
+ * Date-based units and {@code FOREVER} return false.
*
* @return true if a time unit, false if a date unit
*/
- public boolean isTimeUnit() {
+ @Override
+ public boolean isTimeBased() {
return this.compareTo(DAYS) < 0;
}
//-----------------------------------------------------------------------
@Override
public boolean isSupportedBy(Temporal temporal) {
- if (this == FOREVER) {
- return false;
- }
- if (temporal instanceof ChronoLocalDate) {
- return isDateUnit();
- }
- if (temporal instanceof ChronoLocalDateTime || temporal instanceof ChronoZonedDateTime) {
- return true;
- }
- return TemporalUnit.super.isSupportedBy(temporal);
+ return temporal.isSupported(this);
}
@SuppressWarnings("unchecked")
@@ -279,13 +269,13 @@
//-----------------------------------------------------------------------
@Override
public long between(Temporal temporal1, Temporal temporal2) {
- return temporal1.periodUntil(temporal2, this);
+ return temporal1.until(temporal2, this);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
- return getName();
+ return name;
}
}
--- a/jdk/src/share/classes/java/time/temporal/IsoFields.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/IsoFields.java Thu Jul 25 20:30:58 2013 -0400
@@ -71,6 +71,8 @@
import java.time.Duration;
import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
import java.time.format.ResolverStyle;
@@ -289,10 +291,6 @@
private static enum Field implements TemporalField {
DAY_OF_QUARTER {
@Override
- public String getName() {
- return "DayOfQuarter";
- }
- @Override
public TemporalUnit getBaseUnit() {
return DAYS;
}
@@ -344,17 +342,21 @@
return (R) temporal.with(DAY_OF_YEAR, temporal.getLong(DAY_OF_YEAR) + (newValue - curValue));
}
@Override
- public Map<TemporalField, Long> resolve(TemporalAccessor temporal, long doq, ResolverStyle resolverStyle) {
- if ((temporal.isSupported(YEAR) && temporal.isSupported(QUARTER_OF_YEAR)) == false) {
+ public ChronoLocalDate resolve(
+ Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
+ Long yearLong = fieldValues.get(YEAR);
+ Long qoyLong = fieldValues.get(QUARTER_OF_YEAR);
+ if (yearLong == null || qoyLong == null) {
return null;
}
- int y = temporal.get(YEAR); // validated
+ int y = YEAR.checkValidIntValue(yearLong); // always validate
+ long doq = fieldValues.get(DAY_OF_QUARTER);
LocalDate date;
if (resolverStyle == ResolverStyle.LENIENT) {
- long qoy = temporal.getLong(QUARTER_OF_YEAR); // unvalidated
- date = LocalDate.of(y, 1, 1).plusMonths(Math.multiplyExact(Math.subtractExact(qoy, 1), 3));
+ date = LocalDate.of(y, 1, 1).plusMonths(Math.multiplyExact(Math.subtractExact(qoyLong, 1), 3));
+ doq = Math.subtractExact(doq, 1);
} else {
- int qoy = temporal.get(QUARTER_OF_YEAR); // validated
+ int qoy = QUARTER_OF_YEAR.range().checkValidIntValue(qoyLong, QUARTER_OF_YEAR); // validated
date = LocalDate.of(y, ((qoy - 1) * 3) + 1, 1);
if (doq < 1 || doq > 90) {
if (resolverStyle == ResolverStyle.STRICT) {
@@ -363,21 +365,20 @@
range().checkValidValue(doq, this); // allow 1-92 rolling into next quarter
}
}
+ doq--;
}
- long epochDay = Math.addExact(date.toEpochDay(), Math.subtractExact(doq, 1));
- Map<TemporalField, Long> result = new HashMap<>(4, 1.0f);
- result.put(EPOCH_DAY, epochDay);
- result.put(YEAR, null);
- result.put(QUARTER_OF_YEAR, null);
- return result;
+ fieldValues.remove(this);
+ fieldValues.remove(YEAR);
+ fieldValues.remove(QUARTER_OF_YEAR);
+ return date.plusDays(doq);
+ }
+ @Override
+ public String toString() {
+ return "DayOfQuarter";
}
},
QUARTER_OF_YEAR {
@Override
- public String getName() {
- return "QuarterOfYear";
- }
- @Override
public TemporalUnit getBaseUnit() {
return QUARTER_YEARS;
}
@@ -409,20 +410,19 @@
range().checkValidValue(newValue, this); // strictly check from 1 to 4
return (R) temporal.with(MONTH_OF_YEAR, temporal.getLong(MONTH_OF_YEAR) + (newValue - curValue) * 3);
}
+ @Override
+ public String toString() {
+ return "QuarterOfYear";
+ }
},
WEEK_OF_WEEK_BASED_YEAR {
@Override
- public String getName() {
- return "WeekOfWeekBasedYear";
- }
-
- @Override
public String getDisplayName(Locale locale) {
Objects.requireNonNull(locale, "locale");
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
- return rb.containsKey("field.week") ? rb.getString("field.week") : getName();
+ return rb.containsKey("field.week") ? rb.getString("field.week") : toString();
}
@Override
@@ -463,14 +463,18 @@
return (R) temporal.plus(Math.subtractExact(newValue, getFrom(temporal)), WEEKS);
}
@Override
- public Map<TemporalField, Long> resolve(TemporalAccessor temporal, long wowby, ResolverStyle resolverStyle) {
- if ((temporal.isSupported(WEEK_BASED_YEAR) && temporal.isSupported(DAY_OF_WEEK)) == false) {
+ public ChronoLocalDate resolve(
+ Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
+ Long wbyLong = fieldValues.get(WEEK_BASED_YEAR);
+ Long dowLong = fieldValues.get(DAY_OF_WEEK);
+ if (wbyLong == null || dowLong == null) {
return null;
}
- int wby = temporal.get(WEEK_BASED_YEAR); // validated
+ int wby = WEEK_BASED_YEAR.range().checkValidIntValue(wbyLong, WEEK_BASED_YEAR); // always validate
+ long wowby = fieldValues.get(WEEK_OF_WEEK_BASED_YEAR);
LocalDate date = LocalDate.of(wby, 1, 4);
if (resolverStyle == ResolverStyle.LENIENT) {
- long dow = temporal.getLong(DAY_OF_WEEK); // unvalidated
+ long dow = dowLong; // unvalidated
if (dow > 7) {
date = date.plusWeeks((dow - 1) / 7);
dow = ((dow - 1) % 7) + 1;
@@ -480,7 +484,7 @@
}
date = date.plusWeeks(Math.subtractExact(wowby, 1)).with(DAY_OF_WEEK, dow);
} else {
- int dow = temporal.get(DAY_OF_WEEK); // validated
+ int dow = DAY_OF_WEEK.checkValidIntValue(dowLong); // validated
if (wowby < 1 || wowby > 52) {
if (resolverStyle == ResolverStyle.STRICT) {
getWeekRange(date).checkValidValue(wowby, this); // only allow exact range
@@ -490,19 +494,18 @@
}
date = date.plusWeeks(wowby - 1).with(DAY_OF_WEEK, dow);
}
- Map<TemporalField, Long> result = new HashMap<>(2, 1.0f);
- result.put(EPOCH_DAY, date.toEpochDay());
- result.put(WEEK_BASED_YEAR, null);
- result.put(DAY_OF_WEEK, null);
- return result;
+ fieldValues.remove(this);
+ fieldValues.remove(WEEK_BASED_YEAR);
+ fieldValues.remove(DAY_OF_WEEK);
+ return date;
+ }
+ @Override
+ public String toString() {
+ return "WeekOfWeekBasedYear";
}
},
WEEK_BASED_YEAR {
@Override
- public String getName() {
- return "WeekBasedYear";
- }
- @Override
public TemporalUnit getBaseUnit() {
return WEEK_BASED_YEARS;
}
@@ -537,6 +540,10 @@
date = date.withDayOfYear(180).withYear(newVal).with(WEEK_OF_WEEK_BASED_YEAR, week);
return (R) date.with(date);
}
+ @Override
+ public String toString() {
+ return "WeekBasedYear";
+ }
};
@Override
@@ -545,13 +552,13 @@
}
@Override
- public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
- return range();
+ public boolean isTimeBased() {
+ return false;
}
@Override
- public String toString() {
- return getName();
+ public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
+ return range();
}
//-------------------------------------------------------------------------
@@ -636,11 +643,6 @@
}
@Override
- public String getName() {
- return name;
- }
-
- @Override
public Duration getDuration() {
return duration;
}
@@ -651,6 +653,16 @@
}
@Override
+ public boolean isDateBased() {
+ return true;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public boolean isSupportedBy(Temporal temporal) {
return temporal.isSupported(EPOCH_DAY);
}
@@ -658,7 +670,7 @@
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R addTo(R temporal, long amount) {
- switch(this) {
+ switch (this) {
case WEEK_BASED_YEARS:
return (R) temporal.with(WEEK_BASED_YEAR,
Math.addExact(temporal.get(WEEK_BASED_YEAR), amount));
@@ -678,7 +690,7 @@
return Math.subtractExact(temporal2.getLong(WEEK_BASED_YEAR),
temporal1.getLong(WEEK_BASED_YEAR));
case QUARTER_YEARS:
- return temporal1.periodUntil(temporal2, MONTHS) / 3;
+ return temporal1.until(temporal2, MONTHS) / 3;
default:
throw new IllegalStateException("Unreachable");
}
@@ -686,8 +698,7 @@
@Override
public String toString() {
- return getName();
-
+ return name;
}
}
}
--- a/jdk/src/share/classes/java/time/temporal/JulianFields.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/JulianFields.java Thu Jul 25 20:30:58 2013 -0400
@@ -66,6 +66,9 @@
import static java.time.temporal.ChronoUnit.FOREVER;
import java.time.DateTimeException;
+import java.time.ZoneId;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.Chronology;
import java.time.format.ResolverStyle;
import java.util.Collections;
import java.util.Map;
@@ -233,11 +236,6 @@
//-----------------------------------------------------------------------
@Override
- public String getName() {
- return name;
- }
-
- @Override
public TemporalUnit getBaseUnit() {
return baseUnit;
}
@@ -253,6 +251,11 @@
}
@Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public ValueRange range() {
return range;
}
@@ -287,15 +290,14 @@
//-----------------------------------------------------------------------
@Override
- public Map<TemporalField, Long> resolve(TemporalAccessor temporal, long value, ResolverStyle resolverStyle) {
- long epochDay;
+ public ChronoLocalDate resolve(
+ Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
+ long value = fieldValues.remove(this);
if (resolverStyle == ResolverStyle.LENIENT) {
- epochDay = Math.subtractExact(value, offset);
- } else {
- range().checkValidValue(value, this);
- epochDay = value - offset;
+ return chronology.dateEpochDay(Math.subtractExact(value, offset));
}
- return Collections.<TemporalField, Long>singletonMap(EPOCH_DAY, epochDay);
+ range().checkValidValue(value, this);
+ return chronology.dateEpochDay(value - offset);
}
//-----------------------------------------------------------------------
--- a/jdk/src/share/classes/java/time/temporal/Temporal.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/Temporal.java Thu Jul 25 20:30:58 2013 -0400
@@ -62,7 +62,6 @@
package java.time.temporal;
import java.time.DateTimeException;
-import java.time.ZoneId;
/**
* Framework-level interface defining read-write access to a temporal object,
@@ -81,7 +80,8 @@
* See {@link ChronoField} for the standard set of fields.
* <p>
* Two pieces of date/time information cannot be represented by numbers,
- * the {@linkplain java.time.chrono.Chronology chronology} and the {@linkplain ZoneId time-zone}.
+ * the {@linkplain java.time.chrono.Chronology chronology} and the
+ * {@linkplain java.time.ZoneId time-zone}.
* These can be accessed via {@link #query(TemporalQuery) queries} using
* the static methods defined on {@link TemporalQuery}.
* <p>
@@ -129,6 +129,29 @@
public interface Temporal extends TemporalAccessor {
/**
+ * Checks if the specified unit is supported.
+ * <p>
+ * This checks if the specified unit can be added to, or subtracted from, this date-time.
+ * If false, then calling the {@link #plus(long, TemporalUnit)} and
+ * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
+ *
+ * @implSpec
+ * Implementations must check and handle all units defined in {@link ChronoUnit}.
+ * If the unit is supported, then true must be returned, otherwise false must be returned.
+ * <p>
+ * If the field is not a {@code ChronoUnit}, then the result of this method
+ * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
+ * passing {@code this} as the argument.
+ * <p>
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
+ *
+ * @param unit the unit to check, null returns false
+ * @return true if the unit can be added/subtracted, false if not
+ */
+ boolean isSupported(TemporalUnit unit);
+
+ /**
* Returns an adjusted object of the same type as this object with the adjustment made.
* <p>
* This adjusts this date-time according to the rules of the specified adjuster.
@@ -352,7 +375,7 @@
* The start and end points are {@code this} and the specified temporal.
* The result will be negative if the end is before the start.
* For example, the period in hours between two temporal objects can be
- * calculated using {@code startTime.periodUntil(endTime, HOURS)}.
+ * calculated using {@code startTime.until(endTime, HOURS)}.
* <p>
* The calculation returns a whole number, representing the number of
* complete units between the two temporals.
@@ -364,7 +387,7 @@
* The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
* <pre>
* // these two lines are equivalent
- * temporal = start.periodUntil(end, unit);
+ * temporal = start.until(end, unit);
* temporal = unit.between(start, end);
* </pre>
* The choice should be made based on which makes the code more readable.
@@ -372,7 +395,7 @@
* For example, this method allows the number of days between two dates to
* be calculated:
* <pre>
- * long daysBetween = start.periodUntil(end, DAYS);
+ * long daysBetween = start.until(end, DAYS);
* // or alternatively
* long daysBetween = DAYS.between(start, end);
* </pre>
@@ -399,7 +422,8 @@
* return unit.between(this, endTemporal);
* </pre>
* <p>
- * Neither this object, nor the specified temporal, may be altered.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param endTemporal the end temporal, of the same type as this object, not null
* @param unit the unit to measure the amount in, not null
@@ -410,6 +434,6 @@
* @throws UnsupportedTemporalTypeException if the unit is not supported
* @throws ArithmeticException if numeric overflow occurs
*/
- long periodUntil(Temporal endTemporal, TemporalUnit unit);
+ long until(Temporal endTemporal, TemporalUnit unit);
}
--- a/jdk/src/share/classes/java/time/temporal/TemporalAccessor.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/TemporalAccessor.java Thu Jul 25 20:30:58 2013 -0400
@@ -62,7 +62,6 @@
package java.time.temporal;
import java.time.DateTimeException;
-import java.time.ZoneId;
import java.util.Objects;
/**
@@ -80,7 +79,8 @@
* See {@link ChronoField} for the standard set of fields.
* <p>
* Two pieces of date/time information cannot be represented by numbers,
- * the {@linkplain java.time.chrono.Chronology chronology} and the {@linkplain ZoneId time-zone}.
+ * the {@linkplain java.time.chrono.Chronology chronology} and the
+ * {@linkplain java.time.ZoneId time-zone}.
* These can be accessed via {@linkplain #query(TemporalQuery) queries} using
* the static methods defined on {@link TemporalQuery}.
* <p>
@@ -111,13 +111,14 @@
*
* @implSpec
* Implementations must check and handle all fields defined in {@link ChronoField}.
- * If the field is supported, then true is returned, otherwise false
+ * If the field is supported, then true must be returned, otherwise false must be returned.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter either this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param field the field to check, null returns false
* @return true if this date-time can be queried for the field, false if not
@@ -146,7 +147,8 @@
* is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessorl)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter either this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
* <p>
* The default implementation must behave equivalent to this code:
* <pre>
@@ -154,7 +156,7 @@
* if (isSupported(field)) {
* return field.range();
* }
- * throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ * throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
* }
* return field.rangeRefinedBy(this);
* </pre>
@@ -169,7 +171,7 @@
if (isSupported(field)) {
return field.range();
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
Objects.requireNonNull(field, "field");
return field.rangeRefinedBy(this);
@@ -193,7 +195,8 @@
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
* <p>
* The default implementation must behave equivalent to this code:
* <pre>
@@ -240,7 +243,8 @@
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
* passing {@code this} as the argument.
* <p>
- * Implementations must not alter either this object.
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param field the field to get, not null
* @return the value for the field
@@ -291,6 +295,9 @@
* }
* return TemporalAccessor.super.query(query);
* </pre>
+ * <p>
+ * Implementations must ensure that no observable state is altered when this
+ * read-only method is invoked.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
--- a/jdk/src/share/classes/java/time/temporal/TemporalField.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/TemporalField.java Thu Jul 25 20:30:58 2013 -0400
@@ -62,6 +62,9 @@
package java.time.temporal;
import java.time.DateTimeException;
+import java.time.ZoneId;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.Chronology;
import java.time.format.ResolverStyle;
import java.util.Locale;
import java.util.Map;
@@ -93,29 +96,19 @@
public interface TemporalField {
/**
- * Gets a descriptive name for the field.
- * <p>
- * The should be of the format 'BaseOfRange', such as 'MonthOfYear',
- * unless the field has a range of {@code FOREVER}, when only
- * the base unit is mentioned, such as 'Year' or 'Era'.
- *
- * @return the name, not null
- */
- String getName();
-
- /**
* Gets the display name for the field in the requested locale.
* <p>
- * If there is no display name for the locale the value of {@code getName}
- * is returned.
+ * If there is no display name for the locale then a suitable default must be returned.
+ * <p>
+ * The default implementation must check the locale is not null
+ * and return {@code toString()}.
*
* @param locale the locale to use, not null
- * @return the display name for the locale or the value of {@code getName},
- * not null
+ * @return the display name for the locale or a suitable default, not null
*/
default String getDisplayName(Locale locale) {
- Objects.requireNonNull(locale, "local");
- return getName();
+ Objects.requireNonNull(locale, "locale");
+ return toString();
}
/**
@@ -164,28 +157,24 @@
* <p>
* A field is date-based if it can be derived from
* {@link ChronoField#EPOCH_DAY EPOCH_DAY}.
- * <p>
- * The default implementation must return false.
+ * Note that it is valid for both {@code isDateBased()} and {@code isTimeBased()}
+ * to return false, such as when representing a field like minute-of-week.
*
* @return true if this field is a component of a date
*/
- default boolean isDateBased() {
- return false;
- }
+ boolean isDateBased();
/**
* Checks if this field represents a component of a time.
* <p>
* A field is time-based if it can be derived from
* {@link ChronoField#NANO_OF_DAY NANO_OF_DAY}.
- * <p>
- * The default implementation must return false.
+ * Note that it is valid for both {@code isDateBased()} and {@code isTimeBased()}
+ * to return false, such as when representing a field like minute-of-week.
*
* @return true if this field is a component of a time
*/
- default boolean isTimeBased() {
- return false;
- }
+ boolean isTimeBased();
//-----------------------------------------------------------------------
/**
@@ -319,45 +308,79 @@
<R extends Temporal> R adjustInto(R temporal, long newValue);
/**
- * Resolves this field to provide a simpler alternative.
+ * Resolves this field to provide a simpler alternative or a date.
* <p>
* This method is invoked during the resolve phase of parsing.
* It is designed to allow application defined fields to be simplified into
- * more standard fields, such as those on {@code ChronoField}.
- * <p>
- * The method will only be invoked if the specified temporal supports this field.
- * The value of this field is provided.
+ * more standard fields, such as those on {@code ChronoField}, or into a date.
* <p>
- * The temporal must be queried using the methods of {@code TemporalAccessor},
- * not using {@code getFrom}, {@code isSupportedBy} or {@code rangeRefinedBy}.
- * Before querying any field, implementations must ensure it is supported, as
- * exceptions of this type would negatively affect the calculation of a parsed result.
+ * Applications should not normally invoke this method directly.
+ *
+ * @implSpec
+ * If an implementation represents a field that can be simplified, or
+ * combined with others, then this method must be implemented.
+ * <p>
+ * The specified map contains the current state of the parse.
+ * The map is mutable and must be mutated to resolve the field and
+ * any related fields. This method will only be invoked during parsing
+ * if the map contains this field, and implementations should therefore
+ * assume this field is present.
* <p>
- * If this field can resolve, it must return a map, if not it must return null.
- * The returned map contains the changes to be made to the temporal, expressed
- * as field-value pairs. If the value for a field is null, the field is to be
- * removed from the temporal. A null key must not be added to the result map.
+ * Resolving a field will consist of looking at the value of this field,
+ * and potentially other fields, and either updating the map with a
+ * simpler value, such as a {@code ChronoField}, or returning a
+ * complete {@code ChronoLocalDate}. If a resolve is successful,
+ * the code must remove all the fields that were resolved from the map,
+ * including this field.
+ * <p>
+ * For example, the {@code IsoFields} class contains the quarter-of-year
+ * and day-of-quarter fields. The implementation of this method in that class
+ * resolves the two fields plus the {@link ChronoField#YEAR YEAR} into a
+ * complete {@code LocalDate}. The resolve method will remove all three
+ * fields from the map before returning the {@code LocalDate}.
* <p>
- * If the result is non-null, this field will be removed from the temporal.
- * This field should not be added to the result map.
+ * If resolution should be possible, but the data is invalid, the resolver
+ * style should be used to determine an appropriate level of leniency, which
+ * may require throwing a {@code DateTimeException} or {@code ArithmeticException}.
+ * If no resolution is possible, the resolve method must return null.
* <p>
- * The {@link ResolverStyle} should be used by implementations to determine
- * how to perform the resolve.
+ * When resolving time fields, the map will be altered and null returned.
+ * When resolving date fields, the date is normally returned from the method,
+ * with the map altered to remove the resolved fields. However, it would also
+ * be acceptable for the date fields to be resolved into other {@code ChronoField}
+ * instances that can produce a date, such as {@code EPOCH_DAY}.
+ * <p>
+ * The zone is not normally required for resolution, but is provided for completeness.
* <p>
* The default implementation must return null.
*
- * @param temporal the temporal to resolve, not null
- * @param value the value of this field
+ * @param fieldValues the map of fields to values, which can be updated, not null
+ * @param chronology the effective chronology, not null
+ * @param zone the effective zone, not null
* @param resolverStyle the requested type of resolve, not null
- * @return a map of fields to update in the temporal, with a mapping to null
- * indicating a deletion. The whole map must be null if no resolving occurred
+ * @return the resolved date; null if resolving only changed the map,
+ * or no resolve occurred
+ * @throws ArithmeticException if numeric overflow occurs
* @throws DateTimeException if resolving results in an error. This must not be thrown
* by querying a field on the temporal without first checking if it is supported
- * @throws ArithmeticException if numeric overflow occurs
*/
- default Map<TemporalField, Long> resolve(
- TemporalAccessor temporal, long value, ResolverStyle resolverStyle) {
+ default ChronoLocalDate resolve(
+ Map<TemporalField, Long> fieldValues, Chronology chronology,
+ ZoneId zone, ResolverStyle resolverStyle) {
return null;
}
+ /**
+ * Gets a descriptive name for the field.
+ * <p>
+ * The should be of the format 'BaseOfRange', such as 'MonthOfYear',
+ * unless the field has a range of {@code FOREVER}, when only
+ * the base unit is mentioned, such as 'Year' or 'Era'.
+ *
+ * @return the name of the field, not null
+ */
+ @Override
+ String toString();
+
+
}
--- a/jdk/src/share/classes/java/time/temporal/TemporalUnit.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/TemporalUnit.java Thu Jul 25 20:30:58 2013 -0400
@@ -63,7 +63,11 @@
import java.time.DateTimeException;
import java.time.Duration;
+import java.time.LocalTime;
import java.time.Period;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoZonedDateTime;
/**
* A unit of date-time, such as Days or Hours.
@@ -93,15 +97,6 @@
public interface TemporalUnit {
/**
- * Gets a descriptive name for the unit.
- * <p>
- * This should be in the plural and upper-first camel case, such as 'Days' or 'Minutes'.
- *
- * @return the name, not null
- */
- String getName();
-
- /**
* Gets the duration of this unit, which may be an estimate.
* <p>
* All units return a duration measured in standard nanoseconds from this method.
@@ -132,6 +127,33 @@
//-----------------------------------------------------------------------
/**
+ * Checks if this unit represents a component of a date.
+ * <p>
+ * A date is time-based if it can be used to imply meaning from a date.
+ * It must have a {@linkplain #getDuration() duration} that is an integral
+ * multiple of the length of a standard day.
+ * Note that it is valid for both {@code isDateBased()} and {@code isTimeBased()}
+ * to return false, such as when representing a unit like 36 hours.
+ *
+ * @return true if this unit is a component of a date
+ */
+ boolean isDateBased();
+
+ /**
+ * Checks if this unit represents a component of a time.
+ * <p>
+ * A unit is time-based if it can be used to imply meaning from a time.
+ * It must have a {@linkplain #getDuration() duration} that divides into
+ * the length of a standard day without remainder.
+ * Note that it is valid for both {@code isDateBased()} and {@code isTimeBased()}
+ * to return false, such as when representing a unit like 36 hours.
+ *
+ * @return true if this unit is a component of a time
+ */
+ boolean isTimeBased();
+
+ //-----------------------------------------------------------------------
+ /**
* Checks if this unit is supported by the specified temporal object.
* <p>
* This checks that the implementing date-time can add/subtract this unit.
@@ -144,6 +166,15 @@
* @return true if the unit is supported
*/
default boolean isSupportedBy(Temporal temporal) {
+ if (temporal instanceof LocalTime) {
+ return isTimeBased();
+ }
+ if (temporal instanceof ChronoLocalDate) {
+ return isDateBased();
+ }
+ if (temporal instanceof ChronoLocalDateTime || temporal instanceof ChronoZonedDateTime) {
+ return true;
+ }
try {
temporal.plus(1, this);
return true;
@@ -212,11 +243,11 @@
* <p>
* There are two equivalent ways of using this method.
* The first is to invoke this method directly.
- * The second is to use {@link Temporal#periodUntil(Temporal, TemporalUnit)}:
+ * The second is to use {@link Temporal#until(Temporal, TemporalUnit)}:
* <pre>
* // these two lines are equivalent
* between = thisUnit.between(start, end);
- * between = start.periodUntil(end, thisUnit);
+ * between = start.until(end, thisUnit);
* </pre>
* The choice should be made based on which makes the code more readable.
* <p>
@@ -225,7 +256,7 @@
* <pre>
* long daysBetween = DAYS.between(start, end);
* // or alternatively
- * long daysBetween = start.periodUntil(end, DAYS);
+ * long daysBetween = start.until(end, DAYS);
* </pre>
* <p>
* Implementations should perform any queries or calculations using the units
@@ -245,7 +276,9 @@
//-----------------------------------------------------------------------
/**
- * Outputs this unit as a {@code String} using the name.
+ * Gets a descriptive name for the unit.
+ * <p>
+ * This should be in the plural and upper-first camel case, such as 'Days' or 'Minutes'.
*
* @return the name of this unit, not null
*/
--- a/jdk/src/share/classes/java/time/temporal/ValueRange.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/ValueRange.java Thu Jul 25 20:30:58 2013 -0400
@@ -331,7 +331,7 @@
private String genInvalidFieldMessage(TemporalField field, long value) {
if (field != null) {
- return "Invalid value for " + field.getName() + " (valid values " + this + "): " + value;
+ return "Invalid value for " + field + " (valid values " + this + "): " + value;
} else {
return "Invalid value (valid values " + this + "): " + value;
}
--- a/jdk/src/share/classes/java/time/temporal/WeekFields.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/time/temporal/WeekFields.java Thu Jul 25 20:30:58 2013 -0400
@@ -75,7 +75,9 @@
import java.io.InvalidObjectException;
import java.io.Serializable;
+import java.time.DateTimeException;
import java.time.DayOfWeek;
+import java.time.ZoneId;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Chronology;
import java.time.format.ResolverStyle;
@@ -395,6 +397,11 @@
* <p>
* For example, if the first day-of-week is Sunday, then that will have the
* value 1, with other days ranging from Monday as 2 to Saturday as 7.
+ * <p>
+ * In the resolving phase of parsing, a localized day-of-week will be converted
+ * to a standardized {@code ChronoField} day-of-week.
+ * The day-of-week must be in the valid range 1 to 7.
+ * Other fields in this class build dates using the standardized day-of-week.
*
* @return a field providing access to the day-of-week with localized numbering, not null
*/
@@ -421,6 +428,26 @@
* - if the 5th day of the month is a Monday, week two starts on the 5th and the 1st to 4th is in week one<br>
* <p>
* This field can be used with any calendar system.
+ * <p>
+ * In the resolving phase of parsing, a date can be created from a year,
+ * week-of-month, month-of-year and day-of-week.
+ * <p>
+ * In {@linkplain ResolverStyle#STRICT strict mode}, all four fields are
+ * validated against their range of valid values. The week-of-month field
+ * is validated to ensure that the resulting month is the month requested.
+ * <p>
+ * In {@linkplain ResolverStyle#SMART smart mode}, all four fields are
+ * validated against their range of valid values. The week-of-month field
+ * is validated from 0 to 6, meaning that the resulting date can be in a
+ * different month to that specified.
+ * <p>
+ * In {@linkplain ResolverStyle#LENIENT lenient mode}, the year and day-of-week
+ * are validated against the range of valid values. The resulting date is calculated
+ * equivalent to the following four stage approach.
+ * First, create a date on the first day of the first week of January in the requested year.
+ * Then take the month-of-year, subtract one, and add the amount in months to the date.
+ * Then take the week-of-month, subtract one, and add the amount in weeks to the date.
+ * Finally, adjust to the correct day-of-week within the localized week.
*
* @return a field providing access to the week-of-month, not null
*/
@@ -447,6 +474,25 @@
* - if the 5th day of the year is a Monday, week two starts on the 5th and the 1st to 4th is in week one<br>
* <p>
* This field can be used with any calendar system.
+ * <p>
+ * In the resolving phase of parsing, a date can be created from a year,
+ * week-of-year and day-of-week.
+ * <p>
+ * In {@linkplain ResolverStyle#STRICT strict mode}, all three fields are
+ * validated against their range of valid values. The week-of-year field
+ * is validated to ensure that the resulting year is the year requested.
+ * <p>
+ * In {@linkplain ResolverStyle#SMART smart mode}, all three fields are
+ * validated against their range of valid values. The week-of-year field
+ * is validated from 0 to 54, meaning that the resulting date can be in a
+ * different year to that specified.
+ * <p>
+ * In {@linkplain ResolverStyle#LENIENT lenient mode}, the year and day-of-week
+ * are validated against the range of valid values. The resulting date is calculated
+ * equivalent to the following three stage approach.
+ * First, create a date on the first day of the first week in the requested year.
+ * Then take the week-of-year, subtract one, and add the amount in weeks to the date.
+ * Finally, adjust to the correct day-of-week within the localized week.
*
* @return a field providing access to the week-of-year, not null
*/
@@ -477,6 +523,26 @@
* the 1st to 4th is in week one<br>
* <p>
* This field can be used with any calendar system.
+ * <p>
+ * In the resolving phase of parsing, a date can be created from a week-based-year,
+ * week-of-year and day-of-week.
+ * <p>
+ * In {@linkplain ResolverStyle#STRICT strict mode}, all three fields are
+ * validated against their range of valid values. The week-of-year field
+ * is validated to ensure that the resulting week-based-year is the
+ * week-based-year requested.
+ * <p>
+ * In {@linkplain ResolverStyle#SMART smart mode}, all three fields are
+ * validated against their range of valid values. The week-of-week-based-year field
+ * is validated from 1 to 53, meaning that the resulting date can be in the
+ * following week-based-year to that specified.
+ * <p>
+ * In {@linkplain ResolverStyle#LENIENT lenient mode}, the year and day-of-week
+ * are validated against the range of valid values. The resulting date is calculated
+ * equivalent to the following three stage approach.
+ * First, create a date on the first day of the first week in the requested week-based-year.
+ * Then take the week-of-week-based-year, subtract one, and add the amount in weeks to the date.
+ * Finally, adjust to the correct day-of-week within the localized week.
*
* @return a field providing access to the week-of-week-based-year, not null
*/
@@ -499,6 +565,26 @@
* is in the last week of the previous year.
* <p>
* This field can be used with any calendar system.
+ * <p>
+ * In the resolving phase of parsing, a date can be created from a week-based-year,
+ * week-of-year and day-of-week.
+ * <p>
+ * In {@linkplain ResolverStyle#STRICT strict mode}, all three fields are
+ * validated against their range of valid values. The week-of-year field
+ * is validated to ensure that the resulting week-based-year is the
+ * week-based-year requested.
+ * <p>
+ * In {@linkplain ResolverStyle#SMART smart mode}, all three fields are
+ * validated against their range of valid values. The week-of-week-based-year field
+ * is validated from 1 to 53, meaning that the resulting date can be in the
+ * following week-based-year to that specified.
+ * <p>
+ * In {@linkplain ResolverStyle#LENIENT lenient mode}, the year and day-of-week
+ * are validated against the range of valid values. The resulting date is calculated
+ * equivalent to the following three stage approach.
+ * First, create a date on the first day of the first week in the requested week-based-year.
+ * Then take the week-of-week-based-year, subtract one, and add the amount in weeks to the date.
+ * Finally, adjust to the correct day-of-week within the localized week.
*
* @return a field providing access to the week-based-year, not null
*/
@@ -615,9 +701,9 @@
* @param dow the day of the week
* @return a ChronoLocalDate for the requested year, week of year, and day of week
*/
- private ChronoLocalDate<?> ofWeekBasedYear(Chronology chrono,
+ private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
int yowby, int wowby, int dow) {
- ChronoLocalDate<?> date = chrono.date(yowby, 1, 1);
+ ChronoLocalDate date = chrono.date(yowby, 1, 1);
int ldow = localizedDayOfWeek(date);
int offset = startOfWeekOffset(1, ldow);
@@ -671,6 +757,11 @@
return Math.floorMod(isoDow - sow, 7) + 1;
}
+ private int localizedDayOfWeek(int isoDow) {
+ int sow = weekDef.getFirstDayOfWeek().getValue();
+ return Math.floorMod(isoDow - sow, 7) + 1;
+ }
+
private long localizedWeekOfMonth(TemporalAccessor temporal) {
int dow = localizedDayOfWeek(temporal);
int dom = temporal.get(DAY_OF_MONTH);
@@ -800,75 +891,121 @@
}
@Override
- public Map<TemporalField, Long> resolve(TemporalAccessor temporal, long value, ResolverStyle resolverStyle) {
- int newValue = range.checkValidIntValue(value, this);
- int sow = weekDef.getFirstDayOfWeek().getValue();
+ public ChronoLocalDate resolve(
+ Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
+ final long value = fieldValues.get(this);
+ final int newValue = Math.toIntExact(value); // broad limit makes overflow checking lighter
+ // first convert localized day-of-week to ISO day-of-week
+ // doing this first handles case where both ISO and localized were parsed and might mismatch
+ // day-of-week is always strict as two different day-of-week values makes lenient complex
if (rangeUnit == WEEKS) { // day-of-week
- int isoDow = Math.floorMod((sow - 1) + (newValue - 1), 7) + 1;
- return Collections.<TemporalField, Long>singletonMap(DAY_OF_WEEK, (long) isoDow);
- }
- if (temporal.isSupported(DAY_OF_WEEK) == false) {
+ final int checkedValue = range.checkValidIntValue(value, this); // no leniency as too complex
+ final int startDow = weekDef.getFirstDayOfWeek().getValue();
+ long isoDow = Math.floorMod((startDow - 1) + (checkedValue - 1), 7) + 1;
+ fieldValues.remove(this);
+ fieldValues.put(DAY_OF_WEEK, isoDow);
return null;
}
- Chronology chrono = Chronology.from(temporal); // defaults to ISO
- int dow = localizedDayOfWeek(temporal);
- if (temporal.isSupported(YEAR)) {
- int year = temporal.get(YEAR);
- if (rangeUnit == MONTHS) { // week-of-month
- if (temporal.isSupported(MONTH_OF_YEAR) == false) {
- return null;
- }
- int month = temporal.get(ChronoField.MONTH_OF_YEAR);
- @SuppressWarnings("rawtypes")
- ChronoLocalDate date = chrono.date(year, month, 1);
- int dateDow = localizedDayOfWeek(date);
- long weeks = newValue - localizedWeekOfMonth(date);
- int days = dow - dateDow;
- date = date.plus(weeks * 7 + days, DAYS);
- Map<TemporalField, Long> result = new HashMap<>(4, 1.0f);
- result.put(EPOCH_DAY, date.toEpochDay());
- result.put(YEAR, null);
- result.put(MONTH_OF_YEAR, null);
- result.put(DAY_OF_WEEK, null);
- return result;
- } else if (rangeUnit == YEARS) { // week-of-year
- @SuppressWarnings("rawtypes")
- ChronoLocalDate date = chrono.date(year, 1, 1);
- int dateDow = localizedDayOfWeek(date);
- long weeks = newValue - localizedWeekOfYear(date);
- int days = dow - dateDow;
- date = date.plus(weeks * 7 + days, DAYS);
- Map<TemporalField, Long> result = new HashMap<>(4, 1.0f);
- result.put(EPOCH_DAY, date.toEpochDay());
- result.put(YEAR, null);
- result.put(DAY_OF_WEEK, null);
- return result;
+
+ // can only build date if ISO day-of-week is present
+ if (fieldValues.containsKey(DAY_OF_WEEK) == false) {
+ return null;
+ }
+ int isoDow = DAY_OF_WEEK.checkValidIntValue(fieldValues.get(DAY_OF_WEEK));
+ int dow = localizedDayOfWeek(isoDow);
+
+ // build date
+ if (fieldValues.containsKey(YEAR)) {
+ int year = YEAR.checkValidIntValue(fieldValues.get(YEAR)); // validate
+ if (rangeUnit == MONTHS && fieldValues.containsKey(MONTH_OF_YEAR)) { // week-of-month
+ long month = fieldValues.get(MONTH_OF_YEAR); // not validated yet
+ return resolveWoM(fieldValues, chronology, year, month, newValue, dow, resolverStyle);
}
- } else if (rangeUnit == WEEK_BASED_YEARS || rangeUnit == FOREVER) {
- if (temporal.isSupported(weekDef.weekBasedYear) &&
- temporal.isSupported(weekDef.weekOfWeekBasedYear)) {
- // week-of-week-based-year and year-of-week-based-year
- int yowby = temporal.get(weekDef.weekBasedYear);
- int wowby = temporal.get(weekDef.weekOfWeekBasedYear);
- ChronoLocalDate<?> date = ofWeekBasedYear(Chronology.from(temporal), yowby, wowby, dow);
-
- Map<TemporalField, Long> result = new HashMap<>(4, 1.0f);
- result.put(EPOCH_DAY, date.toEpochDay());
- result.put(DAY_OF_WEEK, null);
- result.put(weekDef.weekOfWeekBasedYear, null);
- result.put(weekDef.weekBasedYear, null);
- return result;
+ if (rangeUnit == YEARS) { // week-of-year
+ return resolveWoY(fieldValues, chronology, year, newValue, dow, resolverStyle);
}
+ } else if ((rangeUnit == WEEK_BASED_YEARS || rangeUnit == FOREVER) &&
+ fieldValues.containsKey(weekDef.weekBasedYear) &&
+ fieldValues.containsKey(weekDef.weekOfWeekBasedYear)) { // week-of-week-based-year and year-of-week-based-year
+ return resolveWBY(fieldValues, chronology, dow, resolverStyle);
}
return null;
}
- //-----------------------------------------------------------------------
- @Override
- public String getName() {
- return name;
+ private ChronoLocalDate resolveWoM(
+ Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long month, long wom, int localDow, ResolverStyle resolverStyle) {
+ ChronoLocalDate date;
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ date = chrono.date(year, 1, 1).plus(Math.subtractExact(month, 1), MONTHS);
+ long weeks = Math.subtractExact(wom, localizedWeekOfMonth(date));
+ int days = localDow - localizedDayOfWeek(date); // safe from overflow
+ date = date.plus(Math.addExact(Math.multiplyExact(weeks, 7), days), DAYS);
+ } else {
+ int monthValid = MONTH_OF_YEAR.checkValidIntValue(month); // validate
+ date = chrono.date(year, monthValid, 1);
+ int womInt = range.checkValidIntValue(wom, this); // validate
+ int weeks = (int) (womInt - localizedWeekOfMonth(date)); // safe from overflow
+ int days = localDow - localizedDayOfWeek(date); // safe from overflow
+ date = date.plus(weeks * 7 + days, DAYS);
+ if (resolverStyle == ResolverStyle.STRICT && date.getLong(MONTH_OF_YEAR) != month) {
+ throw new DateTimeException("Strict mode rejected resolved date as it is in a different month");
+ }
+ }
+ fieldValues.remove(this);
+ fieldValues.remove(YEAR);
+ fieldValues.remove(MONTH_OF_YEAR);
+ fieldValues.remove(DAY_OF_WEEK);
+ return date;
}
+ private ChronoLocalDate resolveWoY(
+ Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long woy, int localDow, ResolverStyle resolverStyle) {
+ ChronoLocalDate date = chrono.date(year, 1, 1);
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ long weeks = Math.subtractExact(woy, localizedWeekOfYear(date));
+ int days = localDow - localizedDayOfWeek(date); // safe from overflow
+ date = date.plus(Math.addExact(Math.multiplyExact(weeks, 7), days), DAYS);
+ } else {
+ int womInt = range.checkValidIntValue(woy, this); // validate
+ int weeks = (int) (womInt - localizedWeekOfYear(date)); // safe from overflow
+ int days = localDow - localizedDayOfWeek(date); // safe from overflow
+ date = date.plus(weeks * 7 + days, DAYS);
+ if (resolverStyle == ResolverStyle.STRICT && date.getLong(YEAR) != year) {
+ throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
+ }
+ }
+ fieldValues.remove(this);
+ fieldValues.remove(YEAR);
+ fieldValues.remove(DAY_OF_WEEK);
+ return date;
+ }
+
+ private ChronoLocalDate resolveWBY(
+ Map<TemporalField, Long> fieldValues, Chronology chrono, int localDow, ResolverStyle resolverStyle) {
+ int yowby = weekDef.weekBasedYear.range().checkValidIntValue(
+ fieldValues.get(weekDef.weekBasedYear), weekDef.weekBasedYear);
+ ChronoLocalDate date;
+ if (resolverStyle == ResolverStyle.LENIENT) {
+ date = ofWeekBasedYear(chrono, yowby, 1, localDow);
+ long wowby = fieldValues.get(weekDef.weekOfWeekBasedYear);
+ long weeks = Math.subtractExact(wowby, 1);
+ date = date.plus(weeks, WEEKS);
+ } else {
+ int wowby = weekDef.weekOfWeekBasedYear.range().checkValidIntValue(
+ fieldValues.get(weekDef.weekOfWeekBasedYear), weekDef.weekOfWeekBasedYear); // validate
+ date = ofWeekBasedYear(chrono, yowby, wowby, localDow);
+ if (resolverStyle == ResolverStyle.STRICT && localizedWeekBasedYear(date) != yowby) {
+ throw new DateTimeException("Strict mode rejected resolved date as it is in a different week-based-year");
+ }
+ }
+ fieldValues.remove(this);
+ fieldValues.remove(weekDef.weekBasedYear);
+ fieldValues.remove(weekDef.weekOfWeekBasedYear);
+ fieldValues.remove(DAY_OF_WEEK);
+ return date;
+ }
+
+ //-----------------------------------------------------------------------
@Override
public String getDisplayName(Locale locale) {
Objects.requireNonNull(locale, "locale");
@@ -876,9 +1013,9 @@
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
- return rb.containsKey("field.week") ? rb.getString("field.week") : getName();
+ return rb.containsKey("field.week") ? rb.getString("field.week") : name;
}
- return getName();
+ return name;
}
@Override
@@ -897,6 +1034,11 @@
}
@Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public ValueRange range() {
return range;
}
@@ -988,7 +1130,7 @@
//-----------------------------------------------------------------------
@Override
public String toString() {
- return getName() + "[" + weekDef.toString() + "]";
+ return name + "[" + weekDef.toString() + "]";
}
}
}
--- a/jdk/src/share/classes/java/util/PriorityQueue.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/PriorityQueue.java Thu Jul 25 20:30:58 2013 -0400
@@ -136,6 +136,19 @@
}
/**
+ * Creates a {@code PriorityQueue} with the default initial capacity
+ * that orders its elements according to the specified comparator.
+ *
+ * @param comparator the comparator that will be used to order this
+ * priority queue. If {@code null}, the {@linkplain Comparable
+ * natural ordering} of the elements will be used.
+ * @since 1.8
+ */
+ public PriorityQueue(Comparator<? super E> comparator) {
+ this(DEFAULT_INITIAL_CAPACITY, comparator);
+ }
+
+ /**
* Creates a {@code PriorityQueue} with the specified initial capacity
* that orders its elements according to the specified comparator.
*
--- a/jdk/src/share/classes/java/util/concurrent/AbstractExecutorService.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/AbstractExecutorService.java Thu Jul 25 20:30:58 2013 -0400
@@ -76,6 +76,7 @@
*
* @param runnable the runnable task being wrapped
* @param value the default value for the returned future
+ * @param <T> the type of the given value
* @return a {@code RunnableFuture} which, when run, will run the
* underlying runnable and which, as a {@code Future}, will yield
* the given value as its result and provide for cancellation of
@@ -90,6 +91,7 @@
* Returns a {@code RunnableFuture} for the given callable task.
*
* @param callable the callable task being wrapped
+ * @param <T> the type of the callable's result
* @return a {@code RunnableFuture} which, when run, will call the
* underlying callable and which, as a {@code Future}, will yield
* the callable's result as its result and provide for
--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java Thu Jul 25 20:30:58 2013 -0400
@@ -265,7 +265,8 @@
* @param <K> the type of keys maintained by this map
* @param <V> the type of mapped values
*/
-public class ConcurrentHashMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Serializable {
+public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
+ implements ConcurrentMap<K,V>, Serializable {
private static final long serialVersionUID = 7249069246763182397L;
/*
@@ -439,16 +440,18 @@
* related operations (which is the main reason we cannot use
* existing collections such as TreeMaps). TreeBins contain
* Comparable elements, but may contain others, as well as
- * elements that are Comparable but not necessarily Comparable
- * for the same T, so we cannot invoke compareTo among them. To
- * handle this, the tree is ordered primarily by hash value, then
- * by Comparable.compareTo order if applicable. On lookup at a
- * node, if elements are not comparable or compare as 0 then both
- * left and right children may need to be searched in the case of
- * tied hash values. (This corresponds to the full list search
- * that would be necessary if all elements were non-Comparable and
- * had tied hashes.) The red-black balancing code is updated from
- * pre-jdk-collections
+ * elements that are Comparable but not necessarily Comparable for
+ * the same T, so we cannot invoke compareTo among them. To handle
+ * this, the tree is ordered primarily by hash value, then by
+ * Comparable.compareTo order if applicable. On lookup at a node,
+ * if elements are not comparable or compare as 0 then both left
+ * and right children may need to be searched in the case of tied
+ * hash values. (This corresponds to the full list search that
+ * would be necessary if all elements were non-Comparable and had
+ * tied hashes.) On insertion, to keep a total ordering (or as
+ * close as is required here) across rebalancings, we compare
+ * classes and identityHashCodes as tie-breakers. The red-black
+ * balancing code is updated from pre-jdk-collections
* (http://gee.cs.oswego.edu/dl/classes/collections/RBCell.java)
* based in turn on Cormen, Leiserson, and Rivest "Introduction to
* Algorithms" (CLR).
@@ -478,6 +481,10 @@
* unused "Segment" class that is instantiated in minimal form
* only when serializing.
*
+ * Also, solely for compatibility with previous versions of this
+ * class, it extends AbstractMap, even though all of its methods
+ * are overridden, so it is just useless baggage.
+ *
* This file is organized to make things a little easier to follow
* while reading than they might otherwise: First the main static
* declarations and utilities, then fields, then main public
@@ -1352,6 +1359,7 @@
* Saves the state of the {@code ConcurrentHashMap} instance to a
* stream (i.e., serializes it).
* @param s the stream
+ * @throws java.io.IOException if an I/O error occurs
* @serialData
* the key (Object) and value (Object)
* for each key-value mapping, followed by a null pair.
@@ -1394,6 +1402,9 @@
/**
* Reconstitutes the instance from a stream (that is, deserializes it).
* @param s the stream
+ * @throws ClassNotFoundException if the class of a serialized object
+ * could not be found
+ * @throws java.io.IOException if an I/O error occurs
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
@@ -2080,6 +2091,7 @@
* Creates a new {@link Set} backed by a ConcurrentHashMap
* from the given type to {@code Boolean.TRUE}.
*
+ * @param <K> the element type of the returned set
* @return the new set
* @since 1.8
*/
@@ -2094,9 +2106,10 @@
*
* @param initialCapacity The implementation performs internal
* sizing to accommodate this many elements.
+ * @param <K> the element type of the returned set
+ * @return the new set
* @throws IllegalArgumentException if the initial capacity of
* elements is negative
- * @return the new set
* @since 1.8
*/
public static <K> KeySetView<K,Boolean> newKeySet(int initialCapacity) {
@@ -2643,19 +2656,18 @@
p = pr;
else if ((pk = p.key) == k || (pk != null && k.equals(pk)))
return p;
- else if (pl == null && pr == null)
- break;
+ else if (pl == null)
+ p = pr;
+ else if (pr == null)
+ p = pl;
else if ((kc != null ||
(kc = comparableClassFor(k)) != null) &&
(dir = compareComparables(kc, k, pk)) != 0)
p = (dir < 0) ? pl : pr;
- else if (pl == null)
- p = pr;
- else if (pr == null ||
- (q = pr.findTreeNode(h, k, kc)) == null)
+ else if ((q = pr.findTreeNode(h, k, kc)) != null)
+ return q;
+ else
p = pl;
- else
- return q;
} while (p != null);
}
return null;
@@ -2682,6 +2694,23 @@
static final int READER = 4; // increment value for setting read lock
/**
+ * Tie-breaking utility for ordering insertions when equal
+ * hashCodes and non-comparable. We don't require a total
+ * order, just a consistent insertion rule to maintain
+ * equivalence across rebalancings. Tie-breaking further than
+ * necessary simplifies testing a bit.
+ */
+ static int tieBreakOrder(Object a, Object b) {
+ int d;
+ if (a == null || b == null ||
+ (d = a.getClass().getName().
+ compareTo(b.getClass().getName())) == 0)
+ d = (System.identityHashCode(a) <= System.identityHashCode(b) ?
+ -1 : 1);
+ return d;
+ }
+
+ /**
* Creates bin with initial set of nodes headed by b.
*/
TreeBin(TreeNode<K,V> b) {
@@ -2697,21 +2726,21 @@
r = x;
}
else {
- Object key = x.key;
- int hash = x.hash;
+ K k = x.key;
+ int h = x.hash;
Class<?> kc = null;
for (TreeNode<K,V> p = r;;) {
int dir, ph;
- if ((ph = p.hash) > hash)
+ K pk = p.key;
+ if ((ph = p.hash) > h)
dir = -1;
- else if (ph < hash)
+ else if (ph < h)
dir = 1;
- else if ((kc != null ||
- (kc = comparableClassFor(key)) != null))
- dir = compareComparables(kc, key, p.key);
- else
- dir = 0;
- TreeNode<K,V> xp = p;
+ else if ((kc == null &&
+ (kc = comparableClassFor(k)) == null) ||
+ (dir = compareComparables(kc, k, pk)) == 0)
+ dir = tieBreakOrder(k, pk);
+ TreeNode<K,V> xp = p;
if ((p = (dir <= 0) ? p.left : p.right) == null) {
x.parent = xp;
if (dir <= 0)
@@ -2725,6 +2754,7 @@
}
}
this.root = r;
+ assert checkInvariants(root);
}
/**
@@ -2805,8 +2835,9 @@
*/
final TreeNode<K,V> putTreeVal(int h, K k, V v) {
Class<?> kc = null;
+ boolean searched = false;
for (TreeNode<K,V> p = root;;) {
- int dir, ph; K pk; TreeNode<K,V> q, pr;
+ int dir, ph; K pk;
if (p == null) {
first = root = new TreeNode<K,V>(h, k, v, null, null);
break;
@@ -2820,21 +2851,25 @@
else if ((kc == null &&
(kc = comparableClassFor(k)) == null) ||
(dir = compareComparables(kc, k, pk)) == 0) {
- if (p.left == null)
- dir = 1;
- else if ((pr = p.right) == null ||
- (q = pr.findTreeNode(h, k, kc)) == null)
- dir = -1;
- else
- return q;
+ if (!searched) {
+ TreeNode<K,V> q, ch;
+ searched = true;
+ if (((ch = p.left) != null &&
+ (q = ch.findTreeNode(h, k, kc)) != null) ||
+ ((ch = p.right) != null &&
+ (q = ch.findTreeNode(h, k, kc)) != null))
+ return q;
+ }
+ dir = tieBreakOrder(k, pk);
}
+
TreeNode<K,V> xp = p;
- if ((p = (dir < 0) ? p.left : p.right) == null) {
+ if ((p = (dir <= 0) ? p.left : p.right) == null) {
TreeNode<K,V> x, f = first;
first = x = new TreeNode<K,V>(h, k, v, f, xp);
if (f != null)
f.prev = x;
- if (dir < 0)
+ if (dir <= 0)
xp.left = x;
else
xp.right = x;
@@ -3546,6 +3581,7 @@
* for an element, or null if there is no transformation (in
* which case the action is not applied)
* @param action the action
+ * @param <U> the return type of the transformer
* @since 1.8
*/
public <U> void forEach(long parallelismThreshold,
@@ -3569,6 +3605,7 @@
* needed for this operation to be executed in parallel
* @param searchFunction a function returning a non-null
* result on success, else null
+ * @param <U> the return type of the search function
* @return a non-null result from applying the given search
* function on each (key, value), or null if none
* @since 1.8
@@ -3592,6 +3629,7 @@
* for an element, or null if there is no transformation (in
* which case it is not combined)
* @param reducer a commutative associative combining function
+ * @param <U> the return type of the transformer
* @return the result of accumulating the given transformation
* of all (key, value) pairs
* @since 1.8
@@ -3710,6 +3748,7 @@
* for an element, or null if there is no transformation (in
* which case the action is not applied)
* @param action the action
+ * @param <U> the return type of the transformer
* @since 1.8
*/
public <U> void forEachKey(long parallelismThreshold,
@@ -3733,6 +3772,7 @@
* needed for this operation to be executed in parallel
* @param searchFunction a function returning a non-null
* result on success, else null
+ * @param <U> the return type of the search function
* @return a non-null result from applying the given search
* function on each key, or null if none
* @since 1.8
@@ -3775,6 +3815,7 @@
* for an element, or null if there is no transformation (in
* which case it is not combined)
* @param reducer a commutative associative combining function
+ * @param <U> the return type of the transformer
* @return the result of accumulating the given transformation
* of all keys
* @since 1.8
@@ -3894,6 +3935,7 @@
* for an element, or null if there is no transformation (in
* which case the action is not applied)
* @param action the action
+ * @param <U> the return type of the transformer
* @since 1.8
*/
public <U> void forEachValue(long parallelismThreshold,
@@ -3917,6 +3959,7 @@
* needed for this operation to be executed in parallel
* @param searchFunction a function returning a non-null
* result on success, else null
+ * @param <U> the return type of the search function
* @return a non-null result from applying the given search
* function on each value, or null if none
* @since 1.8
@@ -3958,6 +4001,7 @@
* for an element, or null if there is no transformation (in
* which case it is not combined)
* @param reducer a commutative associative combining function
+ * @param <U> the return type of the transformer
* @return the result of accumulating the given transformation
* of all values
* @since 1.8
@@ -4075,6 +4119,7 @@
* for an element, or null if there is no transformation (in
* which case the action is not applied)
* @param action the action
+ * @param <U> the return type of the transformer
* @since 1.8
*/
public <U> void forEachEntry(long parallelismThreshold,
@@ -4098,6 +4143,7 @@
* needed for this operation to be executed in parallel
* @param searchFunction a function returning a non-null
* result on success, else null
+ * @param <U> the return type of the search function
* @return a non-null result from applying the given search
* function on each entry, or null if none
* @since 1.8
@@ -4139,6 +4185,7 @@
* for an element, or null if there is no transformation (in
* which case it is not combined)
* @param reducer a commutative associative combining function
+ * @param <U> the return type of the transformer
* @return the result of accumulating the given transformation
* of all entries
* @since 1.8
--- a/jdk/src/share/classes/java/util/concurrent/ExecutorService.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/ExecutorService.java Thu Jul 25 20:30:58 2013 -0400
@@ -227,6 +227,7 @@
* {@link Callable} form so they can be submitted.
*
* @param task the task to submit
+ * @param <T> the type of the task's result
* @return a Future representing pending completion of the task
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
@@ -241,6 +242,7 @@
*
* @param task the task to submit
* @param result the result to return
+ * @param <T> the type of the result
* @return a Future representing pending completion of the task
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
@@ -272,6 +274,7 @@
* collection is modified while this operation is in progress.
*
* @param tasks the collection of tasks
+ * @param <T> the type of the values returned from the tasks
* @return a list of Futures representing the tasks, in the same
* sequential order as produced by the iterator for the
* given task list, each of which has completed
@@ -299,6 +302,7 @@
* @param tasks the collection of tasks
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
+ * @param <T> the type of the values returned from the tasks
* @return a list of Futures representing the tasks, in the same
* sequential order as produced by the iterator for the
* given task list. If the operation did not time out,
@@ -324,6 +328,7 @@
* collection is modified while this operation is in progress.
*
* @param tasks the collection of tasks
+ * @param <T> the type of the values returned from the tasks
* @return the result returned by one of the tasks
* @throws InterruptedException if interrupted while waiting
* @throws NullPointerException if tasks or any element task
@@ -348,6 +353,7 @@
* @param tasks the collection of tasks
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
+ * @param <T> the type of the values returned from the tasks
* @return the result returned by one of the tasks
* @throws InterruptedException if interrupted while waiting
* @throws NullPointerException if tasks, or unit, or any element
--- a/jdk/src/share/classes/java/util/concurrent/Executors.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/Executors.java Thu Jul 25 20:30:58 2013 -0400
@@ -397,6 +397,7 @@
* {@code Callable} to an otherwise resultless action.
* @param task the task to run
* @param result the result to return
+ * @param <T> the type of the result
* @return a callable object
* @throws NullPointerException if task null
*/
@@ -458,6 +459,7 @@
* action; or if not possible, throw an associated {@link
* AccessControlException}.
* @param callable the underlying task
+ * @param <T> the type of the callable's result
* @return a callable object
* @throws NullPointerException if callable null
*/
@@ -480,6 +482,7 @@
* AccessControlException}.
*
* @param callable the underlying task
+ * @param <T> the type of the callable's result
* @return a callable object
* @throws NullPointerException if callable null
* @throws AccessControlException if the current access control
--- a/jdk/src/share/classes/java/util/concurrent/ForkJoinPool.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/ForkJoinPool.java Thu Jul 25 20:30:58 2013 -0400
@@ -561,8 +561,8 @@
* Returns a new worker thread operating in the given pool.
*
* @param pool the pool this thread works in
+ * @return the new worker thread
* @throws NullPointerException if the pool is null
- * @return the new worker thread
*/
public ForkJoinWorkerThread newThread(ForkJoinPool pool);
}
@@ -2497,6 +2497,7 @@
* minimally only the latter.
*
* @param task the task
+ * @param <T> the type of the task's result
* @return the task's result
* @throws NullPointerException if the task is null
* @throws RejectedExecutionException if the task cannot be
@@ -2545,6 +2546,7 @@
* Submits a ForkJoinTask for execution.
*
* @param task the task to submit
+ * @param <T> the type of the task's result
* @return the task
* @throws NullPointerException if the task is null
* @throws RejectedExecutionException if the task cannot be
--- a/jdk/src/share/classes/java/util/concurrent/ForkJoinTask.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/ForkJoinTask.java Thu Jul 25 20:30:58 2013 -0400
@@ -810,6 +810,7 @@
* unprocessed.
*
* @param tasks the collection of tasks
+ * @param <T> the type of the values returned from the tasks
* @return the tasks argument, to simplify usage
* @throws NullPointerException if tasks or any element are null
*/
@@ -1472,6 +1473,7 @@
*
* @param runnable the runnable action
* @param result the result upon completion
+ * @param <T> the type of the result
* @return the task
*/
public static <T> ForkJoinTask<T> adapt(Runnable runnable, T result) {
@@ -1485,6 +1487,7 @@
* encountered into {@code RuntimeException}.
*
* @param callable the callable action
+ * @param <T> the type of the callable's result
* @return the task
*/
public static <T> ForkJoinTask<T> adapt(Callable<? extends T> callable) {
@@ -1498,6 +1501,8 @@
/**
* Saves this task to a stream (that is, serializes it).
*
+ * @param s the stream
+ * @throws java.io.IOException if an I/O error occurs
* @serialData the current run status and the exception thrown
* during execution, or {@code null} if none
*/
@@ -1509,6 +1514,10 @@
/**
* Reconstitutes this task from a stream (that is, deserializes it).
+ * @param s the stream
+ * @throws ClassNotFoundException if the class of a serialized object
+ * could not be found
+ * @throws java.io.IOException if an I/O error occurs
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
--- a/jdk/src/share/classes/java/util/concurrent/ScheduledExecutorService.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/ScheduledExecutorService.java Thu Jul 25 20:30:58 2013 -0400
@@ -117,6 +117,7 @@
* @param callable the function to execute
* @param delay the time from now to delay execution
* @param unit the time unit of the delay parameter
+ * @param <V> the type of the callable's result
* @return a ScheduledFuture that can be used to extract result or cancel
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
--- a/jdk/src/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java Thu Jul 25 20:30:58 2013 -0400
@@ -392,6 +392,7 @@
*
* @param runnable the submitted Runnable
* @param task the task created to execute the runnable
+ * @param <V> the type of the task's result
* @return a task that can execute the runnable
* @since 1.6
*/
@@ -408,6 +409,7 @@
*
* @param callable the submitted Callable
* @param task the task created to execute the callable
+ * @param <V> the type of the task's result
* @return a task that can execute the callable
* @since 1.6
*/
--- a/jdk/src/share/classes/java/util/concurrent/TimeUnit.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/TimeUnit.java Thu Jul 25 20:30:58 2013 -0400
@@ -69,6 +69,9 @@
* @author Doug Lea
*/
public enum TimeUnit {
+ /**
+ * Time unit representing one thousandth of a microsecond
+ */
NANOSECONDS {
public long toNanos(long d) { return d; }
public long toMicros(long d) { return d/(C1/C0); }
@@ -80,6 +83,10 @@
public long convert(long d, TimeUnit u) { return u.toNanos(d); }
int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
},
+
+ /**
+ * Time unit representing one thousandth of a millisecond
+ */
MICROSECONDS {
public long toNanos(long d) { return x(d, C1/C0, MAX/(C1/C0)); }
public long toMicros(long d) { return d; }
@@ -91,6 +98,10 @@
public long convert(long d, TimeUnit u) { return u.toMicros(d); }
int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); }
},
+
+ /**
+ * Time unit representing one thousandth of a second
+ */
MILLISECONDS {
public long toNanos(long d) { return x(d, C2/C0, MAX/(C2/C0)); }
public long toMicros(long d) { return x(d, C2/C1, MAX/(C2/C1)); }
@@ -102,6 +113,10 @@
public long convert(long d, TimeUnit u) { return u.toMillis(d); }
int excessNanos(long d, long m) { return 0; }
},
+
+ /**
+ * Time unit representing one second
+ */
SECONDS {
public long toNanos(long d) { return x(d, C3/C0, MAX/(C3/C0)); }
public long toMicros(long d) { return x(d, C3/C1, MAX/(C3/C1)); }
@@ -113,6 +128,10 @@
public long convert(long d, TimeUnit u) { return u.toSeconds(d); }
int excessNanos(long d, long m) { return 0; }
},
+
+ /**
+ * Time unit representing sixty seconds
+ */
MINUTES {
public long toNanos(long d) { return x(d, C4/C0, MAX/(C4/C0)); }
public long toMicros(long d) { return x(d, C4/C1, MAX/(C4/C1)); }
@@ -124,6 +143,10 @@
public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
int excessNanos(long d, long m) { return 0; }
},
+
+ /**
+ * Time unit representing sixty minutes
+ */
HOURS {
public long toNanos(long d) { return x(d, C5/C0, MAX/(C5/C0)); }
public long toMicros(long d) { return x(d, C5/C1, MAX/(C5/C1)); }
@@ -135,6 +158,10 @@
public long convert(long d, TimeUnit u) { return u.toHours(d); }
int excessNanos(long d, long m) { return 0; }
},
+
+ /**
+ * Time unit representing twenty four hours
+ */
DAYS {
public long toNanos(long d) { return x(d, C6/C0, MAX/(C6/C0)); }
public long toMicros(long d) { return x(d, C6/C1, MAX/(C6/C1)); }
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Thu Jul 25 20:30:58 2013 -0400
@@ -71,6 +71,7 @@
*
* @param tclass the class of the objects holding the field
* @param fieldName the name of the field to be updated
+ * @param <U> the type of instances of tclass
* @return the updater
* @throws IllegalArgumentException if the field is not a
* volatile integer type
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Thu Jul 25 20:30:58 2013 -0400
@@ -71,6 +71,7 @@
*
* @param tclass the class of the objects holding the field
* @param fieldName the name of the field to be updated
+ * @param <U> the type of instances of tclass
* @return the updater
* @throws IllegalArgumentException if the field is not a
* volatile long type
--- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Thu Jul 25 20:30:58 2013 -0400
@@ -91,6 +91,8 @@
* @param tclass the class of the objects holding the field
* @param vclass the class of the field
* @param fieldName the name of the field to be updated
+ * @param <U> the type of instances of tclass
+ * @param <W> the type of instances of vclass
* @return the updater
* @throws ClassCastException if the field is of the wrong type
* @throws IllegalArgumentException if the field is not volatile
--- a/jdk/src/share/classes/java/util/function/BiConsumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/BiConsumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,13 +27,16 @@
import java.util.Objects;
/**
- * An operation which accepts two input arguments and returns no result. This is
- * the two-arity specialization of {@link Consumer}. Unlike most other
- * functional interfaces, {@code BiConsumer} is expected to operate via
- * side-effects.
+ * Represents an operation that accepts two input arguments and returns no
+ * result. This is the two-arity specialization of {@link Consumer}.
+ * Unlike most other functional interfaces, {@code BiConsumer} is expected
+ * to operate via side-effects.
*
- * @param <T> the type of the first argument to the {@code accept} operation
- * @param <U> the type of the second argument to the {@code accept} operation
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(Object, Object)}.
+ *
+ * @param <T> the type of the first argument to the operation
+ * @param <U> the type of the second argument to the operation
*
* @see Consumer
* @since 1.8
@@ -42,35 +45,31 @@
public interface BiConsumer<T, U> {
/**
- * Performs operations upon the provided objects which may modify those
- * objects and/or external state.
+ * Performs this operation on the given arguments.
*
- * @param t an input object
- * @param u an input object
+ * @param t the first input argument
+ * @param u the second input argument
*/
void accept(T t, U u);
/**
- * Returns a {@code BiConsumer} which performs, in sequence, the operation
- * represented by this object followed by the operation represented by
- * the other {@code BiConsumer}.
- *
- * <p>Any exceptions thrown by either {@code accept} method are relayed
- * to the caller; if performing this operation throws an exception, the
- * other operation will not be performed.
+ * Returns a composed {@code BiConsumer} that performs, in sequence, this
+ * operation followed by the {@code after} operation. If performing either
+ * operation throws an exception, it is relayed to the caller of the
+ * composed operation. If performing this operation throws an exception,
+ * the {@code after} operation will not be performed.
*
- * @param other a BiConsumer which will be chained after this BiConsumer
- * @return a BiConsumer which performs in sequence the {@code accept} method
- * of this BiConsumer and the {@code accept} method of the specified
- * BiConsumer operation
- * @throws NullPointerException if other is null
+ * @param after the operation to perform after this operation
+ * @return a composed {@code BiConsumer} that performs in sequence this
+ * operation followed by the {@code after} operation
+ * @throws NullPointerException if {@code after} is null
*/
- default BiConsumer<T, U> chain(BiConsumer<? super T, ? super U> other) {
- Objects.requireNonNull(other);
+ default BiConsumer<T, U> andThen(BiConsumer<? super T, ? super U> after) {
+ Objects.requireNonNull(after);
return (l, r) -> {
accept(l, r);
- other.accept(l, r);
+ after.accept(l, r);
};
}
}
--- a/jdk/src/share/classes/java/util/function/BiFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/BiFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,14 +27,15 @@
import java.util.Objects;
/**
- * Apply a function to the input arguments, yielding an appropriate result. This
- * is the two-arity specialization of {@link Function}. A function may
- * variously provide a mapping between types, object instances or keys and
- * values or any other form of transformation upon the input.
+ * Represents a function that accepts two arguments and produces a result.
+ * This is the two-arity specialization of {@link Function}.
*
- * @param <T> the type of the first argument to the {@code apply} operation
- * @param <U> the type of the second argument to the {@code apply} operation
- * @param <R> the type of results returned by the {@code apply} operation
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #apply(Object, Object)}.
+ *
+ * @param <T> the type of the first argument to the function
+ * @param <U> the type of the second argument to the function
+ * @param <R> the type of the result of the function
*
* @see Function
* @since 1.8
@@ -43,25 +44,25 @@
public interface BiFunction<T, U, R> {
/**
- * Compute the result of applying the function to the input arguments
+ * Applies this function to the given arguments.
*
- * @param t an input object
- * @param u an input object
+ * @param t the first function argument
+ * @param u the second function argument
* @return the function result
*/
R apply(T t, U u);
/**
- * Returns a new function which applies this function followed by the
- * provided function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed function that first applies this function to
+ * its input, and then applies the {@code after} function to the result.
+ * If evaluation of either function throws an exception, it is relayed to
+ * the caller of the composed function.
*
- * @param <V> Type of output objects to the combined function. May be the
- * same type as {@code <T>}, {@code <U>} or {@code <R>}
- * @param after An additional function to be applied after this function is
- * applied
- * @return A function which performs this function followed by the provided
- * function
+ * @param <V> the type of output of the {@code after} function, and of the
+ * composed function
+ * @param after the function to apply after this function is applied
+ * @return a composed function that first applies this function and then
+ * applies the {@code after} function
* @throws NullPointerException if after is null
*/
default <V> BiFunction<T, U, V> andThen(Function<? super R, ? extends V> after) {
--- a/jdk/src/share/classes/java/util/function/BiPredicate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/BiPredicate.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,11 +27,14 @@
import java.util.Objects;
/**
- * Determines if the input objects match some criteria. This is the two-arity
- * specialization of {@link Predicate}.
+ * Represents a predicate (boolean-valued function) of two arguments. This is
+ * the two-arity specialization of {@link Predicate}.
*
- * @param <T> the type of the first argument to {@code test}
- * @param <U> the type of the second argument to {@code test}
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #test(Object, Object)}.
+ *
+ * @param <T> the type of the first argument to the predicate
+ * @param <U> the type of the second argument the predicate
*
* @see Predicate
* @since 1.8
@@ -40,34 +43,41 @@
public interface BiPredicate<T, U> {
/**
- * Return {@code true} if the inputs match some criteria.
+ * Evaluates this predicate on the given arguments.
*
- * @param t an input object
- * @param u an input object
- * @return {@code true} if the inputs match some criteria
+ * @param t the first input argument
+ * @param u the second input argument
+ * @return {@code true} if the input arguments match the predicate,
+ * otherwise {@code false}
*/
boolean test(T t, U u);
/**
- * Returns a predicate which evaluates to {@code true} only if this
- * predicate and the provided predicate both evaluate to {@code true}. If
- * this predicate returns {@code false} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * AND of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code false}, then the {@code other}
+ * predicate is not evaluated.
+ *
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ANDed with this predicate
- * @return a new predicate which returns {@code true} only if both
- * predicates return {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ANDed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * AND of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> p) {
- Objects.requireNonNull(p);
- return (T t, U u) -> test(t, u) && p.test(t, u);
+ default BiPredicate<T, U> and(BiPredicate<? super T, ? super U> other) {
+ Objects.requireNonNull(other);
+ return (T t, U u) -> test(t, u) && other.test(t, u);
}
/**
- * Returns a predicate which negates the result of this predicate.
+ * Returns a predicate that represents the logical negation of this
+ * predicate.
*
- * @return a new predicate who's result is always the opposite of this
+ * @return a predicate that represents the logical negation of this
* predicate
*/
default BiPredicate<T, U> negate() {
@@ -75,18 +85,23 @@
}
/**
- * Returns a predicate which evaluates to {@code true} if either this
- * predicate or the provided predicate evaluates to {@code true}. If this
- * predicate returns {@code true} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * OR of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code true}, then the {@code other}
+ * predicate is not evaluated.
+ *
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ORed with this predicate
- * @return a new predicate which returns {@code true} if either predicate
- * returns {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ORed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * OR of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> p) {
- Objects.requireNonNull(p);
- return (T t, U u) -> test(t, u) || p.test(t, u);
+ default BiPredicate<T, U> or(BiPredicate<? super T, ? super U> other) {
+ Objects.requireNonNull(other);
+ return (T t, U u) -> test(t, u) || other.test(t, u);
}
}
--- a/jdk/src/share/classes/java/util/function/BinaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/BinaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -28,42 +28,48 @@
import java.util.Comparator;
/**
- * An operation upon two operands yielding a result. This is a specialization of
- * {@code BiFunction} where the operands and the result are all of the same type.
+ * Represents an operation upon two operands of the same type, producing a result
+ * of the same type as the operands. This is a specialization of
+ * {@link BiFunction} for the case where the operands and the result are all of
+ * the same type.
*
- * @param <T> the type of operands to {@code apply} and of the result
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #apply(Object, Object)}.
+ *
+ * @param <T> the type of the operands and result of the operator
*
* @see BiFunction
+ * @see UnaryOperator
* @since 1.8
*/
@FunctionalInterface
public interface BinaryOperator<T> extends BiFunction<T,T,T> {
/**
* Returns a {@link BinaryOperator} which returns the lesser of two elements
- * according to the specified {@code Comparator}
+ * according to the specified {@code Comparator}.
*
- * @param <T> the type of values to be compared and returned
- * @param comparator a {@code Comparator} for comparing the two values
+ * @param <T> the type of the input arguments of the comparator
+ * @param comparator a {@code Comparator} for comparing the two values
* @return a {@code BinaryOperator} which returns the lesser of its operands,
* according to the supplied {@code Comparator}
* @throws NullPointerException if the argument is null
*/
- public static<T> BinaryOperator<T> minBy(Comparator<? super T> comparator) {
+ public static <T> BinaryOperator<T> minBy(Comparator<? super T> comparator) {
Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
}
/**
* Returns a {@link BinaryOperator} which returns the greater of two elements
- * according to the specified {@code Comparator}
+ * according to the specified {@code Comparator}.
*
- * @param <T> the type of values to be compared and returned
- * @param comparator a {@code Comparator} for comparing the two values
+ * @param <T> the type of the input arguments of the comparator
+ * @param comparator a {@code Comparator} for comparing the two values
* @return a {@code BinaryOperator} which returns the greater of its operands,
* according to the supplied {@code Comparator}
* @throws NullPointerException if the argument is null
*/
- public static<T> BinaryOperator<T> maxBy(Comparator<? super T> comparator) {
+ public static <T> BinaryOperator<T> maxBy(Comparator<? super T> comparator) {
Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) >= 0 ? a : b;
}
--- a/jdk/src/share/classes/java/util/function/BooleanSupplier.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/BooleanSupplier.java Thu Jul 25 20:30:58 2013 -0400
@@ -26,8 +26,14 @@
/**
- * A supplier of {@code boolean} values. This is the {@code boolean}-providing
- * primitive specialization of {@link Supplier}.
+ * Represents a supplier of {@code boolean}-valued results. This is the
+ * {@code boolean}-producing primitive specialization of {@link Supplier}.
+ *
+ * <p>There is no requirement that a new or distinct result be returned each
+ * time the supplier is invoked.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #getAsBoolean()}.
*
* @see Supplier
* @since 1.8
@@ -36,9 +42,9 @@
public interface BooleanSupplier {
/**
- * Returns a {@code boolean} value.
+ * Gets a result.
*
- * @return a {@code boolean} value
+ * @return a result
*/
boolean getAsBoolean();
}
--- a/jdk/src/share/classes/java/util/function/Consumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/Consumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,11 +27,14 @@
import java.util.Objects;
/**
- * An operation which accepts a single input argument and returns no result.
- * Unlike most other functional interfaces, {@code Consumer} is expected to
- * operate via side-effects.
+ * Represents an operation that accepts a single input argument and returns no
+ * result. Unlike most other functional interfaces, {@code Consumer} is expected
+ * to operate via side-effects.
*
- * @param <T> The type of input objects to {@code accept}
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(Object)}.
+ *
+ * @param <T> the type of the input to the operation
*
* @since 1.8
*/
@@ -39,29 +42,26 @@
public interface Consumer<T> {
/**
- * Accept an input value.
+ * Performs this operation on the given argument.
*
- * @param t the input object
+ * @param t the input argument
*/
void accept(T t);
/**
- * Returns a {@code Consumer} which performs, in sequence, the operation
- * represented by this object followed by the operation represented by
- * the other {@code Consumer}.
- *
- * <p>Any exceptions thrown by either {@code accept} method are relayed
- * to the caller; if performing this operation throws an exception, the
- * other operation will not be performed.
+ * Returns a composed {@code Consumer} that performs, in sequence, this
+ * operation followed by the {@code after} operation. If performing either
+ * operation throws an exception, it is relayed to the caller of the
+ * composed operation. If performing this operation throws an exception,
+ * the {@code after} operation will not be performed.
*
- * @param other a Consumer which will be chained after this Consumer
- * @return a Consumer which performs in sequence the {@code accept} method
- * of this Consumer and the {@code accept} method of the specified Consumer
- * operation
- * @throws NullPointerException if other is null
+ * @param after the operation to perform after this operation
+ * @return a composed {@code Consumer} that performs in sequence this
+ * operation followed by the {@code after} operation
+ * @throws NullPointerException if {@code after} is null
*/
- default Consumer<T> chain(Consumer<? super T> other) {
- Objects.requireNonNull(other);
- return (T t) -> { accept(t); other.accept(t); };
+ default Consumer<T> andThen(Consumer<? super T> after) {
+ Objects.requireNonNull(after);
+ return (T t) -> { accept(t); after.accept(t); };
}
}
--- a/jdk/src/share/classes/java/util/function/DoubleBinaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoubleBinaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,23 +25,25 @@
package java.util.function;
/**
- * An operation on two {@code double} operands yielding a {@code double} result.
- * This is the primitive type specialization of {@link BinaryOperator} for
- * {@code double}.
+ * Represents an operation upon two {@code double}-valued operands and producing a
+ * {@code double}-valued result. This is the primitive type specialization of
+ * {@link BinaryOperator} for {@code double}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsDouble(double, double)}.
*
* @see BinaryOperator
+ * @see DoubleUnaryOperator
* @since 1.8
*/
@FunctionalInterface
public interface DoubleBinaryOperator {
/**
- * Returns the {@code double} result of the operation upon the
- * {@code double} operands. The parameters are named {@code left} and
- * {@code right} for operations where the order of parameters matters.
+ * Applies this operator to the given operands.
*
- * @param left the left operand value
- * @param right the right operand value
- * @return the result of the operation
+ * @param left the first operand
+ * @param right the second operand
+ * @return the operator result
*/
double applyAsDouble(double left, double right);
}
--- a/jdk/src/share/classes/java/util/function/DoubleConsumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoubleConsumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,11 +27,14 @@
import java.util.Objects;
/**
- * An operation which accepts a single double argument and returns no result.
- * This is the primitive type specialization of {@link Consumer} for
- * {@code double}. Unlike most other functional interfaces,
+ * Represents an operation that accepts a single {@code double}-valued argument and
+ * returns no result. This is the primitive type specialization of
+ * {@link Consumer} for {@code double}. Unlike most other functional interfaces,
* {@code DoubleConsumer} is expected to operate via side-effects.
*
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(double)}.
+ *
* @see Consumer
* @since 1.8
*/
@@ -39,30 +42,26 @@
public interface DoubleConsumer {
/**
- * Accept an input value.
+ * Performs this operation on the given argument.
*
- * @param value the input value
+ * @param value the input argument
*/
void accept(double value);
/**
- * Returns a {@code DoubleConsumer} which performs, in sequence, the operation
- * represented by this object followed by the operation represented by
- * another {@code DoubleConsumer}.
- *
- * <p>Any exceptions thrown by either {@code accept} method are relayed
- * to the caller; if performing this operation throws an exception, the
- * other operation will not be performed.
+ * Returns a composed {@code DoubleConsumer} that performs, in sequence, this
+ * operation followed by the {@code after} operation. If performing either
+ * operation throws an exception, it is relayed to the caller of the
+ * composed operation. If performing this operation throws an exception,
+ * the {@code after} operation will not be performed.
*
- * @param other a DoubleConsumer which will be chained after this
- * DoubleConsumer
- * @return an DoubleConsumer which performs in sequence the {@code accept} method
- * of this DoubleConsumer and the {@code accept} method of the specified IntConsumer
- * operation
- * @throws NullPointerException if other is null
+ * @param after the operation to perform after this operation
+ * @return a composed {@code DoubleConsumer} that performs in sequence this
+ * operation followed by the {@code after} operation
+ * @throws NullPointerException if {@code after} is null
*/
- default DoubleConsumer chain(DoubleConsumer other) {
- Objects.requireNonNull(other);
- return (double t) -> { accept(t); other.accept(t); };
+ default DoubleConsumer andThen(DoubleConsumer after) {
+ Objects.requireNonNull(after);
+ return (double t) -> { accept(t); after.accept(t); };
}
}
--- a/jdk/src/share/classes/java/util/function/DoubleFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoubleFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,11 +25,14 @@
package java.util.function;
/**
- * Apply a function to the double-valued input argument, yielding an appropriate
- * result. This is the {@code double}-consuming primitive specialization for
+ * Represents a function that accepts a double-valued argument and produces a
+ * result. This is the {@code double}-consuming primitive specialization for
* {@link Function}.
*
- * @param <R> the type of output objects from the function
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #apply(double)}.
+ *
+ * @param <R> the type of the result of the function
*
* @see Function
* @since 1.8
@@ -38,9 +41,9 @@
public interface DoubleFunction<R> {
/**
- * Compute the result of applying the function to the input argument
+ * Applies this function to the given argument.
*
- * @param value the input value
+ * @param value the function argument
* @return the function result
*/
R apply(double value);
--- a/jdk/src/share/classes/java/util/function/DoublePredicate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoublePredicate.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,9 +27,12 @@
import java.util.Objects;
/**
- * Determines if the {@code double} input value matches some criteria. This is
- * the {@code double}-consuming primitive type specialization of
- * {@link Predicate}.
+ * Represents a predicate (boolean-valued function) of one {@code double}-valued
+ * argument. This is the {@code double}-consuming primitive type specialization
+ * of {@link Predicate}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #test(double)}.
*
* @see Predicate
* @since 1.8
@@ -38,38 +41,40 @@
public interface DoublePredicate {
/**
- * Returns {@code true} if the input value matches some criteria.
+ * Evaluates this predicate on the given argument.
*
- * @param value the value to be tested
- * @return {@code true} if the input value matches some criteria, otherwise
- * {@code false}
+ * @param value the input argument
+ * @return {@code true} if the input argument matches the predicate,
+ * otherwise {@code false}
*/
boolean test(double value);
/**
- * Returns a predicate which evaluates to {@code true} only if this
- * predicate and the provided predicate both evaluate to {@code true}. If
- * this predicate returns {@code false} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * AND of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code false}, then the {@code other}
+ * predicate is not evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ANDed with this predicate
- * @return a new predicate which returns {@code true} only if both
- * predicates return {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ANDed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * AND of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default DoublePredicate and(DoublePredicate p) {
- Objects.requireNonNull(p);
- return (value) -> test(value) && p.test(value);
+ default DoublePredicate and(DoublePredicate other) {
+ Objects.requireNonNull(other);
+ return (value) -> test(value) && other.test(value);
}
/**
- * Returns a predicate which negates the result of this predicate.
+ * Returns a predicate that represents the logical negation of this
+ * predicate.
*
- * @return a new predicate who's result is always the opposite of this
+ * @return a predicate that represents the logical negation of this
* predicate
*/
default DoublePredicate negate() {
@@ -77,22 +82,23 @@
}
/**
- * Returns a predicate which evaluates to {@code true} if either this
- * predicate or the provided predicate evaluates to {@code true}. If this
- * predicate returns {@code true} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * OR of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code true}, then the {@code other}
+ * predicate is not evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ANDed with this predicate
- * @return a new predicate which returns {@code true} if either predicate
- * returns {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ORed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * OR of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default DoublePredicate or(DoublePredicate p) {
- Objects.requireNonNull(p);
- return (value) -> test(value) || p.test(value);
+ default DoublePredicate or(DoublePredicate other) {
+ Objects.requireNonNull(other);
+ return (value) -> test(value) || other.test(value);
}
}
--- a/jdk/src/share/classes/java/util/function/DoubleSupplier.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoubleSupplier.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,8 +25,14 @@
package java.util.function;
/**
- * A supplier of {@code double} values. This is the {@code double}-providing
- * primitive specialization of {@link Supplier}.
+ * Represents a supplier of {@code double}-valued results. This is the
+ * {@code double}-producing primitive specialization of {@link Supplier}.
+ *
+ * <p>There is no requirement that a distinct result be returned each
+ * time the supplier is invoked.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #getAsDouble()}.
*
* @see Supplier
* @since 1.8
@@ -35,9 +41,9 @@
public interface DoubleSupplier {
/**
- * Returns a {@code double} value.
+ * Gets a result.
*
- * @return a {@code double} value
+ * @return a result
*/
double getAsDouble();
}
--- a/jdk/src/share/classes/java/util/function/DoubleToIntFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoubleToIntFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,22 +25,24 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code double}-to-{@code int} specialization for {@link Function}.
+ * Represents a function that accepts a double-valued argument and produces an
+ * int-valued result. This is the {@code double}-to-{@code int} primitive
+ * specialization for {@link Function}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsInt(double)}.
*
* @see Function
- * @see IntToDoubleFunction
- * @see LongToIntFunction
* @since 1.8
*/
@FunctionalInterface
public interface DoubleToIntFunction {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given argument.
*
- * @param value the input value
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
int applyAsInt(double value);
}
--- a/jdk/src/share/classes/java/util/function/DoubleToLongFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoubleToLongFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,22 +25,24 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code double}-to-{@code long} specialization for {@link Function}.
+ * Represents a function that accepts a double-valued argument and produces a
+ * long-valued result. This is the {@code double}-to-{@code long} primitive
+ * specialization for {@link Function}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsLong(double)}.
*
* @see Function
- * @see LongToDoubleFunction
- * @see IntToLongFunction
* @since 1.8
*/
@FunctionalInterface
public interface DoubleToLongFunction {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given argument.
*
- * @param value the input value
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
long applyAsLong(double value);
}
--- a/jdk/src/share/classes/java/util/function/DoubleUnaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/DoubleUnaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,9 +27,12 @@
import java.util.Objects;
/**
- * An operation on a {@code double} operand yielding a {@code double}
- * result. This is the primitive type specialization of {@link UnaryOperator}
- * for {@code double}.
+ * Represents an operation on a single {@code double}-valued operand that produces
+ * a {@code double}-valued result. This is the primitive type specialization of
+ * {@link UnaryOperator} for {@code double}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsDouble(double)}.
*
* @see UnaryOperator
* @since 1.8
@@ -38,24 +41,25 @@
public interface DoubleUnaryOperator {
/**
- * Returns the {@code double} result of the operation upon the
- * {@code double} operand.
+ * Applies this operator to the given operand.
*
- * @param operand the operand value
- * @return the operation result value
+ * @param operand the operand
+ * @return the operator result
*/
double applyAsDouble(double operand);
/**
- * Compose a new function which applies the provided function followed by
- * this function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed operator that first applies the {@code before}
+ * operator to its input, and then applies this operator to the result.
+ * If evaluation of either operator throws an exception, it is relayed to
+ * the caller of the composed operator.
*
- * @param before An additional function to be applied before this function
- * is applied
- * @return A function which performs the provided function followed by this
- * function
+ * @param before the operator to apply before this operator is applied
+ * @return a composed operator that first applies the {@code before}
+ * operator and then applies this operator
* @throws NullPointerException if before is null
+ *
+ * @see #andThen(DoubleUnaryOperator)
*/
default DoubleUnaryOperator compose(DoubleUnaryOperator before) {
Objects.requireNonNull(before);
@@ -63,15 +67,17 @@
}
/**
- * Compose a new function which applies this function followed by the
- * provided function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed operator that first applies this operator to
+ * its input, and then applies the {@code after} operator to the result.
+ * If evaluation of either operator throws an exception, it is relayed to
+ * the caller of the composed operator.
*
- * @param after An additional function to be applied after this function is
- * applied
- * @return A function which performs this function followed by the provided
- * function followed
+ * @param after the operator to apply after this operator is applied
+ * @return a composed operator that first applies this operator and then
+ * applies the {@code after} operator
* @throws NullPointerException if after is null
+ *
+ * @see #compose(DoubleUnaryOperator)
*/
default DoubleUnaryOperator andThen(DoubleUnaryOperator after) {
Objects.requireNonNull(after);
@@ -79,9 +85,9 @@
}
/**
- * Returns a unary operator that provides its input value as the result.
+ * Returns a unary operator that always returns its input argument.
*
- * @return a unary operator that provides its input value as the result
+ * @return a unary operator that always returns its input argument
*/
static DoubleUnaryOperator identity() {
return t -> t;
--- a/jdk/src/share/classes/java/util/function/Function.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/Function.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,12 +27,13 @@
import java.util.Objects;
/**
- * Apply a function to the input argument, yielding an appropriate result. A
- * function may variously provide a mapping between types, object instances or
- * keys and values or any other form of transformation upon the input.
+ * Represents a function that accepts one argument and produces a result.
*
- * @param <T> the type of the input to the {@code apply} operation
- * @param <R> the type of the result of the {@code apply} operation
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #apply(Object)}.
+ *
+ * @param <T> the type of the input to the function
+ * @param <R> the type of the result of the function
*
* @since 1.8
*/
@@ -40,25 +41,27 @@
public interface Function<T, R> {
/**
- * Compute the result of applying the function to the input argument
+ * Applies this function to the given argument.
*
- * @param t the input object
+ * @param t the function argument
* @return the function result
*/
R apply(T t);
/**
- * Returns a new function which applies the provided function followed by
- * this function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed function that first applies the {@code before}
+ * function to its input, and then applies this function to the result.
+ * If evaluation of either function throws an exception, it is relayed to
+ * the caller of the composed function.
*
- * @param <V> type of input objects to the combined function. May be the
- * same type as {@code <T>} or {@code <R>}
- * @param before an additional function to be applied before this function
- * is applied
- * @return a function which performs the provided function followed by this
- * function
+ * @param <V> the type of input to the {@code before} function, and to the
+ * composed function
+ * @param before the function to apply before this function is applied
+ * @return a composed function that first applies the {@code before}
+ * function and then applies this function
* @throws NullPointerException if before is null
+ *
+ * @see #andThen(Function)
*/
default <V> Function<V, R> compose(Function<? super V, ? extends T> before) {
Objects.requireNonNull(before);
@@ -66,17 +69,19 @@
}
/**
- * Returns a new function which applies this function followed by the
- * provided function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed function that first applies this function to
+ * its input, and then applies the {@code after} function to the result.
+ * If evaluation of either function throws an exception, it is relayed to
+ * the caller of the composed function.
*
- * @param <V> type of output objects to the combined function. May be the
- * same type as {@code <T>} or {@code <R>}
- * @param after an additional function to be applied after this function is
- * applied
- * @return a function which performs this function followed by the provided
- * function
+ * @param <V> the type of output of the {@code after} function, and of the
+ * composed function
+ * @param after the function to apply after this function is applied
+ * @return a composed function that first applies this function and then
+ * applies the {@code after} function
* @throws NullPointerException if after is null
+ *
+ * @see #compose(Function)
*/
default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after);
@@ -84,10 +89,10 @@
}
/**
- * Returns a {@code Function} whose {@code apply} method returns its input.
+ * Returns a function that always returns its input argument.
*
* @param <T> the type of the input and output objects to the function
- * @return a {@code Function} whose {@code apply} method returns its input
+ * @return a function that always returns its input argument
*/
static <T> Function<T, T> identity() {
return t -> t;
--- a/jdk/src/share/classes/java/util/function/IntBinaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntBinaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,24 +25,26 @@
package java.util.function;
/**
- * An operation on two {@code int} operands yielding an {@code int} result.
- * This is the primitive type specialization of {@link BinaryOperator} for
- * {@code int}.
+ * Represents an operation upon two {@code int}-valued operands and producing an
+ * {@code int}-valued result. This is the primitive type specialization of
+ * {@link BinaryOperator} for {@code int}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsInt(int, int)}.
*
* @see BinaryOperator
+ * @see IntUnaryOperator
* @since 1.8
*/
@FunctionalInterface
public interface IntBinaryOperator {
/**
- * Returns the {@code int} result of the operation upon the {@code int}
- * operands. The parameters are named {@code left} and {@code right} for
- * operations where the order of parameters matters.
+ * Applies this operator to the given operands.
*
- * @param left the left operand value
- * @param right the right operand value
- * @return the result of the operation
+ * @param left the first operand
+ * @param right the second operand
+ * @return the operator result
*/
int applyAsInt(int left, int right);
}
--- a/jdk/src/share/classes/java/util/function/IntConsumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntConsumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,10 +27,13 @@
import java.util.Objects;
/**
- * An operation which accepts a single integer argument and returns no result.
- * This is the primitive type specialization of {@link Consumer} for {@code int}.
- * Unlike most other functional interfaces, {@code IntConsumer} is expected to
- * operate via side-effects.
+ * Represents an operation that accepts a single {@code int}-valued argument and
+ * returns no result. This is the primitive type specialization of
+ * {@link Consumer} for {@code int}. Unlike most other functional interfaces,
+ * {@code IntConsumer} is expected to operate via side-effects.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(int)}.
*
* @see Consumer
* @since 1.8
@@ -39,30 +42,26 @@
public interface IntConsumer {
/**
- * Accept an input value.
+ * Performs this operation on the given argument.
*
- * @param value the input value
+ * @param value the input argument
*/
void accept(int value);
/**
- * Returns an {@code IntConsumer} which performs, in sequence, the operation
- * represented by this object followed by the operation represented by
- * another {@code IntConsumer}.
- *
- * <p>Any exceptions thrown by either {@code accept} method are relayed
- * to the caller; if performing this operation throws an exception, the
- * other operation will not be performed.
+ * Returns a composed {@code IntConsumer} that performs, in sequence, this
+ * operation followed by the {@code after} operation. If performing either
+ * operation throws an exception, it is relayed to the caller of the
+ * composed operation. If performing this operation throws an exception,
+ * the {@code after} operation will not be performed.
*
- * @param other an IntConsumer which will be chained after this
- * IntConsumer
- * @return an IntConsumer which performs in sequence the {@code accept} method
- * of this IntConsumer and the {@code accept} method of the specified IntConsumer
- * operation
- * @throws NullPointerException if other is null
+ * @param after the operation to perform after this operation
+ * @return a composed {@code IntConsumer} that performs in sequence this
+ * operation followed by the {@code after} operation
+ * @throws NullPointerException if {@code after} is null
*/
- default IntConsumer chain(IntConsumer other) {
- Objects.requireNonNull(other);
- return (int t) -> { accept(t); other.accept(t); };
+ default IntConsumer andThen(IntConsumer after) {
+ Objects.requireNonNull(after);
+ return (int t) -> { accept(t); after.accept(t); };
}
}
--- a/jdk/src/share/classes/java/util/function/IntFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,11 +25,14 @@
package java.util.function;
/**
- * Apply a function to the integer-valued input argument, yielding an
- * appropriate result. This is the {@code int}-consuming primitive
- * specialization for {@link Function}.
+ * Represents a function that accepts an int-valued argument and produces a
+ * result. This is the {@code int}-consuming primitive specialization for
+ * {@link Function}.
*
- * @param <R> the type of output objects from the function
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #apply(int)}.
+ *
+ * @param <R> the type of the result of the function
*
* @see Function
* @since 1.8
@@ -38,9 +41,9 @@
public interface IntFunction<R> {
/**
- * Compute the result of applying the function to the input argument
+ * Applies this function to the given argument.
*
- * @param value the input value
+ * @param value the function argument
* @return the function result
*/
R apply(int value);
--- a/jdk/src/share/classes/java/util/function/IntPredicate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntPredicate.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,8 +27,12 @@
import java.util.Objects;
/**
- * Determines if the {@code int} input value matches some criteria. This is the
- * {@code int}-consuming primitive type specialization of {@link Predicate}.
+ * Represents a predicate (boolean-valued function) of one {@code int}-valued
+ * argument. This is the {@code int}-consuming primitive type specialization of
+ * {@link Predicate}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #test(int)}.
*
* @see Predicate
* @since 1.8
@@ -37,38 +41,40 @@
public interface IntPredicate {
/**
- * Returns {@code true} if the input value matches some criteria.
+ * Evaluates this predicate on the given argument.
*
- * @param value the value to be tested
- * @return {@code true} if the input value matches some criteria, otherwise
- * {@code false}
+ * @param value the input argument
+ * @return {@code true} if the input argument matches the predicate,
+ * otherwise {@code false}
*/
boolean test(int value);
/**
- * Returns a predicate which evaluates to {@code true} only if this
- * predicate and the provided predicate both evaluate to {@code true}. If
- * this predicate returns {@code false} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * AND of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code false}, then the {@code other}
+ * predicate is not evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ANDed with this predicate
- * @return a new predicate which returns {@code true} only if both
- * predicates return {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ANDed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * AND of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default IntPredicate and(IntPredicate p) {
- Objects.requireNonNull(p);
- return (value) -> test(value) && p.test(value);
+ default IntPredicate and(IntPredicate other) {
+ Objects.requireNonNull(other);
+ return (value) -> test(value) && other.test(value);
}
/**
- * Returns a predicate which negates the result of this predicate.
+ * Returns a predicate that represents the logical negation of this
+ * predicate.
*
- * @return a new predicate who's result is always the opposite of this
+ * @return a predicate that represents the logical negation of this
* predicate
*/
default IntPredicate negate() {
@@ -76,22 +82,23 @@
}
/**
- * Returns a predicate which evaluates to {@code true} if either this
- * predicate or the provided predicate evaluates to {@code true}. If this
- * predicate returns {@code true} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * OR of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code true}, then the {@code other}
+ * predicate is not evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ORed with this predicate
- * @return a new predicate which returns {@code true} if either predicate
- * returns {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ORed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * OR of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default IntPredicate or(IntPredicate p) {
- Objects.requireNonNull(p);
- return (value) -> test(value) || p.test(value);
+ default IntPredicate or(IntPredicate other) {
+ Objects.requireNonNull(other);
+ return (value) -> test(value) || other.test(value);
}
}
--- a/jdk/src/share/classes/java/util/function/IntSupplier.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntSupplier.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,8 +25,14 @@
package java.util.function;
/**
- * A supplier of {@code int} values. This is the {@code int}-providing
- * primitive specialization of {@link Supplier}.
+ * Represents a supplier of {@code int}-valued results. This is the
+ * {@code int}-producing primitive specialization of {@link Supplier}.
+ *
+ * <p>There is no requirement that a distinct result be returned each
+ * time the supplier is invoked.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #getAsInt()}.
*
* @see Supplier
* @since 1.8
@@ -35,9 +41,9 @@
public interface IntSupplier {
/**
- * Returns an {@code int} value.
+ * Gets a result.
*
- * @return an {@code int} value
+ * @return a result
*/
int getAsInt();
}
--- a/jdk/src/share/classes/java/util/function/IntToDoubleFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntToDoubleFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,22 +25,24 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code int}-to-{@code double} specialization for {@link Function}.
+ * Represents a function that accepts an int-valued argument and produces a
+ * double-valued result. This is the {@code int}-to-{@code double} primitive
+ * specialization for {@link Function}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsDouble(int)}.
*
* @see Function
- * @see DoubleToIntFunction
- * @see LongToDoubleFunction
* @since 1.8
*/
@FunctionalInterface
public interface IntToDoubleFunction {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given argument.
*
- * @param value the input value
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
double applyAsDouble(int value);
}
--- a/jdk/src/share/classes/java/util/function/IntToLongFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntToLongFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,22 +25,24 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code int}-to-{@code long} specialization for {@link Function}.
+ * Represents a function that accepts an int-valued argument and produces a
+ * long-valued result. This is the {@code int}-to-{@code long} primitive
+ * specialization for {@link Function}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsLong(int)}.
*
* @see Function
- * @see LongToIntFunction
- * @see DoubleToLongFunction
* @since 1.8
*/
@FunctionalInterface
public interface IntToLongFunction {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given argument.
*
- * @param value the input value
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
long applyAsLong(int value);
}
--- a/jdk/src/share/classes/java/util/function/IntUnaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/IntUnaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,9 +27,12 @@
import java.util.Objects;
/**
- * An operation on a single {@code int} operand yielding an {@code int} result.
- * This is the primitive type specialization of {@link UnaryOperator} for
- * {@code int}.
+ * Represents an operation on a single {@code int}-valued operand that produces
+ * an {@code int}-valued result. This is the primitive type specialization of
+ * {@link UnaryOperator} for {@code int}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsInt(int)}.
*
* @see UnaryOperator
* @since 1.8
@@ -38,24 +41,25 @@
public interface IntUnaryOperator {
/**
- * Returns the {@code int} value result of the operation upon the
- * {@code int} operand.
+ * Applies this operator to the given operand.
*
- * @param operand the operand value
- * @return the operation result value
+ * @param operand the operand
+ * @return the operator result
*/
int applyAsInt(int operand);
/**
- * Compose a new function which applies the provided function followed by
- * this function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed operator that first applies the {@code before}
+ * operator to its input, and then applies this operator to the result.
+ * If evaluation of either operator throws an exception, it is relayed to
+ * the caller of the composed operator.
*
- * @param before an additional function to be applied before this function
- * is applied
- * @return a function which performs the provided function followed by this
- * function
+ * @param before the operator to apply before this operator is applied
+ * @return a composed operator that first applies the {@code before}
+ * operator and then applies this operator
* @throws NullPointerException if before is null
+ *
+ * @see #andThen(IntUnaryOperator)
*/
default IntUnaryOperator compose(IntUnaryOperator before) {
Objects.requireNonNull(before);
@@ -63,15 +67,17 @@
}
/**
- * Compose a new function which applies this function followed by the
- * provided function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed operator that first applies this operator to
+ * its input, and then applies the {@code after} operator to the result.
+ * If evaluation of either operator throws an exception, it is relayed to
+ * the caller of the composed operator.
*
- * @param after an additional function to be applied after this function is
- * applied
- * @return a function which performs this function followed by the provided
- * function followed
+ * @param after the operator to apply after this operator is applied
+ * @return a composed operator that first applies this operator and then
+ * applies the {@code after} operator
* @throws NullPointerException if after is null
+ *
+ * @see #compose(IntUnaryOperator)
*/
default IntUnaryOperator andThen(IntUnaryOperator after) {
Objects.requireNonNull(after);
@@ -79,9 +85,9 @@
}
/**
- * Returns a unary operator that provides its input value as the result.
+ * Returns a unary operator that always returns its input argument.
*
- * @return a unary operator that provides its input value as the result
+ * @return a unary operator that always returns its input argument
*/
static IntUnaryOperator identity() {
return t -> t;
--- a/jdk/src/share/classes/java/util/function/LongBinaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongBinaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,24 +25,26 @@
package java.util.function;
/**
- * An operation on two {@code long} operands yielding a {@code long} result.
- * This is the primitive type specialization of {@link BinaryOperator} for
- * {@code long}.
+ * Represents an operation upon two {@code long}-valued operands and producing a
+ * {@code long}-valued result. This is the primitive type specialization of
+ * {@link BinaryOperator} for {@code long}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsLong(long, long)}.
*
* @see BinaryOperator
+ * @see LongUnaryOperator
* @since 1.8
*/
@FunctionalInterface
public interface LongBinaryOperator {
/**
- * Returns the {@code long} result of the operation upon the {@code long}
- * operands. The parameters are named {@code left} and {@code right} for
- * operations where the order of parameters matters.
+ * Applies this operator to the given operands.
*
- * @param left the left operand value
- * @param right the right operand value
- * @return the result of the operation
+ * @param left the first operand
+ * @param right the second operand
+ * @return the operator result
*/
long applyAsLong(long left, long right);
}
--- a/jdk/src/share/classes/java/util/function/LongConsumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongConsumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,10 +27,13 @@
import java.util.Objects;
/**
- * An operation which accepts a single long argument and returns no result.
- * This is the {@code long}-consuming primitive type specialization of
- * {@link Consumer}. Unlike most other functional interfaces, {@code LongConsumer}
- * is expected to operate via side-effects.
+ * Represents an operation that accepts a single {@code long}-valued argument and
+ * returns no result. This is the primitive type specialization of
+ * {@link Consumer} for {@code long}. Unlike most other functional interfaces,
+ * {@code LongConsumer} is expected to operate via side-effects.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(long)}.
*
* @see Consumer
* @since 1.8
@@ -39,30 +42,26 @@
public interface LongConsumer {
/**
- * Accept an input value.
+ * Performs this operation on the given argument.
*
- * @param value the input value
+ * @param value the input argument
*/
void accept(long value);
/**
- * Returns a {@code LongConsumer} which performs, in sequence, the operation
- * represented by this object followed by the operation represented by
- * another {@code LongConsumer}.
- *
- * <p>Any exceptions thrown by either {@code accept} method are relayed
- * to the caller; if performing this operation throws an exception, the
- * other operation will not be performed.
+ * Returns a composed {@code LongConsumer} that performs, in sequence, this
+ * operation followed by the {@code after} operation. If performing either
+ * operation throws an exception, it is relayed to the caller of the
+ * composed operation. If performing this operation throws an exception,
+ * the {@code after} operation will not be performed.
*
- * @param other a LongConsumer which will be chained after this
- * LongConsumer
- * @return a LongConsumer which performs in sequence the {@code accept} method
- * of this LongConsumer and the {@code accept} method of the specified LongConsumer
- * operation
- * @throws NullPointerException if other is null
+ * @param after the operation to perform after this operation
+ * @return a composed {@code LongConsumer} that performs in sequence this
+ * operation followed by the {@code after} operation
+ * @throws NullPointerException if {@code after} is null
*/
- default LongConsumer chain(LongConsumer other) {
- Objects.requireNonNull(other);
- return (long t) -> { accept(t); other.accept(t); };
+ default LongConsumer andThen(LongConsumer after) {
+ Objects.requireNonNull(after);
+ return (long t) -> { accept(t); after.accept(t); };
}
}
--- a/jdk/src/share/classes/java/util/function/LongFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,11 +25,14 @@
package java.util.function;
/**
- * Apply a function to the long-valued input argument, yielding an appropriate
- * result. This is the {@code long}-consuming primitive specialization for
+ * Represents a function that accepts a long-valued argument and produces a
+ * result. This is the {@code long}-consuming primitive specialization for
* {@link Function}.
*
- * @param <R> the type of output objects from the function
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #apply(long)}.
+ *
+ * @param <R> the type of the result of the function
*
* @see Function
* @since 1.8
@@ -38,9 +41,9 @@
public interface LongFunction<R> {
/**
- * Compute the result of applying the function to the input argument
+ * Applies this function to the given argument.
*
- * @param value the input value
+ * @param value the function argument
* @return the function result
*/
R apply(long value);
--- a/jdk/src/share/classes/java/util/function/LongPredicate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongPredicate.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,8 +27,12 @@
import java.util.Objects;
/**
- * Determines if the {@code long} input value matches some criteria. This is the
- * {@code long}-consuming primitive type specialization of {@link Predicate}.
+ * Represents a predicate (boolean-valued function) of one {@code long}-valued
+ * argument. This is the {@code long}-consuming primitive type specialization of
+ * {@link Predicate}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #test(long)}.
*
* @see Predicate
* @since 1.8
@@ -37,37 +41,40 @@
public interface LongPredicate {
/**
- * Returns {@code true} if the input value matches some criteria.
+ * Evaluates this predicate on the given argument.
*
- * @param value the value to be tested
- * @return {@code true} if the input value matches some criteria, otherwise
- * {@code false}
+ * @param value the input argument
+ * @return {@code true} if the input argument matches the predicate,
+ * otherwise {@code false}
*/
boolean test(long value);
/**
- * Returns a predicate which evaluates to {@code true} only if this
- * predicate and the provided predicate both evaluate to {@code true}. If
- * this predicate returns {@code false} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * AND of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code false}, then the {@code other}
+ * predicate is not evaluated.
+ *
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
- *
- * @param p a predicate which will be logically-ANDed with this predicate
- * @return a new predicate which returns {@code true} only if both
- * predicates return {@code true}
+ * @param other a predicate that will be logically-ANDed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * AND of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default LongPredicate and(LongPredicate p) {
- Objects.requireNonNull(p);
- return (value) -> test(value) && p.test(value);
+ default LongPredicate and(LongPredicate other) {
+ Objects.requireNonNull(other);
+ return (value) -> test(value) && other.test(value);
}
/**
- * Returns a predicate which negates the result of this predicate.
+ * Returns a predicate that represents the logical negation of this
+ * predicate.
*
- * @return a new predicate who's result is always the opposite of this
+ * @return a predicate that represents the logical negation of this
* predicate
*/
default LongPredicate negate() {
@@ -75,22 +82,23 @@
}
/**
- * Returns a predicate which evaluates to {@code true} if either this
- * predicate or the provided predicate evaluates to {@code true}. If this
- * predicate returns {@code true} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * OR of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code true}, then the {@code other}
+ * predicate is not evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ORed with this predicate
- * @return a new predicate which returns {@code true} if either predicate
- * returns {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ORed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * OR of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default LongPredicate or(LongPredicate p) {
- Objects.requireNonNull(p);
- return (value) -> test(value) || p.test(value);
+ default LongPredicate or(LongPredicate other) {
+ Objects.requireNonNull(other);
+ return (value) -> test(value) || other.test(value);
}
}
--- a/jdk/src/share/classes/java/util/function/LongSupplier.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongSupplier.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,8 +25,14 @@
package java.util.function;
/**
- * A supplier of {@code long} values. This is the {@code long}-providing
- * primitive specialization of {@link Supplier}.
+ * Represents a supplier of {@code long}-valued results. This is the
+ * {@code long}-producing primitive specialization of {@link Supplier}.
+ *
+ * <p>There is no requirement that a distinct result be returned each
+ * time the supplier is invoked.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #getAsLong()}.
*
* @see Supplier
* @since 1.8
@@ -35,9 +41,9 @@
public interface LongSupplier {
/**
- * Returns a {@code long} value.
+ * Gets a result.
*
- * @return a {@code long} value
+ * @return a result
*/
long getAsLong();
}
--- a/jdk/src/share/classes/java/util/function/LongToDoubleFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongToDoubleFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,22 +25,24 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code long}-to-{@code double} specialization for {@link Function}.
+ * Represents a function that accepts a long-valued argument and produces a
+ * double-valued result. This is the {@code long}-to-{@code double} primitive
+ * specialization for {@link Function}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsDouble(long)}.
*
* @see Function
- * @see DoubleToLongFunction
- * @see IntToDoubleFunction
* @since 1.8
*/
@FunctionalInterface
public interface LongToDoubleFunction {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given argument.
*
- * @param value the input value
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
double applyAsDouble(long value);
}
--- a/jdk/src/share/classes/java/util/function/LongToIntFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongToIntFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,22 +25,24 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code long}-to-{@code int} specialization for {@link Function}.
+ * Represents a function that accepts a long-valued argument and produces an
+ * int-valued result. This is the {@code long}-to-{@code int} primitive
+ * specialization for {@link Function}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsInt(long)}.
*
* @see Function
- * @see IntToLongFunction
- * @see DoubleToIntFunction
* @since 1.8
*/
@FunctionalInterface
public interface LongToIntFunction {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given argument.
*
- * @param value the input value
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
int applyAsInt(long value);
}
--- a/jdk/src/share/classes/java/util/function/LongUnaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/LongUnaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,9 +27,12 @@
import java.util.Objects;
/**
- * An operation on a single {@code long} operand yielding a {@code long} result.
- * This is the primitive type specialization of {@link UnaryOperator} for
- * {@code long}.
+ * Represents an operation on a single {@code long}-valued operand that produces
+ * a {@code long}-valued result. This is the primitive type specialization of
+ * {@link UnaryOperator} for {@code long}.
+ *
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsLong(long)}.
*
* @see UnaryOperator
* @since 1.8
@@ -38,24 +41,25 @@
public interface LongUnaryOperator {
/**
- * Returns the {@code long} result of the operation upon the {@code long}
- * operand.
+ * Applies this operator to the given operand.
*
- * @param operand the operand value
- * @return the operation result value
+ * @param operand the operand
+ * @return the operator result
*/
long applyAsLong(long operand);
/**
- * Compose a new function which applies the provided function followed by
- * this function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed operator that first applies the {@code before}
+ * operator to its input, and then applies this operator to the result.
+ * If evaluation of either operator throws an exception, it is relayed to
+ * the caller of the composed operator.
*
- * @param before An additional function to be applied before this function
- * is applied
- * @return A function which performs the provided function followed by this
- * function
+ * @param before the operator to apply before this operator is applied
+ * @return a composed operator that first applies the {@code before}
+ * operator and then applies this operator
* @throws NullPointerException if before is null
+ *
+ * @see #andThen(LongUnaryOperator)
*/
default LongUnaryOperator compose(LongUnaryOperator before) {
Objects.requireNonNull(before);
@@ -63,15 +67,17 @@
}
/**
- * Compose a new function which applies this function followed by the
- * provided function. If either function throws an exception, it is relayed
- * to the caller.
+ * Returns a composed operator that first applies this operator to
+ * its input, and then applies the {@code after} operator to the result.
+ * If evaluation of either operator throws an exception, it is relayed to
+ * the caller of the composed operator.
*
- * @param after An additional function to be applied after this function is
- * applied
- * @return A function which performs this function followed by the provided
- * function followed
+ * @param after the operator to apply after this operator is applied
+ * @return a composed operator that first applies this operator and then
+ * applies the {@code after} operator
* @throws NullPointerException if after is null
+ *
+ * @see #compose(LongUnaryOperator)
*/
default LongUnaryOperator andThen(LongUnaryOperator after) {
Objects.requireNonNull(after);
@@ -79,9 +85,9 @@
}
/**
- * Returns a unary operator that provides its input value as the result.
+ * Returns a unary operator that always returns its input argument.
*
- * @return a unary operator that provides its input value as the result
+ * @return a unary operator that always returns its input argument
*/
static LongUnaryOperator identity() {
return t -> t;
--- a/jdk/src/share/classes/java/util/function/ObjDoubleConsumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ObjDoubleConsumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,12 +25,16 @@
package java.util.function;
/**
- * An operation which accepts an object reference and a double, and returns no
- * result. This is the {@code (reference, double)} specialization of
- * {@link BiConsumer}. Unlike most other functional interfaces,
- * {@code ObjDoubleConsumer} is expected to operate via side-effects.
+ * Represents an operation that accepts an object-valued and a
+ * {@code double}-valued argument, and returns no result. This is the
+ * {@code (reference, double)} specialization of {@link BiConsumer}.
+ * Unlike most other functional interfaces, {@code ObjDoubleConsumer} is
+ * expected to operate via side-effects.
*
- * @param <T> Type of reference argument to {@code accept()}.
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(Object, double)}.
+ *
+ * @param <T> the type of the object argument to the operation
*
* @see BiConsumer
* @since 1.8
@@ -39,10 +43,10 @@
public interface ObjDoubleConsumer<T> {
/**
- * Accept a set of input values.
+ * Performs this operation on the given arguments.
*
- * @param t an input object
- * @param value an input value
+ * @param t the first input argument
+ * @param value the second input argument
*/
void accept(T t, double value);
}
--- a/jdk/src/share/classes/java/util/function/ObjIntConsumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ObjIntConsumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,12 +25,16 @@
package java.util.function;
/**
- * An operation which accepts an object reference and an int, and returns no
- * result. This is the {@code (reference, int)} specialization of
- * {@link BiConsumer}. Unlike most other functional interfaces,
- * {@code ObjIntConsumer} is expected to operate via side-effects.
+ * Represents an operation that accepts an object-valued and a
+ * {@code int}-valued argument, and returns no result. This is the
+ * {@code (reference, int)} specialization of {@link BiConsumer}.
+ * Unlike most other functional interfaces, {@code ObjIntConsumer} is
+ * expected to operate via side-effects.
*
- * @param <T> Type of reference argument to {@code accept()}
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(Object, int)}.
+ *
+ * @param <T> the type of the object argument to the operation
*
* @see BiConsumer
* @since 1.8
@@ -39,10 +43,10 @@
public interface ObjIntConsumer<T> {
/**
- * Accept a set of input values.
+ * Performs this operation on the given arguments.
*
- * @param t an input object
- * @param value an input value
+ * @param t the first input argument
+ * @param value the second input argument
*/
void accept(T t, int value);
}
--- a/jdk/src/share/classes/java/util/function/ObjLongConsumer.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ObjLongConsumer.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,12 +25,16 @@
package java.util.function;
/**
- * An operation which accepts an object reference and a long, and returns no
- * result. This is the {@code (reference, long)} specialization of
- * {@link BiConsumer}. Unlike most other functional interfaces,
- * {@code ObjLongConsumer} is expected to operate via side-effects.
+ * Represents an operation that accepts an object-valued and a
+ * {@code long}-valued argument, and returns no result. This is the
+ * {@code (reference, long)} specialization of {@link BiConsumer}.
+ * Unlike most other functional interfaces, {@code ObjLongConsumer} is
+ * expected to operate via side-effects.
*
- * @param <T> Type of reference argument to {@code accept()}
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(Object, long)}.
+ *
+ * @param <T> the type of the object argument to the operation
*
* @see BiConsumer
* @since 1.8
@@ -39,10 +43,10 @@
public interface ObjLongConsumer<T> {
/**
- * Accept a set of input values.
+ * Performs this operation on the given arguments.
*
- * @param t an input object
- * @param value an input value
+ * @param t the first input argument
+ * @param value the second input argument
*/
void accept(T t, long value);
}
--- a/jdk/src/share/classes/java/util/function/Predicate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/Predicate.java Thu Jul 25 20:30:58 2013 -0400
@@ -27,9 +27,12 @@
import java.util.Objects;
/**
- * Determines if the input object matches some criteria.
+ * Represents a predicate (boolean-valued function) of one argument.
*
- * @param <T> the type of argument to {@code test}
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #test(Object)}.
+ *
+ * @param <T> the type of the input to the predicate
*
* @since 1.8
*/
@@ -37,76 +40,80 @@
public interface Predicate<T> {
/**
- * Returns {@code true} if the input object matches some criteria.
+ * Evaluates this predicate on the given argument.
*
- * @param t the input object
- * @return {@code true} if the input object matches some criteria, otherwise
- * {@code false}
+ * @param t the input argument
+ * @return {@code true} if the input argument matches the predicate,
+ * otherwise {@code false}
*/
boolean test(T t);
/**
- * Returns a predicate which evaluates to {@code true} only if this
- * predicate and the provided predicate both evaluate to {@code true}. If
- * this predicate returns {@code false} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * AND of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code false}, then the {@code other}
+ * predicate is not evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ANDed with this predicate
- * @return a new predicate which returns {@code true} only if both
- * predicates return {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ANDed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * AND of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default Predicate<T> and(Predicate<? super T> p) {
- Objects.requireNonNull(p);
- return (t) -> test(t) && p.test(t);
+ default Predicate<T> and(Predicate<? super T> other) {
+ Objects.requireNonNull(other);
+ return (t) -> test(t) && other.test(t);
}
/**
- * Returns a predicate which negates the result of this predicate.
+ * Returns a predicate that represents the logical negation of this
+ * predicate.
*
- * @return a new predicate who's result is always the opposite of this
- * predicate.
+ * @return a predicate that represents the logical negation of this
+ * predicate
*/
default Predicate<T> negate() {
return (t) -> !test(t);
}
/**
- * Returns a predicate which evaluates to {@code true} if either this
- * predicate or the provided predicate evaluates to {@code true}. If this
- * predicate returns {@code true} then the remaining predicate is not
- * evaluated.
+ * Returns a composed predicate that represents a short-circuiting logical
+ * OR of this predicate and another. When evaluating the composed
+ * predicate, if this predicate is {@code true}, then the {@code other}
+ * predicate is not evaluated.
*
- * <p>Any exceptions thrown by either {@code test} method are relayed
- * to the caller; if performing first operation throws an exception, the
- * second operation will not be performed.
+ * <p>Any exceptions thrown during evaluation of either predicate are relayed
+ * to the caller; if evaluation of this predicate throws an exception, the
+ * {@code other} predicate will not be evaluated.
*
- * @param p a predicate which will be logically-ORed with this predicate
- * @return a new predicate which returns {@code true} if either predicate
- * returns {@code true}
- * @throws NullPointerException if p is null
+ * @param other a predicate that will be logically-ORed with this
+ * predicate
+ * @return a composed predicate that represents the short-circuiting logical
+ * OR of this predicate and the {@code other} predicate
+ * @throws NullPointerException if other is null
*/
- default Predicate<T> or(Predicate<? super T> p) {
- Objects.requireNonNull(p);
- return (t) -> test(t) || p.test(t);
+ default Predicate<T> or(Predicate<? super T> other) {
+ Objects.requireNonNull(other);
+ return (t) -> test(t) || other.test(t);
}
/**
- * Returns a predicate who's result matches
- * {@code Objects.equals(target, t)}.
+ * Returns a predicate that tests if two arguments are equal according
+ * to {@link Objects#equals(Object, Object)}.
*
- * @param <T> the type of values evaluated by the predicate
- * @param target the target value to be compared for equality
- * @return a predicate who's result matches
- * {@code Objects.equals(target, t)}
+ * @param <T> the type of arguments to the predicate
+ * @param targetRef the object reference with which to compare for equality,
+ * which may be {@code null}
+ * @return a predicate that tests if two arguments are equal according
+ * to {@link Objects#equals(Object, Object)}
*/
- static <T> Predicate<T> isEqual(Object target) {
- return (null == target)
+ static <T> Predicate<T> isEqual(Object targetRef) {
+ return (null == targetRef)
? Objects::isNull
- : object -> target.equals(object);
+ : object -> targetRef.equals(object);
}
}
--- a/jdk/src/share/classes/java/util/function/Supplier.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/Supplier.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,10 +25,15 @@
package java.util.function;
/**
- * A supplier of objects. The result objects are either created during the
- * invocation of {@link #get} or by some prior action.
+ * Represents a supplier of results.
+ *
+ * <p>There is no requirement that a new or distinct result be returned each
+ * time the supplier is invoked.
*
- * @param <T> The type of objects returned by {@code get}
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #get()}.
+ *
+ * @param <T> the type of results supplied by this supplier
*
* @since 1.8
*/
@@ -36,9 +41,9 @@
public interface Supplier<T> {
/**
- * Returns an object.
+ * Gets a result.
*
- * @return an object
+ * @return a result
*/
T get();
}
--- a/jdk/src/share/classes/java/util/function/ToDoubleBiFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ToDoubleBiFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,13 +25,15 @@
package java.util.function;
/**
- * Apply a function to the input arguments, yielding an appropriate result.
- * This is the {@code double}-bearing specialization for {@link BiFunction}.
+ * Represents a function that accepts two arguments and produces a double-valued
+ * result. This is the {@code double}-producing primitive specialization for
+ * {@link BiFunction}.
*
- * @param <T> the type of the first argument to the {@code applyAsDouble}
- * operation.
- * @param <U> the type of the second argument to the {@code applyAsDouble}
- * operation.
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsDouble(Object, Object)}.
+ *
+ * @param <T> the type of the first argument to the function
+ * @param <U> the type of the second argument to the function
*
* @see BiFunction
* @since 1.8
@@ -40,11 +42,11 @@
public interface ToDoubleBiFunction<T, U> {
/**
- * Compute the result of applying the function to the input arguments
+ * Applies this function to the given arguments.
*
- * @param t an input object
- * @param u an input object
- * @return the function result value
+ * @param t the first function argument
+ * @param u the second function argument
+ * @return the function result
*/
double applyAsDouble(T t, U u);
}
--- a/jdk/src/share/classes/java/util/function/ToDoubleFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ToDoubleFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,10 +25,13 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code double}-bearing specialization for {@link Function}.
+ * Represents a function that produces a double-valued result. This is the
+ * {@code double}-producing primitive specialization for {@link Function}.
*
- * @param <T> the type of input objects to the function
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsDouble(Object)}.
+ *
+ * @param <T> the type of the input to the function
*
* @see Function
* @since 1.8
@@ -37,10 +40,10 @@
public interface ToDoubleFunction<T> {
/**
- * Compute the result of applying the function to the input argument
+ * Applies this function to the given argument.
*
- * @param t the input object
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
- double applyAsDouble(T t);
+ double applyAsDouble(T value);
}
--- a/jdk/src/share/classes/java/util/function/ToIntBiFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ToIntBiFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,13 +25,15 @@
package java.util.function;
/**
- * Apply a function to the input arguments, yielding an appropriate result.
- * This is the {@code int}-bearing specialization for {@link BiFunction}.
+ * Represents a function that accepts two arguments and produces an int-valued
+ * result. This is the {@code int}-producing primitive specialization for
+ * {@link BiFunction}.
*
- * @param <T> the type of the first argument to the {@code applyAsInt}
- * operation
- * @param <U> the type of the second argument to the {@code applyAsInt}
- * operation
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsInt(Object, Object)}.
+ *
+ * @param <T> the type of the first argument to the function
+ * @param <U> the type of the second argument to the function
*
* @see BiFunction
* @since 1.8
@@ -40,11 +42,11 @@
public interface ToIntBiFunction<T, U> {
/**
- * Compute the result of applying the function to the input arguments
+ * Applies this function to the given arguments.
*
- * @param t an input object
- * @param u an input object
- * @return the function result value
+ * @param t the first function argument
+ * @param u the second function argument
+ * @return the function result
*/
int applyAsInt(T t, U u);
}
--- a/jdk/src/share/classes/java/util/function/ToIntFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ToIntFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,10 +25,13 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code int}-bearing specialization for {@link Function}.
+ * Represents a function that produces an int-valued result. This is the
+ * {@code int}-producing primitive specialization for {@link Function}.
*
- * @param <T> the type of input objects to the function
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsInt(Object)}.
+ *
+ * @param <T> the type of the input to the function
*
* @see Function
* @since 1.8
@@ -37,10 +40,10 @@
public interface ToIntFunction<T> {
/**
- * Compute the result of applying the function to the input arguments
+ * Applies this function to the given argument.
*
- * @param t the input object
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
- int applyAsInt(T t);
+ int applyAsInt(T value);
}
--- a/jdk/src/share/classes/java/util/function/ToLongBiFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ToLongBiFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,13 +25,15 @@
package java.util.function;
/**
- * Apply a function to the input arguments, yielding an appropriate result.
- * This is the {@code long}-bearing specialization for {@link BiFunction}.
+ * Represents a function that accepts two arguments and produces a long-valued
+ * result. This is the {@code long}-producing primitive specialization for
+ * {@link BiFunction}.
*
- * @param <T> the type of the first argument to the {@code applyAsLong}
- * operation.
- * @param <U> the type of the second argument to the {@code applyAsLong}
- * operation.
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsLong(Object, Object)}.
+ *
+ * @param <T> the type of the first argument to the function
+ * @param <U> the type of the second argument to the function
*
* @see BiFunction
* @since 1.8
@@ -40,11 +42,11 @@
public interface ToLongBiFunction<T, U> {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given arguments.
*
- * @param t an input object
- * @param u an input object
- * @return the function result value
+ * @param t the first function argument
+ * @param u the second function argument
+ * @return the function result
*/
long applyAsLong(T t, U u);
}
--- a/jdk/src/share/classes/java/util/function/ToLongFunction.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/ToLongFunction.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,10 +25,13 @@
package java.util.function;
/**
- * Apply a function to the input argument, yielding an appropriate result.
- * This is the {@code long}-bearing specialization for {@link Function}.
+ * Represents a function that produces a long-valued result. This is the
+ * {@code long}-producing primitive specialization for {@link Function}.
*
- * @param <T> the type of input objects to the function
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #applyAsLong(Object)}.
+ *
+ * @param <T> the type of the input to the function
*
* @see Function
* @since 1.8
@@ -37,10 +40,10 @@
public interface ToLongFunction<T> {
/**
- * Compute the result of applying the function to the input arguments.
+ * Applies this function to the given argument.
*
- * @param t the input object
- * @return the function result value
+ * @param value the function argument
+ * @return the function result
*/
- long applyAsLong(T t);
+ long applyAsLong(T value);
}
--- a/jdk/src/share/classes/java/util/function/UnaryOperator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/UnaryOperator.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,11 +25,14 @@
package java.util.function;
/**
- * An operation upon a single operand yielding a result. The operand and the
- * result are of the same type. This is a specialization of {@code Function} for
+ * Represents an operation on a single operand that produces a result of the
+ * same type as its operand. This is a specialization of {@code Function} for
* the case where the operand and result are of the same type.
*
- * @param <T> the type of operand to {@code apply} and of the result
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #apply(Object)}.
+ *
+ * @param <T> the type of the operand and result of the operator
*
* @see Function
* @since 1.8
@@ -38,10 +41,10 @@
public interface UnaryOperator<T> extends Function<T, T> {
/**
- * Returns a unary operator that provides its input value as the result.
+ * Returns a unary operator that always returns its input argument.
*
- * @param <T> the type of the input and output objects to the function
- * @return a unary operator that provides its input value as the result
+ * @param <T> the type of the input and output of the operator
+ * @return a unary operator that always returns its input argument
*/
static <T> UnaryOperator<T> identity() {
return t -> t;
--- a/jdk/src/share/classes/java/util/function/package-info.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/function/package-info.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,56 +25,82 @@
/**
* <em>Functional interfaces</em> provide target types for lambda expressions
- * and method references. Each functional interface has a single abstract method
+ * and method references. Each functional interface has a single abstract
+ * method, called the <em>functional method</em> for that functional interface,
* to which the lambda expression's parameter and return types are matched or
- * adapted. Functional interfaces can provide a target type in multiple contexts,
- * such as assignment context, method invocation, or cast context:
+ * adapted. Functional interfaces can provide a target type in multiple
+ * contexts, such as assignment context, method invocation, or cast context:
*
- * <pre>
- * Predicate<String> p = String::isEmpty;
+ * <pre>{@code
+ * // Assignment context
+ * Predicate<String> p = String::isEmpty;
*
+ * // Method invocation context
* stream.filter(e -> e.getSize() > 10)...
*
+ * // Cast context
* stream.map((ToIntFunction) e -> e.getSize())...
- * </pre>
+ * }</pre>
*
- * <p>The interfaces in this package are functional interfaces used by the JDK,
- * and are available to be used by user code as well. While they do not identify
- * a complete set of function shapes to which lambda expressions might be adapted,
- * they provide enough to cover common requirements.
+ * <p>The interfaces in this package are general purpose functional interfaces
+ * used by the JDK, and are available to be used by user code as well. While
+ * they do not identify a complete set of function shapes to which lambda
+ * expressions might be adapted, they provide enough to cover common
+ * requirements. Other functional interfaces provided for specific purposes,
+ * such as {@link java.io.FileFilter}, are defined in the packages where they
+ * are used.
*
- * <p>The interfaces in this package are annotated with @{link FunctionalInterface}.
- * This annotation is not a requirement for the compiler to recognize an interface
- * as a functional interface, but merely an aid to capture design intent and enlist the
- * help of the compiler in identifying accidental violations of design intent.
+ * <p>The interfaces in this package are annotated with
+ * {@link java.lang.FunctionalInterface}. This annotation is not a requirement
+ * for the compiler to recognize an interface as a functional interface, but
+ * merely an aid to capture design intent and enlist the help of the compiler in
+ * identifying accidental violations of design intent.
*
- * <p>The functional interfaces in this package follow an extensible naming convention,
- * as follows:
+ * <p>Functional interfaces often represent abstract concepts like functions,
+ * actions, or predicates. In documenting functional interfaces, or referring
+ * to variables typed as functional interfaces, it is common to refer directly
+ * to those abstract concepts, for example using "this function" instead of
+ * "the function represented by this object".
+ *
+ * <p>The functional interfaces in this package follow an extensible naming
+ * convention, as follows:
*
* <ul>
- * <li>There are several basic function shapes, including {@link java.util.function.Function} ({@code T -> R}),
- * {@link java.util.function.Consumer} ({@code T -> void}),
- * {@link java.util.function.Predicate} ({@code T -> boolean}),
- * and {@link java.util.function.Supplier} ({@code () -> T}).
+ * <li>There are several basic function shapes, including
+ * {@link java.util.function.Function} (unary function from {@code T} to {@code R}),
+ * {@link java.util.function.Consumer} (unary function from {@code T} to {@code void}),
+ * {@link java.util.function.Predicate} (unary function from {@code T} to {@code boolean}),
+ * and {@link java.util.function.Supplier} (nilary function to {@code R}).
* </li>
- * <li>Function shapes have a natural arity based on how they are most commonly used.
- * The basic shapes can be modified by an arity prefix to indicate a different arity,
- * such as {@link java.util.function.BiFunction} ({@code (T, U) -> R}).
+ *
+ * <li>Function shapes have a natural arity based on how they are most
+ * commonly used. The basic shapes can be modified by an arity prefix to
+ * indicate a different arity, such as
+ * {@link java.util.function.BiFunction} (binary function from {@code T} and
+ * {@code U} to {@code R}).
* </li>
- * <li>There are additional derived function shapes which extend the basic function
- * shapes, including {@link java.util.function.UnaryOperator} (extends {@code Function}) and
- * {@link java.util.function.BinaryOperator} (extends {@code BiFunction}).
+ *
+ * <li>There are additional derived function shapes which extend the basic
+ * function shapes, including {@link java.util.function.UnaryOperator}
+ * (extends {@code Function}) and {@link java.util.function.BinaryOperator}
+ * (extends {@code BiFunction}).
* </li>
- * <li>Type parameters of functional interfaces can be specialized to primitives with
- * additional type prefixes. To specialize the return type for a type that has both
- * generic return type and generic arguments, we prefix {@code ToXxx}, as in
- * {@link java.util.function.ToIntFunction}. Otherwise, type arguments are specialized left-to-right,
- * as in {@link java.util.function.DoubleConsumer} or {@link java.util.function.ObjIntConsumer}.
- * (The type prefix {@code Obj} is used to indicate that we don't want to specialize this parameter,
- * but want to move on to the next parameter.) These schemes can be combined as in {@code IntToDoubleFunction}.
+ *
+ * <li>Type parameters of functional interfaces can be specialized to
+ * primitives with additional type prefixes. To specialize the return type
+ * for a type that has both generic return type and generic arguments, we
+ * prefix {@code ToXxx}, as in {@link java.util.function.ToIntFunction}.
+ * Otherwise, type arguments are specialized left-to-right, as in
+ * {@link java.util.function.DoubleConsumer}
+ * or {@link java.util.function.ObjIntConsumer}.
+ * (The type prefix {@code Obj} is used to indicate that we don't want to
+ * specialize this parameter, but want to move on to the next parameter,
+ * as in {@link java.util.function.ObjIntConsumer}.)
+ * These schemes can be combined, as in {@code IntToDoubleFunction}.
* </li>
- * <li>If there are specialization prefixes for all arguments, the arity prefix may be left
- * out (as in {@link java.util.function.ObjIntConsumer}).
+ *
+ * <li>If there are specialization prefixes for all arguments, the arity
+ * prefix may be left out (as in {@link java.util.function.ObjIntConsumer}).
* </li>
* </ul>
*
--- a/jdk/src/share/classes/java/util/jar/Attributes.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/jar/Attributes.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -527,7 +527,7 @@
* <code>Name</code> object for <code>Manifest-Version</code>
* manifest attribute. This attribute indicates the version number
* of the manifest standard to which a JAR file's manifest conforms.
- * @see <a href="../../../../technotes/guides/jar/jar.html#JAR Manifest">
+ * @see <a href="../../../../technotes/guides/jar/jar.html#JAR_Manifest">
* Manifest and Signature Specification</a>
*/
public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
@@ -535,7 +535,7 @@
/**
* <code>Name</code> object for <code>Signature-Version</code>
* manifest attribute used when signing JAR files.
- * @see <a href="../../../../technotes/guides/jar/jar.html#JAR Manifest">
+ * @see <a href="../../../../technotes/guides/jar/jar.html#JAR_Manifest">
* Manifest and Signature Specification</a>
*/
public static final Name SIGNATURE_VERSION = new Name("Signature-Version");
--- a/jdk/src/share/classes/java/util/jar/JarEntry.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/jar/JarEntry.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -81,6 +81,7 @@
*
* @return the <code>Manifest</code> <code>Attributes</code> for this
* entry, or <code>null</code> if none
+ * @throws IOException if an I/O error has occurred
*/
public Attributes getAttributes() throws IOException {
return attr;
--- a/jdk/src/share/classes/java/util/jar/JarFile.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/jar/JarFile.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -168,6 +168,7 @@
*
* @throws IllegalStateException
* may be thrown if the jar file has been closed
+ * @throws IOException if an I/O error has occurred
*/
public Manifest getManifest() throws IOException {
return getManifestFromReference();
--- a/jdk/src/share/classes/java/util/stream/StreamSupport.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/java/util/stream/StreamSupport.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, 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
@@ -96,6 +96,7 @@
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
* more details.
*
+ * @param <T> the type of stream elements
* @param supplier a {@code Supplier} of a {@code Spliterator}
* @param characteristics Spliterator characteristics of the supplied
* {@code Spliterator}. The characteristics must be equal to
--- a/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -310,7 +310,8 @@
private static final Byte[][] PKCS9_VALUE_TAGS = {
null,
{new Byte(DerValue.tag_IA5String)}, // EMailAddress
- {new Byte(DerValue.tag_IA5String)}, // UnstructuredName
+ {new Byte(DerValue.tag_IA5String), // UnstructuredName
+ new Byte(DerValue.tag_PrintableString)},
{new Byte(DerValue.tag_ObjectId)}, // ContentType
{new Byte(DerValue.tag_OctetString)}, // MessageDigest
{new Byte(DerValue.tag_UtcTime)}, // SigningTime
--- a/jdk/src/share/classes/sun/security/provider/certpath/OCSP.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/provider/certpath/OCSP.java Thu Jul 25 20:30:58 2013 -0400
@@ -255,7 +255,9 @@
}
response = Arrays.copyOf(response, total);
} catch (IOException ioe) {
- throw new NetworkFailureException(ioe);
+ throw new CertPathValidatorException(
+ "Unable to determine revocation status due to network error",
+ ioe, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
} finally {
if (in != null) {
try {
@@ -355,17 +357,4 @@
*/
Map<String, Extension> getSingleExtensions();
}
-
- static class NetworkFailureException extends CertPathValidatorException {
- private static final long serialVersionUID = 0l;
-
- NetworkFailureException(Throwable t) {
- super(t);
- }
-
- @Override
- public CertPathValidatorException.Reason getReason() {
- return BasicReason.UNDETERMINED_REVOCATION_STATUS;
- }
- }
}
--- a/jdk/src/share/classes/sun/security/provider/certpath/OCSPResponse.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/provider/certpath/OCSPResponse.java Thu Jul 25 20:30:58 2013 -0400
@@ -30,6 +30,7 @@
import java.security.cert.CertificateException;
import java.security.cert.CertificateParsingException;
import java.security.cert.CertPathValidatorException;
+import java.security.cert.CertPathValidatorException.BasicReason;
import java.security.cert.CRLReason;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
@@ -121,8 +122,8 @@
public enum ResponseStatus {
SUCCESSFUL, // Response has valid confirmations
- MALFORMED_REQUEST, // Illegal confirmation request
- INTERNAL_ERROR, // Internal error in issuer
+ MALFORMED_REQUEST, // Illegal request
+ INTERNAL_ERROR, // Internal error in responder
TRY_LATER, // Try again later
UNUSED, // is not used
SIG_REQUIRED, // Must sign the request
@@ -381,9 +382,18 @@
Date date, byte[] nonce)
throws CertPathValidatorException
{
- if (responseStatus != ResponseStatus.SUCCESSFUL) {
- throw new CertPathValidatorException
- ("OCSP response error: " + responseStatus);
+ switch (responseStatus) {
+ case SUCCESSFUL:
+ break;
+ case UNAUTHORIZED:
+ case TRY_LATER:
+ case INTERNAL_ERROR:
+ throw new CertPathValidatorException(
+ "OCSP response error: " + responseStatus, null, null, -1,
+ BasicReason.UNDETERMINED_REVOCATION_STATUS);
+ default:
+ throw new CertPathValidatorException("OCSP response error: " +
+ responseStatus);
}
// Check that the response includes a response for all of the
--- a/jdk/src/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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
@@ -193,10 +193,15 @@
List<PKIXCertPathChecker> checkers = params.certPathCheckers();
for (PKIXCertPathChecker checker : checkers) {
if (checker instanceof PKIXRevocationChecker) {
+ if (revCheckerAdded) {
+ throw new CertPathValidatorException(
+ "Only one PKIXRevocationChecker can be specified");
+ }
revCheckerAdded = true;
// if it's our own, initialize it
- if (checker instanceof RevocationChecker)
+ if (checker instanceof RevocationChecker) {
((RevocationChecker)checker).init(anchor, params);
+ }
}
}
// only add a RevocationChecker if revocation is enabled and
--- a/jdk/src/share/classes/sun/security/provider/certpath/ReverseState.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/provider/certpath/ReverseState.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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,6 +30,7 @@
import java.security.cert.CertificateException;
import java.security.cert.CertPathValidatorException;
import java.security.cert.PKIXCertPathChecker;
+import java.security.cert.PKIXRevocationChecker;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
@@ -235,9 +236,16 @@
for (PKIXCertPathChecker checker : userCheckers) {
if (checker instanceof AlgorithmChecker) {
((AlgorithmChecker)checker).trySetTrustAnchor(anchor);
- } else if (checker instanceof RevocationChecker) {
- ((RevocationChecker)checker).init(anchor, buildParams);
- ((RevocationChecker)checker).init(false);
+ } else if (checker instanceof PKIXRevocationChecker) {
+ if (revCheckerAdded) {
+ throw new CertPathValidatorException(
+ "Only one PKIXRevocationChecker can be specified");
+ }
+ // if it's our own, initialize it
+ if (checker instanceof RevocationChecker) {
+ ((RevocationChecker)checker).init(anchor, buildParams);
+ }
+ ((PKIXRevocationChecker)checker).init(false);
revCheckerAdded = true;
}
}
--- a/jdk/src/share/classes/sun/security/provider/certpath/RevocationChecker.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/provider/certpath/RevocationChecker.java Thu Jul 25 20:30:58 2013 -0400
@@ -38,14 +38,7 @@
import java.security.cert.CertPathValidatorException.BasicReason;
import java.security.cert.Extension;
import java.security.cert.*;
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import javax.security.auth.x500.X500Principal;
import static sun.security.provider.certpath.OCSP.*;
@@ -70,13 +63,16 @@
private Map<X509Certificate, byte[]> ocspResponses;
private List<Extension> ocspExtensions;
private boolean legacy;
+ private LinkedList<CertPathValidatorException> softFailExceptions =
+ new LinkedList<>();
// state variables
private X509Certificate issuerCert;
private PublicKey prevPubKey;
private boolean crlSignFlag;
+ private int certIndex;
- private enum Mode { PREFER_OCSP, PREFER_CRLS, ONLY_CRLS };
+ private enum Mode { PREFER_OCSP, PREFER_CRLS, ONLY_CRLS, ONLY_OCSP };
private Mode mode = Mode.PREFER_OCSP;
private static class RevocationProperties {
@@ -104,9 +100,9 @@
throws CertPathValidatorException
{
RevocationProperties rp = getRevocationProperties();
- URI uri = getOCSPResponder();
+ URI uri = getOcspResponder();
responderURI = (uri == null) ? toURI(rp.ocspUrl) : uri;
- X509Certificate cert = getOCSPResponderCert();
+ X509Certificate cert = getOcspResponderCert();
responderCert = (cert == null)
? getResponderCert(rp, params.trustAnchors(),
params.certStores())
@@ -117,31 +113,38 @@
case ONLY_END_ENTITY:
case PREFER_CRLS:
case SOFT_FAIL:
+ case NO_FALLBACK:
break;
default:
throw new CertPathValidatorException(
"Unrecognized revocation parameter option: " + option);
}
}
+ softFail = options.contains(Option.SOFT_FAIL);
// set mode, only end entity flag
if (legacy) {
mode = (rp.ocspEnabled) ? Mode.PREFER_OCSP : Mode.ONLY_CRLS;
onlyEE = rp.onlyEE;
} else {
- if (options.contains(Option.PREFER_CRLS)) {
+ if (options.contains(Option.NO_FALLBACK)) {
+ if (options.contains(Option.PREFER_CRLS)) {
+ mode = Mode.ONLY_CRLS;
+ } else {
+ mode = Mode.ONLY_OCSP;
+ }
+ } else if (options.contains(Option.PREFER_CRLS)) {
mode = Mode.PREFER_CRLS;
}
onlyEE = options.contains(Option.ONLY_END_ENTITY);
}
- softFail = options.contains(Option.SOFT_FAIL);
if (legacy) {
crlDP = rp.crlDPEnabled;
} else {
crlDP = true;
}
- ocspResponses = getOCSPResponses();
- ocspExtensions = getOCSPExtensions();
+ ocspResponses = getOcspResponses();
+ ocspExtensions = getOcspExtensions();
this.anchor = anchor;
this.params = params;
@@ -297,14 +300,19 @@
if (forward) {
throw new
CertPathValidatorException("forward checking not supported");
+ }
+ if (anchor != null) {
+ issuerCert = anchor.getTrustedCert();
+ prevPubKey = (issuerCert != null) ? issuerCert.getPublicKey()
+ : anchor.getCAPublicKey();
+ }
+ crlSignFlag = true;
+ if (params.certPath() != null) {
+ certIndex = params.certPath().getCertificates().size() - 1;
} else {
- if (anchor != null) {
- issuerCert = anchor.getTrustedCert();
- prevPubKey = (issuerCert != null) ? issuerCert.getPublicKey()
- : anchor.getCAPublicKey();
- }
- crlSignFlag = true;
+ certIndex = -1;
}
+ softFailExceptions.clear();
}
@Override
@@ -318,27 +326,34 @@
}
@Override
+ public List<CertPathValidatorException> getSoftFailExceptions() {
+ return Collections.unmodifiableList(softFailExceptions);
+ }
+
+ @Override
public void check(Certificate cert, Collection<String> unresolvedCritExts)
throws CertPathValidatorException
{
- X509Certificate xcert = (X509Certificate)cert;
- if (onlyEE && xcert.getBasicConstraints() != -1) {
- if (debug != null) {
- debug.println("Skipping revocation check, not end entity cert");
- }
- } else {
- check(xcert, unresolvedCritExts, prevPubKey, crlSignFlag);
- }
- updateState(xcert);
+ check((X509Certificate)cert, unresolvedCritExts,
+ prevPubKey, crlSignFlag);
}
- void check(X509Certificate xcert, Collection<String> unresolvedCritExts,
- PublicKey pubKey, boolean crlSignFlag)
+ private void check(X509Certificate xcert,
+ Collection<String> unresolvedCritExts,
+ PublicKey pubKey, boolean crlSignFlag)
throws CertPathValidatorException
{
try {
+ if (onlyEE && xcert.getBasicConstraints() != -1) {
+ if (debug != null) {
+ debug.println("Skipping revocation check, not end " +
+ "entity cert");
+ }
+ return;
+ }
switch (mode) {
case PREFER_OCSP:
+ case ONLY_OCSP:
checkOCSP(xcert, unresolvedCritExts);
break;
case PREFER_CRLS:
@@ -351,14 +366,17 @@
if (e.getReason() == BasicReason.REVOKED) {
throw e;
}
- CertPathValidatorException cause = e;
- if (softFail && e instanceof NetworkFailureException) {
- if (mode == Mode.ONLY_CRLS) return;
+ boolean eSoftFail = isSoftFailException(e);
+ if (eSoftFail) {
+ if (mode == Mode.ONLY_OCSP || mode == Mode.ONLY_CRLS) {
+ return;
+ }
+ } else {
+ if (mode == Mode.ONLY_OCSP || mode == Mode.ONLY_CRLS) {
+ throw e;
+ }
}
- // Rethrow the exception if ONLY_CRLS
- if (mode == Mode.ONLY_CRLS) {
- throw e;
- }
+ CertPathValidatorException cause = e;
// Otherwise, failover
if (debug != null) {
debug.println("RevocationChecker.check() " + e.getMessage());
@@ -382,22 +400,35 @@
if (x.getReason() == BasicReason.REVOKED) {
throw x;
}
- if (cause != null) {
- if (softFail && cause instanceof NetworkFailureException) {
- return;
- } else {
- cause.addSuppressed(x);
+ if (!isSoftFailException(x)) {
+ cause.addSuppressed(x);
+ throw cause;
+ } else {
+ // only pass if both exceptions were soft failures
+ if (!eSoftFail) {
throw cause;
}
}
- if (softFail && x instanceof NetworkFailureException) {
- return;
- }
- throw x;
}
+ } finally {
+ updateState(xcert);
}
}
+ private boolean isSoftFailException(CertPathValidatorException e) {
+ if (softFail &&
+ e.getReason() == BasicReason.UNDETERMINED_REVOCATION_STATUS)
+ {
+ // recreate exception with correct index
+ CertPathValidatorException e2 = new CertPathValidatorException(
+ e.getMessage(), e.getCause(), params.certPath(), certIndex,
+ e.getReason());
+ softFailExceptions.addFirst(e2);
+ return true;
+ }
+ return false;
+ }
+
private void updateState(X509Certificate cert)
throws CertPathValidatorException
{
@@ -411,6 +442,9 @@
}
prevPubKey = pubKey;
crlSignFlag = certCanSignCrl(cert);
+ if (certIndex > 0) {
+ certIndex--;
+ }
}
// Maximum clock skew in milliseconds (15 minutes) allowed when checking
@@ -446,8 +480,8 @@
" circular dependency");
}
throw new CertPathValidatorException
- ("Could not determine revocation status", null, null, -1,
- BasicReason.UNDETERMINED_REVOCATION_STATUS);
+ ("Could not determine revocation status", null, null, -1,
+ BasicReason.UNDETERMINED_REVOCATION_STATUS);
}
Set<X509CRL> possibleCRLs = new HashSet<>();
@@ -457,7 +491,7 @@
CertPathHelper.setDateAndTime(sel, params.date(), MAX_CLOCK_SKEW);
// First, check user-specified CertStores
- NetworkFailureException nfe = null;
+ CertPathValidatorException networkFailureException = null;
for (CertStore store : certStores) {
try {
for (CRL crl : store.getCRLs(sel)) {
@@ -468,10 +502,13 @@
debug.println("RevocationChecker.checkCRLs() " +
"CertStoreException: " + e.getMessage());
}
- if (softFail && nfe == null &&
+ if (networkFailureException == null &&
CertStoreHelper.isCausedByNetworkIssue(store.getType(),e)) {
// save this exception, we may need to throw it later
- nfe = new NetworkFailureException(e);
+ networkFailureException = new CertPathValidatorException(
+ "Unable to determine revocation status due to " +
+ "network error", e, null, -1,
+ BasicReason.UNDETERMINED_REVOCATION_STATUS);
}
}
}
@@ -508,14 +545,17 @@
approvedCRLs.addAll(DistributionPointFetcher.getCRLs(
sel, signFlag, prevKey,
params.sigProvider(), certStores,
- reasonsMask, anchors, params.date()));
+ reasonsMask, anchors, null));
}
} catch (CertStoreException e) {
- if (softFail && e instanceof CertStoreTypeException) {
+ if (e instanceof CertStoreTypeException) {
CertStoreTypeException cste = (CertStoreTypeException)e;
if (CertStoreHelper.isCausedByNetworkIssue(cste.getType(),
e)) {
- throw new NetworkFailureException(e);
+ throw new CertPathValidatorException(
+ "Unable to determine revocation status due to " +
+ "network error", e, null, -1,
+ BasicReason.UNDETERMINED_REVOCATION_STATUS);
}
}
throw new CertPathValidatorException(e);
@@ -531,26 +571,26 @@
stackedCerts);
return;
} catch (CertPathValidatorException cpve) {
- if (nfe != null) {
+ if (networkFailureException != null) {
// if a network issue previously prevented us from
// retrieving a CRL from one of the user-specified
- // CertStores and SOFT_FAIL is enabled, throw it now
- // so it can be handled appropriately
- throw nfe;
+ // CertStores, throw it now so it can be handled
+ // appropriately
+ throw networkFailureException;
}
throw cpve;
}
} else {
- if (nfe != null) {
+ if (networkFailureException != null) {
// if a network issue previously prevented us from
// retrieving a CRL from one of the user-specified
- // CertStores and SOFT_FAIL is enabled, throw it now
- // so it can be handled appropriately
- throw nfe;
+ // CertStores, throw it now so it can be handled
+ // appropriately
+ throw networkFailureException;
}
- throw new CertPathValidatorException
- ("Could not determine revocation status", null, null, -1,
- BasicReason.UNDETERMINED_REVOCATION_STATUS);
+ throw new CertPathValidatorException(
+ "Could not determine revocation status", null, null, -1,
+ BasicReason.UNDETERMINED_REVOCATION_STATUS);
}
}
}
@@ -595,14 +635,9 @@
unresCritExts.remove(ReasonCode_Id.toString());
unresCritExts.remove(CertificateIssuer_Id.toString());
if (!unresCritExts.isEmpty()) {
- if (debug != null) {
- debug.println("Unrecognized "
- + "critical extension(s) in revoked CRL entry: "
- + unresCritExts);
- }
- throw new CertPathValidatorException
- ("Could not determine revocation status", null, null,
- -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
+ throw new CertPathValidatorException(
+ "Unrecognized critical extension(s) in revoked " +
+ "CRL entry");
}
}
@@ -610,11 +645,14 @@
if (reasonCode == null) {
reasonCode = CRLReason.UNSPECIFIED;
}
- Throwable t = new CertificateRevokedException
- (entry.getRevocationDate(), reasonCode,
- crl.getIssuerX500Principal(), entry.getExtensions());
- throw new CertPathValidatorException(t.getMessage(), t,
- null, -1, BasicReason.REVOKED);
+ Date revocationDate = entry.getRevocationDate();
+ if (revocationDate.before(params.date())) {
+ Throwable t = new CertificateRevokedException(
+ revocationDate, reasonCode,
+ crl.getIssuerX500Principal(), entry.getExtensions());
+ throw new CertPathValidatorException(
+ t.getMessage(), t, null, -1, BasicReason.REVOKED);
+ }
}
}
}
@@ -630,9 +668,6 @@
throw new CertPathValidatorException(ce);
}
- URI responderURI = (this.responderURI != null)
- ? this.responderURI : getOCSPServerURI(currCert);
-
X509Certificate respCert = (responderCert == null) ? issuerCert
: responderCert;
@@ -671,23 +706,38 @@
params.date(), nonce);
} else {
+ URI responderURI = (this.responderURI != null)
+ ? this.responderURI
+ : OCSP.getResponderURI(currCert);
+ if (responderURI == null) {
+ throw new CertPathValidatorException(
+ "Certificate does not specify OCSP responder", null,
+ null, -1);
+ }
+
response = OCSP.check(Collections.singletonList(certId),
- responderURI, respCert, params.date(),
+ responderURI, respCert, null,
ocspExtensions);
}
} catch (IOException e) {
- throw new CertPathValidatorException(e);
+ throw new CertPathValidatorException(
+ "Unable to determine revocation status due to network error",
+ e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
}
RevocationStatus rs =
(RevocationStatus)response.getSingleResponse(certId);
RevocationStatus.CertStatus certStatus = rs.getCertStatus();
if (certStatus == RevocationStatus.CertStatus.REVOKED) {
- Throwable t = new CertificateRevokedException(
- rs.getRevocationTime(), rs.getRevocationReason(),
- respCert.getSubjectX500Principal(), rs.getSingleExtensions());
- throw new CertPathValidatorException(t.getMessage(), t, null,
- -1, BasicReason.REVOKED);
+ Date revocationTime = rs.getRevocationTime();
+ if (revocationTime.before(params.date())) {
+ Throwable t = new CertificateRevokedException(
+ revocationTime, rs.getRevocationReason(),
+ respCert.getSubjectX500Principal(),
+ rs.getSingleExtensions());
+ throw new CertPathValidatorException(t.getMessage(), t, null,
+ -1, BasicReason.REVOKED);
+ }
} else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
throw new CertPathValidatorException(
"Certificate's revocation status is unknown", null,
@@ -711,34 +761,6 @@
return hexNumber.toString();
}
- private static URI getOCSPServerURI(X509CertImpl cert)
- throws CertPathValidatorException
- {
- // Examine the certificate's AuthorityInfoAccess extension
- AuthorityInfoAccessExtension aia =
- cert.getAuthorityInfoAccessExtension();
- if (aia == null) {
- throw new CertPathValidatorException(
- "Must specify the location of an OCSP Responder");
- }
-
- List<AccessDescription> descriptions = aia.getAccessDescriptions();
- for (AccessDescription description : descriptions) {
- if (description.getAccessMethod().equals((Object)
- AccessDescription.Ad_OCSP_Id)) {
-
- GeneralName generalName = description.getAccessLocation();
- if (generalName.getType() == GeneralNameInterface.NAME_URI) {
- URIName uri = (URIName)generalName.getName();
- return uri.getURI();
- }
- }
- }
-
- throw new CertPathValidatorException(
- "Cannot find the location of the OCSP Responder");
- }
-
/**
* Checks that a cert can be used to verify a CRL.
*
@@ -870,8 +892,8 @@
" circular dependency");
}
throw new CertPathValidatorException
- ("Could not determine revocation status", null, null,
- -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
+ ("Could not determine revocation status", null, null, -1,
+ BasicReason.UNDETERMINED_REVOCATION_STATUS);
}
// Try to find another key that might be able to sign
@@ -1067,6 +1089,15 @@
}
}
+ @Override
+ public RevocationChecker clone() {
+ RevocationChecker copy = (RevocationChecker)super.clone();
+ // we don't deep-copy the exceptions, but that is ok because they
+ // are never modified after they are instantiated
+ copy.softFailExceptions = new LinkedList<>(softFailExceptions);
+ return copy;
+ }
+
/*
* This inner class extends the X509CertSelector to add an additional
* check to make sure the subject public key isn't on a particular list.
--- a/jdk/src/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, 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
@@ -422,7 +422,6 @@
buildParams.anyPolicyInhibited(),
buildParams.policyQualifiersRejected(),
rootNode);
-
checkers.add(policyChecker);
// add the algorithm checker
@@ -455,11 +454,16 @@
List<PKIXCertPathChecker> ckrs = buildParams.certPathCheckers();
for (PKIXCertPathChecker ckr : ckrs) {
if (ckr instanceof PKIXRevocationChecker) {
+ if (revCheckerAdded) {
+ throw new CertPathValidatorException(
+ "Only one PKIXRevocationChecker can be specified");
+ }
revCheckerAdded = true;
// if it's our own, initialize it
- if (ckr instanceof RevocationChecker)
+ if (ckr instanceof RevocationChecker) {
((RevocationChecker)ckr).init(builder.trustAnchor,
buildParams);
+ }
}
}
// only add a RevocationChecker if revocation is enabled and
--- a/jdk/src/share/classes/sun/security/tools/keytool/Main.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/classes/sun/security/tools/keytool/Main.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -2198,8 +2198,15 @@
printExtensions(rb.getString("Extension.Request."), exts, out);
}
} else {
- out.println(attr.getAttributeId());
- out.println(attr.getAttributeValue());
+ out.println("Attribute: " + attr.getAttributeId());
+ PKCS9Attribute pkcs9Attr =
+ new PKCS9Attribute(attr.getAttributeId(),
+ attr.getAttributeValue());
+ out.print(pkcs9Attr.getName() + ": ");
+ Object attrVal = attr.getAttributeValue();
+ out.println(attrVal instanceof String[] ?
+ Arrays.toString((String[]) attrVal) :
+ attrVal);
}
}
if (debug) {
--- a/jdk/src/share/lib/hijrah-config-umalqura.properties Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/lib/hijrah-config-umalqura.properties Thu Jul 25 20:30:58 2013 -0400
@@ -1,58 +1,369 @@
-#
-# hijrah-config-umalqura.properties
-#
-#
-# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
-#
-# This properties file defines a Hijrah calendar variant.
-#
-# Fields:
-#
-# <version> ::= 'version' '=' <version string>
-# <id> ::= 'id' '=' <id string>
-# <type> ::= 'type' '=' <type string>
-# <iso-start> ::= 'iso-start' '=' <start date in the ISO calendar>
-# <year> ::= <yyyy> '=' <nn nn nn nn nn nn nn nn nn nn nn nn>
-#
-# version ... (Required)
-#
-# id ... (Required)
-# Identifies the Java Chronology
-#
-# type ... (Required)
-# Identifies the type of calendar in the standard calendar ID scheme
-# iso-start ... (Required)
-# Specifies the corresponding ISO date to the first Hijrah day
-# in the defined range of dates
-#
-# year ... (Required)
-# Number of days for each month of a Hijrah year
-# * Each line defines a year. The years must be in the chronological
-# order and no gap is allowed.
-# * Each line is in the form indicated above. <yyyy> is a Hijrah year and
-# nn is the number of days for a month listed in the order of the months.
-# * Each year must have 12 months.
-# * Each month should be 29 or 30 days long.
-# * There must be one or more space characters between the months.
-#
-
-# indicates the version of this definition
-version=1.8.0_1
-
-# Java chronology ID
-id=Hijrah-umalqura
-
-# Standard calendar type specification
-type=islamic-umalqura
-
-# defines the corresponding ISO date to the earliest Hijrah date
-iso-start=2010-12-07
-
-#
-# the data section; defines the dates with the number of days for each month
-#
-# Placeholder data until full Umm alQura data can be validated
-1432=29 30 30 30 29 30 29 30 29 30 29 29
-1433=30 29 30 30 29 30 30 29 30 29 30 29
-1434=29 30 29 30 29 30 30 29 30 30 29 29
-1435=30 29 30 29 30 29 30 29 30 30 29 30
+# Copyright (c) 2013, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation. Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+# This properties file defines a Hijrah calendar variant.
+#
+# Fields:
+#
+# <version> ::= 'version' '=' <version string>
+# <id> ::= 'id' '=' <id string>
+# <type> ::= 'type' '=' <type string>
+# <iso-start> ::= 'iso-start' '=' <start date in the ISO calendar>
+# <year> ::= <yyyy> '=' <nn nn nn nn nn nn nn nn nn nn nn nn>
+#
+# version ... (Required)
+#
+# id ... (Required)
+# Identifies the Java Chronology
+#
+# type ... (Required)
+# Identifies the type of calendar in the standard calendar ID scheme
+# iso-start ... (Required)
+# Specifies the corresponding ISO date to the first Hijrah day
+# in the defined range of dates
+#
+# year ... (Required)
+# Number of days for each month of a Hijrah year
+# * Each line defines a year. The years must be in chronological
+# order and no gap is allowed.
+# * Each line is in the form indicated above. <yyyy> is a Hijrah year and
+# nn is the number of days for a month listed in the order of the months.
+# * Each year must have 12 months.
+# * Each month should be 29 or 30 days long.
+# * There must be one or more space characters between the months.
+#
+
+# Version of this definition
+version=1.8.0_1
+
+# Java chronology ID
+id=Hijrah-umalqura
+
+# Standard calendar type specification
+type=islamic-umalqura
+
+# defines the corresponding ISO date to the earliest Hijrah date
+iso-start=1882-11-12
+
+# 1 2 3 4 5 6 7 8 9 10 11 12
+1300=30 29 30 29 30 29 30 29 30 29 30 29
+1301=30 30 29 30 29 30 29 30 29 30 29 29
+1302=30 30 30 29 30 30 29 29 30 29 29 30
+1303=29 30 30 29 30 30 29 30 29 30 29 29
+1304=29 30 30 29 30 30 30 29 30 29 30 29
+1305=29 29 30 30 29 30 30 29 30 30 29 29
+1306=30 29 30 29 30 29 30 29 30 30 29 30
+1307=29 30 29 30 29 30 29 30 29 30 29 30
+1308=29 30 30 29 30 29 30 29 30 29 29 30
+1309=29 30 30 30 30 29 29 30 29 29 30 29
+1310=30 29 30 30 30 29 30 29 30 29 29 30
+1311=29 30 29 30 30 30 29 30 29 30 29 29
+1312=30 29 30 29 30 30 29 30 30 29 30 29
+1313=29 30 29 30 29 30 29 30 30 30 29 29
+1314=30 30 29 30 29 29 30 29 30 30 29 30
+1315=29 30 30 29 30 29 29 30 29 30 29 30
+1316=29 30 30 30 29 30 29 29 30 29 30 29
+1317=30 29 30 30 29 30 29 30 29 30 29 29
+1318=30 29 30 30 29 30 30 29 30 29 30 29
+1319=29 30 29 30 30 29 30 29 30 30 29 30
+1320=29 30 29 29 30 29 30 29 30 30 30 29
+1321=30 29 30 29 29 30 29 29 30 30 30 30
+1322=29 30 29 30 29 29 29 30 29 30 30 30
+1323=29 30 30 29 30 29 29 29 30 29 30 30
+1324=29 30 30 29 30 29 30 29 29 30 29 30
+1325=30 29 30 29 30 30 29 30 29 30 29 30
+1326=29 29 30 29 30 30 29 30 29 30 30 29
+1327=30 29 29 30 29 30 29 30 30 29 30 30
+1328=29 30 29 29 30 29 29 30 30 30 29 30
+1329=30 29 30 29 29 30 29 29 30 30 29 30
+1330=30 30 29 30 29 29 30 29 29 30 30 29
+1331=30 30 29 30 30 29 29 30 29 30 29 30
+1332=29 30 29 30 30 29 30 29 30 30 29 29
+1333=30 29 29 30 30 29 30 30 29 30 30 29
+1334=29 29 30 29 30 29 30 30 30 29 30 29
+1335=30 29 30 29 29 30 29 30 30 29 30 30
+1336=29 30 29 30 29 29 30 29 30 29 30 30
+1337=30 29 30 29 30 29 29 30 29 30 29 30
+1338=29 30 30 29 30 30 29 29 30 29 30 29
+1339=30 29 30 29 30 30 30 29 30 29 29 30
+1340=29 29 30 29 30 30 30 30 29 30 29 29
+1341=30 29 29 30 29 30 30 30 29 30 30 29
+1342=29 29 30 29 30 29 30 30 29 30 30 29
+1343=30 29 29 30 29 30 29 30 29 30 30 29
+1344=30 29 30 29 30 30 29 29 30 29 30 29
+1345=30 29 30 30 30 29 30 29 29 30 29 29
+1346=30 29 30 30 30 30 29 30 29 29 30 29
+1347=29 30 29 30 30 30 29 30 30 29 29 30
+1348=29 29 30 29 30 30 29 30 30 30 29 29
+1349=30 29 29 30 29 30 30 29 30 30 29 30
+1350=29 30 29 30 29 30 29 29 30 30 29 30
+1351=30 29 30 29 30 29 30 29 29 30 29 30
+1352=30 29 30 30 29 30 29 30 29 29 30 29
+1353=30 29 30 30 30 29 30 29 29 30 29 30
+1354=29 30 29 30 30 29 30 30 29 30 29 29
+1355=30 29 29 30 30 29 30 30 29 30 30 29
+1356=29 30 29 30 29 30 29 30 29 30 30 30
+1357=29 29 30 29 30 29 29 30 29 30 30 30
+1358=29 30 29 30 29 30 29 29 30 29 30 30
+1359=29 30 30 29 30 29 30 29 29 29 30 30
+1360=29 30 30 30 29 30 29 30 29 29 30 29
+1361=30 29 30 30 29 30 30 29 29 30 29 30
+1362=29 30 29 30 29 30 30 29 30 29 30 29
+1363=30 29 30 29 30 29 30 29 30 29 30 30
+1364=29 30 29 30 29 29 30 29 30 29 30 30
+1365=30 30 29 29 30 29 29 30 29 30 29 30
+1366=30 30 29 30 29 30 29 29 30 29 30 29
+1367=30 30 29 30 30 29 30 29 29 30 29 30
+1368=29 30 29 30 30 30 29 29 30 29 30 29
+1369=30 29 30 29 30 30 29 30 29 30 30 29
+1370=30 29 29 30 29 30 29 30 29 30 30 30
+1371=29 30 29 29 30 29 30 29 30 29 30 30
+1372=30 29 29 30 29 30 29 29 30 29 30 30
+1373=30 29 30 29 30 29 30 29 29 30 29 30
+1374=30 29 30 30 29 30 29 30 29 29 30 29
+1375=30 29 30 30 29 30 30 29 30 29 30 29
+1376=29 30 29 30 29 30 30 30 29 30 29 30
+1377=29 29 30 29 29 30 30 30 29 30 30 29
+1378=30 29 29 29 30 29 30 30 29 30 30 30
+1379=29 30 29 29 29 30 29 30 30 29 30 30
+1380=29 30 29 30 29 30 29 30 29 30 29 30
+1381=29 30 29 30 30 29 30 29 30 29 29 30
+1382=29 30 29 30 30 29 30 30 29 30 29 29
+1383=30 29 29 30 30 30 29 30 30 29 30 29
+1384=29 30 29 29 30 30 29 30 30 30 29 30
+1385=29 29 30 29 29 30 30 29 30 30 30 29
+1386=30 29 29 30 29 29 30 30 29 30 30 29
+1387=30 29 30 29 30 29 30 29 30 29 30 29
+1388=30 30 29 30 29 30 29 30 29 30 29 29
+1389=30 30 29 30 30 29 30 30 29 29 30 29
+1390=29 30 29 30 30 30 29 30 29 30 29 30
+1391=29 29 30 29 30 30 29 30 30 29 30 29
+1392=30 29 29 30 29 30 29 30 30 29 30 30
+1393=29 30 29 29 30 29 30 29 30 29 30 30
+1394=30 29 30 29 29 30 29 30 29 30 29 30
+1395=30 29 30 30 29 30 29 29 30 29 29 30
+1396=30 29 30 30 29 30 30 29 29 30 29 29
+1397=30 29 30 30 29 30 30 30 29 29 29 30
+1398=29 30 29 30 30 29 30 30 29 30 29 29
+1399=30 29 30 29 30 29 30 30 29 30 29 30
+1400=30 29 30 29 29 30 29 30 29 30 29 30
+1401=30 30 29 30 29 29 30 29 29 30 29 30
+1402=30 30 30 29 30 29 29 30 29 29 30 29
+1403=30 30 30 29 30 30 29 29 30 29 29 30
+1404=29 30 30 29 30 30 29 30 29 30 29 29
+1405=30 29 30 29 30 30 30 29 30 29 29 30
+1406=30 29 29 30 29 30 30 29 30 29 30 30
+1407=29 30 29 29 30 29 30 29 30 29 30 30
+1408=30 29 30 29 30 29 29 30 29 29 30 30
+1409=30 30 29 30 29 30 29 29 30 29 29 30
+1410=30 30 29 30 30 29 30 29 29 30 29 29
+1411=30 30 29 30 30 29 30 30 29 29 30 29
+1412=30 29 30 29 30 29 30 30 30 29 29 30
+1413=29 30 29 29 30 29 30 30 30 29 30 29
+1414=30 29 30 29 29 30 29 30 30 29 30 30
+1415=29 30 29 30 29 29 30 29 30 29 30 30
+1416=30 29 30 29 30 29 29 30 29 30 29 30
+1417=30 29 30 30 29 29 30 29 30 29 30 29
+1418=30 29 30 30 29 30 29 30 29 30 29 30
+1419=29 30 29 30 29 30 29 30 30 30 29 29
+1420=29 30 29 29 30 29 30 30 30 30 29 30
+1421=29 29 30 29 29 29 30 30 30 30 29 30
+1422=30 29 29 30 29 29 29 30 30 30 29 30
+1423=30 29 30 29 30 29 29 30 29 30 29 30
+1424=30 29 30 30 29 30 29 29 30 29 30 29
+1425=30 29 30 30 29 30 29 30 30 29 30 29
+1426=29 30 29 30 29 30 30 29 30 30 29 30
+1427=29 29 30 29 30 29 30 30 29 30 30 29
+1428=30 29 29 30 29 29 30 30 30 29 30 30
+1429=29 30 29 29 30 29 29 30 30 29 30 30
+1430=29 30 30 29 29 30 29 30 29 30 29 30
+1431=29 30 30 29 30 29 30 29 30 29 29 30
+1432=29 30 30 30 29 30 29 30 29 30 29 29
+1433=30 29 30 30 29 30 30 29 30 29 30 29
+1434=29 30 29 30 29 30 30 29 30 30 29 29
+1435=30 29 30 29 30 29 30 29 30 30 29 30
+1436=29 30 29 30 29 30 29 30 29 30 29 30
+1437=30 29 30 30 29 29 30 29 30 29 29 30
+1438=30 29 30 30 30 29 29 30 29 29 30 29
+1439=30 29 30 30 30 29 30 29 30 29 29 30
+1440=29 30 29 30 30 30 29 30 29 30 29 29
+1441=30 29 30 29 30 30 29 30 30 29 30 29
+1442=29 30 29 30 29 30 29 30 30 29 30 29
+1443=30 29 30 29 30 29 30 29 30 29 30 30
+1444=29 30 29 30 30 29 29 30 29 30 29 30
+1445=29 30 30 30 29 30 29 29 30 29 29 30
+1446=29 30 30 30 29 30 30 29 29 30 29 29
+1447=30 29 30 30 30 29 30 29 30 29 30 29
+1448=29 30 29 30 30 29 30 30 29 30 29 30
+1449=29 29 30 29 30 29 30 30 29 30 30 29
+1450=30 29 30 29 29 30 29 30 29 30 30 29
+1451=30 30 30 29 29 30 29 29 30 30 29 30
+1452=30 29 30 30 29 29 30 29 29 30 29 30
+1453=30 29 30 30 29 30 29 30 29 29 30 29
+1454=30 29 30 30 29 30 30 29 30 29 30 29
+1455=29 30 29 30 30 29 30 29 30 30 29 30
+1456=29 29 30 29 30 29 30 29 30 30 30 29
+1457=30 29 29 30 29 29 30 29 30 30 30 30
+1458=29 30 29 29 30 29 29 30 29 30 30 30
+1459=29 30 30 29 29 30 29 29 30 29 30 30
+1460=29 30 30 29 30 29 30 29 29 30 29 30
+1461=29 30 30 29 30 29 30 29 30 30 29 29
+1462=30 29 30 29 30 30 29 30 29 30 30 29
+1463=29 30 29 30 29 30 29 30 30 30 29 30
+1464=29 30 29 29 30 29 29 30 30 30 29 30
+1465=30 29 30 29 29 30 29 29 30 30 29 30
+1466=30 30 29 30 29 29 29 30 29 30 30 29
+1467=30 30 29 30 30 29 29 30 29 30 29 30
+1468=29 30 29 30 30 29 30 29 30 29 30 29
+1469=29 30 29 30 30 29 30 30 29 30 29 30
+1470=29 29 30 29 30 30 29 30 30 29 30 29
+1471=30 29 29 30 29 30 29 30 30 29 30 30
+1472=29 30 29 29 30 29 30 29 30 30 29 30
+1473=29 30 29 30 30 29 29 30 29 30 29 30
+1474=29 30 30 29 30 30 29 29 30 29 30 29
+1475=29 30 30 29 30 30 30 29 29 30 29 29
+1476=30 29 30 29 30 30 30 29 30 29 30 29
+1477=29 30 29 29 30 30 30 30 29 30 29 30
+1478=29 29 30 29 30 29 30 30 29 30 30 29
+1479=30 29 29 30 29 30 29 30 29 30 30 29
+1480=30 29 30 29 30 29 30 29 30 29 30 29
+1481=30 29 30 30 29 30 29 30 29 30 29 29
+1482=30 29 30 30 30 30 29 30 29 29 30 29
+1483=29 30 29 30 30 30 29 30 30 29 29 30
+1484=29 29 30 29 30 30 30 29 30 29 30 29
+1485=30 29 29 30 29 30 30 29 30 30 29 30
+1486=29 30 29 29 30 29 30 29 30 30 29 30
+1487=30 29 30 29 30 29 29 30 29 30 29 30
+1488=30 29 30 30 29 30 29 29 30 29 30 29
+1489=30 29 30 30 30 29 30 29 29 30 29 30
+1490=29 30 29 30 30 29 30 30 29 29 30 29
+1491=30 29 29 30 30 29 30 30 29 30 29 30
+1492=29 30 29 29 30 30 29 30 29 30 30 29
+1493=30 29 30 29 30 29 29 30 29 30 30 30
+1494=29 30 29 30 29 30 29 29 29 30 30 30
+1495=29 30 30 29 30 29 29 30 29 29 30 30
+1496=29 30 30 30 29 30 29 29 30 29 29 30
+1497=30 29 30 30 29 30 29 30 29 30 29 30
+1498=29 30 29 30 29 30 30 29 30 29 30 29
+1499=30 29 30 29 29 30 30 29 30 29 30 30
+1500=29 30 29 30 29 29 30 29 30 29 30 30
+1501=30 29 30 29 30 29 29 29 30 29 30 30
+1502=30 30 29 30 29 30 29 29 29 30 30 29
+1503=30 30 29 30 30 29 30 29 29 29 30 30
+1504=29 30 29 30 30 30 29 29 30 29 30 29
+1505=30 29 30 29 30 30 29 30 29 30 30 29
+1506=29 30 29 29 30 30 29 30 30 29 30 30
+1507=29 29 30 29 29 30 30 29 30 29 30 30
+1508=30 29 29 30 29 30 29 29 30 29 30 30
+1509=30 29 30 29 30 29 30 29 29 30 29 30
+1510=30 29 30 30 29 30 29 30 29 29 30 29
+1511=30 29 30 30 29 30 30 29 30 29 29 30
+1512=29 30 29 30 29 30 30 30 29 30 29 30
+1513=29 29 29 30 29 30 30 30 29 30 30 29
+1514=30 29 29 29 30 29 30 30 29 30 30 30
+1515=29 29 30 29 29 30 29 30 30 29 30 30
+1516=29 30 29 30 29 29 30 29 30 29 30 30
+1517=29 30 29 30 29 30 30 29 29 30 29 30
+1518=29 30 29 30 30 29 30 30 29 30 29 29
+1519=30 29 29 30 30 30 29 30 30 29 30 29
+1520=29 30 29 29 30 30 30 29 30 30 29 30
+1521=29 29 29 30 29 30 30 29 30 30 29 30
+1522=30 29 29 29 30 29 30 30 29 30 30 29
+1523=30 29 30 29 30 29 30 29 29 30 30 29
+1524=30 30 29 30 29 30 29 30 29 29 30 29
+1525=30 30 29 30 30 29 30 29 30 29 29 30
+1526=29 30 29 30 30 30 29 30 29 30 29 29
+1527=30 29 30 29 30 30 29 30 30 29 30 29
+1528=30 29 29 30 29 30 29 30 30 29 30 30
+1529=29 30 29 29 30 29 30 29 30 29 30 30
+1530=29 30 30 29 29 30 29 30 29 29 30 30
+1531=29 30 30 30 29 29 30 29 30 29 29 30
+1532=29 30 30 30 29 30 30 29 29 29 30 29
+1533=30 29 30 30 30 29 30 29 30 29 29 30
+1534=29 30 29 30 30 29 30 30 29 29 30 29
+1535=30 29 30 29 30 29 30 30 29 30 29 30
+1536=29 30 29 30 29 30 29 30 29 30 29 30
+1537=30 29 30 30 29 29 30 29 29 30 29 30
+1538=30 30 29 30 30 29 29 30 29 29 30 29
+1539=30 30 30 29 30 30 29 29 30 29 29 30
+1540=29 30 30 29 30 30 29 30 29 29 30 29
+1541=30 29 30 29 30 30 30 29 30 29 29 30
+1542=29 30 29 30 29 30 30 29 30 29 30 30
+1543=29 30 29 29 30 29 30 29 30 29 30 30
+1544=30 29 30 29 29 30 29 30 29 30 29 30
+1545=30 30 29 30 29 29 30 29 30 29 29 30
+1546=30 30 29 30 29 30 29 30 29 30 29 29
+1547=30 30 29 30 30 29 30 29 30 29 30 29
+1548=30 29 29 30 30 29 30 30 29 30 29 30
+1549=29 30 29 29 30 29 30 30 30 29 30 29
+1550=30 29 30 29 29 29 30 30 30 29 30 30
+1551=29 30 29 29 30 29 29 30 30 29 30 30
+1552=30 29 30 29 29 30 29 29 30 30 29 30
+1553=30 29 30 29 30 29 30 29 30 29 30 29
+1554=30 29 30 29 30 30 29 30 29 30 29 30
+1555=29 29 30 29 30 30 29 30 30 29 30 29
+1556=30 29 29 30 29 30 29 30 30 30 29 30
+1557=29 30 29 29 29 30 29 30 30 30 30 29
+1558=30 29 30 29 29 29 30 29 30 30 30 29
+1559=30 30 29 29 30 29 29 30 30 29 30 29
+1560=30 30 29 30 29 30 29 30 29 30 29 30
+1561=29 30 30 29 30 29 30 30 29 29 30 29
+1562=29 30 30 29 30 29 30 30 30 29 29 30
+1563=29 30 29 29 30 29 30 30 30 29 30 29
+1564=30 29 30 29 29 30 29 30 30 30 29 30
+1565=29 30 29 30 29 29 30 29 30 30 29 30
+1566=30 29 30 29 30 29 29 30 29 30 29 30
+1567=30 29 30 30 29 30 29 30 29 29 30 29
+1568=30 29 30 30 30 29 30 29 30 29 29 29
+1569=30 29 30 30 30 29 30 30 29 30 29 29
+1570=29 30 29 30 30 29 30 30 30 29 29 30
+1571=29 29 30 29 30 30 29 30 30 29 30 29
+1572=30 29 29 30 29 30 29 30 30 29 30 29
+1573=30 29 30 30 29 30 29 29 30 29 30 29
+1574=30 30 29 30 30 29 30 29 29 30 29 29
+1575=30 30 30 29 30 30 29 30 29 29 29 30
+1576=29 30 30 29 30 30 30 29 30 29 29 29
+1577=30 29 30 30 29 30 30 29 30 29 30 29
+1578=29 30 29 30 29 30 30 29 30 30 29 30
+1579=29 30 29 30 29 29 30 30 29 30 29 30
+1580=29 30 30 29 30 29 29 30 29 30 29 30
+1581=30 30 29 30 29 30 29 29 30 29 30 29
+1582=30 30 29 30 30 29 30 29 30 29 29 29
+1583=30 30 29 30 30 30 29 30 29 30 29 29
+1584=29 30 30 29 30 30 29 30 30 29 30 29
+1585=29 30 29 30 29 30 29 30 30 29 30 30
+1586=29 29 30 29 30 29 29 30 30 30 29 30
+1587=29 30 30 29 29 29 30 29 30 29 30 30
+1588=30 29 30 30 29 29 29 30 29 30 29 30
+1589=30 29 30 30 29 30 29 29 30 29 30 29
+1590=30 29 30 30 30 29 29 30 29 30 29 30
+1591=29 30 29 30 30 29 30 29 30 29 30 29
+1592=30 29 30 29 30 29 30 29 30 30 30 29
+1593=30 29 29 30 29 29 30 29 30 30 30 29
+1594=30 30 29 29 30 29 29 29 30 30 30 30
+1595=29 30 29 30 29 29 30 29 29 30 30 30
+1596=29 30 30 29 30 29 29 30 29 30 29 30
+1597=29 30 30 29 30 29 30 29 30 29 30 29
+1598=30 29 30 29 30 30 29 30 29 30 30 29
+1599=29 30 29 30 29 30 29 30 30 30 29 30
+1600=29 29 30 29 30 29 29 30 30 30 29 30
--- a/jdk/src/share/native/java/io/io_util.c Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/native/java/io/io_util.c Thu Jul 25 20:30:58 2013 -0400
@@ -211,7 +211,11 @@
n = getLastErrorString(buf, sizeof(buf));
if (n > 0) {
+#ifdef WIN32
+ why = (*env)->NewStringUTF(env, buf);
+#else
why = JNU_NewStringPlatform(env, buf);
+#endif
}
x = JNU_NewObjectByName(env,
"java/io/FileNotFoundException",
--- a/jdk/src/share/native/java/net/net_util.c Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/share/native/java/net/net_util.c Thu Jul 25 20:30:58 2013 -0400
@@ -75,7 +75,7 @@
static int initialized = 0;
-void init(JNIEnv *env) {
+static void initInetAddrs(JNIEnv *env) {
if (!initialized) {
Java_java_net_InetAddress_init(env, 0);
Java_java_net_Inet4Address_init(env, 0);
@@ -96,42 +96,43 @@
void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) {
jobject holder;
- init(env);
+ initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
(*env)->SetIntField(env, holder, iac_addressID, address);
}
void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) {
jobject holder;
- init(env);
+ initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
(*env)->SetIntField(env, holder, iac_familyID, family);
}
void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) {
jobject holder;
- init(env);
+ initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
(*env)->SetObjectField(env, holder, iac_hostNameID, host);
}
int getInetAddress_addr(JNIEnv *env, jobject iaObj) {
jobject holder;
- init(env);
+ initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
return (*env)->GetIntField(env, holder, iac_addressID);
}
int getInetAddress_family(JNIEnv *env, jobject iaObj) {
jobject holder;
- init(env);
+
+ initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
return (*env)->GetIntField(env, holder, iac_familyID);
}
jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) {
jobject holder;
- init(env);
+ initInetAddrs(env);
holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
return (*env)->GetObjectField(env, holder, iac_hostNameID);
}
@@ -139,7 +140,7 @@
JNIEXPORT jobject JNICALL
NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
jobject iaObj;
- init(env);
+ initInetAddrs(env);
#ifdef AF_INET6
if (him->sa_family == AF_INET6) {
jbyteArray ipaddress;
--- a/jdk/src/windows/native/java/io/io_util_md.c Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/windows/native/java/io/io_util_md.c Thu Jul 25 20:30:58 2013 -0400
@@ -29,6 +29,7 @@
#include "io_util.h"
#include "io_util_md.h"
#include <stdio.h>
+#include <windows.h>
#include <wchar.h>
#include <io.h>
@@ -40,6 +41,7 @@
#include <limits.h>
#include <wincon.h>
+
static DWORD MAX_INPUT_EVENTS = 2000;
/* If this returns NULL then an exception is pending */
@@ -569,42 +571,75 @@
}
size_t
-getLastErrorString(char *buf, size_t len)
+getLastErrorString(char *utf8_jvmErrorMsg, size_t cbErrorMsg)
{
- DWORD errval;
- if (len > 0) {
- if ((errval = GetLastError()) != 0) {
- // DOS error
- size_t n = (size_t)FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- errval,
- 0,
- buf,
- (DWORD)len,
- NULL);
- if (n > 3) {
- // Drop final '.', CR, LF
- if (buf[n - 1] == '\n') n--;
- if (buf[n - 1] == '\r') n--;
- if (buf[n - 1] == '.') n--;
- buf[n] = '\0';
+ size_t n = 0;
+ if (cbErrorMsg > 0) {
+ BOOLEAN noError = FALSE;
+ WCHAR *utf16_osErrorMsg = (WCHAR *)malloc(cbErrorMsg*sizeof(WCHAR));
+ if (utf16_osErrorMsg == NULL) {
+ // OOM accident
+ strncpy(utf8_jvmErrorMsg, "Out of memory", cbErrorMsg);
+ // truncate if too long
+ utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0';
+ n = strlen(utf8_jvmErrorMsg);
+ } else {
+ DWORD errval = GetLastError();
+ if (errval != 0) {
+ // WIN32 error
+ n = (size_t)FormatMessageW(
+ FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ errval,
+ 0,
+ utf16_osErrorMsg,
+ (DWORD)cbErrorMsg,
+ NULL);
+ if (n > 3) {
+ // Drop final '.', CR, LF
+ if (utf16_osErrorMsg[n - 1] == L'\n') --n;
+ if (utf16_osErrorMsg[n - 1] == L'\r') --n;
+ if (utf16_osErrorMsg[n - 1] == L'.') --n;
+ utf16_osErrorMsg[n] = L'\0';
+ }
+ } else if (errno != 0) {
+ // C runtime error that has no corresponding WIN32 error code
+ const WCHAR *rtError = _wcserror(errno);
+ if (rtError != NULL) {
+ wcsncpy(utf16_osErrorMsg, rtError, cbErrorMsg);
+ // truncate if too long
+ utf16_osErrorMsg[cbErrorMsg - 1] = L'\0';
+ n = wcslen(utf16_osErrorMsg);
+ }
+ } else
+ noError = TRUE; //OS has no error to report
+
+ if (!noError) {
+ if (n > 0) {
+ n = WideCharToMultiByte(
+ CP_UTF8,
+ 0,
+ utf16_osErrorMsg,
+ n,
+ utf8_jvmErrorMsg,
+ cbErrorMsg,
+ NULL,
+ NULL);
+
+ // no way to die
+ if (n > 0)
+ utf8_jvmErrorMsg[min(cbErrorMsg - 1, n)] = '\0';
+ }
+
+ if (n <= 0) {
+ strncpy(utf8_jvmErrorMsg, "Secondary error while OS message extraction", cbErrorMsg);
+ // truncate if too long
+ utf8_jvmErrorMsg[cbErrorMsg - 1] = '\0';
+ n = strlen(utf8_jvmErrorMsg);
+ }
}
- return n;
- }
-
- if (errno != 0) {
- // C runtime error that has no corresponding DOS error code
- const char *err = strerror(errno);
- size_t n = strlen(err);
- if (n >= len)
- n = len - 1;
-
- strncpy(buf, err, n);
- buf[n] = '\0';
- return n;
+ free(utf16_osErrorMsg);
}
}
-
- return 0;
+ return n;
}
--- a/jdk/src/windows/native/java/lang/ProcessImpl_md.c Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/src/windows/native/java/lang/ProcessImpl_md.c Thu Jul 25 20:30:58 2013 -0400
@@ -40,20 +40,70 @@
*/
#define PIPE_SIZE (4096+24)
+/* We have THREE locales in action:
+ * 1. Thread default locale - dictates UNICODE-to-8bit conversion
+ * 2. System locale that defines the message localization
+ * 3. The file name locale
+ * Each locale could be an extended locale, that means that text cannot be
+ * mapped to 8bit sequence without multibyte encoding.
+ * VM is ready for that, if text is UTF-8.
+ * Here we make the work right from the beginning.
+ */
+size_t os_error_message(int errnum, WCHAR* utf16_OSErrorMsg, size_t maxMsgLength) {
+ size_t n = (size_t)FormatMessageW(
+ FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ (DWORD)errnum,
+ 0,
+ utf16_OSErrorMsg,
+ (DWORD)maxMsgLength,
+ NULL);
+ if (n > 3) {
+ // Drop final '.', CR, LF
+ if (utf16_OSErrorMsg[n - 1] == L'\n') --n;
+ if (utf16_OSErrorMsg[n - 1] == L'\r') --n;
+ if (utf16_OSErrorMsg[n - 1] == L'.') --n;
+ utf16_OSErrorMsg[n] = L'\0';
+ }
+ return n;
+}
+
+#define MESSAGE_LENGTH (256 + 100)
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
+
static void
-win32Error(JNIEnv *env, const char *functionName)
+win32Error(JNIEnv *env, const WCHAR *functionName)
{
- static const char * const format = "%s error=%d, %s";
- static const char * const fallbackFormat = "%s failed, error=%d";
- char buf[256];
- char errmsg[sizeof(buf) + 100];
- const int errnum = GetLastError();
- const int n = JVM_GetLastErrorString(buf, sizeof(buf));
- if (n > 0)
- sprintf(errmsg, format, functionName, errnum, buf);
- else
- sprintf(errmsg, fallbackFormat, functionName, errnum);
- JNU_ThrowIOException(env, errmsg);
+ WCHAR utf16_OSErrorMsg[MESSAGE_LENGTH - 100];
+ WCHAR utf16_javaMessage[MESSAGE_LENGTH];
+ /*Good suggestion about 2-bytes-per-symbol in localized error reports*/
+ char utf8_javaMessage[MESSAGE_LENGTH*2];
+ const int errnum = (int)GetLastError();
+ int n = os_error_message(errnum, utf16_OSErrorMsg, ARRAY_SIZE(utf16_OSErrorMsg));
+ n = (n > 0)
+ ? swprintf(utf16_javaMessage, MESSAGE_LENGTH, L"%s error=%d, %s", functionName, errnum, utf16_OSErrorMsg)
+ : swprintf(utf16_javaMessage, MESSAGE_LENGTH, L"%s failed, error=%d", functionName, errnum);
+
+ if (n > 0) /*terminate '\0' is not a part of conversion procedure*/
+ n = WideCharToMultiByte(
+ CP_UTF8,
+ 0,
+ utf16_javaMessage,
+ n, /*by creation n <= MESSAGE_LENGTH*/
+ utf8_javaMessage,
+ MESSAGE_LENGTH*2,
+ NULL,
+ NULL);
+
+ /*no way to die*/
+ {
+ const char *errorMessage = "Secondary error while OS message extraction";
+ if (n > 0) {
+ utf8_javaMessage[min(MESSAGE_LENGTH*2 - 1, n)] = '\0';
+ errorMessage = utf8_javaMessage;
+ }
+ JNU_ThrowIOException(env, errorMessage);
+ }
}
static void
@@ -116,7 +166,7 @@
handles[0] = (jlong) -1;
} else {
if (! CreatePipe(&inRead, &inWrite, &sa, PIPE_SIZE)) {
- win32Error(env, "CreatePipe");
+ win32Error(env, L"CreatePipe");
goto Catch;
}
si.hStdInput = inRead;
@@ -132,7 +182,7 @@
handles[1] = (jlong) -1;
} else {
if (! CreatePipe(&outRead, &outWrite, &sa, PIPE_SIZE)) {
- win32Error(env, "CreatePipe");
+ win32Error(env, L"CreatePipe");
goto Catch;
}
si.hStdOutput = outWrite;
@@ -151,7 +201,7 @@
handles[2] = (jlong) -1;
} else {
if (! CreatePipe(&errRead, &errWrite, &sa, PIPE_SIZE)) {
- win32Error(env, "CreatePipe");
+ win32Error(env, L"CreatePipe");
goto Catch;
}
si.hStdError = errWrite;
@@ -174,7 +224,7 @@
&si, /* (in) startup information */
&pi); /* (out) process information */
if (!ret) {
- win32Error(env, "CreateProcess");
+ win32Error(env, L"CreateProcess");
goto Catch;
}
@@ -210,7 +260,7 @@
{
DWORD exit_code;
if (GetExitCodeProcess((HANDLE) handle, &exit_code) == 0)
- win32Error(env, "GetExitCodeProcess");
+ win32Error(env, L"GetExitCodeProcess");
return exit_code;
}
@@ -231,7 +281,7 @@
FALSE, /* Wait for ANY event */
INFINITE) /* Wait forever */
== WAIT_FAILED)
- win32Error(env, "WaitForMultipleObjects");
+ win32Error(env, L"WaitForMultipleObjects");
}
JNIEXPORT void JNICALL
@@ -250,7 +300,7 @@
dwTimeout); /* Wait for dwTimeout */
if (result == WAIT_FAILED)
- win32Error(env, "WaitForMultipleObjects");
+ win32Error(env, L"WaitForMultipleObjects");
}
JNIEXPORT void JNICALL
@@ -263,7 +313,7 @@
Java_java_lang_ProcessImpl_isProcessAlive(JNIEnv *env, jclass ignored, jlong handle)
{
DWORD dwExitStatus;
- GetExitCodeProcess(handle, &dwExitStatus);
+ GetExitCodeProcess((HANDLE) handle, &dwExitStatus);
return dwExitStatus == STILL_ACTIVE;
}
--- a/jdk/test/ProblemList.txt Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/ProblemList.txt Thu Jul 25 20:30:58 2013 -0400
@@ -131,12 +131,14 @@
# 7196801
java/lang/management/MemoryMXBean/LowMemoryTest2.sh generic-all
-# 8008200
-java/lang/Class/asSubclass/BasicUnit.java generic-all
-
# 8015780
java/lang/reflect/Method/GenericStringTest.java generic-all
+# 8019845 due to memleak not related to the tested fix
+java/lang/instrument/RedefineBigClass.sh linux-x64
+java/lang/instrument/RetransformBigClass.sh linux-x64
+
+
############################################################################
# jdk_management
@@ -165,6 +167,9 @@
# 7027502
demo/jvmti/hprof/MonitorTest.java generic-all
+# 8021186
+jdk/lambda/vm/DefaultMethodsTest.java generic-all
+
############################################################################
# jdk_net
@@ -371,6 +376,9 @@
# Filed 6772009
java/util/concurrent/locks/ReentrantLock/CancelledLockLoops.java generic-all
+# 8020435
+java/util/concurrent/CompletableFuture/Basic.java generic-all
+
# 7041639, Solaris DSA keypair generation bug
java/util/TimeZone/TimeZoneDatePermissionCheck.sh solaris-all
--- a/jdk/test/com/sun/management/DiagnosticCommandMBean/DcmdMBeanDoubleInvocationTest.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/com/sun/management/DiagnosticCommandMBean/DcmdMBeanDoubleInvocationTest.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,25 +25,15 @@
* @test
* @bug 7150256
* @summary Basic Test for the DiagnosticCommandMBean
- * @author Frederic Parain
+ * @author Frederic Parain, Shanliang JIANG
*
- * @run main/othervm -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8125 DcmdMBeanDoubleInvocationTest
+ * @run main/othervm DcmdMBeanDoubleInvocationTest
*/
-import java.io.IOException;
import java.lang.management.ManagementFactory;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.management.Descriptor;
-import javax.management.InstanceNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import javax.management.ReflectionException;
import javax.management.*;
import javax.management.remote.*;
@@ -52,39 +42,42 @@
private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
"com.sun.management:type=DiagnosticCommand";
- public static void main(String[] args) {
- MBeanServerConnection mbs = null;
- try {
- JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8125/jmxrmi");
- JMXConnector connector = JMXConnectorFactory.connect(url);
- mbs = connector.getMBeanServerConnection();
- } catch(Throwable t) {
- t.printStackTrace();
- }
- ObjectName name;
+ public static void main(String[] args) throws Exception {
+ System.out.println("--->JRCMD MBean Test: invocation on \"help VM.version\" ...");
+
+ ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
+ String[] helpArgs = {"-all", "\n", "VM.version"};
+ Object[] dcmdArgs = {helpArgs};
+ String[] signature = {String[].class.getName()};
+
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
+ JMXConnectorServer cs = null;
+ JMXConnector cc = null;
try {
- name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
- MBeanInfo info = mbs.getMBeanInfo(name);
- String[] helpArgs = {"-all", "\n", "VM.version"};
- Object[] dcmdArgs = {helpArgs};
- String[] signature = {String[].class.getName()};
- String result = (String) mbs.invoke(name, "help", dcmdArgs, signature);
+ cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
+ cs.start();
+ JMXServiceURL addr = cs.getAddress();
+ cc = JMXConnectorFactory.connect(addr);
+ MBeanServerConnection mbsc = cc.getMBeanServerConnection();
+
+ String result = (String) mbsc.invoke(name, "help", dcmdArgs, signature);
System.out.println(result);
- } catch (RuntimeMBeanException ex) {
+
+ throw new Error("Test failed: Double commands have not been detected");
+ } catch (RuntimeMBeanException ex) {
if (ex.getCause() instanceof IllegalArgumentException) {
- System.out.println("Test passed");
- return;
+ System.out.println("JTest passed: Double commands have been detected");
} else {
ex.printStackTrace();
- throw new RuntimeException("TEST FAILED");
+ throw new Error("TEST FAILED: got unknown exception "+ex);
}
- } catch (InstanceNotFoundException | IntrospectionException
- | ReflectionException | MalformedObjectNameException
- | MBeanException|IOException ex) {
- ex.printStackTrace();
- throw new RuntimeException("TEST FAILED");
+ } finally {
+ try {
+ cc.close();
+ cs.stop();
+ } catch (Exception e) {
+ }
}
- System.out.println("Double commands have not been detected");
- throw new RuntimeException("TEST FAILED");
}
}
--- a/jdk/test/com/sun/management/DiagnosticCommandMBean/DcmdMBeanInvocationTest.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/com/sun/management/DiagnosticCommandMBean/DcmdMBeanInvocationTest.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,25 +25,15 @@
* @test
* @bug 7150256
* @summary Basic Test for the DiagnosticCommandMBean
- * @author Frederic Parain
+ * @author Frederic Parain, Shanliang JIANG
*
- * @run main/othervm -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8129 DcmdMBeanInvocationTest
+ * @run main/othervm DcmdMBeanInvocationTest
*/
-import java.io.IOException;
import java.lang.management.ManagementFactory;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.management.Descriptor;
-import javax.management.InstanceNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import javax.management.ReflectionException;
import javax.management.*;
import javax.management.remote.*;
@@ -52,30 +42,35 @@
private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
"com.sun.management:type=DiagnosticCommand";
- public static void main(String[] args) {
- MBeanServerConnection mbs = null;
- try {
- JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8129/jmxrmi");
- JMXConnector connector = JMXConnectorFactory.connect(url);
- mbs = connector.getMBeanServerConnection();
- } catch(Throwable t) {
- t.printStackTrace();
- }
- ObjectName name;
+ public static void main(String[] args) throws Exception {
+ System.out.println("--->JRCMD MBean Test: invocation on \"help -all\" ...");
+
+ ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
+ String[] helpArgs = {"-all"};
+ Object[] dcmdArgs = {helpArgs};
+ String[] signature = {String[].class.getName()};
+
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
+ JMXConnectorServer cs = null;
+ JMXConnector cc = null;
try {
- name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
- MBeanInfo info = mbs.getMBeanInfo(name);
- String[] helpArgs = {"-all"};
- Object[] dcmdArgs = {helpArgs};
- String[] signature = {String[].class.getName()};
- String result = (String) mbs.invoke(name, "help", dcmdArgs, signature);
+ cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
+ cs.start();
+ JMXServiceURL addr = cs.getAddress();
+ cc = JMXConnectorFactory.connect(addr);
+ MBeanServerConnection mbsc = cc.getMBeanServerConnection();
+
+ String result = (String) mbsc.invoke(name, "help", dcmdArgs, signature);
System.out.println(result);
- } catch (InstanceNotFoundException | IntrospectionException
- | ReflectionException | MalformedObjectNameException
- | MBeanException|IOException ex) {
- ex.printStackTrace();
- throw new RuntimeException("TEST FAILED");
+ } finally {
+ try {
+ cc.close();
+ cs.stop();
+ } catch (Exception e) {
+ }
}
+
System.out.println("Test passed");
}
}
--- a/jdk/test/com/sun/management/DiagnosticCommandMBean/DcmdMBeanTest.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/com/sun/management/DiagnosticCommandMBean/DcmdMBeanTest.java Thu Jul 25 20:30:58 2013 -0400
@@ -25,25 +25,18 @@
* @test
* @bug 7150256
* @summary Basic Test for the DiagnosticCommandMBean
- * @author Frederic Parain
+ * @author Frederic Parain, Shanliang JIANG
*
- * @run main/othervm -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8127 DcmdMBeanTest
+ * @run main/othervm DcmdMBeanTest
*/
-import java.io.IOException;
import java.lang.management.ManagementFactory;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.management.Descriptor;
-import javax.management.InstanceNotFoundException;
-import javax.management.IntrospectionException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import javax.management.ReflectionException;
import javax.management.*;
import javax.management.remote.*;
@@ -52,34 +45,42 @@
private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
"com.sun.management:type=DiagnosticCommand";
- public static void main(String[] args) {
- MBeanServerConnection mbs = null;
+ public static void main(String[] args) throws Exception {
+ System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"...");
+
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
+ JMXConnectorServer cs = null;
+ JMXConnector cc = null;
try {
- JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8127/jmxrmi");
- JMXConnector connector = JMXConnectorFactory.connect(url);
- mbs = connector.getMBeanServerConnection();
- } catch(Throwable t) {
- t.printStackTrace();
- }
- ObjectName name;
- try {
- name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
- MBeanInfo info = mbs.getMBeanInfo(name);
+ cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
+ cs.start();
+ JMXServiceURL addr = cs.getAddress();
+ cc = JMXConnectorFactory.connect(addr);
+ MBeanServerConnection mbsc = cc.getMBeanServerConnection();
+ ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
+ MBeanInfo info = mbsc.getMBeanInfo(name);
+
// the test should check that the MBean doesn't have any
// Attribute, notification or constructor. Current version only
// check operations
- System.out.println("Class Name:"+info.getClassName());
- System.out.println("Description:"+info.getDescription());
+ System.out.println("Class Name:" + info.getClassName());
+ System.out.println("Description:" + info.getDescription());
MBeanOperationInfo[] opInfo = info.getOperations();
System.out.println("Operations:");
- for(int i=0; i<opInfo.length; i++) {
+ for (int i = 0; i < opInfo.length; i++) {
printOperation(opInfo[i]);
System.out.println("\n@@@@@@\n");
}
- } catch (InstanceNotFoundException|IntrospectionException|ReflectionException
- |MalformedObjectNameException|IOException ex) {
- Logger.getLogger(DcmdMBeanTest.class.getName()).log(Level.SEVERE, null, ex);
+ } finally {
+ try {
+ cc.close();
+ cs.stop();
+ } catch (Exception e) {
+ }
}
+
+ System.out.println("Test passed");
}
static void printOperation(MBeanOperationInfo info) {
@@ -110,4 +111,3 @@
}
}
}
-
--- a/jdk/test/java/lang/instrument/RedefineBigClass.sh Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/lang/instrument/RedefineBigClass.sh Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2013 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
@@ -22,7 +22,7 @@
#
# @test
-# @bug 7121600
+# @bug 7121600 8016838
# @summary Redefine a big class.
# @author Daniel D. Daugherty
#
--- a/jdk/test/java/lang/instrument/RedefineBigClassApp.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/lang/instrument/RedefineBigClassApp.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013 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
@@ -21,12 +21,21 @@
* questions.
*/
+import java.io.*;
+
public class RedefineBigClassApp {
+ /**
+ * Memory leak is assumed, if application consumes more than specified amount of memory during its execution.
+ * The number is given in Kb.
+ */
+ private static final long MEM_LEAK_THRESHOLD = 32 * 1024; // 32Mb
+
public static void main(String[] args) throws Exception {
System.out.println("Creating instance of " +
RedefineBigClassAgent.clz);
RedefineBigClassAgent.clz.newInstance();
+ long vMemBefore = getVMemSize();
int count = 0;
while (!RedefineBigClassAgent.doneRedefining) {
System.out.println("App loop count: " + ++count);
@@ -37,6 +46,39 @@
}
System.out.println("App looped " + count + " times.");
+ long vMemAfter = getVMemSize();
+ if (vMemBefore == 0 || vMemAfter == 0) {
+ System.err.println("WARNING: Cannot perform memory leak detection on this OS");
+ } else {
+ long vMemDelta = vMemAfter - vMemBefore;
+ if (vMemDelta > MEM_LEAK_THRESHOLD) {
+ System.err.println("FAIL: Virtual memory usage increased by " + vMemDelta + "Kb " +
+ "(greater than " + MEM_LEAK_THRESHOLD + "Kb)");
+ System.exit(1);
+ }
+ System.err.println("PASS: Virtual memory usage increased by " + vMemDelta + "Kb " +
+ "(not greater than " + MEM_LEAK_THRESHOLD + "Kb)");
+ }
System.exit(0);
}
+
+ /**
+ * Return size of virtual memory allocated to the process in Kb.
+ * Linux specific. On other platforms and in case of any errors return 0.
+ */
+ private static long getVMemSize() {
+
+ // Refer to the Linux proc(5) man page for details about /proc/self/stat file
+ //
+ // In short, this file contains status information about the current process
+ // written in one line. The fields are separated with spaces.
+ // The 23rd field is defined as 'vsize %lu Virtual memory size in bytes'
+
+ try (FileReader fileReader = new FileReader("/proc/self/stat");
+ BufferedReader bufferedReader = new BufferedReader(fileReader)) {
+ String line = bufferedReader.readLine();
+ return Long.parseLong(line.split(" ")[22]) / 1024;
+ } catch (Exception ex) {}
+ return 0;
+ }
}
--- a/jdk/test/java/lang/instrument/RetransformBigClass.sh Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/lang/instrument/RetransformBigClass.sh Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2013 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
@@ -22,7 +22,7 @@
#
# @test
-# @bug 7122253
+# @bug 7122253 8016838
# @summary Retransform a big class.
# @author Daniel D. Daugherty
#
--- a/jdk/test/java/lang/instrument/RetransformBigClassApp.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/lang/instrument/RetransformBigClassApp.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013 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
@@ -21,12 +21,21 @@
* questions.
*/
+import java.io.*;
+
public class RetransformBigClassApp {
+ /**
+ * Memory leak is assumed, if application consumes more than specified amount of memory during its execution.
+ * The number is given in Kb.
+ */
+ private static final long MEM_LEAK_THRESHOLD = 32 * 1024; // 32Mb
+
public static void main(String[] args) throws Exception {
System.out.println("Creating instance of " +
RetransformBigClassAgent.clz);
RetransformBigClassAgent.clz.newInstance();
+ long vMemBefore = getVMemSize();
int count = 0;
while (!RetransformBigClassAgent.doneRetransforming) {
System.out.println("App loop count: " + ++count);
@@ -37,6 +46,39 @@
}
System.out.println("App looped " + count + " times.");
+ long vMemAfter = getVMemSize();
+ if (vMemBefore == 0 || vMemAfter == 0) {
+ System.err.println("WARNING: Cannot perform memory leak detection on this OS");
+ } else {
+ long vMemDelta = vMemAfter - vMemBefore;
+ if (vMemDelta > MEM_LEAK_THRESHOLD) {
+ System.err.println("FAIL: Virtual memory usage increased by " + vMemDelta + "Kb " +
+ "(greater than " + MEM_LEAK_THRESHOLD + "Kb)");
+ System.exit(1);
+ }
+ System.err.println("PASS: Virtual memory usage increased by " + vMemDelta + "Kb " +
+ "(not greater than " + MEM_LEAK_THRESHOLD + "Kb)");
+ }
System.exit(0);
}
+
+ /**
+ * Return size of virtual memory allocated to the process in Kb.
+ * Linux specific. On other platforms and in case of any errors return 0.
+ */
+ private static long getVMemSize() {
+
+ // Refer to the Linux proc(5) man page for details about /proc/self/stat file
+ //
+ // In short, this file contains status information about the current process
+ // written in one line. The fields are separated with spaces.
+ // The 23rd field is defined as 'vsize %lu Virtual memory size in bytes'
+
+ try (FileReader fileReader = new FileReader("/proc/self/stat");
+ BufferedReader bufferedReader = new BufferedReader(fileReader)) {
+ String line = bufferedReader.readLine();
+ return Long.parseLong(line.split(" ")[22]) / 1024;
+ } catch (Exception ex) {}
+ return 0;
+ }
}
--- a/jdk/test/java/security/cert/PKIXRevocationChecker/UnitTest.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/security/cert/PKIXRevocationChecker/UnitTest.java Thu Jul 25 20:30:58 2013 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, 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
@@ -23,7 +23,7 @@
/**
* @test
- * @bug 6854712 7171570
+ * @bug 6854712 7171570 8010748
* @summary Basic unit test for PKIXRevocationChecker
*/
@@ -32,19 +32,9 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
-import java.security.cert.CertificateFactory;
-import java.security.cert.CertPathBuilder;
-import java.security.cert.CertPathChecker;
-import java.security.cert.CertPathValidator;
-import java.security.cert.Extension;
-import java.security.cert.PKIXRevocationChecker;
+import java.security.cert.*;
import java.security.cert.PKIXRevocationChecker.Option;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
public class UnitTest {
@@ -56,22 +46,23 @@
System.out.println("Testing that get methods return null or " +
"empty lists/sets/maps");
- requireNull(prc.getOCSPResponder(), "getOCSPResponder()");
- requireNull(prc.getOCSPResponderCert(), "getOCSPResponderCert()");
- requireEmpty(prc.getOCSPExtensions(), "getOCSPExtensions()");
- requireEmpty(prc.getOCSPResponses(), "getOCSPResponses()");
+ requireNull(prc.getOcspResponder(), "getOcspResponder()");
+ requireNull(prc.getOcspResponderCert(), "getOcspResponderCert()");
+ requireEmpty(prc.getOcspExtensions(), "getOcspExtensions()");
+ requireEmpty(prc.getOcspResponses(), "getOcspResponses()");
requireEmpty(prc.getOptions(), "getOptions()");
+ requireEmpty(prc.getSoftFailExceptions(), "getSoftFailExceptions()");
System.out.println("Testing that get methods return same parameters " +
"that are passed to set methods");
URI uri = new URI("http://localhost");
- prc.setOCSPResponder(uri);
- requireEquals(uri, prc.getOCSPResponder(), "getOCSPResponder()");
+ prc.setOcspResponder(uri);
+ requireEquals(uri, prc.getOcspResponder(), "getOcspResponder()");
X509Certificate cert = getCert();
- prc.setOCSPResponderCert(cert);
- requireEquals(cert, prc.getOCSPResponderCert(),
- "getOCSPResponderCert()");
+ prc.setOcspResponderCert(cert);
+ requireEquals(cert, prc.getOcspResponderCert(),
+ "getOcspResponderCert()");
List<Extension> exts = new ArrayList<>();
for (String oid : cert.getNonCriticalExtensionOIDs()) {
@@ -79,8 +70,8 @@
exts.add(new ExtensionImpl(oid,
cert.getExtensionValue(oid), false));
}
- prc.setOCSPExtensions(exts);
- requireEquals(exts, prc.getOCSPExtensions(), "getOCSPExtensions()");
+ prc.setOcspExtensions(exts);
+ requireEquals(exts, prc.getOcspExtensions(), "getOcspExtensions()");
Set<Option> options = EnumSet.of(Option.ONLY_END_ENTITY);
prc.setOptions(options);
@@ -88,14 +79,14 @@
System.out.println("Testing that parameters are re-initialized to " +
"default values if null is passed to set methods");
- prc.setOCSPResponder(null);
- requireNull(prc.getOCSPResponder(), "getOCSPResponder()");
- prc.setOCSPResponderCert(null);
- requireNull(prc.getOCSPResponderCert(), "getOCSPResponderCert()");
- prc.setOCSPExtensions(null);
- requireEmpty(prc.getOCSPExtensions(), "getOCSPExtensions()");
- prc.setOCSPResponses(null);
- requireEmpty(prc.getOCSPResponses(), "getOCSPResponses()");
+ prc.setOcspResponder(null);
+ requireNull(prc.getOcspResponder(), "getOcspResponder()");
+ prc.setOcspResponderCert(null);
+ requireNull(prc.getOcspResponderCert(), "getOcspResponderCert()");
+ prc.setOcspExtensions(null);
+ requireEmpty(prc.getOcspExtensions(), "getOcspExtensions()");
+ prc.setOcspResponses(null);
+ requireEmpty(prc.getOcspResponses(), "getOcspResponses()");
prc.setOptions(null);
requireEmpty(prc.getOptions(), "getOptions()");
--- a/jdk/test/java/time/tck/java/time/MockSimplePeriod.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/MockSimplePeriod.java Thu Jul 25 20:30:58 2013 -0400
@@ -176,7 +176,7 @@
@Override
public String toString() {
- return amount + " " + unit.getName();
+ return amount + " " + unit;
}
}
--- a/jdk/test/java/time/tck/java/time/TCKClock_Fixed.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKClock_Fixed.java Thu Jul 25 20:30:58 2013 -0400
@@ -91,6 +91,7 @@
Clock test = Clock.fixed(INSTANT, PARIS);
assertEquals(test.instant(), INSTANT);
assertEquals(test.getZone(), PARIS);
+ assertEquals(test.instant().getEpochSecond()*1000, test.millis());
}
@Test(expectedExceptions = NullPointerException.class)
--- a/jdk/test/java/time/tck/java/time/TCKDayOfWeek.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKDayOfWeek.java Thu Jul 25 20:30:58 2013 -0400
@@ -159,6 +159,44 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(DayOfWeek.THURSDAY.isSupported((TemporalField) null), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.ERA), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(DayOfWeek.THURSDAY.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
--- a/jdk/test/java/time/tck/java/time/TCKInstant.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKInstant.java Thu Jul 25 20:30:58 2013 -0400
@@ -570,10 +570,6 @@
//-----------------------------------------------------------------------
TemporalUnit NINETY_MINS = new TemporalUnit() {
@Override
- public String getName() {
- return "NinetyMins";
- }
- @Override
public Duration getDuration() {
return Duration.ofMinutes(90);
}
@@ -582,6 +578,49 @@
return false;
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+ @Override
+ public boolean isTimeBased() {
+ return true;
+ }
+ @Override
+ public boolean isSupportedBy(Temporal temporal) {
+ return false;
+ }
+ @Override
+ public <R extends Temporal> R addTo(R temporal, long amount) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public long between(Temporal temporal1, Temporal temporal2) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public String toString() {
+ return "NinetyMins";
+ }
+ };
+
+ TemporalUnit NINETY_FIVE_MINS = new TemporalUnit() {
+ @Override
+ public Duration getDuration() {
+ return Duration.ofMinutes(95);
+ }
+ @Override
+ public boolean isDurationEstimated() {
+ return false;
+ }
+ @Override
+ public boolean isDateBased() {
+ return false;
+ }
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+ @Override
public boolean isSupportedBy(Temporal temporal) {
return false;
}
@@ -593,33 +632,10 @@
public long between(Temporal temporal1, Temporal temporal2) {
throw new UnsupportedOperationException();
}
- };
-
- TemporalUnit NINETY_FIVE_MINS = new TemporalUnit() {
@Override
- public String getName() {
+ public String toString() {
return "NinetyFiveMins";
}
- @Override
- public Duration getDuration() {
- return Duration.ofMinutes(95);
- }
- @Override
- public boolean isDurationEstimated() {
- return false;
- }
- @Override
- public boolean isSupportedBy(Temporal temporal) {
- return false;
- }
- @Override
- public <R extends Temporal> R addTo(R temporal, long amount) {
- throw new UnsupportedOperationException();
- }
- @Override
- public long between(Temporal temporal1, Temporal temporal2) {
- throw new UnsupportedOperationException();
- }
};
@DataProvider(name="truncatedToValid")
@@ -1709,7 +1725,7 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal, TemporalUnit)
+ // until(Temporal, TemporalUnit)
//-----------------------------------------------------------------------
@DataProvider(name="periodUntilUnit")
Object[][] data_periodUntilUnit() {
@@ -1805,7 +1821,7 @@
public void test_periodUntil_TemporalUnit(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
- long amount = i1.periodUntil(i2, unit);
+ long amount = i1.until(i2, unit);
assertEquals(amount, expected);
}
@@ -1813,23 +1829,23 @@
public void test_periodUntil_TemporalUnit_negated(long seconds1, int nanos1, long seconds2, long nanos2, TemporalUnit unit, long expected) {
Instant i1 = Instant.ofEpochSecond(seconds1, nanos1);
Instant i2 = Instant.ofEpochSecond(seconds2, nanos2);
- long amount = i2.periodUntil(i1, unit);
+ long amount = i2.until(i1, unit);
assertEquals(amount, -expected);
}
@Test(expectedExceptions = UnsupportedTemporalTypeException.class)
public void test_periodUntil_TemporalUnit_unsupportedUnit() {
- TEST_12345_123456789.periodUntil(TEST_12345_123456789, MONTHS);
+ TEST_12345_123456789.until(TEST_12345_123456789, MONTHS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullEnd() {
- TEST_12345_123456789.periodUntil(null, HOURS);
+ TEST_12345_123456789.until(null, HOURS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullUnit() {
- TEST_12345_123456789.periodUntil(TEST_12345_123456789, null);
+ TEST_12345_123456789.until(TEST_12345_123456789, null);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/TCKLocalDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKLocalDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -620,6 +620,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2007_07_15.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2007_07_15.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.NANOS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MICROS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MILLIS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.SECONDS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MINUTES), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.HOURS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.HALF_DAYS), false);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2007_07_15.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -1635,7 +1697,7 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal, TemporalUnit)
+ // until(Temporal, TemporalUnit)
//-----------------------------------------------------------------------
@DataProvider(name="periodUntilUnit")
Object[][] data_periodUntilUnit() {
@@ -1684,35 +1746,35 @@
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit(LocalDate date1, LocalDate date2, TemporalUnit unit, long expected) {
- long amount = date1.periodUntil(date2, unit);
+ long amount = date1.until(date2, unit);
assertEquals(amount, expected);
}
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit_negated(LocalDate date1, LocalDate date2, TemporalUnit unit, long expected) {
- long amount = date2.periodUntil(date1, unit);
+ long amount = date2.until(date1, unit);
assertEquals(amount, -expected);
}
@Test(expectedExceptions = UnsupportedTemporalTypeException.class)
public void test_periodUntil_TemporalUnit_unsupportedUnit() {
- TEST_2007_07_15.periodUntil(TEST_2007_07_15, HOURS);
+ TEST_2007_07_15.until(TEST_2007_07_15, HOURS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullEnd() {
- TEST_2007_07_15.periodUntil(null, DAYS);
+ TEST_2007_07_15.until(null, DAYS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullUnit() {
- TEST_2007_07_15.periodUntil(TEST_2007_07_15, null);
+ TEST_2007_07_15.until(TEST_2007_07_15, null);
}
//-----------------------------------------------------------------------
- // periodUntil(ChronoLocalDate)
+ // until(ChronoLocalDate)
//-----------------------------------------------------------------------
- @DataProvider(name="periodUntil")
+ @DataProvider(name="until")
Object[][] data_periodUntil() {
return new Object[][] {
{2010, 1, 1, 2010, 1, 1, 0, 0, 0},
@@ -1799,11 +1861,11 @@
};
}
- @Test(dataProvider="periodUntil")
+ @Test(dataProvider="until")
public void test_periodUntil_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
LocalDate start = LocalDate.of(y1, m1, d1);
LocalDate end = LocalDate.of(y2, m2, d2);
- Period test = start.periodUntil(end);
+ Period test = start.until(end);
assertEquals(test.getYears(), ye);
assertEquals(test.getMonths(), me);
assertEquals(test.getDays(), de);
@@ -1812,12 +1874,12 @@
@Test
public void test_periodUntil_LocalDate_max() {
int years = Math.toIntExact((long) Year.MAX_VALUE - (long) Year.MIN_VALUE);
- assertEquals(LocalDate.MIN.periodUntil(LocalDate.MAX), Period.of(years, 11, 30));
+ assertEquals(LocalDate.MIN.until(LocalDate.MAX), Period.of(years, 11, 30));
}
@Test(expectedExceptions=NullPointerException.class)
public void test_periodUntil_LocalDate_null() {
- TEST_2007_07_15.periodUntil(null);
+ TEST_2007_07_15.until(null);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/TCKLocalDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKLocalDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -938,6 +938,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2007_07_15_12_30_40_987654321.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -2717,7 +2779,7 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal, TemporalUnit)
+ // until(Temporal, TemporalUnit)
//-----------------------------------------------------------------------
@DataProvider(name="periodUntilUnit")
Object[][] data_periodUntilUnit() {
@@ -2859,24 +2921,24 @@
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit(LocalDateTime dt1, LocalDateTime dt2, TemporalUnit unit, long expected) {
- long amount = dt1.periodUntil(dt2, unit);
+ long amount = dt1.until(dt2, unit);
assertEquals(amount, expected);
}
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit_negated(LocalDateTime dt1, LocalDateTime dt2, TemporalUnit unit, long expected) {
- long amount = dt2.periodUntil(dt1, unit);
+ long amount = dt2.until(dt1, unit);
assertEquals(amount, -expected);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullEnd() {
- TEST_2007_07_15_12_30_40_987654321.periodUntil(null, HOURS);
+ TEST_2007_07_15_12_30_40_987654321.until(null, HOURS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullUnit() {
- TEST_2007_07_15_12_30_40_987654321.periodUntil(TEST_2007_07_15_12_30_40_987654321, null);
+ TEST_2007_07_15_12_30_40_987654321.until(TEST_2007_07_15_12_30_40_987654321, null);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/TCKLocalTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKLocalTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -620,6 +620,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_12_30_40_987654321.isSupported((TemporalField) null), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.YEAR), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.ERA), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_12_30_40_987654321.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MONTHS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.YEARS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.DECADES), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.CENTURIES), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.MILLENNIA), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.ERAS), false);
+ assertEquals(TEST_12_30_40_987654321.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -953,10 +1015,6 @@
//-----------------------------------------------------------------------
TemporalUnit NINETY_MINS = new TemporalUnit() {
@Override
- public String getName() {
- return "NinetyMins";
- }
- @Override
public Duration getDuration() {
return Duration.ofMinutes(90);
}
@@ -965,6 +1023,49 @@
return false;
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+ @Override
+ public boolean isTimeBased() {
+ return true;
+ }
+ @Override
+ public boolean isSupportedBy(Temporal temporal) {
+ return false;
+ }
+ @Override
+ public <R extends Temporal> R addTo(R temporal, long amount) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public long between(Temporal temporal1, Temporal temporal2) {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public String toString() {
+ return "NinetyMins";
+ }
+ };
+
+ TemporalUnit NINETY_FIVE_MINS = new TemporalUnit() {
+ @Override
+ public Duration getDuration() {
+ return Duration.ofMinutes(95);
+ }
+ @Override
+ public boolean isDurationEstimated() {
+ return false;
+ }
+ @Override
+ public boolean isDateBased() {
+ return false;
+ }
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+ @Override
public boolean isSupportedBy(Temporal temporal) {
return false;
}
@@ -976,33 +1077,10 @@
public long between(Temporal temporal1, Temporal temporal2) {
throw new UnsupportedOperationException();
}
- };
-
- TemporalUnit NINETY_FIVE_MINS = new TemporalUnit() {
@Override
- public String getName() {
+ public String toString() {
return "NinetyFiveMins";
}
- @Override
- public Duration getDuration() {
- return Duration.ofMinutes(95);
- }
- @Override
- public boolean isDurationEstimated() {
- return false;
- }
- @Override
- public boolean isSupportedBy(Temporal temporal) {
- return false;
- }
- @Override
- public <R extends Temporal> R addTo(R temporal, long amount) {
- throw new UnsupportedOperationException();
- }
- @Override
- public long between(Temporal temporal1, Temporal temporal2) {
- throw new UnsupportedOperationException();
- }
};
@DataProvider(name="truncatedToValid")
@@ -1922,7 +2000,7 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal, TemporalUnit)
+ // until(Temporal, TemporalUnit)
//-----------------------------------------------------------------------
@DataProvider(name="periodUntilUnit")
Object[][] data_periodUntilUnit() {
@@ -1962,29 +2040,29 @@
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit(LocalTime time1, LocalTime time2, TemporalUnit unit, long expected) {
- long amount = time1.periodUntil(time2, unit);
+ long amount = time1.until(time2, unit);
assertEquals(amount, expected);
}
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit_negated(LocalTime time1, LocalTime time2, TemporalUnit unit, long expected) {
- long amount = time2.periodUntil(time1, unit);
+ long amount = time2.until(time1, unit);
assertEquals(amount, -expected);
}
@Test(expectedExceptions = UnsupportedTemporalTypeException.class)
public void test_periodUntil_TemporalUnit_unsupportedUnit() {
- TEST_12_30_40_987654321.periodUntil(TEST_12_30_40_987654321, DAYS);
+ TEST_12_30_40_987654321.until(TEST_12_30_40_987654321, DAYS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullEnd() {
- TEST_12_30_40_987654321.periodUntil(null, HOURS);
+ TEST_12_30_40_987654321.until(null, HOURS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullUnit() {
- TEST_12_30_40_987654321.periodUntil(TEST_12_30_40_987654321, null);
+ TEST_12_30_40_987654321.until(TEST_12_30_40_987654321, null);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/TCKMonth.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKMonth.java Thu Jul 25 20:30:58 2013 -0400
@@ -151,6 +151,44 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(Month.AUGUST.isSupported((TemporalField) null), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.ERA), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(Month.AUGUST.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
--- a/jdk/test/java/time/tck/java/time/TCKMonthDay.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKMonthDay.java Thu Jul 25 20:30:58 2013 -0400
@@ -388,6 +388,44 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_07_15.isSupported((TemporalField) null), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_07_15.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_07_15.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.YEAR), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.ERA), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_07_15.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
--- a/jdk/test/java/time/tck/java/time/TCKOffsetDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKOffsetDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -126,6 +126,7 @@
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
+import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -555,6 +556,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.INSTANT_SECONDS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoField.OFFSET_SECONDS), true);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2008_6_30_11_30_59_000000500.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -1203,6 +1266,7 @@
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
+ assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
@Test
@@ -1214,6 +1278,7 @@
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
+ assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
@Test
@@ -1225,6 +1290,7 @@
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
+ assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
@Test
@@ -1236,6 +1302,7 @@
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
+ assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
@Test
@@ -1247,6 +1314,7 @@
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
+ assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
@Test
@@ -1258,6 +1326,7 @@
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
+ assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
@Test
@@ -1269,6 +1338,14 @@
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
+ assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
+ }
+
+ @Test
+ public void test_compareTo_bothInstantComparator() {
+ OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 20, 40, 4, OFFSET_PTWO);
+ OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 10, 20, 40, 5, OFFSET_PONE);
+ assertEquals(a.compareTo(b), OffsetDateTime.timeLineOrder().compare(a,b), "for nano != nano, compareTo and timeLineOrder() should be the same");
}
@Test
--- a/jdk/test/java/time/tck/java/time/TCKOffsetTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKOffsetTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -543,6 +543,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalField) null), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR_OF_ERA), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ERA), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.OFFSET_SECONDS), true);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MONTHS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.YEARS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DECADES), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.CENTURIES), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLENNIA), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.ERAS), false);
+ assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -1038,7 +1100,7 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal, TemporalUnit)
+ // until(Temporal, TemporalUnit)
//-----------------------------------------------------------------------
@DataProvider(name="periodUntilUnit")
Object[][] data_periodUntilUnit() {
@@ -1063,13 +1125,13 @@
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) {
- long amount = offsetTime1.periodUntil(offsetTime2, unit);
+ long amount = offsetTime1.until(offsetTime2, unit);
assertEquals(amount, expected);
}
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit_negated(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) {
- long amount = offsetTime2.periodUntil(offsetTime1, unit);
+ long amount = offsetTime2.until(offsetTime1, unit);
assertEquals(amount, -expected);
}
@@ -1077,14 +1139,14 @@
public void test_periodUntil_InvalidType() {
OffsetTime offsetTime = OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1));
OffsetDateTime offsetDateTime = offsetTime.atDate(LocalDate.of(1980, 2, 10));
- offsetTime.periodUntil(offsetDateTime, SECONDS);
+ offsetTime.until(offsetDateTime, SECONDS);
}
@Test(expectedExceptions=DateTimeException.class)
public void test_periodUntil_InvalidTemporalUnit() {
OffsetTime offsetTime1 = OffsetTime.of(LocalTime.of(1, 1, 1), ZoneOffset.ofHours(1));
OffsetTime offsetTime2 = OffsetTime.of(LocalTime.of(2, 1, 1), ZoneOffset.ofHours(1));
- offsetTime1.periodUntil(offsetTime2, MONTHS);
+ offsetTime1.until(offsetTime2, MONTHS);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/TCKPeriod.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKPeriod.java Thu Jul 25 20:30:58 2013 -0400
@@ -121,10 +121,23 @@
}
//-----------------------------------------------------------------------
+ // ofWeeks(int)
+ //-----------------------------------------------------------------------
+ @Test
+ public void factory_ofWeeks_int() {
+ assertPeriod(Period.ofWeeks(0), 0, 0, 0);
+ assertPeriod(Period.ofWeeks(1), 0, 0, 7);
+ assertPeriod(Period.ofWeeks(234), 0, 0, 234 * 7);
+ assertPeriod(Period.ofWeeks(-100), 0, 0, -100 * 7);
+ assertPeriod(Period.ofWeeks(Integer.MAX_VALUE / 7), 0, 0, (Integer.MAX_VALUE / 7) * 7);
+ assertPeriod(Period.ofWeeks(Integer.MIN_VALUE / 7), 0, 0, (Integer.MIN_VALUE / 7) * 7);
+ }
+
+ //-----------------------------------------------------------------------
// ofDays(int)
//-----------------------------------------------------------------------
@Test
- public void factory_ofDay_int() {
+ public void factory_ofDays_int() {
assertPeriod(Period.ofDays(0), 0, 0, 0);
assertPeriod(Period.ofDays(1), 0, 0, 1);
assertPeriod(Period.ofDays(234), 0, 0, 234);
@@ -251,6 +264,18 @@
{"P" + Integer.MAX_VALUE + "M", Period.ofMonths(Integer.MAX_VALUE)},
{"P" + Integer.MIN_VALUE + "M", Period.ofMonths(Integer.MIN_VALUE)},
+ {"P1W", Period.ofDays(1 * 7)},
+ {"P12W", Period.ofDays(12 * 7)},
+ {"P7654321W", Period.ofDays(7654321 * 7)},
+ {"P+1W", Period.ofDays(1 * 7)},
+ {"P+12W", Period.ofDays(12 * 7)},
+ {"P+7654321W", Period.ofDays(7654321 * 7)},
+ {"P+0W", Period.ofDays(0)},
+ {"P0W", Period.ofDays(0)},
+ {"P-0W", Period.ofDays(0)},
+ {"P-25W", Period.ofDays(-25 * 7)},
+ {"P-7654321W", Period.ofDays(-7654321 * 7)},
+
{"P1D", Period.ofDays(1)},
{"P12D", Period.ofDays(12)},
{"P987654321D", Period.ofDays(987654321)},
@@ -274,6 +299,10 @@
{"P2Y-3M25D", Period.of(2, -3, 25)},
{"P2Y3M-25D", Period.of(2, 3, -25)},
{"P-2Y-3M-25D", Period.of(-2, -3, -25)},
+
+ {"P0Y0M0W0D", Period.of(0, 0, 0)},
+ {"P2Y3M4W25D", Period.of(2, 3, 4 * 7 + 25)},
+ {"P-2Y-3M-4W-25D", Period.of(-2, -3, -4 * 7 - 25)},
};
}
@@ -334,6 +363,13 @@
{"P1Y2Y"},
{"PT1M+3S"},
+ {"P1M2Y"},
+ {"P1W2Y"},
+ {"P1D2Y"},
+ {"P1W2M"},
+ {"P1D2M"},
+ {"P1D2W"},
+
{"PT1S1"},
{"PT1S."},
{"PT1SA"},
--- a/jdk/test/java/time/tck/java/time/TCKYear.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKYear.java Thu Jul 25 20:30:58 2013 -0400
@@ -348,6 +348,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2008.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.MONTH_OF_YEAR), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.PROLEPTIC_MONTH), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2008.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2008.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2008.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2008.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2008.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.NANOS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MICROS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MILLIS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.SECONDS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MINUTES), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.HOURS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.HALF_DAYS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MONTHS), false);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2008.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -829,7 +891,7 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal, TemporalUnit)
+ // until(Temporal, TemporalUnit)
//-----------------------------------------------------------------------
@DataProvider(name="periodUntilUnit")
Object[][] data_periodUntilUnit() {
@@ -881,29 +943,29 @@
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit(Year year1, Year year2, TemporalUnit unit, long expected) {
- long amount = year1.periodUntil(year2, unit);
+ long amount = year1.until(year2, unit);
assertEquals(amount, expected);
}
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit_negated(Year year1, Year year2, TemporalUnit unit, long expected) {
- long amount = year2.periodUntil(year1, unit);
+ long amount = year2.until(year1, unit);
assertEquals(amount, -expected);
}
@Test(expectedExceptions = UnsupportedTemporalTypeException.class)
public void test_periodUntil_TemporalUnit_unsupportedUnit() {
- TEST_2008.periodUntil(TEST_2008, MONTHS);
+ TEST_2008.until(TEST_2008, MONTHS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullEnd() {
- TEST_2008.periodUntil(null, DAYS);
+ TEST_2008.until(null, DAYS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullUnit() {
- TEST_2008.periodUntil(TEST_2008, null);
+ TEST_2008.until(TEST_2008, null);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/TCKYearMonth.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKYearMonth.java Thu Jul 25 20:30:58 2013 -0400
@@ -408,6 +408,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_2008_06.isSupported((TemporalField) null), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.NANO_OF_SECOND), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.NANO_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MICRO_OF_SECOND), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MICRO_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MILLI_OF_SECOND), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MILLI_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.SECOND_OF_MINUTE), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.SECOND_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MINUTE_OF_HOUR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MINUTE_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.HOUR_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.AMPM_OF_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.DAY_OF_WEEK), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.DAY_OF_MONTH), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.DAY_OF_YEAR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.EPOCH_DAY), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.INSTANT_SECONDS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoField.OFFSET_SECONDS), false);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_2008_06.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.NANOS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MICROS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MILLIS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.SECONDS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MINUTES), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.HOURS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.HALF_DAYS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.DAYS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.WEEKS), false);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_2008_06.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -1120,7 +1182,7 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal, TemporalUnit)
+ // until(Temporal, TemporalUnit)
//-----------------------------------------------------------------------
@DataProvider(name="periodUntilUnit")
Object[][] data_periodUntilUnit() {
@@ -1200,29 +1262,29 @@
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit(YearMonth ym1, YearMonth ym2, TemporalUnit unit, long expected) {
- long amount = ym1.periodUntil(ym2, unit);
+ long amount = ym1.until(ym2, unit);
assertEquals(amount, expected);
}
@Test(dataProvider="periodUntilUnit")
public void test_periodUntil_TemporalUnit_negated(YearMonth ym1, YearMonth ym2, TemporalUnit unit, long expected) {
- long amount = ym2.periodUntil(ym1, unit);
+ long amount = ym2.until(ym1, unit);
assertEquals(amount, -expected);
}
@Test(expectedExceptions = UnsupportedTemporalTypeException.class)
public void test_periodUntil_TemporalUnit_unsupportedUnit() {
- TEST_2008_06.periodUntil(TEST_2008_06, HOURS);
+ TEST_2008_06.until(TEST_2008_06, HOURS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullEnd() {
- TEST_2008_06.periodUntil(null, DAYS);
+ TEST_2008_06.until(null, DAYS);
}
@Test(expectedExceptions = NullPointerException.class)
public void test_periodUntil_TemporalUnit_nullUnit() {
- TEST_2008_06.periodUntil(TEST_2008_06, null);
+ TEST_2008_06.until(TEST_2008_06, null);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/TCKZoneId.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKZoneId.java Thu Jul 25 20:30:58 2013 -0400
@@ -465,6 +465,53 @@
}
//-----------------------------------------------------------------------
+ @DataProvider(name="prefixValid")
+ Object[][] data_prefixValid() {
+ return new Object[][] {
+ {"GMT", "+01:00"},
+ {"UTC", "+01:00"},
+ {"UT", "+01:00"},
+ {"", "+01:00"},
+ };
+ }
+
+ @Test(dataProvider="prefixValid")
+ public void test_prefixOfOffset(String prefix, String offset) {
+ ZoneOffset zoff = ZoneOffset.of(offset);
+ ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
+ assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);
+
+ }
+
+ //-----------------------------------------------------------------------
+ @DataProvider(name="prefixInvalid")
+ Object[][] data_prefixInvalid() {
+ return new Object[][] {
+ {"GM", "+01:00"},
+ {"U", "+01:00"},
+ {"UTC0", "+01:00"},
+ {"A", "+01:00"},
+ };
+ }
+
+ @Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class)
+ public void test_invalidPrefixOfOffset(String prefix, String offset) {
+ ZoneOffset zoff = ZoneOffset.of(offset);
+ ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
+ fail("should have thrown an exception for prefix: " + prefix);
+ }
+
+ @Test(expectedExceptions=java.lang.NullPointerException.class)
+ public void test_nullPrefixOfOffset() {
+ ZoneId.ofOffset(null, ZoneOffset.ofTotalSeconds(1));
+ }
+
+ @Test(expectedExceptions=java.lang.NullPointerException.class)
+ public void test_nullOffsetOfOffset() {
+ ZoneId.ofOffset("GMT", null);
+ }
+
+ //-----------------------------------------------------------------------
@DataProvider(name="offsetBasedValidOther")
Object[][] data_offsetBasedValidOther() {
return new Object[][] {
--- a/jdk/test/java/time/tck/java/time/TCKZonedDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/TCKZonedDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -127,6 +127,7 @@
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
+import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -723,10 +724,12 @@
public boolean isSupported(TemporalField field) {
return TEST_DATE_TIME_PARIS.toLocalDateTime().isSupported(field);
}
+
@Override
public long getLong(TemporalField field) {
return TEST_DATE_TIME_PARIS.toLocalDateTime().getLong(field);
}
+
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
@@ -791,17 +794,18 @@
@DataProvider(name="parseAdditional")
Object[][] data_parseAdditional() {
return new Object[][] {
- {"2012-06-30T12:30:40Z[GMT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
- {"2012-06-30T12:30:40Z[UT]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
- {"2012-06-30T12:30:40Z[UTC]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
+ {"2012-06-30T12:30:40Z[GMT]", 2012, 6, 30, 12, 30, 40, 0, "GMT"},
+ {"2012-06-30T12:30:40Z[UT]", 2012, 6, 30, 12, 30, 40, 0, "UT"},
+ {"2012-06-30T12:30:40Z[UTC]", 2012, 6, 30, 12, 30, 40, 0, "UTC"},
+ {"2012-06-30T12:30:40+01:00[Z]", 2012, 6, 30, 12, 30, 40, 0, "Z"},
{"2012-06-30T12:30:40+01:00[+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
- {"2012-06-30T12:30:40+01:00[GMT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
- {"2012-06-30T12:30:40+01:00[UT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
- {"2012-06-30T12:30:40+01:00[UTC+01:00]", 2012, 6, 30, 12, 30, 40, 0, "+01:00"},
+ {"2012-06-30T12:30:40+01:00[GMT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "GMT+01:00"},
+ {"2012-06-30T12:30:40+01:00[UT+01:00]", 2012, 6, 30, 12, 30, 40, 0, "UT+01:00"},
+ {"2012-06-30T12:30:40+01:00[UTC+01:00]", 2012, 6, 30, 12, 30, 40, 0, "UTC+01:00"},
{"2012-06-30T12:30:40-01:00[-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
- {"2012-06-30T12:30:40-01:00[GMT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
- {"2012-06-30T12:30:40-01:00[UT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
- {"2012-06-30T12:30:40-01:00[UTC-01:00]", 2012, 6, 30, 12, 30, 40, 0, "-01:00"},
+ {"2012-06-30T12:30:40-01:00[GMT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "GMT-01:00"},
+ {"2012-06-30T12:30:40-01:00[UT-01:00]", 2012, 6, 30, 12, 30, 40, 0, "UT-01:00"},
+ {"2012-06-30T12:30:40-01:00[UTC-01:00]", 2012, 6, 30, 12, 30, 40, 0, "UTC-01:00"},
{"2012-06-30T12:30:40+01:00[Europe/London]", 2012, 6, 30, 12, 30, 40, 0, "Europe/London"},
};
}
@@ -900,6 +904,68 @@
}
//-----------------------------------------------------------------------
+ // isSupported(TemporalField)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalField() {
+ assertEquals(TEST_DATE_TIME.isSupported((TemporalField) null), false);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.NANO_OF_SECOND), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.NANO_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MICRO_OF_SECOND), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MICRO_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MILLI_OF_SECOND), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MILLI_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.SECOND_OF_MINUTE), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.SECOND_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MINUTE_OF_HOUR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MINUTE_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.HOUR_OF_AMPM), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.HOUR_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.AMPM_OF_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_WEEK), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.DAY_OF_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.EPOCH_DAY), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.MONTH_OF_YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.PROLEPTIC_MONTH), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.YEAR), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.YEAR_OF_ERA), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.ERA), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.INSTANT_SECONDS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoField.OFFSET_SECONDS), true);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupported(TemporalUnit)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_isSupported_TemporalUnit() {
+ assertEquals(TEST_DATE_TIME.isSupported((TemporalUnit) null), false);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.NANOS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MICROS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MILLIS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.SECONDS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MINUTES), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.HOURS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.HALF_DAYS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.DAYS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.WEEKS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MONTHS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.YEARS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.DECADES), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.CENTURIES), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.MILLENNIA), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.ERAS), true);
+ assertEquals(TEST_DATE_TIME.isSupported(ChronoUnit.FOREVER), false);
+ }
+
+ //-----------------------------------------------------------------------
// get(TemporalField)
//-----------------------------------------------------------------------
@Test
@@ -1977,37 +2043,37 @@
}
//-----------------------------------------------------------------------
- // periodUntil(Temporal,TemporalUnit)
+ // until(Temporal,TemporalUnit)
//-----------------------------------------------------------------------
// TODO: more tests for period between two different zones
- // compare results to OffsetDateTime.periodUntil, especially wrt dates
+ // compare results to OffsetDateTime.until, especially wrt dates
@Test(dataProvider="plusDays")
public void test_periodUntil_days(ZonedDateTime base, long expected, ZonedDateTime end) {
if (base.toLocalTime().equals(end.toLocalTime()) == false) {
return; // avoid DST gap input values
}
- assertEquals(base.periodUntil(end, DAYS), expected);
+ assertEquals(base.until(end, DAYS), expected);
}
@Test(dataProvider="plusTime")
public void test_periodUntil_hours(ZonedDateTime base, long expected, ZonedDateTime end) {
- assertEquals(base.periodUntil(end, HOURS), expected);
+ assertEquals(base.until(end, HOURS), expected);
}
@Test(dataProvider="plusTime")
public void test_periodUntil_minutes(ZonedDateTime base, long expected, ZonedDateTime end) {
- assertEquals(base.periodUntil(end, MINUTES), expected * 60);
+ assertEquals(base.until(end, MINUTES), expected * 60);
}
@Test(dataProvider="plusTime")
public void test_periodUntil_seconds(ZonedDateTime base, long expected, ZonedDateTime end) {
- assertEquals(base.periodUntil(end, SECONDS), expected * 3600);
+ assertEquals(base.until(end, SECONDS), expected * 3600);
}
@Test(dataProvider="plusTime")
public void test_periodUntil_nanos(ZonedDateTime base, long expected, ZonedDateTime end) {
- assertEquals(base.periodUntil(end, NANOS), expected * 3600_000_000_000L);
+ assertEquals(base.until(end, NANOS), expected * 3600_000_000_000L);
}
@Test
@@ -2017,13 +2083,13 @@
ZonedDateTime oneAm1 = LocalDateTime.of(2012, 6, 29, 1, 0).atZone(ZONE_PARIS);
ZonedDateTime midnightParis2 = LocalDate.of(2012, 6, 30).atStartOfDay(ZONE_PARIS);
- assertEquals(midnightLondon.periodUntil(midnightParis1, HOURS), 23);
- assertEquals(midnightLondon.periodUntil(oneAm1, HOURS), 24);
- assertEquals(midnightLondon.periodUntil(midnightParis2, HOURS), 23 + 24);
+ assertEquals(midnightLondon.until(midnightParis1, HOURS), 23);
+ assertEquals(midnightLondon.until(oneAm1, HOURS), 24);
+ assertEquals(midnightLondon.until(midnightParis2, HOURS), 23 + 24);
- assertEquals(midnightLondon.periodUntil(midnightParis1, DAYS), 0);
- assertEquals(midnightLondon.periodUntil(oneAm1, DAYS), 1);
- assertEquals(midnightLondon.periodUntil(midnightParis2, DAYS), 1);
+ assertEquals(midnightLondon.until(midnightParis1, DAYS), 0);
+ assertEquals(midnightLondon.until(oneAm1, DAYS), 1);
+ assertEquals(midnightLondon.until(midnightParis2, DAYS), 1);
}
@Test
@@ -2031,8 +2097,8 @@
ZonedDateTime before = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
ZonedDateTime after = TEST_PARIS_GAP_2008_03_30_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
- assertEquals(before.periodUntil(after, HOURS), 23);
- assertEquals(before.periodUntil(after, DAYS), 1);
+ assertEquals(before.until(after, HOURS), 23);
+ assertEquals(before.until(after, DAYS), 1);
}
@Test
@@ -2040,23 +2106,23 @@
ZonedDateTime before = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).atZone(ZONE_PARIS);
ZonedDateTime after = TEST_PARIS_OVERLAP_2008_10_26_02_30.withHour(0).withMinute(0).plusDays(1).atZone(ZONE_PARIS);
- assertEquals(before.periodUntil(after, HOURS), 25);
- assertEquals(before.periodUntil(after, DAYS), 1);
+ assertEquals(before.until(after, HOURS), 25);
+ assertEquals(before.until(after, DAYS), 1);
}
@Test(expectedExceptions=DateTimeException.class)
public void test_periodUntil_differentType() {
- TEST_DATE_TIME_PARIS.periodUntil(TEST_LOCAL_2008_06_30_11_30_59_500, DAYS);
+ TEST_DATE_TIME_PARIS.until(TEST_LOCAL_2008_06_30_11_30_59_500, DAYS);
}
@Test(expectedExceptions=NullPointerException.class)
public void test_periodUntil_nullTemporal() {
- TEST_DATE_TIME_PARIS.periodUntil(null, DAYS);
+ TEST_DATE_TIME_PARIS.until(null, DAYS);
}
@Test(expectedExceptions=NullPointerException.class)
public void test_periodUntil_nullUnit() {
- TEST_DATE_TIME_PARIS.periodUntil(TEST_DATE_TIME_PARIS, null);
+ TEST_DATE_TIME_PARIS.until(TEST_DATE_TIME_PARIS, null);
}
//-----------------------------------------------------------------------
--- a/jdk/test/java/time/tck/java/time/chrono/CopticDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/CopticDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -87,7 +87,7 @@
* This class is immutable and thread-safe.
*/
public final class CopticDate
- implements ChronoLocalDate<CopticDate>, Serializable {
+ implements ChronoLocalDate, Serializable {
/**
* Serialization version.
@@ -202,7 +202,7 @@
}
return getChronology().range(f);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
@@ -224,7 +224,7 @@
case YEAR: return prolepticYear;
case ERA: return (prolepticYear >= 1 ? 1 : 0);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
@@ -249,7 +249,7 @@
case YEAR: return resolvePreviousValid(nvalue, month, day);
case ERA: return resolvePreviousValid(1 - prolepticYear, month, day);
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
@@ -268,7 +268,7 @@
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
}
- throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
return unit.addTo(this, amountToAdd);
}
@@ -297,22 +297,22 @@
}
@Override
- public long periodUntil(Temporal endDateTime, TemporalUnit unit) {
+ public long until(Temporal endDateTime, TemporalUnit unit) {
if (endDateTime instanceof ChronoLocalDate == false) {
throw new DateTimeException("Unable to calculate period between objects of two different types");
}
- ChronoLocalDate<?> end = (ChronoLocalDate<?>) endDateTime;
+ ChronoLocalDate end = (ChronoLocalDate) endDateTime;
if (getChronology().equals(end.getChronology()) == false) {
throw new DateTimeException("Unable to calculate period between two different chronologies");
}
if (unit instanceof ChronoUnit) {
- return LocalDate.from(this).periodUntil(end, unit); // TODO: this is wrong
+ return LocalDate.from(this).until(end, unit); // TODO: this is wrong
}
return unit.between(this, endDateTime);
}
@Override
- public Period periodUntil(ChronoLocalDate<?> endDate) {
+ public Period until(ChronoLocalDate endDate) {
// TODO: untested
CopticDate end = (CopticDate) getChronology().date(endDate);
long totalMonths = (end.prolepticYear - this.prolepticYear) * 13 + (end.month - this.month); // safe
--- a/jdk/test/java/time/tck/java/time/chrono/TCKChronoLocalDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKChronoLocalDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -113,10 +113,10 @@
@Test(dataProvider="calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
- ChronoLocalDate<?> date = chrono.date(refDate);
+ ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
- ChronoLocalDate<?> date2 = chrono2.date(refDate);
+ ChronoLocalDate date2 = chrono2.date(refDate);
TemporalAdjuster adjuster = new FixedAdjuster(date2);
if (chrono != chrono2) {
try {
@@ -127,7 +127,7 @@
}
} else {
// Same chronology,
- ChronoLocalDate<?> result = date.with(adjuster);
+ ChronoLocalDate result = date.with(adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
@@ -136,10 +136,10 @@
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
- ChronoLocalDate<?> date = chrono.date(refDate);
+ ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
- ChronoLocalDate<?> date2 = chrono2.date(refDate);
+ ChronoLocalDate date2 = chrono2.date(refDate);
TemporalAmount adjuster = new FixedAdjuster(date2);
if (chrono != chrono2) {
try {
@@ -150,7 +150,7 @@
}
} else {
// Same chronology,
- ChronoLocalDate<?> result = date.plus(adjuster);
+ ChronoLocalDate result = date.plus(adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
@@ -159,10 +159,10 @@
@Test(dataProvider="calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
- ChronoLocalDate<?> date = chrono.date(refDate);
+ ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
- ChronoLocalDate<?> date2 = chrono2.date(refDate);
+ ChronoLocalDate date2 = chrono2.date(refDate);
TemporalAmount adjuster = new FixedAdjuster(date2);
if (chrono != chrono2) {
try {
@@ -173,7 +173,7 @@
}
} else {
// Same chronology,
- ChronoLocalDate<?> result = date.minus(adjuster);
+ ChronoLocalDate result = date.minus(adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
@@ -182,10 +182,10 @@
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
- ChronoLocalDate<?> date = chrono.date(refDate);
+ ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
- ChronoLocalDate<?> date2 = chrono2.date(refDate);
+ ChronoLocalDate date2 = chrono2.date(refDate);
TemporalUnit adjuster = new FixedTemporalUnit(date2);
if (chrono != chrono2) {
try {
@@ -197,7 +197,7 @@
}
} else {
// Same chronology,
- ChronoLocalDate<?> result = date.plus(1, adjuster);
+ ChronoLocalDate result = date.plus(1, adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
@@ -206,10 +206,10 @@
@Test(dataProvider="calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
- ChronoLocalDate<?> date = chrono.date(refDate);
+ ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
- ChronoLocalDate<?> date2 = chrono2.date(refDate);
+ ChronoLocalDate date2 = chrono2.date(refDate);
TemporalUnit adjuster = new FixedTemporalUnit(date2);
if (chrono != chrono2) {
try {
@@ -221,7 +221,7 @@
}
} else {
// Same chronology,
- ChronoLocalDate<?> result = date.minus(1, adjuster);
+ ChronoLocalDate result = date.minus(1, adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
@@ -230,10 +230,10 @@
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
- ChronoLocalDate<?> date = chrono.date(refDate);
+ ChronoLocalDate date = chrono.date(refDate);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
- ChronoLocalDate<?> date2 = chrono2.date(refDate);
+ ChronoLocalDate date2 = chrono2.date(refDate);
TemporalField adjuster = new FixedTemporalField(date2);
if (chrono != chrono2) {
try {
@@ -245,7 +245,7 @@
}
} else {
// Same chronology,
- ChronoLocalDate<?> result = date.with(adjuster, 1);
+ ChronoLocalDate result = date.with(adjuster, 1);
assertEquals(result, date2, "TemporalField doSet failed to replace date");
}
}
@@ -258,7 +258,7 @@
public void test_date_comparisons(Chronology chrono) {
List<ChronoLocalDate> dates = new ArrayList<>();
- ChronoLocalDate<?> date = chrono.date(LocalDate.of(2013, 1, 1));
+ ChronoLocalDate date = chrono.date(LocalDate.of(2013, 1, 1));
// Insert dates in order, no duplicates
dates.add(date.minus(1, ChronoUnit.YEARS));
@@ -273,17 +273,17 @@
// Check these dates against the corresponding dates for every calendar
for (Chronology[] clist : data_of_calendars()) {
- List<ChronoLocalDate<?>> otherDates = new ArrayList<>();
+ List<ChronoLocalDate> otherDates = new ArrayList<>();
Chronology chrono2 = clist[0];
- for (ChronoLocalDate<?> d : dates) {
+ for (ChronoLocalDate d : dates) {
otherDates.add(chrono2.date(d));
}
// Now compare the sequence of original dates with the sequence of converted dates
for (int i = 0; i < dates.size(); i++) {
- ChronoLocalDate<?> a = dates.get(i);
+ ChronoLocalDate a = dates.get(i);
for (int j = 0; j < otherDates.size(); j++) {
- ChronoLocalDate<?> b = otherDates.get(j);
+ ChronoLocalDate b = otherDates.get(j);
int cmp = ChronoLocalDate.timeLineOrder().compare(a, b);
if (i < j) {
assertTrue(cmp < 0, a + " compare " + b);
@@ -312,7 +312,7 @@
@Test( dataProvider="calendars")
public void test_ChronoSerialization(Chronology chrono) throws Exception {
LocalDate ref = LocalDate.of(2013, 1, 5);
- ChronoLocalDate<?> orginal = chrono.date(ref);
+ ChronoLocalDate orginal = chrono.date(ref);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(orginal);
@@ -320,7 +320,7 @@
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bais);
@SuppressWarnings("unchecked")
- ChronoLocalDate<?> ser = (ChronoLocalDate<?>) in.readObject();
+ ChronoLocalDate ser = (ChronoLocalDate) in.readObject();
assertEquals(ser, orginal, "deserialized date is wrong");
}
@@ -328,12 +328,12 @@
@Test(dataProvider="calendars")
public void test_from_TemporalAccessor(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
- ChronoLocalDate<?> date = chrono.date(refDate);
- ChronoLocalDate<?> test1 = ChronoLocalDate.from(date);
+ ChronoLocalDate date = chrono.date(refDate);
+ ChronoLocalDate test1 = ChronoLocalDate.from(date);
assertEquals(test1, date);
- ChronoLocalDate<?> test2 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)));
+ ChronoLocalDate test2 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)));
assertEquals(test2, date);
- ChronoLocalDate<?> test3 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)).atZone(ZoneOffset.UTC));
+ ChronoLocalDate test3 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)).atZone(ZoneOffset.UTC));
assertEquals(test3, date);
}
@@ -397,11 +397,6 @@
}
@Override
- public String getName() {
- return "FixedTemporalUnit";
- }
-
- @Override
public Duration getDuration() {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -412,6 +407,16 @@
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public boolean isSupportedBy(Temporal temporal) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -426,6 +431,11 @@
public long between(Temporal temporal1, Temporal temporal2) {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ @Override
+ public String toString() {
+ return "FixedTemporalUnit";
+ }
}
/**
@@ -439,11 +449,6 @@
}
@Override
- public String getName() {
- return "FixedTemporalField";
- }
-
- @Override
public TemporalUnit getBaseUnit() {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -459,6 +464,16 @@
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public boolean isSupportedBy(TemporalAccessor temporal) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -478,5 +493,10 @@
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
return (R) this.temporal;
}
+
+ @Override
+ public String toString() {
+ return "FixedTemporalField";
+ }
}
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKChronoLocalDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKChronoLocalDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -411,11 +411,6 @@
}
@Override
- public String getName() {
- return "FixedTemporalUnit";
- }
-
- @Override
public Duration getDuration() {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -426,6 +421,16 @@
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public boolean isSupportedBy(Temporal temporal) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -440,6 +445,11 @@
public long between(Temporal temporal1, Temporal temporal2) {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ @Override
+ public String toString() {
+ return "FixedTemporalUnit";
+ }
}
/**
@@ -453,11 +463,6 @@
}
@Override
- public String getName() {
- return "FixedTemporalField";
- }
-
- @Override
public TemporalUnit getBaseUnit() {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -473,6 +478,16 @@
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public boolean isSupportedBy(TemporalAccessor temporal) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -492,5 +507,10 @@
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
return (R) this.temporal;
}
+
+ @Override
+ public String toString() {
+ return "FixedTemporalField";
+ }
}
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKChronoZonedDateTime.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKChronoZonedDateTime.java Thu Jul 25 20:30:58 2013 -0400
@@ -256,7 +256,7 @@
}
//-----------------------------------------------------------------------
- // isBefore, isAfter, isEqual, INSTANT_COMPARATOR test a Chronology against the other Chronos
+ // isBefore, isAfter, isEqual, timeLineOrder() test a Chronology against the other Chronos
//-----------------------------------------------------------------------
@Test(dataProvider="calendars")
public void test_zonedDateTime_comparisons(Chronology chrono) {
@@ -413,11 +413,6 @@
}
@Override
- public String getName() {
- return "FixedTemporalUnit";
- }
-
- @Override
public Duration getDuration() {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -428,6 +423,16 @@
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public boolean isSupportedBy(Temporal temporal) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -442,6 +447,12 @@
public long between(Temporal temporal1, Temporal temporal2) {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ @Override
+ public String toString() {
+ return "FixedTemporalUnit";
+ }
+
}
/**
@@ -455,11 +466,6 @@
}
@Override
- public String getName() {
- return "FixedTemporalField";
- }
-
- @Override
public TemporalUnit getBaseUnit() {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -475,6 +481,16 @@
}
@Override
+ public boolean isDateBased() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
+ @Override
public boolean isSupportedBy(TemporalAccessor temporal) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -494,5 +510,10 @@
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
return (R) this.temporal;
}
+
+ @Override
+ public String toString() {
+ return "FixedTemporalField";
+ }
}
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -64,18 +64,27 @@
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
+import java.util.Locale;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.time.ZoneId;
+import java.time.Clock;
import java.time.DateTimeException;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Chronology;
import java.time.chrono.HijrahChronology;
+import java.time.chrono.HijrahEra;
import java.time.chrono.IsoChronology;
+import java.time.chrono.IsoEra;
import java.time.chrono.JapaneseChronology;
+import java.time.chrono.JapaneseEra;
import java.time.chrono.MinguoChronology;
+import java.time.chrono.MinguoEra;
import java.time.chrono.ThaiBuddhistChronology;
+import java.time.chrono.ThaiBuddhistEra;
+import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
import java.util.Locale;
import java.util.Set;
@@ -133,15 +142,35 @@
+ ", expected >= " + data_of_calendars().length);
}
+ //-----------------------------------------------------------------------
+ // getDisplayName()
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "calendarDisplayName")
+ Object[][] data_of_calendarDisplayNames() {
+ return new Object[][] {
+ {"Hijrah", "Hijrah-umalqura"},
+ {"ISO", "ISO"},
+ {"Japanese", "Japanese Calendar"},
+ {"Minguo", "Minguo Calendar"},
+ {"ThaiBuddhist", "Buddhist Calendar"},
+ };
+ }
+
+ @Test(dataProvider = "calendarDisplayName")
+ public void test_getDisplayName(String chronoId, String calendarDisplayName) {
+ Chronology chrono = Chronology.of(chronoId);
+ assertEquals(chrono.getDisplayName(TextStyle.FULL, Locale.ENGLISH), calendarDisplayName);
+ }
+
/**
* Compute the number of days from the Epoch and compute the date from the number of days.
*/
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
- ChronoLocalDate<?> date1 = chrono.dateNow();
+ ChronoLocalDate date1 = chrono.dateNow();
long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
- ChronoLocalDate<?> date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
+ ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
@@ -150,9 +179,9 @@
@Test(dataProvider = "calendarNameAndType")
public void test_dateEpochDay(String name, String alias) {
Chronology chrono = Chronology.of(name);
- ChronoLocalDate<?> date = chrono.dateNow();
+ ChronoLocalDate date = chrono.dateNow();
long epochDay = date.getLong(ChronoField.EPOCH_DAY);
- ChronoLocalDate<?> test = chrono.dateEpochDay(epochDay);
+ ChronoLocalDate test = chrono.dateEpochDay(epochDay);
assertEquals(test, date);
}
@@ -184,6 +213,101 @@
assertEquals(Chronology.ofLocale(locale), chrono);
}
+ //-----------------------------------------------------------------------
+ // dateNow()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_MinguoChronology_dateNow() {
+ ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
+ Clock clock = Clock.system(zoneId_paris);
+
+ Chronology chrono = Chronology.of("Minguo");
+ assertEquals(chrono.dateNow(), MinguoChronology.INSTANCE.dateNow());
+ assertEquals(chrono.dateNow(zoneId_paris), MinguoChronology.INSTANCE.dateNow(zoneId_paris));
+ assertEquals(chrono.dateNow(clock), MinguoChronology.INSTANCE.dateNow(clock));
+ }
+
+ @Test
+ public void test_IsoChronology_dateNow() {
+ ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
+ Clock clock = Clock.system(zoneId_paris);
+
+ Chronology chrono = Chronology.of("ISO");
+ assertEquals(chrono.dateNow(), IsoChronology.INSTANCE.dateNow());
+ assertEquals(chrono.dateNow(zoneId_paris), IsoChronology.INSTANCE.dateNow(zoneId_paris));
+ assertEquals(chrono.dateNow(clock), IsoChronology.INSTANCE.dateNow(clock));
+ }
+
+ @Test
+ public void test_JapaneseChronology_dateNow() {
+ ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
+ Clock clock = Clock.system(zoneId_paris);
+
+ Chronology chrono = Chronology.of("Japanese");
+ assertEquals(chrono.dateNow(), JapaneseChronology.INSTANCE.dateNow());
+ assertEquals(chrono.dateNow(zoneId_paris), JapaneseChronology.INSTANCE.dateNow(zoneId_paris));
+ assertEquals(chrono.dateNow(clock), JapaneseChronology.INSTANCE.dateNow(clock));
+ }
+
+ @Test
+ public void test_ThaiBuddhistChronology_dateNow() {
+ ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
+ Clock clock = Clock.system(zoneId_paris);
+
+ Chronology chrono = Chronology.of("ThaiBuddhist");
+ assertEquals(chrono.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow());
+ assertEquals(chrono.dateNow(zoneId_paris), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId_paris));
+ assertEquals(chrono.dateNow(clock), ThaiBuddhistChronology.INSTANCE.dateNow(clock));
+ }
+
+ //-----------------------------------------------------------------------
+ // dateYearDay() and date()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_HijrahChronology_dateYearDay() {
+ Chronology chrono = Chronology.of("Hijrah");
+ ChronoLocalDate date1 = chrono.dateYearDay(HijrahEra.AH, 1434, 178);
+ ChronoLocalDate date2 = chrono.date(HijrahEra.AH, 1434, 7, 1);
+ assertEquals(date1, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
+ assertEquals(date2, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
+ }
+
+ @Test
+ public void test_MinguoChronology_dateYearDay() {
+ Chronology chrono = Chronology.of("Minguo");
+ ChronoLocalDate date1 = chrono.dateYearDay(MinguoEra.ROC, 5, 60);
+ ChronoLocalDate date2 = chrono.date(MinguoEra.ROC, 5, 2, 29);
+ assertEquals(date1, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
+ assertEquals(date2, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
+ }
+
+ @Test
+ public void test_IsoChronology_dateYearDay() {
+ Chronology chrono = Chronology.of("ISO");
+ ChronoLocalDate date1 = chrono.dateYearDay(IsoEra.CE, 5, 60);
+ ChronoLocalDate date2 = chrono.date(IsoEra.CE, 5, 3, 1);
+ assertEquals(date1, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60));
+ assertEquals(date2, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60));
+ }
+
+ @Test
+ public void test_JapaneseChronology_dateYearDay() {
+ Chronology chrono = Chronology.of("Japanese");
+ ChronoLocalDate date1 = chrono.dateYearDay(JapaneseEra.HEISEI, 8, 60);
+ ChronoLocalDate date2 = chrono.date(JapaneseEra.HEISEI, 8, 2, 29);
+ assertEquals(date1, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
+ assertEquals(date2, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
+ }
+
+ @Test
+ public void test_ThaiBuddhistChronology_dateYearDay() {
+ Chronology chrono = Chronology.of("ThaiBuddhist");
+ ChronoLocalDate date1 = chrono.dateYearDay(ThaiBuddhistEra.BE, 2459, 60);
+ ChronoLocalDate date2 = chrono.date(ThaiBuddhistEra.BE, 2459, 2, 29);
+ assertEquals(date1, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
+ assertEquals(date2, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
+ }
+
/**
* Test lookup by calendarType of each chronology.
* Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}.
--- a/jdk/test/java/time/tck/java/time/chrono/TCKHijrahChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKHijrahChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -56,18 +56,13 @@
*/
package tck.java.time.chrono;
-import static java.time.temporal.ChronoField.DAY_OF_WEEK;
+import java.time.Clock;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-import java.time.Clock;
import java.time.DateTimeException;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.Month;
-import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.chrono.ChronoLocalDate;
@@ -77,11 +72,12 @@
import java.time.chrono.HijrahDate;
import java.time.chrono.HijrahEra;
import java.time.chrono.IsoChronology;
-import java.time.chrono.MinguoChronology;
-import java.time.chrono.MinguoDate;
-import java.time.temporal.ChronoUnit;
-import java.time.temporal.TemporalAdjuster;
+import java.time.format.ResolverStyle;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalField;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@@ -106,49 +102,7 @@
Assert.assertEquals(test, c);
}
- //-----------------------------------------------------------------------
- // creation, toLocalDate()
- //-----------------------------------------------------------------------
- @DataProvider(name="samples")
- Object[][] data_samples() {
- return new Object[][] {
- //{HijrahChronology.INSTANCE.date(1320, 1, 1), LocalDate.of(1902, 4, 9)},
- //{HijrahChronology.INSTANCE.date(1320, 1, 2), LocalDate.of(1902, 4, 10)},
- //{HijrahChronology.INSTANCE.date(1320, 1, 3), LocalDate.of(1902, 4, 11)},
-
- //{HijrahChronology.INSTANCE.date(1322, 1, 1), LocalDate.of(1904, 3, 18)},
- //{HijrahChronology.INSTANCE.date(1323, 1, 1), LocalDate.of(1905, 3, 7)},
- //{HijrahChronology.INSTANCE.date(1323, 12, 6), LocalDate.of(1906, 1, 30)},
- //{HijrahChronology.INSTANCE.date(1324, 1, 1), LocalDate.of(1906, 2, 24)},
- //{HijrahChronology.INSTANCE.date(1324, 7, 3), LocalDate.of(1906, 8, 23)},
- //{HijrahChronology.INSTANCE.date(1324, 7, 4), LocalDate.of(1906, 8, 24)},
- //{HijrahChronology.INSTANCE.date(1325, 1, 1), LocalDate.of(1907, 2, 13)},
-
- {HijrahChronology.INSTANCE.date(1434, 7, 1), LocalDate.of(2013, 5, 11)},
- {HijrahChronology.INSTANCE.date(HijrahEra.AH, 1434, 7, 1), LocalDate.of(2013, 5, 11)},
- {HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178), LocalDate.of(2013, 5, 11)},
- {HijrahChronology.INSTANCE.dateYearDay(1434, 178), LocalDate.of(2013, 5, 11)},
- //{HijrahChronology.INSTANCE.date(1500, 3, 3), LocalDate.of(2079, 1, 5)},
- //{HijrahChronology.INSTANCE.date(1500, 10, 28), LocalDate.of(2079, 8, 25)},
- //{HijrahChronology.INSTANCE.date(1500, 10, 29), LocalDate.of(2079, 8, 26)},
- };
- }
-
- @Test(dataProvider="samples")
- public void test_toLocalDate(ChronoLocalDate<?> hijrahDate, LocalDate iso) {
- assertEquals(LocalDate.from(hijrahDate), iso);
- }
-
- @Test(dataProvider="samples")
- public void test_fromCalendrical(ChronoLocalDate<?> hijrahDate, LocalDate iso) {
- assertEquals(HijrahChronology.INSTANCE.date(iso), hijrahDate);
- }
-
- @Test(dataProvider="samples")
- public void test_dayOfWeekEqualIsoDayOfWeek(ChronoLocalDate<?> hijrahDate, LocalDate iso) {
- assertEquals(hijrahDate.get(DAY_OF_WEEK), iso.get(DAY_OF_WEEK), "Hijrah day of week should be same as ISO day of week");
- }
-
+ // Tests for dateNow() method
@Test
public void test_dateNow(){
assertEquals(HijrahChronology.INSTANCE.dateNow(), HijrahDate.now()) ;
@@ -169,31 +123,41 @@
assertEquals(HijrahChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), HijrahChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
}
+ // Sample invalid dates
@DataProvider(name="badDates")
Object[][] data_badDates() {
return new Object[][] {
- {1434, 0, 0},
-
+ {1299, 12, 29},
+ {1320, 1, 29 + 1},
+ {1320, 12, 29 + 1},
{1434, -1, 1},
+ {1605, 1, 29},
{1434, 0, 1},
{1434, 14, 1},
{1434, 15, 1},
-
{1434, 1, -1},
{1434, 1, 0},
{1434, 1, 32},
-
{1434, 12, -1},
{1434, 12, 0},
{1434, 12, 32},
};
}
+ // This is a negative test to verify if the API throws exception if an invalid date is provided
@Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
public void test_badDates(int year, int month, int dom) {
HijrahChronology.INSTANCE.date(year, month, dom);
}
+ // Negative test or dateYearDay with day too large
+ @Test(expectedExceptions=java.time.DateTimeException.class)
+ public void test_ofYearDayTooLarge() {
+ int year = 1435;
+ int lengthOfYear = HijrahChronology.INSTANCE.dateYearDay(year, 1).lengthOfYear();
+ HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(year, lengthOfYear + 1);
+ }
+
//-----------------------------------------------------------------------
// Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
//-----------------------------------------------------------------------
@@ -213,7 +177,7 @@
; // ignore expected exception
}
- /* TODO: Test for missing HijrahDate.of(Era, y, m, d) method.
+ /* TODO: Test for checking HijrahDate.of(Era, y, m, d) method if it is added.
try {
@SuppressWarnings("unused")
HijrahDate jdate = HijrahDate.of(era, 1, 1, 1);
@@ -233,102 +197,344 @@
}
}
}
-
//-----------------------------------------------------------------------
- // with(WithAdjuster)
+ // Tests for HijrahChronology resolve
//-----------------------------------------------------------------------
- @Test
- public void test_adjust1() {
- ChronoLocalDate<?> base = HijrahChronology.INSTANCE.date(1434, 5, 15);
- ChronoLocalDate<?> test = base.with(TemporalAdjuster.lastDayOfMonth());
- assertEquals(test, HijrahChronology.INSTANCE.date(1434, 5, 29));
+ @DataProvider(name = "resolve_styleByEra")
+ Object[][] data_resolve_styleByEra() {
+ Object[][] result = new Object[ResolverStyle.values().length * HijrahEra.values().length][];
+ int i = 0;
+ for (ResolverStyle style : ResolverStyle.values()) {
+ for (HijrahEra era : HijrahEra.values()) {
+ result[i++] = new Object[] {style, era};
+ }
+ }
+ return result;
+ }
+
+ @Test(dataProvider = "resolve_styleByEra")
+ public void test_resolve_yearOfEra_eraOnly_valid(ResolverStyle style, HijrahEra era) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, (long) era.getValue());
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
+ assertEquals(fieldValues.size(), 1);
+ }
+
+ @Test(dataProvider = "resolve_styleByEra")
+ public void test_resolve_yearOfEra_eraAndYearOfEraOnly_valid(ResolverStyle style, HijrahEra era) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, (long) era.getValue());
+ fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.ERA), null);
+ assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), null);
+ assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
+ assertEquals(fieldValues.size(), 1);
}
- @Test
- public void test_adjust2() {
- ChronoLocalDate<?> base = HijrahChronology.INSTANCE.date(1434, 6, 2);
- ChronoLocalDate<?> test = base.with(TemporalAdjuster.lastDayOfMonth());
- assertEquals(test, HijrahChronology.INSTANCE.date(1434, 6, 30));
+ @Test(dataProvider = "resolve_styleByEra")
+ public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, HijrahEra era) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, (long) era.getValue());
+ fieldValues.put(ChronoField.YEAR, 1343L);
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
+ assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
+ assertEquals(fieldValues.size(), 2);
+ }
+
+ @DataProvider(name = "resolve_styles")
+ Object[][] data_resolve_styles() {
+ Object[][] result = new Object[ResolverStyle.values().length][];
+ int i = 0;
+ for (ResolverStyle style : ResolverStyle.values()) {
+ result[i++] = new Object[] {style};
+ }
+ return result;
}
- //-----------------------------------------------------------------------
- // HijrahDate.with(Local*)
- //-----------------------------------------------------------------------
- @Test
- public void test_adjust_toLocalDate() {
- ChronoLocalDate<?> hijrahDate = HijrahChronology.INSTANCE.date(1435, 1, 4);
- ChronoLocalDate<?> test = hijrahDate.with(LocalDate.of(2012, 7, 6));
- assertEquals(test, HijrahChronology.INSTANCE.date(1433, 8, 16));
+ @Test(dataProvider = "resolve_styles")
+ public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (style != ResolverStyle.STRICT) ? null : (Long) 1343L);
+ assertEquals(fieldValues.get(ChronoField.YEAR), (style == ResolverStyle.STRICT) ? null : (Long) 1343L);
+ assertEquals(fieldValues.size(), 1);
}
- @Test(expectedExceptions=DateTimeException.class)
- public void test_adjust_toMonth() {
- ChronoLocalDate<?> hijrahDate = HijrahChronology.INSTANCE.date(1435, 1, 4);
- hijrahDate.with(Month.APRIL);
+ @Test(dataProvider = "resolve_styles")
+ public void test_resolve_yearOfEra_yearOfEraAndYearOnly_valid(ResolverStyle style) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
+ fieldValues.put(ChronoField.YEAR, 1343L);
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), null);
+ assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
+ assertEquals(fieldValues.size(), 1);
}
//-----------------------------------------------------------------------
- // LocalDate.with(HijrahDate)
+ // Sample Hijrah Calendar data; official data is in lib/hijrah-ummalqura.properties
+ // 1432=29 30 30 30 29 30 29 30 29 30 29 29 total = 354
+ // 1433=30 29 30 30 29 30 30 29 30 29 30 29 total = 355
+ // 1434=29 30 29 30 29 30 30 29 30 30 29 29 total = 354
+ // 1435=30 29 30 29 30 29 30 29 30 30 29 30 total = 355
//-----------------------------------------------------------------------
- @Test
- public void test_LocalDate_adjustToHijrahDate() {
- ChronoLocalDate<?> hijrahDate = HijrahChronology.INSTANCE.date(1434, 5, 15);
- LocalDate test = LocalDate.MIN.with(hijrahDate);
- assertEquals(test, LocalDate.of(2013, 3, 27));
+ @DataProvider(name = "resolve_ymd")
+ Object[][] data_resolve_ymd() {
+ // Compute the number of days in various month and years so that test cases
+ // are not dependent on specific calendar data
+ // Month numbers are always 1..12 so they can be used literally
+ final int year = 1434;
+ final int yearP1 = year + 1;
+ final int yearP2 = year + 2;
+ final int yearM1 = year - 1;
+ final int yearM2 = year - 2;
+ final int lastDayInYear = dateYearDay(year, 1).lengthOfYear();
+ final int lastDayInYearP1 = dateYearDay(yearP1, 1).lengthOfYear();
+ final int lastDayInYearM1 = dateYearDay(yearM1, 1).lengthOfYear();
+ final int lastDayInYearM2 = dateYearDay(yearM2, 1).lengthOfYear();
+ final int lastDayInMonthM1 = date(yearM1, 12, 1).lengthOfMonth();
+ final int lastDayInMonthM2 = date(yearM1, 11, 1).lengthOfMonth();
+ final int lastDayInMonthM11 = date(yearM1, 2, 1).lengthOfMonth();
+
+ final int lastDayInMonth1 = date(year, 1, 1).lengthOfMonth();
+ final int lastDayInMonth2 = date(year, 2, 1).lengthOfMonth();
+ final int lastDayInMonth4 = date(year, 4, 1).lengthOfMonth();
+ final int lastDayInMonth5 = date(year, 5, 1).lengthOfMonth();
+ final int lastDayInMonth6 = date(year, 6, 1).lengthOfMonth();
+ final int lastDayInMonth7 = date(year, 7, 1).lengthOfMonth();
+
+ return new Object[][] {
+ {year, 1, -lastDayInYearM1, dateYearDay(yearM2, lastDayInYearM2), false, false},
+ {year, 1, -lastDayInYearM1 + 1, date(yearM1, 1, 1), false, false},
+ {year, 1, -lastDayInMonthM1, date(yearM1, 11, lastDayInMonthM2), false, false},
+ {year, 1, -lastDayInMonthM1 + 1, date(yearM1, 12, 1), false, false},
+ {year, 1, -12, date(yearM1, 12, lastDayInMonthM1 - 12), false, false},
+ {year, 1, 1, date(year, 1, 1), true, true},
+ {year, 1, lastDayInMonth1 + lastDayInMonth2 - 1, date(year, 2, lastDayInMonth2 - 1), false, false},
+ {year, 1, lastDayInMonth1 + lastDayInMonth2, date(year, 2, lastDayInMonth2), false, false},
+ {year, 1, lastDayInMonth1 + lastDayInMonth2 + 1 , date(year, 3, 1), false, false},
+ {year, 1, lastDayInYear, dateYearDay(year, lastDayInYear), false, false},
+ {year, 1, lastDayInYear + 1, date(1435, 1, 1), false, false},
+ {year, 1, lastDayInYear + lastDayInYearP1, dateYearDay(yearP1, lastDayInYearP1), false, false},
+ {year, 1, lastDayInYear + lastDayInYearP1 + 1, date(yearP2, 1, 1), false, false},
+
+ {year, 2, 1, date(year, 2, 1), true, true},
+ {year, 2, lastDayInMonth2 - 2, date(year, 2, lastDayInMonth2 - 2), true, true},
+ {year, 2, lastDayInMonth2 - 1, date(year, 2, lastDayInMonth2 - 1), true, true},
+ {year, 2, lastDayInMonth2, date(year, 2, lastDayInMonth2), date(year, 2, lastDayInMonth2), true},
+ {year, 2, lastDayInMonth2 + 1, date(year, 3, 1), false, false},
+
+ {year, -12, 1, date(yearM2, 12, 1), false, false},
+ {year, -11, 1, date(yearM1, 1, 1), false, false},
+ {year, -1, 1, date(yearM1, 11, 1), false, false},
+ {year, 0, 1, date(yearM1, 12, 1), false, false},
+ {year, 1, 1, date(year, 1, 1), true, true},
+ {year, 12, 1, date(year, 12, 1), true, true},
+ {year, 13, 1, date(yearP1, 1, 1), false, false},
+ {year, 24, 1, date(yearP1, 12, 1), false, false},
+ {year, 25, 1, date(yearP2, 1, 1), false, false},
+
+ {year, 6, -lastDayInMonth5, date(year, 4, lastDayInMonth4), false, false},
+ {year, 6, -lastDayInMonth5 + 1, date(year, 5, 1), false, false},
+ {year, 6, -1, date(year, 5, lastDayInMonth5 - 1), false, false},
+ {year, 6, 0, date(year, 5, lastDayInMonth5), false, false},
+ {year, 6, 1, date(year, 6, 1), true, true},
+ {year, 6, lastDayInMonth6 - 1 , date(year, 6, lastDayInMonth6 - 1), true, true},
+ {year, 6, lastDayInMonth6, date(year, 6, lastDayInMonth6), date(year, 6, lastDayInMonth6), true},
+ {year, 6, lastDayInMonth6 + 1, date(year, 7, 1), false, false},
+ {year, 6, lastDayInMonth6 + lastDayInMonth7 , date(year, 7, lastDayInMonth7), false, false},
+ {year, 6, lastDayInMonth6 + lastDayInMonth7 + 1, date(year, 8, 1), false, false},
+
+ {yearM1, 2, 1, date(yearM1, 2, 1), true, true},
+ {yearM1, 2, lastDayInMonthM11 - 1, date(yearM1, 2, lastDayInMonthM11 - 1), true, true},
+ {yearM1, 2, lastDayInMonthM11, date(yearM1, 2, lastDayInMonthM11), true, true},
+ {yearM1, 2, lastDayInMonthM11 + 1, date(yearM1, 3, 1), date(yearM1, 2, lastDayInMonthM11), false},
+ {yearM1, 2, lastDayInMonthM11 + 2, date(yearM1, 3, 2), false, false},
+ // Bad dates
+ {1299, 12, 1, null, false, false},
+ {1601, 1, 1, null, false, false},
+
+ };
}
- @Test
- public void test_LocalDateTime_adjustToHijrahDate() {
- ChronoLocalDate<?> hijrahDate = HijrahChronology.INSTANCE.date(1435, 5, 15);
- LocalDateTime test = LocalDateTime.MIN.with(hijrahDate);
- assertEquals(test, LocalDateTime.of(2014, 3, 16, 0, 0));
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_lenient(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+
+ if (expected != null) {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ fail("Should have failed, returned: " + date);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_smart(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (Boolean.TRUE.equals(smart)) {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else if (smart instanceof HijrahDate) {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, smart);
+ } else {
+ try {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed, returned: " + date);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_strict(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (strict) {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected, "Resolved to incorrect date");
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed, returned: " + date);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
}
//-----------------------------------------------------------------------
- // PeriodUntil()
- //-----------------------------------------------------------------------
- @Test
- public void test_periodUntilDate() {
- HijrahDate mdate1 = HijrahDate.of(1434, 1, 1);
- HijrahDate mdate2 = HijrahDate.of(1435, 2, 2);
- Period period = mdate1.periodUntil(mdate2);
- assertEquals(period, Period.of(1, 1, 1));
+ @DataProvider(name = "resolve_yd")
+ Object[][] data_resolve_yd() {
+ // Compute the number of days in various month and years so that test cases
+ // are not dependent on specific calendar data
+ // Month numbers are always 1..12 so they can be used literally
+ final int year = 1343;
+ final int yearP1 = year + 1;
+ final int yearP2 = year + 2;
+ final int yearM1 = year - 1;
+ final int yearM2 = year - 2;
+ final int lastDayInYear = dateYearDay(year, 1).lengthOfYear();
+ final int lastDayInYearP1 = dateYearDay(yearP1, 1).lengthOfYear();
+ final int lastDayInYearM1 = dateYearDay(yearM1, 1).lengthOfYear();
+ final int lastDayInYearM2 = dateYearDay(yearM2, 1).lengthOfYear();
+
+ final int lastDayInMonthM1 = date(yearM1, 12, 1).lengthOfMonth();
+ final int lastDayInMonthM2 = date(yearM1, 11, 1).lengthOfMonth();
+ final int lastDayInMonthM11 = date(yearM1, 2, 1).lengthOfMonth();
+
+ final int lastDayInMonth1 = date(year, 1, 1).lengthOfMonth();
+ final int lastDayInMonth2 = date(year, 2, 1).lengthOfMonth();
+ final int lastDayInMonth4 = date(year, 4, 1).lengthOfMonth();
+ final int lastDayInMonth5 = date(year, 5, 1).lengthOfMonth();
+ final int lastDayInMonth6 = date(year, 6, 1).lengthOfMonth();
+ final int lastDayInMonth7 = date(year, 7, 1).lengthOfMonth();
+
+ return new Object[][] {
+ {year, -lastDayInYearM1, dateYearDay(yearM2, lastDayInYearM2), false, false},
+ {year, -lastDayInYearM1 + 1, date(yearM1, 1, 1), false, false},
+ {year, -lastDayInMonthM1, date(yearM1, 11, lastDayInMonthM2), false, false},
+ {year, -lastDayInMonthM1 + 1, date(yearM1, 12, 1), false, false},
+ {year, -12, date(yearM1, 12, lastDayInMonthM1 - 12), false, false},
+ {year, -1, date(yearM1, 12, lastDayInMonthM1 - 1), false, false},
+ {year, 0, date(yearM1, 12, lastDayInMonthM1), false, false},
+ {year, 1, date(year, 1, 1), true, true},
+ {year, 2, date(year, 1, 2), true, true},
+ {year, lastDayInMonth1, date(year, 1, lastDayInMonth1), true, true},
+ {year, lastDayInMonth1 + 1, date(year, 2, 1), true, true},
+ {year, lastDayInMonth1 + lastDayInMonth2 - 1, date(year, 2, lastDayInMonth2 - 1), true, true},
+ {year, lastDayInMonth1 + lastDayInMonth2, date(year, 2, lastDayInMonth2), true, true},
+ {year, lastDayInMonth1 + lastDayInMonth2 + 1, date(year, 3, 1), true, true},
+ {year, lastDayInYear - 1, dateYearDay(year, lastDayInYear - 1), true, true},
+ {year, lastDayInYear, dateYearDay(year, lastDayInYear), true, true},
+ {year, lastDayInYear + 1, date(yearP1, 1, 1), false, false},
+ {year, lastDayInYear + lastDayInYearP1, dateYearDay(yearP1, lastDayInYearP1), false, false},
+ {year, lastDayInYear + lastDayInYearP1 + 1, date(yearP2, 1, 1), false, false},
+ };
}
- @Test
- public void test_periodUntilUnit() {
- HijrahDate mdate1 = HijrahDate.of(1434, 1, 1);
- HijrahDate mdate2 = HijrahDate.of(1435, 2, 2);
- long months = mdate1.periodUntil(mdate2, ChronoUnit.MONTHS);
- assertEquals(months, 13);
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_lenient(int y, int d, HijrahDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
}
- @Test
- public void test_periodUntilDiffChrono() {
- HijrahDate mdate1 = HijrahDate.of(1434, 1, 1);
- HijrahDate mdate2 = HijrahDate.of(1435, 2, 2);
- MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
- Period period = mdate1.periodUntil(ldate2);
- assertEquals(period, Period.of(1, 1, 1));
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_smart(int y, int d, HijrahDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (smart) {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed, returned date: " + date);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_strict(int y, int d, HijrahDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (strict) {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed, returned date: " + date);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
}
//-----------------------------------------------------------------------
- // toString()
- //-----------------------------------------------------------------------
- @DataProvider(name="toString")
- Object[][] data_toString() {
- return new Object[][] {
- //{HijrahChronology.INSTANCE.date(1320, 1, 1), "Hijrah AH 1320-01-01"},
- //{HijrahChronology.INSTANCE.date(1500, 10, 28), "Hijrah AH 1500-10-28"},
- //{HijrahChronology.INSTANCE.date(1500, 10, 29), "Hijrah AH 1500-10-29"},
- {HijrahChronology.INSTANCE.date(1434, 12, 5), "Hijrah-umalqura AH 1434-12-05"},
- {HijrahChronology.INSTANCE.date(1434, 12, 6), "Hijrah-umalqura AH 1434-12-06"},
- };
+ private static HijrahDate date(int y, int m, int d) {
+ return HijrahDate.of(y, m, d);
}
- @Test(dataProvider="toString")
- public void test_toString(ChronoLocalDate<?> hijrahDate, String expected) {
- assertEquals(hijrahDate.toString(), expected);
+ private static HijrahDate dateYearDay(int y, int doy) {
+ return HijrahChronology.INSTANCE.dateYearDay(y, doy);
}
//-----------------------------------------------------------------------
@@ -343,5 +549,4 @@
public void test_equals_false() {
assertFalse(HijrahChronology.INSTANCE.equals(IsoChronology.INSTANCE));
}
-
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKHijrahEra.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKHijrahEra.java Thu Jul 25 20:30:58 2013 -0400
@@ -85,6 +85,8 @@
@Test(dataProvider="HijrahEras")
public void test_valueOf(HijrahEra era , String eraName, int eraValue) {
assertEquals(era.getValue(), eraValue);
+
+ assertEquals(HijrahChronology.INSTANCE.eraOf(eraValue), era);
assertEquals(HijrahEra.of(eraValue), era);
assertEquals(HijrahEra.valueOf(eraName), era);
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKIsoChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKIsoChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -278,91 +278,88 @@
@DataProvider(name = "resolve_yearOfEra")
Object[][] data_resolve_yearOfEra() {
return new Object[][] {
- {-1, 2012, null, null, false, false},
- {0, 2012, null, -2011, true, true},
- {1, 2012, null, 2012, true, true},
- {2, 2012, null, null, false, false},
+ // era only
+ {ResolverStyle.STRICT, -1, null, null, null, null},
+ {ResolverStyle.SMART, -1, null, null, null, null},
+ {ResolverStyle.LENIENT, -1, null, null, null, null},
+
+ {ResolverStyle.STRICT, 0, null, null, ChronoField.ERA, 0},
+ {ResolverStyle.SMART, 0, null, null, ChronoField.ERA, 0},
+ {ResolverStyle.LENIENT, 0, null, null, ChronoField.ERA, 0},
+
+ {ResolverStyle.STRICT, 1, null, null, ChronoField.ERA, 1},
+ {ResolverStyle.SMART, 1, null, null, ChronoField.ERA, 1},
+ {ResolverStyle.LENIENT, 1, null, null, ChronoField.ERA, 1},
+
+ {ResolverStyle.STRICT, 2, null, null, null, null},
+ {ResolverStyle.SMART, 2, null, null, null, null},
+ {ResolverStyle.LENIENT, 2, null, null, null, null},
+
+ // era and year-of-era
+ {ResolverStyle.STRICT, -1, 2012, null, null, null},
+ {ResolverStyle.SMART, -1, 2012, null, null, null},
+ {ResolverStyle.LENIENT, -1, 2012, null, null, null},
+
+ {ResolverStyle.STRICT, 0, 2012, null, ChronoField.YEAR, -2011},
+ {ResolverStyle.SMART, 0, 2012, null, ChronoField.YEAR, -2011},
+ {ResolverStyle.LENIENT, 0, 2012, null, ChronoField.YEAR, -2011},
+
+ {ResolverStyle.STRICT, 1, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.SMART, 1, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, 1, 2012, null, ChronoField.YEAR, 2012},
- {null, 2012, null, 2012, true, null},
- {null, 2012, 2012, 2012, true, true},
- {null, 2012, -2011, -2011, true, true},
- {null, 2012, 2013, null, false, false},
- {null, 2012, -2013, null, false, false},
+ {ResolverStyle.STRICT, 2, 2012, null, null, null},
+ {ResolverStyle.SMART, 2, 2012, null, null, null},
+ {ResolverStyle.LENIENT, 2, 2012, null, null, null},
+
+ // year-of-era only
+ {ResolverStyle.STRICT, null, 2012, null, ChronoField.YEAR_OF_ERA, 2012},
+ {ResolverStyle.SMART, null, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, null, 2012, null, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, null, Integer.MAX_VALUE, null, null, null},
+ {ResolverStyle.SMART, null, Integer.MAX_VALUE, null, null, null},
+ {ResolverStyle.LENIENT, null, Integer.MAX_VALUE, null, ChronoField.YEAR, Integer.MAX_VALUE},
+
+ // year-of-era and year
+ {ResolverStyle.STRICT, null, 2012, 2012, ChronoField.YEAR, 2012},
+ {ResolverStyle.SMART, null, 2012, 2012, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, null, 2012, 2012, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, null, 2012, -2011, ChronoField.YEAR, -2011},
+ {ResolverStyle.SMART, null, 2012, -2011, ChronoField.YEAR, -2011},
+ {ResolverStyle.LENIENT, null, 2012, -2011, ChronoField.YEAR, -2011},
+
+ {ResolverStyle.STRICT, null, 2012, 2013, null, null},
+ {ResolverStyle.SMART, null, 2012, 2013, null, null},
+ {ResolverStyle.LENIENT, null, 2012, 2013, null, null},
+
+ {ResolverStyle.STRICT, null, 2012, -2013, null, null},
+ {ResolverStyle.SMART, null, 2012, -2013, null, null},
+ {ResolverStyle.LENIENT, null, 2012, -2013, null, null},
};
}
@Test(dataProvider = "resolve_yearOfEra")
- public void test_resolve_yearOfEra_lenient(Integer e, int yoe, Integer y, Integer expected, boolean smart, Boolean strict) {
+ public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
if (e != null) {
fieldValues.put(ChronoField.ERA, (long) e);
}
- fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
- if (y != null) {
- fieldValues.put(ChronoField.YEAR, (long) y);
+ if (yoe != null) {
+ fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
}
- if (smart) {
- LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
- assertEquals(date, null);
- assertEquals(fieldValues.get(ChronoField.YEAR), (Long) (long) expected);
- assertEquals(fieldValues.size(), 1);
- } else {
- try {
- IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
- fail("Should have failed");
- } catch (DateTimeException ex) {
- // expected
- }
- }
- }
-
- @Test(dataProvider = "resolve_yearOfEra")
- public void test_resolve_yearOfEra_smart(Integer e, int yoe, Integer y, Integer expected, boolean smart, Boolean strict) {
- Map<TemporalField, Long> fieldValues = new HashMap<>();
- if (e != null) {
- fieldValues.put(ChronoField.ERA, (long) e);
- }
- fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
if (y != null) {
fieldValues.put(ChronoField.YEAR, (long) y);
}
- if (smart) {
- LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ if (field != null) {
+ LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, style);
assertEquals(date, null);
- assertEquals(fieldValues.get(ChronoField.YEAR), (Long) (long) expected);
+ assertEquals(fieldValues.get(field), (Long) expected.longValue());
assertEquals(fieldValues.size(), 1);
} else {
try {
- IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
- fail("Should have failed");
- } catch (DateTimeException ex) {
- // expected
- }
- }
- }
-
- @Test(dataProvider = "resolve_yearOfEra")
- public void test_resolve_yearOfEra_strict(Integer e, int yoe, Integer y, Integer expected, boolean smart, Boolean strict) {
- Map<TemporalField, Long> fieldValues = new HashMap<>();
- if (e != null) {
- fieldValues.put(ChronoField.ERA, (long) e);
- }
- fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
- if (y != null) {
- fieldValues.put(ChronoField.YEAR, (long) y);
- }
- if (strict == null) {
- LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
- assertEquals(date, null);
- assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) (long) yoe);
- } else if (strict) {
- LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
- assertEquals(date, null);
- assertEquals(fieldValues.get(ChronoField.YEAR), (Long) (long) expected);
- assertEquals(fieldValues.size(), 1);
- } else {
- try {
- IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ IsoChronology.INSTANCE.resolveDate(fieldValues, style);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
@@ -381,6 +378,11 @@
{2012, 1, -30, date(2011, 12, 1), false, false},
{2012, 1, -12, date(2011, 12, 19), false, false},
{2012, 1, 1, date(2012, 1, 1), true, true},
+ {2012, 1, 27, date(2012, 1, 27), true, true},
+ {2012, 1, 28, date(2012, 1, 28), true, true},
+ {2012, 1, 29, date(2012, 1, 29), true, true},
+ {2012, 1, 30, date(2012, 1, 30), true, true},
+ {2012, 1, 31, date(2012, 1, 31), true, true},
{2012, 1, 59, date(2012, 2, 28), false, false},
{2012, 1, 60, date(2012, 2, 29), false, false},
{2012, 1, 61, date(2012, 3, 1), false, false},
--- a/jdk/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -57,12 +57,15 @@
package tck.java.time.chrono;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
+import static java.time.temporal.ChronoField.DAY_OF_YEAR;
+import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.ERA;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -84,10 +87,19 @@
import java.time.chrono.JapaneseEra;
import java.time.chrono.MinguoChronology;
import java.time.chrono.MinguoDate;
+import java.time.format.ResolverStyle;
+import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
+import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalField;
+import java.time.temporal.TemporalQuery;
+import java.time.temporal.ValueRange;
+
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@@ -155,59 +167,145 @@
}
//-----------------------------------------------------------------------
- // creation, toLocalDate()
+ // creation and cross-checks
//-----------------------------------------------------------------------
- @DataProvider(name="samples")
- Object[][] data_samples() {
+ @DataProvider(name="createByEra")
+ Object[][] data_createByEra() {
return new Object[][] {
- {JapaneseChronology.INSTANCE.date(1, 1, 1), LocalDate.of(1, 1, 1)},
- {JapaneseChronology.INSTANCE.date(1, 1, 2), LocalDate.of(1, 1, 2)},
- {JapaneseChronology.INSTANCE.date(1, 1, 3), LocalDate.of(1, 1, 3)},
-
- {JapaneseChronology.INSTANCE.date(2, 1, 1), LocalDate.of(2, 1, 1)},
- {JapaneseChronology.INSTANCE.date(3, 1, 1), LocalDate.of(3, 1, 1)},
- {JapaneseChronology.INSTANCE.date(3, 12, 6), LocalDate.of(3, 12, 6)},
- {JapaneseChronology.INSTANCE.date(4, 1, 1), LocalDate.of(4, 1, 1)},
- {JapaneseChronology.INSTANCE.date(4, 7, 3), LocalDate.of(4, 7, 3)},
- {JapaneseChronology.INSTANCE.date(4, 7, 4), LocalDate.of(4, 7, 4)},
- {JapaneseChronology.INSTANCE.date(5, 1, 1), LocalDate.of(5, 1, 1)},
- {JapaneseChronology.INSTANCE.date(1662, 3, 3), LocalDate.of(1662, 3, 3)},
- {JapaneseChronology.INSTANCE.date(1728, 10, 28), LocalDate.of(1728, 10, 28)},
- {JapaneseChronology.INSTANCE.date(1728, 10, 29), LocalDate.of(1728, 10, 29)},
-
- {JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29), LocalDate.of(1996, 2, 29)},
- {JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29), LocalDate.of(2000, 2, 29)},
- {JapaneseChronology.INSTANCE.date(JapaneseEra.MEIJI, 1868 - YDIFF_MEIJI, 2, 29), LocalDate.of(1868, 2, 29)},
- {JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 1928 - YDIFF_SHOWA, 12, 25), LocalDate.of(1928, 12, 25)},
- {JapaneseChronology.INSTANCE.date(JapaneseEra.TAISHO, 1912 - YDIFF_TAISHO, 7, 30), LocalDate.of(1912, 7, 30)},
-
- {JapaneseChronology.INSTANCE.dateYearDay(1996, 60), LocalDate.of(1996, 2, 29)},
- {JapaneseChronology.INSTANCE.dateYearDay(1868, 60), LocalDate.of(1868, 2, 29)},
- {JapaneseChronology.INSTANCE.dateYearDay(1928, 60), LocalDate.of(1928, 2, 29)},
- {JapaneseChronology.INSTANCE.dateYearDay(1912, 60), LocalDate.of(1912, 2, 29)},
-
- {JapaneseDate.ofYearDay(1996, 60), LocalDate.of(1996, 2, 29)},
- {JapaneseDate.ofYearDay(1868, 60), LocalDate.of(1868, 2, 29)},
- {JapaneseDate.ofYearDay(1928, 60), LocalDate.of(1928, 2, 29)},
- {JapaneseDate.ofYearDay(1912, 60), LocalDate.of(1912, 2, 29)},
-
- {JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 60), LocalDate.of(1996, 2, 29)},
- {JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.MEIJI, 1868 - YDIFF_MEIJI, 60), LocalDate.of(1868, 2, 29)},
- {JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.SHOWA, 1928 - YDIFF_SHOWA, 60), LocalDate.of(1928, 2, 29)},
-// {JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.TAISHO, 1916 - YDIFF_TAISHO, 60), LocalDate.of(1912, 2, 29)},
+ {JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(1996, 2, 29)},
+ {JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2000, 2, 29)},
+ {JapaneseEra.MEIJI, 1874 - YDIFF_MEIJI, 2, 28, 59, LocalDate.of(1874, 2, 28)},
+ {JapaneseEra.SHOWA, 1928 - YDIFF_SHOWA, 12, 25, 360, LocalDate.of(1928, 12, 25)},
+ {JapaneseEra.TAISHO, 1916 - YDIFF_TAISHO, 7, 30, 212, LocalDate.of(1916, 7, 30)},
+ {JapaneseEra.MEIJI, 6, 1, 1, 1, LocalDate.of(1873, 1, 1)},
+ {JapaneseEra.MEIJI, 45, 7, 29, 211, LocalDate.of(1912, 7, 29)},
+ {JapaneseEra.TAISHO, 1, 7, 30, 1, LocalDate.of(1912, 7, 30)},
+ {JapaneseEra.TAISHO, 15, 12, 24, 358, LocalDate.of(1926, 12, 24)},
+ {JapaneseEra.SHOWA, 1, 12, 25, 1, LocalDate.of(1926, 12, 25)},
+ {JapaneseEra.SHOWA, 64, 1, 7, 7, LocalDate.of(1989, 1, 7)},
+ {JapaneseEra.HEISEI, 1, 1, 8, 1, LocalDate.of(1989, 1, 8)},
};
}
- @Test(dataProvider="samples")
- public void test_toLocalDate(JapaneseDate jdate, LocalDate iso) {
- assertEquals(LocalDate.from(jdate), iso);
+ @Test(dataProvider="createByEra")
+ public void test_createEymd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.date(era, yoe, moy, dom);
+ JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
+ assertEquals(dateByChronoFactory, dateByDateFactory);
+ assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
+ }
+
+ @Test(dataProvider="createByEra")
+ public void test_createEyd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(era, yoe, doy);
+ JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
+ assertEquals(dateByChronoFactory, dateByDateFactory);
+ assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
+ }
+
+ @Test(dataProvider="createByEra")
+ public void test_createByEra_isEqual(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
+ assertEquals(test.isEqual(iso), true);
+ assertEquals(iso.isEqual(test), true);
+ }
+
+ @Test(dataProvider="createByEra")
+ public void test_createByEra_chronologyTemporalFactory(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
+ assertEquals(IsoChronology.INSTANCE.date(test), iso);
+ assertEquals(JapaneseChronology.INSTANCE.date(iso), test);
+ }
+
+ @Test(dataProvider="createByEra")
+ public void test_createByEra_dateFrom(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
+ assertEquals(LocalDate.from(test), iso);
+ assertEquals(JapaneseDate.from(iso), test);
+ }
+
+ @Test(dataProvider="createByEra")
+ public void test_createByEra_query(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
+ assertEquals(test.query(TemporalQuery.localDate()), iso);
+ }
+
+ @Test(dataProvider="createByEra")
+ public void test_createByEra_epochDay(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
+ assertEquals(test.getLong(EPOCH_DAY), iso.getLong(EPOCH_DAY));
+ assertEquals(test.toEpochDay(), iso.toEpochDay());
}
- @Test(dataProvider="samples")
- public void test_fromCalendrical(JapaneseDate jdate, LocalDate iso) {
- assertEquals(JapaneseChronology.INSTANCE.date(iso), jdate);
+ //-----------------------------------------------------------------------
+ @DataProvider(name="createByProleptic")
+ Object[][] data_createByProleptic() {
+ return new Object[][] {
+ {1928, 2, 28, 59, LocalDate.of(1928, 2, 28)},
+ {1928, 2, 29, 60, LocalDate.of(1928, 2, 29)},
+
+ {1873, 9, 7, 250, LocalDate.of(1873, 9, 7)},
+ {1873, 9, 8, 251, LocalDate.of(1873, 9, 8)},
+ {1912, 7, 29, 211, LocalDate.of(1912, 7, 29)},
+ {1912, 7, 30, 212, LocalDate.of(1912, 7, 30)},
+ {1926, 12, 24, 358, LocalDate.of(1926, 12, 24)},
+ {1926, 12, 25, 359, LocalDate.of(1926, 12, 25)},
+ {1989, 1, 7, 7, LocalDate.of(1989, 1, 7)},
+ {1989, 1, 8, 8, LocalDate.of(1989, 1, 8)},
+ };
+ }
+
+ @Test(dataProvider="createByProleptic")
+ public void test_createYmd(int y, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.date(y, moy, dom);
+ JapaneseDate dateByDateFactory = JapaneseDate.of(y, moy, dom);
+ assertEquals(dateByChronoFactory, dateByDateFactory);
+ assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
+ }
+
+ @Test(dataProvider="createByProleptic")
+ public void test_createYd(int y, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(y, doy);
+ JapaneseDate dateByDateFactory = JapaneseDate.of(y, moy, dom);
+ assertEquals(dateByChronoFactory, dateByDateFactory);
+ assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
}
+ @Test(dataProvider="createByProleptic")
+ public void test_createByProleptic_isEqual(int y, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(y, moy, dom);
+ assertEquals(test.isEqual(iso), true);
+ assertEquals(iso.isEqual(test), true);
+ }
+
+ @Test(dataProvider="createByProleptic")
+ public void test_createByProleptic_chronologyTemporalFactory(int y, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(y, moy, dom);
+ assertEquals(IsoChronology.INSTANCE.date(test), iso);
+ assertEquals(JapaneseChronology.INSTANCE.date(iso), test);
+ }
+
+ @Test(dataProvider="createByProleptic")
+ public void test_createByProleptic_dateFrom(int y, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(y, moy, dom);
+ assertEquals(LocalDate.from(test), iso);
+ assertEquals(JapaneseDate.from(iso), test);
+ }
+
+ @Test(dataProvider="createByProleptic")
+ public void test_createByProleptic_query(int y, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(y, moy, dom);
+ assertEquals(test.query(TemporalQuery.localDate()), iso);
+ }
+
+ @Test(dataProvider="createByProleptic")
+ public void test_createByProleptic_epochDay(int y, int moy, int dom, int doy, LocalDate iso) {
+ JapaneseDate test = JapaneseDate.of(y, moy, dom);
+ assertEquals(test.getLong(EPOCH_DAY), iso.getLong(EPOCH_DAY));
+ assertEquals(test.toEpochDay(), iso.toEpochDay());
+ }
+
+ //-----------------------------------------------------------------------
@Test
public void test_dateNow(){
assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now()) ;
@@ -228,27 +326,30 @@
assertEquals(JapaneseChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), JapaneseChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
}
+ //-----------------------------------------------------------------------
@DataProvider(name="badDates")
Object[][] data_badDates() {
return new Object[][] {
- {1728, 0, 0},
+ {1928, 0, 0},
- {1728, -1, 1},
- {1728, 0, 1},
- {1728, 14, 1},
- {1728, 15, 1},
+ {1928, -1, 1},
+ {1928, 0, 1},
+ {1928, 14, 1},
+ {1928, 15, 1},
- {1728, 1, -1},
- {1728, 1, 0},
- {1728, 1, 32},
+ {1928, 1, -1},
+ {1928, 1, 0},
+ {1928, 1, 32},
- {1728, 12, -1},
- {1728, 12, 0},
- {1728, 12, 32},
+ {1928, 12, -1},
+ {1928, 12, 0},
+ {1928, 12, 32},
{1725, 2, 29},
{500, 2, 29},
{2100, 2, 29},
+
+ {1872, 12, 31}, // Last day of MEIJI 5
};
}
@@ -266,8 +367,8 @@
{2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false},
{2, JapaneseEra.HEISEI, 100, 100 + YDIFF_HEISEI, true},
- {-1, JapaneseEra.MEIJI, 1, 1 + YDIFF_MEIJI, true},
- {-1, JapaneseEra.MEIJI, 4, 4 + YDIFF_MEIJI, false},
+ {-1, JapaneseEra.MEIJI, 9, 9 + YDIFF_MEIJI, true},
+ {-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false},
{1, JapaneseEra.SHOWA, 1, 1 + YDIFF_SHOWA, false},
{1, JapaneseEra.SHOWA, 7, 7 + YDIFF_SHOWA, true},
@@ -279,12 +380,24 @@
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
- Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue) ;
+ Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue);
assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj));
assertEquals(eraObj, era);
assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
- assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
- assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap()) ;
+ }
+
+ @Test(dataProvider="prolepticYear")
+ public void test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
+ assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
+ assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap());
+
+ JapaneseDate jdate = JapaneseDate.now();
+ jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
+ if (isLeapYear) {
+ assertEquals(jdate.lengthOfMonth(), 29);
+ } else {
+ assertEquals(jdate.lengthOfMonth(), 28);
+ }
}
@DataProvider(name="prolepticYearError")
@@ -327,15 +440,6 @@
} catch (ClassCastException cex) {
; // ignore expected exception
}
-
- try {
- @SuppressWarnings("unused")
- JapaneseDate jdate = JapaneseDate.of(era, 1, 1, 1);
- fail("JapaneseDate.of did not throw ClassCastException for Era: " + era);
- } catch (ClassCastException cex) {
- ; // ignore expected exception
- }
-
try {
@SuppressWarnings("unused")
int year = JapaneseChronology.INSTANCE.prolepticYear(era, 1);
@@ -388,16 +492,16 @@
//-----------------------------------------------------------------------
@Test
public void test_adjust1() {
- JapaneseDate base = JapaneseChronology.INSTANCE.date(1728, 10, 29);
+ JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 10, 29);
JapaneseDate test = base.with(TemporalAdjuster.lastDayOfMonth());
- assertEquals(test, JapaneseChronology.INSTANCE.date(1728, 10, 31));
+ assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 10, 31));
}
@Test
public void test_adjust2() {
- JapaneseDate base = JapaneseChronology.INSTANCE.date(1728, 12, 2);
+ JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 12, 2);
JapaneseDate test = base.with(TemporalAdjuster.lastDayOfMonth());
- assertEquals(test, JapaneseChronology.INSTANCE.date(1728, 12, 31));
+ assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 12, 31));
}
//-----------------------------------------------------------------------
@@ -405,14 +509,14 @@
//-----------------------------------------------------------------------
@Test
public void test_adjust_toLocalDate() {
- JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1726, 1, 4);
+ JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
JapaneseDate test = jdate.with(LocalDate.of(2012, 7, 6));
assertEquals(test, JapaneseChronology.INSTANCE.date(2012, 7, 6));
}
@Test(expectedExceptions=DateTimeException.class)
public void test_adjust_toMonth() {
- JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1726, 1, 4);
+ JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
jdate.with(Month.APRIL);
}
@@ -421,16 +525,16 @@
//-----------------------------------------------------------------------
@Test
public void test_LocalDate_adjustToJapaneseDate() {
- JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1728, 10, 29);
+ JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1928, 10, 29);
LocalDate test = LocalDate.MIN.with(jdate);
- assertEquals(test, LocalDate.of(1728, 10, 29));
+ assertEquals(test, LocalDate.of(1928, 10, 29));
}
@Test
public void test_LocalDateTime_adjustToJapaneseDate() {
- JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1728, 10, 29);
+ JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1928, 10, 29);
LocalDateTime test = LocalDateTime.MIN.with(jdate);
- assertEquals(test, LocalDateTime.of(1728, 10, 29, 0, 0));
+ assertEquals(test, LocalDateTime.of(1928, 10, 29, 0, 0));
}
//-----------------------------------------------------------------------
@@ -439,7 +543,6 @@
@DataProvider(name="japaneseEras")
Object[][] data_japanseseEras() {
return new Object[][] {
- { JapaneseEra.SEIREKI, -999, "Seireki"},
{ JapaneseEra.MEIJI, -1, "Meiji"},
{ JapaneseEra.TAISHO, 0, "Taisho"},
{ JapaneseEra.SHOWA, 1, "Showa"},
@@ -512,7 +615,7 @@
public void test_periodUntilDate() {
JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
- Period period = mdate1.periodUntil(mdate2);
+ Period period = mdate1.until(mdate2);
assertEquals(period, Period.of(1, 1, 1));
}
@@ -520,7 +623,7 @@
public void test_periodUntilUnit() {
JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
- long months = mdate1.periodUntil(mdate2, ChronoUnit.MONTHS);
+ long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
assertEquals(months, 13);
}
@@ -529,22 +632,49 @@
JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
- Period period = mdate1.periodUntil(ldate2);
+ Period period = mdate1.until(ldate2);
assertEquals(period, Period.of(1, 1, 1));
}
//-----------------------------------------------------------------------
+ // JapaneseChronology.dateYearDay, getDayOfYear
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_getDayOfYear() {
+ // Test all the Eras
+ for (JapaneseEra era : JapaneseEra.values()) {
+ int firstYear = (era == JapaneseEra.MEIJI) ? 6 : 1; // Until Era supports range(YEAR_OF_ERA)
+ JapaneseDate hd1 = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, 1);
+ ValueRange range = hd1.range(DAY_OF_YEAR);
+ assertEquals(range.getMaximum(), hd1.lengthOfYear(), "lengthOfYear should match range.getMaximum()");
+
+ for (int i = 1; i <= hd1.lengthOfYear(); i++) {
+ JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, i);
+ int doy = hd.get(DAY_OF_YEAR);
+ assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i + ", of date: " + hd);
+ }
+ }
+ }
+
+ @Test
+ public void test_withDayOfYear() {
+ JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(1990, 1);
+ for (int i = 1; i <= hd.lengthOfYear(); i++) {
+ JapaneseDate hd2 = hd.with(DAY_OF_YEAR, i);
+ int doy = hd2.get(DAY_OF_YEAR);
+ assertEquals(doy, i, "with(DAY_OF_YEAR) incorrect for " + i + " " + hd2);
+ }
+ }
+
+ //-----------------------------------------------------------------------
// toString()
//-----------------------------------------------------------------------
@DataProvider(name="toString")
Object[][] data_toString() {
return new Object[][] {
- {JapaneseChronology.INSTANCE.date(0001, 1, 1), "Japanese 0001-01-01"},
- {JapaneseChronology.INSTANCE.date(1728, 10, 28), "Japanese 1728-10-28"},
- {JapaneseChronology.INSTANCE.date(1728, 10, 29), "Japanese 1728-10-29"},
- {JapaneseChronology.INSTANCE.date(1727, 12, 5), "Japanese 1727-12-05"},
- {JapaneseChronology.INSTANCE.date(1727, 12, 6), "Japanese 1727-12-06"},
- {JapaneseChronology.INSTANCE.date(1868, 9, 8), "Japanese Meiji 1-09-08"},
+ {JapaneseChronology.INSTANCE.date(1873, 12, 5), "Japanese Meiji 6-12-05"},
+ {JapaneseChronology.INSTANCE.date(1873, 12, 6), "Japanese Meiji 6-12-06"},
+ {JapaneseChronology.INSTANCE.date(1873, 9, 8), "Japanese Meiji 6-09-08"},
{JapaneseChronology.INSTANCE.date(1912, 7, 29), "Japanese Meiji 45-07-29"},
{JapaneseChronology.INSTANCE.date(1912, 7, 30), "Japanese Taisho 1-07-30"},
{JapaneseChronology.INSTANCE.date(1926, 12, 24), "Japanese Taisho 15-12-24"},
@@ -573,4 +703,476 @@
assertFalse(JapaneseChronology.INSTANCE.equals(IsoChronology.INSTANCE));
}
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_styleByEra")
+ Object[][] data_resolve_styleByEra() {
+ Object[][] result = new Object[ResolverStyle.values().length * JapaneseEra.values().length][];
+ int i = 0;
+ for (ResolverStyle style : ResolverStyle.values()) {
+ for (JapaneseEra era : JapaneseEra.values()) {
+ result[i++] = new Object[] {style, era};
+ }
+ }
+ return result;
+ }
+
+ @Test(dataProvider = "resolve_styleByEra")
+ public void test_resolve_yearOfEra_eraOnly_valid(ResolverStyle style, JapaneseEra era) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, (long) era.getValue());
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
+ assertEquals(fieldValues.size(), 1);
+ }
+
+ @Test(dataProvider = "resolve_styleByEra")
+ public void test_resolve_yearOfEra_eraAndYearOfEraOnly_valid(ResolverStyle style, JapaneseEra era) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, (long) era.getValue());
+ fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
+ assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
+ assertEquals(fieldValues.size(), 2);
+ }
+
+ @Test(dataProvider = "resolve_styleByEra")
+ public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, JapaneseEra era) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, (long) era.getValue());
+ fieldValues.put(ChronoField.YEAR, 1L);
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
+ assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1L);
+ assertEquals(fieldValues.size(), 2);
+ }
+
+ @DataProvider(name = "resolve_styles")
+ Object[][] data_resolve_styles() {
+ Object[][] result = new Object[ResolverStyle.values().length][];
+ int i = 0;
+ for (ResolverStyle style : ResolverStyle.values()) {
+ result[i++] = new Object[] {style};
+ }
+ return result;
+ }
+
+ @Test(dataProvider = "resolve_styles")
+ public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
+ assertEquals(fieldValues.size(), 1);
+ }
+
+ @Test(dataProvider = "resolve_styles")
+ public void test_resolve_yearOfEra_yearOfEraAndYearOnly_valid(ResolverStyle style) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
+ fieldValues.put(ChronoField.YEAR, 2012L);
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
+ assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 2012L);
+ assertEquals(fieldValues.size(), 2);
+ }
+
+ public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() {
+ for (ResolverStyle style : ResolverStyle.values()) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L);
+ try {
+ JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ fail("Should have failed: " + style);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() {
+ for (ResolverStyle style : ResolverStyle.values()) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L);
+ try {
+ JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ fail("Should have failed: " + style);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_ymd")
+ Object[][] data_resolve_ymd() {
+ return new Object[][] {
+ {2012, 1, -365, date(2010, 12, 31), false, false},
+ {2012, 1, -364, date(2011, 1, 1), false, false},
+ {2012, 1, -31, date(2011, 11, 30), false, false},
+ {2012, 1, -30, date(2011, 12, 1), false, false},
+ {2012, 1, -12, date(2011, 12, 19), false, false},
+ {2012, 1, 1, date(2012, 1, 1), true, true},
+ {2012, 1, 59, date(2012, 2, 28), false, false},
+ {2012, 1, 60, date(2012, 2, 29), false, false},
+ {2012, 1, 61, date(2012, 3, 1), false, false},
+ {2012, 1, 365, date(2012, 12, 30), false, false},
+ {2012, 1, 366, date(2012, 12, 31), false, false},
+ {2012, 1, 367, date(2013, 1, 1), false, false},
+ {2012, 1, 367 + 364, date(2013, 12, 31), false, false},
+ {2012, 1, 367 + 365, date(2014, 1, 1), false, false},
+
+ {2012, 2, 1, date(2012, 2, 1), true, true},
+ {2012, 2, 28, date(2012, 2, 28), true, true},
+ {2012, 2, 29, date(2012, 2, 29), true, true},
+ {2012, 2, 30, date(2012, 3, 1), date(2012, 2, 29), false},
+ {2012, 2, 31, date(2012, 3, 2), date(2012, 2, 29), false},
+ {2012, 2, 32, date(2012, 3, 3), false, false},
+
+ {2012, -12, 1, date(2010, 12, 1), false, false},
+ {2012, -11, 1, date(2011, 1, 1), false, false},
+ {2012, -1, 1, date(2011, 11, 1), false, false},
+ {2012, 0, 1, date(2011, 12, 1), false, false},
+ {2012, 1, 1, date(2012, 1, 1), true, true},
+ {2012, 12, 1, date(2012, 12, 1), true, true},
+ {2012, 13, 1, date(2013, 1, 1), false, false},
+ {2012, 24, 1, date(2013, 12, 1), false, false},
+ {2012, 25, 1, date(2014, 1, 1), false, false},
+
+ {2012, 6, -31, date(2012, 4, 30), false, false},
+ {2012, 6, -30, date(2012, 5, 1), false, false},
+ {2012, 6, -1, date(2012, 5, 30), false, false},
+ {2012, 6, 0, date(2012, 5, 31), false, false},
+ {2012, 6, 1, date(2012, 6, 1), true, true},
+ {2012, 6, 30, date(2012, 6, 30), true, true},
+ {2012, 6, 31, date(2012, 7, 1), date(2012, 6, 30), false},
+ {2012, 6, 61, date(2012, 7, 31), false, false},
+ {2012, 6, 62, date(2012, 8, 1), false, false},
+
+ {2011, 2, 1, date(2011, 2, 1), true, true},
+ {2011, 2, 28, date(2011, 2, 28), true, true},
+ {2011, 2, 29, date(2011, 3, 1), date(2011, 2, 28), false},
+ {2011, 2, 30, date(2011, 3, 2), date(2011, 2, 28), false},
+ {2011, 2, 31, date(2011, 3, 3), date(2011, 2, 28), false},
+ {2011, 2, 32, date(2011, 3, 4), false, false},
+ };
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_lenient(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_smart(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (Boolean.TRUE.equals(smart)) {
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else if (smart instanceof JapaneseDate) {
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, smart);
+ } else {
+ try {
+ JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (strict) {
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_yd")
+ Object[][] data_resolve_yd() {
+ return new Object[][] {
+ {2012, -365, date(2010, 12, 31), false, false},
+ {2012, -364, date(2011, 1, 1), false, false},
+ {2012, -31, date(2011, 11, 30), false, false},
+ {2012, -30, date(2011, 12, 1), false, false},
+ {2012, -12, date(2011, 12, 19), false, false},
+ {2012, -1, date(2011, 12, 30), false, false},
+ {2012, 0, date(2011, 12, 31), false, false},
+ {2012, 1, date(2012, 1, 1), true, true},
+ {2012, 2, date(2012, 1, 2), true, true},
+ {2012, 31, date(2012, 1, 31), true, true},
+ {2012, 32, date(2012, 2, 1), true, true},
+ {2012, 59, date(2012, 2, 28), true, true},
+ {2012, 60, date(2012, 2, 29), true, true},
+ {2012, 61, date(2012, 3, 1), true, true},
+ {2012, 365, date(2012, 12, 30), true, true},
+ {2012, 366, date(2012, 12, 31), true, true},
+ {2012, 367, date(2013, 1, 1), false, false},
+ {2012, 367 + 364, date(2013, 12, 31), false, false},
+ {2012, 367 + 365, date(2014, 1, 1), false, false},
+
+ {2011, 59, date(2011, 2, 28), true, true},
+ {2011, 60, date(2011, 3, 1), true, true},
+ };
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_lenient(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_smart(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (smart) {
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_strict(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (strict) {
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_eymd")
+ Object[][] data_resolve_eymd() {
+ return new Object[][] {
+ // lenient
+ {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 1, 1, date(1989, 1, 1)}, // SHOWA, not HEISEI
+ {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 1, 7, date(1989, 1, 7)}, // SHOWA, not HEISEI
+ {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 1, 8, date(1989, 1, 8)},
+ {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 1, 12, 31, date(1989, 12, 31)},
+ {ResolverStyle.LENIENT, JapaneseEra.HEISEI, 2, 1, 1, date(1990, 1, 1)},
+
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 7, date(1989, 1, 7)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 8, date(1989, 1, 8)}, // HEISEI, not SHOWA
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 12, 31, date(1989, 12, 31)}, // HEISEI, not SHOWA
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 65, 1, 1, date(1990, 1, 1)}, // HEISEI, not SHOWA
+
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -366, date(1987, 12, 31)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -365, date(1988, 1, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -31, date(1988, 11, 30)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, -30, date(1988, 12, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 0, date(1988, 12, 31)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 27, date(1989, 1, 27)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 28, date(1989, 1, 28)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 29, date(1989, 1, 29)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 30, date(1989, 1, 30)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 31, date(1989, 1, 31)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 32, date(1989, 2, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 58, date(1989, 2, 27)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 59, date(1989, 2, 28)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 60, date(1989, 3, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 365, date(1989, 12, 31)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 1, 366, date(1990, 1, 1)},
+
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 1, date(1988, 1, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 31, date(1988, 1, 31)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 32, date(1988, 2, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 58, date(1988, 2, 27)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 59, date(1988, 2, 28)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 60, date(1988, 2, 29)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 1, 61, date(1988, 3, 1)},
+
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 2, 1, date(1989, 2, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 2, 28, date(1989, 2, 28)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 64, 2, 29, date(1989, 3, 1)},
+
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 1, date(1988, 2, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 28, date(1988, 2, 28)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 29, date(1988, 2, 29)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 63, 2, 30, date(1988, 3, 1)},
+
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, -11, 1, date(1986, 1, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, -1, 1, date(1986, 11, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, 0, 1, date(1986, 12, 1)},
+ {ResolverStyle.LENIENT, JapaneseEra.SHOWA, 62, 13, 1, date(1988, 1, 1)},
+
+ // smart
+ {ResolverStyle.SMART, JapaneseEra.HEISEI, 0, 1, 1, null},
+ {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 1, 1, date(1989, 1, 1)}, // SHOWA, not HEISEI
+ {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 1, 7, date(1989, 1, 7)}, // SHOWA, not HEISEI
+ {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 1, 8, date(1989, 1, 8)},
+ {ResolverStyle.SMART, JapaneseEra.HEISEI, 1, 12, 31, date(1989, 12, 31)},
+ {ResolverStyle.SMART, JapaneseEra.HEISEI, 2, 1, 1, date(1990, 1, 1)},
+
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 1, 7, date(1989, 1, 7)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 1, 8, date(1989, 1, 8)}, // HEISEI, not SHOWA
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 64, 12, 31, date(1989, 12, 31)}, // HEISEI, not SHOWA
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 65, 1, 1, null}, // HEISEI, not SHOWA
+
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 0, null},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 1, date(1987, 1, 1)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 27, date(1987, 1, 27)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 28, date(1987, 1, 28)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 29, date(1987, 1, 29)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 30, date(1987, 1, 30)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 31, date(1987, 1, 31)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 1, 32, null},
+
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 0, null},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 1, date(1987, 2, 1)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 27, date(1987, 2, 27)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 28, date(1987, 2, 28)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 29, date(1987, 2, 28)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 30, date(1987, 2, 28)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 31, date(1987, 2, 28)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 2, 32, null},
+
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 0, null},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 1, date(1988, 2, 1)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 27, date(1988, 2, 27)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 28, date(1988, 2, 28)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 29, date(1988, 2, 29)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 30, date(1988, 2, 29)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 31, date(1988, 2, 29)},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 63, 2, 32, null},
+
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, -12, 1, null},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, -1, 1, null},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 0, 1, null},
+ {ResolverStyle.SMART, JapaneseEra.SHOWA, 62, 13, 1, null},
+
+ // strict
+ {ResolverStyle.STRICT, JapaneseEra.HEISEI, 0, 1, 1, null},
+ {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 1, 1, null}, // SHOWA, not HEISEI
+ {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 1, 7, null}, // SHOWA, not HEISEI
+ {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 1, 8, date(1989, 1, 8)},
+ {ResolverStyle.STRICT, JapaneseEra.HEISEI, 1, 12, 31, date(1989, 12, 31)},
+ {ResolverStyle.STRICT, JapaneseEra.HEISEI, 2, 1, 1, date(1990, 1, 1)},
+
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 1, 1, date(1989, 1, 1)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 1, 7, date(1989, 1, 7)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 1, 8, null}, // HEISEI, not SHOWA
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 64, 12, 31, null}, // HEISEI, not SHOWA
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 65, 1, 1, null}, // HEISEI, not SHOWA
+
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 0, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 1, date(1987, 1, 1)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 27, date(1987, 1, 27)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 28, date(1987, 1, 28)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 29, date(1987, 1, 29)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 30, date(1987, 1, 30)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 31, date(1987, 1, 31)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 1, 32, null},
+
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 0, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 1, date(1987, 2, 1)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 27, date(1987, 2, 27)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 28, date(1987, 2, 28)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 29, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 30, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 31, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 2, 32, null},
+
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 0, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 1, date(1988, 2, 1)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 27, date(1988, 2, 27)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 28, date(1988, 2, 28)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 29, date(1988, 2, 29)},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 30, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 31, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 63, 2, 32, null},
+
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, -12, 1, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, -1, 1, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 0, 1, null},
+ {ResolverStyle.STRICT, JapaneseEra.SHOWA, 62, 13, 1, null},
+ };
+ }
+
+ @Test(dataProvider = "resolve_eymd")
+ public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.ERA, (long) era.getValue());
+ fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (expected != null) {
+ JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ private static JapaneseDate date(int y, int m, int d) {
+ return JapaneseDate.of(y, m, d);
+ }
+
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java Thu Jul 25 20:30:58 2013 -0400
@@ -81,7 +81,6 @@
{JapaneseEra.SHOWA, "Showa", 1},
{JapaneseEra.TAISHO, "Taisho", 0},
{JapaneseEra.MEIJI, "Meiji", -1},
- {JapaneseEra.SEIREKI, "Seireki", -999},
};
}
@@ -112,8 +111,8 @@
public void test_range() {
// eras may be added after release
for (JapaneseEra era : JapaneseEra.values()) {
- assertEquals(era.range(ERA).getMinimum(), -999);
- assertEquals(era.range(ERA).getLargestMinimum(), -999);
+ assertEquals(era.range(ERA).getMinimum(), -1);
+ assertEquals(era.range(ERA).getLargestMinimum(), -1);
assertEquals(era.range(ERA).getSmallestMaximum(), era.range(ERA).getMaximum());
assertEquals(era.range(ERA).getMaximum() >= 2, true);
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKMinguoChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKMinguoChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -58,6 +58,7 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -83,12 +84,19 @@
import java.time.chrono.MinguoChronology;
import java.time.chrono.MinguoDate;
import java.time.chrono.MinguoEra;
+import java.time.chrono.MinguoChronology;
+import java.time.chrono.MinguoDate;
import java.time.chrono.ThaiBuddhistChronology;
import java.time.chrono.ThaiBuddhistDate;
+import java.time.format.ResolverStyle;
+import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalField;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@@ -162,6 +170,18 @@
@Test(dataProvider="samples")
public void test_fromCalendrical(MinguoDate minguo, LocalDate iso) {
assertEquals(MinguoChronology.INSTANCE.date(iso), minguo);
+ assertEquals(MinguoDate.from(iso), minguo);
+ }
+
+ @Test(dataProvider="samples")
+ public void test_isEqual(MinguoDate minguo, LocalDate iso) {
+ assertTrue(minguo.isEqual(iso));
+ }
+
+ @Test(dataProvider="samples")
+ public void test_date_equals(MinguoDate minguo, LocalDate iso) {
+ assertFalse(minguo.equals(iso));
+ assertNotEquals(minguo.hashCode(), iso.hashCode());
}
@Test
@@ -276,12 +296,24 @@
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
- Era eraObj = MinguoChronology.INSTANCE.eraOf(eraValue) ;
+ Era eraObj = MinguoChronology.INSTANCE.eraOf(eraValue);
assertTrue(MinguoChronology.INSTANCE.eras().contains(eraObj));
assertEquals(eraObj, era);
assertEquals(MinguoChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
- assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
- assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap()) ;
+ }
+
+ @Test(dataProvider="prolepticYear")
+ public void test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
+ assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
+ assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());
+
+ MinguoDate minguo = MinguoDate.now();
+ minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
+ if (isLeapYear) {
+ assertEquals(minguo.lengthOfMonth(), 29);
+ } else {
+ assertEquals(minguo.lengthOfMonth(), 28);
+ }
}
//-----------------------------------------------------------------------
@@ -467,7 +499,7 @@
public void test_periodUntilDate() {
MinguoDate mdate1 = MinguoDate.of(1970, 1, 1);
MinguoDate mdate2 = MinguoDate.of(1971, 2, 2);
- Period period = mdate1.periodUntil(mdate2);
+ Period period = mdate1.until(mdate2);
assertEquals(period, Period.of(1, 1, 1));
}
@@ -475,7 +507,7 @@
public void test_periodUntilUnit() {
MinguoDate mdate1 = MinguoDate.of(1970, 1, 1);
MinguoDate mdate2 = MinguoDate.of(1971, 2, 2);
- long months = mdate1.periodUntil(mdate2, ChronoUnit.MONTHS);
+ long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
assertEquals(months, 13);
}
@@ -484,7 +516,7 @@
MinguoDate mdate1 = MinguoDate.of(1970, 1, 1);
MinguoDate mdate2 = MinguoDate.of(1971, 2, 2);
ThaiBuddhistDate ldate2 = ThaiBuddhistChronology.INSTANCE.date(mdate2);
- Period period = mdate1.periodUntil(ldate2);
+ Period period = mdate1.until(ldate2);
assertEquals(period, Period.of(1, 1, 1));
}
@@ -520,4 +552,409 @@
assertFalse(MinguoChronology.INSTANCE.equals(IsoChronology.INSTANCE));
}
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_yearOfEra")
+ Object[][] data_resolve_yearOfEra() {
+ return new Object[][] {
+ // era only
+ {ResolverStyle.STRICT, -1, null, null, null, null},
+ {ResolverStyle.SMART, -1, null, null, null, null},
+ {ResolverStyle.LENIENT, -1, null, null, null, null},
+
+ {ResolverStyle.STRICT, 0, null, null, ChronoField.ERA, 0},
+ {ResolverStyle.SMART, 0, null, null, ChronoField.ERA, 0},
+ {ResolverStyle.LENIENT, 0, null, null, ChronoField.ERA, 0},
+
+ {ResolverStyle.STRICT, 1, null, null, ChronoField.ERA, 1},
+ {ResolverStyle.SMART, 1, null, null, ChronoField.ERA, 1},
+ {ResolverStyle.LENIENT, 1, null, null, ChronoField.ERA, 1},
+
+ {ResolverStyle.STRICT, 2, null, null, null, null},
+ {ResolverStyle.SMART, 2, null, null, null, null},
+ {ResolverStyle.LENIENT, 2, null, null, null, null},
+
+ // era and year-of-era
+ {ResolverStyle.STRICT, -1, 2012, null, null, null},
+ {ResolverStyle.SMART, -1, 2012, null, null, null},
+ {ResolverStyle.LENIENT, -1, 2012, null, null, null},
+
+ {ResolverStyle.STRICT, 0, 2012, null, ChronoField.YEAR, -2011},
+ {ResolverStyle.SMART, 0, 2012, null, ChronoField.YEAR, -2011},
+ {ResolverStyle.LENIENT, 0, 2012, null, ChronoField.YEAR, -2011},
+
+ {ResolverStyle.STRICT, 1, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.SMART, 1, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, 1, 2012, null, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, 2, 2012, null, null, null},
+ {ResolverStyle.SMART, 2, 2012, null, null, null},
+ {ResolverStyle.LENIENT, 2, 2012, null, null, null},
+
+ // year-of-era only
+ {ResolverStyle.STRICT, null, 2012, null, ChronoField.YEAR_OF_ERA, 2012},
+ {ResolverStyle.SMART, null, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, null, 2012, null, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, null, Integer.MAX_VALUE, null, null, null},
+ {ResolverStyle.SMART, null, Integer.MAX_VALUE, null, null, null},
+ {ResolverStyle.LENIENT, null, Integer.MAX_VALUE, null, ChronoField.YEAR, Integer.MAX_VALUE},
+
+ // year-of-era and year
+ {ResolverStyle.STRICT, null, 2012, 2012, ChronoField.YEAR, 2012},
+ {ResolverStyle.SMART, null, 2012, 2012, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, null, 2012, 2012, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, null, 2012, -2011, ChronoField.YEAR, -2011},
+ {ResolverStyle.SMART, null, 2012, -2011, ChronoField.YEAR, -2011},
+ {ResolverStyle.LENIENT, null, 2012, -2011, ChronoField.YEAR, -2011},
+
+ {ResolverStyle.STRICT, null, 2012, 2013, null, null},
+ {ResolverStyle.SMART, null, 2012, 2013, null, null},
+ {ResolverStyle.LENIENT, null, 2012, 2013, null, null},
+
+ {ResolverStyle.STRICT, null, 2012, -2013, null, null},
+ {ResolverStyle.SMART, null, 2012, -2013, null, null},
+ {ResolverStyle.LENIENT, null, 2012, -2013, null, null},
+ };
+ }
+
+ @Test(dataProvider = "resolve_yearOfEra")
+ public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ if (e != null) {
+ fieldValues.put(ChronoField.ERA, (long) e);
+ }
+ if (yoe != null) {
+ fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
+ }
+ if (y != null) {
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ }
+ if (field != null) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(field), (Long) expected.longValue());
+ assertEquals(fieldValues.size(), 1);
+ } else {
+ try {
+ MinguoChronology.INSTANCE.resolveDate(fieldValues, style);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_ymd")
+ Object[][] data_resolve_ymd() {
+ return new Object[][] {
+ {2012 - YDIFF, 1, -365, date(2010 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 1, -364, date(2011 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, 1, -31, date(2011 - YDIFF, 11, 30), false, false},
+ {2012 - YDIFF, 1, -30, date(2011 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, 1, -12, date(2011 - YDIFF, 12, 19), false, false},
+ {2012 - YDIFF, 1, 1, date(2012 - YDIFF, 1, 1), true, true},
+ {2012 - YDIFF, 1, 27, date(2012 - YDIFF, 1, 27), true, true},
+ {2012 - YDIFF, 1, 28, date(2012 - YDIFF, 1, 28), true, true},
+ {2012 - YDIFF, 1, 29, date(2012 - YDIFF, 1, 29), true, true},
+ {2012 - YDIFF, 1, 30, date(2012 - YDIFF, 1, 30), true, true},
+ {2012 - YDIFF, 1, 31, date(2012 - YDIFF, 1, 31), true, true},
+ {2012 - YDIFF, 1, 59, date(2012 - YDIFF, 2, 28), false, false},
+ {2012 - YDIFF, 1, 60, date(2012 - YDIFF, 2, 29), false, false},
+ {2012 - YDIFF, 1, 61, date(2012 - YDIFF, 3, 1), false, false},
+ {2012 - YDIFF, 1, 365, date(2012 - YDIFF, 12, 30), false, false},
+ {2012 - YDIFF, 1, 366, date(2012 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 1, 367, date(2013 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, 1, 367 + 364, date(2013 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 1, 367 + 365, date(2014 - YDIFF, 1, 1), false, false},
+
+ {2012 - YDIFF, 2, 1, date(2012 - YDIFF, 2, 1), true, true},
+ {2012 - YDIFF, 2, 28, date(2012 - YDIFF, 2, 28), true, true},
+ {2012 - YDIFF, 2, 29, date(2012 - YDIFF, 2, 29), true, true},
+ {2012 - YDIFF, 2, 30, date(2012 - YDIFF, 3, 1), date(2012 - YDIFF, 2, 29), false},
+ {2012 - YDIFF, 2, 31, date(2012 - YDIFF, 3, 2), date(2012 - YDIFF, 2, 29), false},
+ {2012 - YDIFF, 2, 32, date(2012 - YDIFF, 3, 3), false, false},
+
+ {2012 - YDIFF, -12, 1, date(2010 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, -11, 1, date(2011 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, -1, 1, date(2011 - YDIFF, 11, 1), false, false},
+ {2012 - YDIFF, 0, 1, date(2011 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, 1, 1, date(2012 - YDIFF, 1, 1), true, true},
+ {2012 - YDIFF, 12, 1, date(2012 - YDIFF, 12, 1), true, true},
+ {2012 - YDIFF, 13, 1, date(2013 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, 24, 1, date(2013 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, 25, 1, date(2014 - YDIFF, 1, 1), false, false},
+
+ {2012 - YDIFF, 6, -31, date(2012 - YDIFF, 4, 30), false, false},
+ {2012 - YDIFF, 6, -30, date(2012 - YDIFF, 5, 1), false, false},
+ {2012 - YDIFF, 6, -1, date(2012 - YDIFF, 5, 30), false, false},
+ {2012 - YDIFF, 6, 0, date(2012 - YDIFF, 5, 31), false, false},
+ {2012 - YDIFF, 6, 1, date(2012 - YDIFF, 6, 1), true, true},
+ {2012 - YDIFF, 6, 30, date(2012 - YDIFF, 6, 30), true, true},
+ {2012 - YDIFF, 6, 31, date(2012 - YDIFF, 7, 1), date(2012 - YDIFF, 6, 30), false},
+ {2012 - YDIFF, 6, 61, date(2012 - YDIFF, 7, 31), false, false},
+ {2012 - YDIFF, 6, 62, date(2012 - YDIFF, 8, 1), false, false},
+
+ {2011 - YDIFF, 2, 1, date(2011 - YDIFF, 2, 1), true, true},
+ {2011 - YDIFF, 2, 28, date(2011 - YDIFF, 2, 28), true, true},
+ {2011 - YDIFF, 2, 29, date(2011 - YDIFF, 3, 1), date(2011 - YDIFF, 2, 28), false},
+ {2011 - YDIFF, 2, 30, date(2011 - YDIFF, 3, 2), date(2011 - YDIFF, 2, 28), false},
+ {2011 - YDIFF, 2, 31, date(2011 - YDIFF, 3, 3), date(2011 - YDIFF, 2, 28), false},
+ {2011 - YDIFF, 2, 32, date(2011 - YDIFF, 3, 4), false, false},
+ };
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_lenient(int y, int m, int d, MinguoDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_smart(int y, int m, int d, MinguoDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (Boolean.TRUE.equals(smart)) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else if (smart instanceof MinguoDate) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, smart);
+ } else {
+ try {
+ MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_strict(int y, int m, int d, MinguoDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (strict) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_yd")
+ Object[][] data_resolve_yd() {
+ return new Object[][] {
+ {2012 - YDIFF, -365, date(2010 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, -364, date(2011 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, -31, date(2011 - YDIFF, 11, 30), false, false},
+ {2012 - YDIFF, -30, date(2011 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, -12, date(2011 - YDIFF, 12, 19), false, false},
+ {2012 - YDIFF, -1, date(2011 - YDIFF, 12, 30), false, false},
+ {2012 - YDIFF, 0, date(2011 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 1, date(2012 - YDIFF, 1, 1), true, true},
+ {2012 - YDIFF, 2, date(2012 - YDIFF, 1, 2), true, true},
+ {2012 - YDIFF, 31, date(2012 - YDIFF, 1, 31), true, true},
+ {2012 - YDIFF, 32, date(2012 - YDIFF, 2, 1), true, true},
+ {2012 - YDIFF, 59, date(2012 - YDIFF, 2, 28), true, true},
+ {2012 - YDIFF, 60, date(2012 - YDIFF, 2, 29), true, true},
+ {2012 - YDIFF, 61, date(2012 - YDIFF, 3, 1), true, true},
+ {2012 - YDIFF, 365, date(2012 - YDIFF, 12, 30), true, true},
+ {2012 - YDIFF, 366, date(2012 - YDIFF, 12, 31), true, true},
+ {2012 - YDIFF, 367, date(2013 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, 367 + 364, date(2013 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 367 + 365, date(2014 - YDIFF, 1, 1), false, false},
+
+ {2011 - YDIFF, 59, date(2011 - YDIFF, 2, 28), true, true},
+ {2011 - YDIFF, 60, date(2011 - YDIFF, 3, 1), true, true},
+ };
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_lenient(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_smart(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (smart) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_strict(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (strict) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_ymaa")
+ Object[][] data_resolve_ymaa() {
+ return new Object[][] {
+ {2012 - YDIFF, 1, 1, -365, date(2010 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 1, 1, -364, date(2011 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, 1, 1, -31, date(2011 - YDIFF, 11, 30), false, false},
+ {2012 - YDIFF, 1, 1, -30, date(2011 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, 1, 1, -12, date(2011 - YDIFF, 12, 19), false, false},
+ {2012 - YDIFF, 1, 1, 1, date(2012 - YDIFF, 1, 1), true, true},
+ {2012 - YDIFF, 1, 1, 59, date(2012 - YDIFF, 2, 28), false, false},
+ {2012 - YDIFF, 1, 1, 60, date(2012 - YDIFF, 2, 29), false, false},
+ {2012 - YDIFF, 1, 1, 61, date(2012 - YDIFF, 3, 1), false, false},
+ {2012 - YDIFF, 1, 1, 365, date(2012 - YDIFF, 12, 30), false, false},
+ {2012 - YDIFF, 1, 1, 366, date(2012 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 1, 1, 367, date(2013 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, 1, 1, 367 + 364, date(2013 - YDIFF, 12, 31), false, false},
+ {2012 - YDIFF, 1, 1, 367 + 365, date(2014 - YDIFF, 1, 1), false, false},
+
+ {2012 - YDIFF, 2, 0, 1, date(2012 - YDIFF, 1, 25), false, false},
+ {2012 - YDIFF, 2, 0, 7, date(2012 - YDIFF, 1, 31), false, false},
+ {2012 - YDIFF, 2, 1, 1, date(2012 - YDIFF, 2, 1), true, true},
+ {2012 - YDIFF, 2, 1, 7, date(2012 - YDIFF, 2, 7), true, true},
+ {2012 - YDIFF, 2, 2, 1, date(2012 - YDIFF, 2, 8), true, true},
+ {2012 - YDIFF, 2, 2, 7, date(2012 - YDIFF, 2, 14), true, true},
+ {2012 - YDIFF, 2, 3, 1, date(2012 - YDIFF, 2, 15), true, true},
+ {2012 - YDIFF, 2, 3, 7, date(2012 - YDIFF, 2, 21), true, true},
+ {2012 - YDIFF, 2, 4, 1, date(2012 - YDIFF, 2, 22), true, true},
+ {2012 - YDIFF, 2, 4, 7, date(2012 - YDIFF, 2, 28), true, true},
+ {2012 - YDIFF, 2, 5, 1, date(2012 - YDIFF, 2, 29), true, true},
+ {2012 - YDIFF, 2, 5, 2, date(2012 - YDIFF, 3, 1), true, false},
+ {2012 - YDIFF, 2, 5, 7, date(2012 - YDIFF, 3, 6), true, false},
+ {2012 - YDIFF, 2, 6, 1, date(2012 - YDIFF, 3, 7), false, false},
+ {2012 - YDIFF, 2, 6, 7, date(2012 - YDIFF, 3, 13), false, false},
+
+ {2012 - YDIFF, 12, 1, 1, date(2012 - YDIFF, 12, 1), true, true},
+ {2012 - YDIFF, 12, 5, 1, date(2012 - YDIFF, 12, 29), true, true},
+ {2012 - YDIFF, 12, 5, 2, date(2012 - YDIFF, 12, 30), true, true},
+ {2012 - YDIFF, 12, 5, 3, date(2012 - YDIFF, 12, 31), true, true},
+ {2012 - YDIFF, 12, 5, 4, date(2013 - YDIFF, 1, 1), true, false},
+ {2012 - YDIFF, 12, 5, 7, date(2013 - YDIFF, 1, 4), true, false},
+
+ {2012 - YDIFF, -12, 1, 1, date(2010 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, -11, 1, 1, date(2011 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, -1, 1, 1, date(2011 - YDIFF, 11, 1), false, false},
+ {2012 - YDIFF, 0, 1, 1, date(2011 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, 1, 1, 1, date(2012 - YDIFF, 1, 1), true, true},
+ {2012 - YDIFF, 12, 1, 1, date(2012 - YDIFF, 12, 1), true, true},
+ {2012 - YDIFF, 13, 1, 1, date(2013 - YDIFF, 1, 1), false, false},
+ {2012 - YDIFF, 24, 1, 1, date(2013 - YDIFF, 12, 1), false, false},
+ {2012 - YDIFF, 25, 1, 1, date(2014 - YDIFF, 1, 1), false, false},
+
+ {2011 - YDIFF, 2, 1, 1, date(2011 - YDIFF, 2, 1), true, true},
+ {2011 - YDIFF, 2, 4, 7, date(2011 - YDIFF, 2, 28), true, true},
+ {2011 - YDIFF, 2, 5, 1, date(2011 - YDIFF, 3, 1), true, false},
+ };
+ }
+
+ @Test(dataProvider = "resolve_ymaa")
+ public void test_resolve_ymaa_lenient(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
+ fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_ymaa")
+ public void test_resolve_ymaa_smart(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
+ fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
+ if (smart) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_ymaa")
+ public void test_resolve_ymaa_strict(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
+ fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
+ if (strict) {
+ MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ private static MinguoDate date(int y, int m, int d) {
+ return MinguoDate.of(y, m, d);
+ }
+
}
--- a/jdk/test/java/time/tck/java/time/chrono/TCKThaiBuddhistChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/chrono/TCKThaiBuddhistChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -63,6 +63,7 @@
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@@ -84,12 +85,16 @@
import java.time.chrono.ThaiBuddhistChronology;
import java.time.chrono.ThaiBuddhistDate;
import java.time.chrono.ThaiBuddhistEra;
+import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@@ -200,6 +205,18 @@
@Test(dataProvider="samples")
public void test_fromCalendrical(ThaiBuddhistDate jdate, LocalDate iso) {
assertEquals(ThaiBuddhistChronology.INSTANCE.date(iso), jdate);
+ assertEquals(ThaiBuddhistDate.from(iso), jdate);
+ }
+
+ @Test(dataProvider="samples")
+ public void test_isEqual(ThaiBuddhistDate jdate, LocalDate iso) {
+ assertTrue(jdate.isEqual(iso));
+ }
+
+ @Test(dataProvider="samples")
+ public void test_date_equals(ThaiBuddhistDate jdate, LocalDate iso) {
+ assertFalse(jdate.equals(iso));
+ assertNotEquals(jdate.hashCode(), iso.hashCode());
}
@Test
@@ -251,46 +268,58 @@
ThaiBuddhistChronology.INSTANCE.date(year, month, dom);
}
- //-----------------------------------------------------------------------
- // prolepticYear() and is LeapYear()
- //-----------------------------------------------------------------------
- @DataProvider(name="prolepticYear")
- Object[][] data_prolepticYear() {
- return new Object[][] {
- {1, ThaiBuddhistEra.BE, 4 + YDIFF, 4 + YDIFF, true},
- {1, ThaiBuddhistEra.BE, 7 + YDIFF, 7 + YDIFF, false},
- {1, ThaiBuddhistEra.BE, 8 + YDIFF, 8 + YDIFF, true},
- {1, ThaiBuddhistEra.BE, 1000 + YDIFF, 1000 + YDIFF, false},
- {1, ThaiBuddhistEra.BE, 2000 + YDIFF, 2000 + YDIFF, true},
- {1, ThaiBuddhistEra.BE, 0, 0, false},
- {1, ThaiBuddhistEra.BE, -4 + YDIFF, -4 + YDIFF, true},
- {1, ThaiBuddhistEra.BE, -7 + YDIFF, -7 + YDIFF, false},
- {1, ThaiBuddhistEra.BE, -100 + YDIFF, -100 + YDIFF, false},
- {1, ThaiBuddhistEra.BE, -800 + YDIFF, -800 + YDIFF, true},
+ //-----------------------------------------------------------------------
+ // prolepticYear() and is LeapYear()
+ //-----------------------------------------------------------------------
+ @DataProvider(name="prolepticYear")
+ Object[][] data_prolepticYear() {
+ return new Object[][] {
+ {1, ThaiBuddhistEra.BE, 4 + YDIFF, 4 + YDIFF, true},
+ {1, ThaiBuddhistEra.BE, 7 + YDIFF, 7 + YDIFF, false},
+ {1, ThaiBuddhistEra.BE, 8 + YDIFF, 8 + YDIFF, true},
+ {1, ThaiBuddhistEra.BE, 1000 + YDIFF, 1000 + YDIFF, false},
+ {1, ThaiBuddhistEra.BE, 2000 + YDIFF, 2000 + YDIFF, true},
+ {1, ThaiBuddhistEra.BE, 0, 0, false},
+ {1, ThaiBuddhistEra.BE, -4 + YDIFF, -4 + YDIFF, true},
+ {1, ThaiBuddhistEra.BE, -7 + YDIFF, -7 + YDIFF, false},
+ {1, ThaiBuddhistEra.BE, -100 + YDIFF, -100 + YDIFF, false},
+ {1, ThaiBuddhistEra.BE, -800 + YDIFF, -800 + YDIFF, true},
- {0, ThaiBuddhistEra.BEFORE_BE, -3 - YDIFF, 4 + YDIFF, true},
- {0, ThaiBuddhistEra.BEFORE_BE, -6 - YDIFF, 7 + YDIFF, false},
- {0, ThaiBuddhistEra.BEFORE_BE, -7 - YDIFF, 8 + YDIFF, true},
- {0, ThaiBuddhistEra.BEFORE_BE, -999 - YDIFF, 1000 + YDIFF, false},
- {0, ThaiBuddhistEra.BEFORE_BE, -1999 - YDIFF, 2000 + YDIFF, true},
- {0, ThaiBuddhistEra.BEFORE_BE, 1, 0, false},
- {0, ThaiBuddhistEra.BEFORE_BE, 5 - YDIFF, -4 + YDIFF, true},
- {0, ThaiBuddhistEra.BEFORE_BE, 8 - YDIFF, -7 + YDIFF, false},
- {0, ThaiBuddhistEra.BEFORE_BE, 101 - YDIFF, -100 + YDIFF, false},
- {0, ThaiBuddhistEra.BEFORE_BE, 801 - YDIFF, -800 + YDIFF, true},
+ {0, ThaiBuddhistEra.BEFORE_BE, -3 - YDIFF, 4 + YDIFF, true},
+ {0, ThaiBuddhistEra.BEFORE_BE, -6 - YDIFF, 7 + YDIFF, false},
+ {0, ThaiBuddhistEra.BEFORE_BE, -7 - YDIFF, 8 + YDIFF, true},
+ {0, ThaiBuddhistEra.BEFORE_BE, -999 - YDIFF, 1000 + YDIFF, false},
+ {0, ThaiBuddhistEra.BEFORE_BE, -1999 - YDIFF, 2000 + YDIFF, true},
+ {0, ThaiBuddhistEra.BEFORE_BE, 1, 0, false},
+ {0, ThaiBuddhistEra.BEFORE_BE, 5 - YDIFF, -4 + YDIFF, true},
+ {0, ThaiBuddhistEra.BEFORE_BE, 8 - YDIFF, -7 + YDIFF, false},
+ {0, ThaiBuddhistEra.BEFORE_BE, 101 - YDIFF, -100 + YDIFF, false},
+ {0, ThaiBuddhistEra.BEFORE_BE, 801 - YDIFF, -800 + YDIFF, true},
+
+ };
+ }
- };
- }
+ @Test(dataProvider="prolepticYear")
+ public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
+ Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue);
+ assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj));
+ assertEquals(eraObj, era);
+ assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
+ }
- @Test(dataProvider="prolepticYear")
- public void test_prolepticYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
- Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue) ;
- assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj));
- assertEquals(eraObj, era);
- assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
- assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
- assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap()) ;
- }
+ @Test(dataProvider="prolepticYear")
+ public void test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
+ assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
+ assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());
+
+ ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
+ jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
+ if (isLeapYear) {
+ assertEquals(jdate.lengthOfMonth(), 29);
+ } else {
+ assertEquals(jdate.lengthOfMonth(), 28);
+ }
+ }
//-----------------------------------------------------------------------
// Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
@@ -429,7 +458,7 @@
public void test_periodUntilDate() {
ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
- Period period = mdate1.periodUntil(mdate2);
+ Period period = mdate1.until(mdate2);
assertEquals(period, Period.of(1, 1, 1));
}
@@ -437,7 +466,7 @@
public void test_periodUntilUnit() {
ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
- long months = mdate1.periodUntil(mdate2, ChronoUnit.MONTHS);
+ long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
assertEquals(months, 13);
}
@@ -446,7 +475,7 @@
ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
- Period period = mdate1.periodUntil(ldate2);
+ Period period = mdate1.until(ldate2);
assertEquals(period, Period.of(1, 1, 1));
}
@@ -497,4 +526,409 @@
assertFalse(ThaiBuddhistChronology.INSTANCE.equals(IsoChronology.INSTANCE));
}
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_yearOfEra")
+ Object[][] data_resolve_yearOfEra() {
+ return new Object[][] {
+ // era only
+ {ResolverStyle.STRICT, -1, null, null, null, null},
+ {ResolverStyle.SMART, -1, null, null, null, null},
+ {ResolverStyle.LENIENT, -1, null, null, null, null},
+
+ {ResolverStyle.STRICT, 0, null, null, ChronoField.ERA, 0},
+ {ResolverStyle.SMART, 0, null, null, ChronoField.ERA, 0},
+ {ResolverStyle.LENIENT, 0, null, null, ChronoField.ERA, 0},
+
+ {ResolverStyle.STRICT, 1, null, null, ChronoField.ERA, 1},
+ {ResolverStyle.SMART, 1, null, null, ChronoField.ERA, 1},
+ {ResolverStyle.LENIENT, 1, null, null, ChronoField.ERA, 1},
+
+ {ResolverStyle.STRICT, 2, null, null, null, null},
+ {ResolverStyle.SMART, 2, null, null, null, null},
+ {ResolverStyle.LENIENT, 2, null, null, null, null},
+
+ // era and year-of-era
+ {ResolverStyle.STRICT, -1, 2012, null, null, null},
+ {ResolverStyle.SMART, -1, 2012, null, null, null},
+ {ResolverStyle.LENIENT, -1, 2012, null, null, null},
+
+ {ResolverStyle.STRICT, 0, 2012, null, ChronoField.YEAR, -2011},
+ {ResolverStyle.SMART, 0, 2012, null, ChronoField.YEAR, -2011},
+ {ResolverStyle.LENIENT, 0, 2012, null, ChronoField.YEAR, -2011},
+
+ {ResolverStyle.STRICT, 1, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.SMART, 1, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, 1, 2012, null, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, 2, 2012, null, null, null},
+ {ResolverStyle.SMART, 2, 2012, null, null, null},
+ {ResolverStyle.LENIENT, 2, 2012, null, null, null},
+
+ // year-of-era only
+ {ResolverStyle.STRICT, null, 2012, null, ChronoField.YEAR_OF_ERA, 2012},
+ {ResolverStyle.SMART, null, 2012, null, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, null, 2012, null, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, null, Integer.MAX_VALUE, null, null, null},
+ {ResolverStyle.SMART, null, Integer.MAX_VALUE, null, null, null},
+ {ResolverStyle.LENIENT, null, Integer.MAX_VALUE, null, ChronoField.YEAR, Integer.MAX_VALUE},
+
+ // year-of-era and year
+ {ResolverStyle.STRICT, null, 2012, 2012, ChronoField.YEAR, 2012},
+ {ResolverStyle.SMART, null, 2012, 2012, ChronoField.YEAR, 2012},
+ {ResolverStyle.LENIENT, null, 2012, 2012, ChronoField.YEAR, 2012},
+
+ {ResolverStyle.STRICT, null, 2012, -2011, ChronoField.YEAR, -2011},
+ {ResolverStyle.SMART, null, 2012, -2011, ChronoField.YEAR, -2011},
+ {ResolverStyle.LENIENT, null, 2012, -2011, ChronoField.YEAR, -2011},
+
+ {ResolverStyle.STRICT, null, 2012, 2013, null, null},
+ {ResolverStyle.SMART, null, 2012, 2013, null, null},
+ {ResolverStyle.LENIENT, null, 2012, 2013, null, null},
+
+ {ResolverStyle.STRICT, null, 2012, -2013, null, null},
+ {ResolverStyle.SMART, null, 2012, -2013, null, null},
+ {ResolverStyle.LENIENT, null, 2012, -2013, null, null},
+ };
+ }
+
+ @Test(dataProvider = "resolve_yearOfEra")
+ public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ if (e != null) {
+ fieldValues.put(ChronoField.ERA, (long) e);
+ }
+ if (yoe != null) {
+ fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
+ }
+ if (y != null) {
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ }
+ if (field != null) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
+ assertEquals(date, null);
+ assertEquals(fieldValues.get(field), (Long) expected.longValue());
+ assertEquals(fieldValues.size(), 1);
+ } else {
+ try {
+ ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_ymd")
+ Object[][] data_resolve_ymd() {
+ return new Object[][] {
+ {YDIFF + 2012, 1, -365, date(YDIFF + 2010, 12, 31), false, false},
+ {YDIFF + 2012, 1, -364, date(YDIFF + 2011, 1, 1), false, false},
+ {YDIFF + 2012, 1, -31, date(YDIFF + 2011, 11, 30), false, false},
+ {YDIFF + 2012, 1, -30, date(YDIFF + 2011, 12, 1), false, false},
+ {YDIFF + 2012, 1, -12, date(YDIFF + 2011, 12, 19), false, false},
+ {YDIFF + 2012, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
+ {YDIFF + 2012, 1, 27, date(YDIFF + 2012, 1, 27), true, true},
+ {YDIFF + 2012, 1, 28, date(YDIFF + 2012, 1, 28), true, true},
+ {YDIFF + 2012, 1, 29, date(YDIFF + 2012, 1, 29), true, true},
+ {YDIFF + 2012, 1, 30, date(YDIFF + 2012, 1, 30), true, true},
+ {YDIFF + 2012, 1, 31, date(YDIFF + 2012, 1, 31), true, true},
+ {YDIFF + 2012, 1, 59, date(YDIFF + 2012, 2, 28), false, false},
+ {YDIFF + 2012, 1, 60, date(YDIFF + 2012, 2, 29), false, false},
+ {YDIFF + 2012, 1, 61, date(YDIFF + 2012, 3, 1), false, false},
+ {YDIFF + 2012, 1, 365, date(YDIFF + 2012, 12, 30), false, false},
+ {YDIFF + 2012, 1, 366, date(YDIFF + 2012, 12, 31), false, false},
+ {YDIFF + 2012, 1, 367, date(YDIFF + 2013, 1, 1), false, false},
+ {YDIFF + 2012, 1, 367 + 364, date(YDIFF + 2013, 12, 31), false, false},
+ {YDIFF + 2012, 1, 367 + 365, date(YDIFF + 2014, 1, 1), false, false},
+
+ {YDIFF + 2012, 2, 1, date(YDIFF + 2012, 2, 1), true, true},
+ {YDIFF + 2012, 2, 28, date(YDIFF + 2012, 2, 28), true, true},
+ {YDIFF + 2012, 2, 29, date(YDIFF + 2012, 2, 29), true, true},
+ {YDIFF + 2012, 2, 30, date(YDIFF + 2012, 3, 1), date(YDIFF + 2012, 2, 29), false},
+ {YDIFF + 2012, 2, 31, date(YDIFF + 2012, 3, 2), date(YDIFF + 2012, 2, 29), false},
+ {YDIFF + 2012, 2, 32, date(YDIFF + 2012, 3, 3), false, false},
+
+ {YDIFF + 2012, -12, 1, date(YDIFF + 2010, 12, 1), false, false},
+ {YDIFF + 2012, -11, 1, date(YDIFF + 2011, 1, 1), false, false},
+ {YDIFF + 2012, -1, 1, date(YDIFF + 2011, 11, 1), false, false},
+ {YDIFF + 2012, 0, 1, date(YDIFF + 2011, 12, 1), false, false},
+ {YDIFF + 2012, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
+ {YDIFF + 2012, 12, 1, date(YDIFF + 2012, 12, 1), true, true},
+ {YDIFF + 2012, 13, 1, date(YDIFF + 2013, 1, 1), false, false},
+ {YDIFF + 2012, 24, 1, date(YDIFF + 2013, 12, 1), false, false},
+ {YDIFF + 2012, 25, 1, date(YDIFF + 2014, 1, 1), false, false},
+
+ {YDIFF + 2012, 6, -31, date(YDIFF + 2012, 4, 30), false, false},
+ {YDIFF + 2012, 6, -30, date(YDIFF + 2012, 5, 1), false, false},
+ {YDIFF + 2012, 6, -1, date(YDIFF + 2012, 5, 30), false, false},
+ {YDIFF + 2012, 6, 0, date(YDIFF + 2012, 5, 31), false, false},
+ {YDIFF + 2012, 6, 1, date(YDIFF + 2012, 6, 1), true, true},
+ {YDIFF + 2012, 6, 30, date(YDIFF + 2012, 6, 30), true, true},
+ {YDIFF + 2012, 6, 31, date(YDIFF + 2012, 7, 1), date(YDIFF + 2012, 6, 30), false},
+ {YDIFF + 2012, 6, 61, date(YDIFF + 2012, 7, 31), false, false},
+ {YDIFF + 2012, 6, 62, date(YDIFF + 2012, 8, 1), false, false},
+
+ {YDIFF + 2011, 2, 1, date(YDIFF + 2011, 2, 1), true, true},
+ {YDIFF + 2011, 2, 28, date(YDIFF + 2011, 2, 28), true, true},
+ {YDIFF + 2011, 2, 29, date(YDIFF + 2011, 3, 1), date(YDIFF + 2011, 2, 28), false},
+ {YDIFF + 2011, 2, 30, date(YDIFF + 2011, 3, 2), date(YDIFF + 2011, 2, 28), false},
+ {YDIFF + 2011, 2, 31, date(YDIFF + 2011, 3, 3), date(YDIFF + 2011, 2, 28), false},
+ {YDIFF + 2011, 2, 32, date(YDIFF + 2011, 3, 4), false, false},
+ };
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_lenient(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_smart(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (Boolean.TRUE.equals(smart)) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else if (smart instanceof ThaiBuddhistDate) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, smart);
+ } else {
+ try {
+ ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_ymd")
+ public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
+ if (strict) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_yd")
+ Object[][] data_resolve_yd() {
+ return new Object[][] {
+ {YDIFF + 2012, -365, date(YDIFF + 2010, 12, 31), false, false},
+ {YDIFF + 2012, -364, date(YDIFF + 2011, 1, 1), false, false},
+ {YDIFF + 2012, -31, date(YDIFF + 2011, 11, 30), false, false},
+ {YDIFF + 2012, -30, date(YDIFF + 2011, 12, 1), false, false},
+ {YDIFF + 2012, -12, date(YDIFF + 2011, 12, 19), false, false},
+ {YDIFF + 2012, -1, date(YDIFF + 2011, 12, 30), false, false},
+ {YDIFF + 2012, 0, date(YDIFF + 2011, 12, 31), false, false},
+ {YDIFF + 2012, 1, date(YDIFF + 2012, 1, 1), true, true},
+ {YDIFF + 2012, 2, date(YDIFF + 2012, 1, 2), true, true},
+ {YDIFF + 2012, 31, date(YDIFF + 2012, 1, 31), true, true},
+ {YDIFF + 2012, 32, date(YDIFF + 2012, 2, 1), true, true},
+ {YDIFF + 2012, 59, date(YDIFF + 2012, 2, 28), true, true},
+ {YDIFF + 2012, 60, date(YDIFF + 2012, 2, 29), true, true},
+ {YDIFF + 2012, 61, date(YDIFF + 2012, 3, 1), true, true},
+ {YDIFF + 2012, 365, date(YDIFF + 2012, 12, 30), true, true},
+ {YDIFF + 2012, 366, date(YDIFF + 2012, 12, 31), true, true},
+ {YDIFF + 2012, 367, date(YDIFF + 2013, 1, 1), false, false},
+ {YDIFF + 2012, 367 + 364, date(YDIFF + 2013, 12, 31), false, false},
+ {YDIFF + 2012, 367 + 365, date(YDIFF + 2014, 1, 1), false, false},
+
+ {YDIFF + 2011, 59, date(YDIFF + 2011, 2, 28), true, true},
+ {YDIFF + 2011, 60, date(YDIFF + 2011, 3, 1), true, true},
+ };
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_lenient(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_smart(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (smart) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_yd")
+ public void test_resolve_yd_strict(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
+ if (strict) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @DataProvider(name = "resolve_ymaa")
+ Object[][] data_resolve_ymaa() {
+ return new Object[][] {
+ {YDIFF + 2012, 1, 1, -365, date(YDIFF + 2010, 12, 31), false, false},
+ {YDIFF + 2012, 1, 1, -364, date(YDIFF + 2011, 1, 1), false, false},
+ {YDIFF + 2012, 1, 1, -31, date(YDIFF + 2011, 11, 30), false, false},
+ {YDIFF + 2012, 1, 1, -30, date(YDIFF + 2011, 12, 1), false, false},
+ {YDIFF + 2012, 1, 1, -12, date(YDIFF + 2011, 12, 19), false, false},
+ {YDIFF + 2012, 1, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
+ {YDIFF + 2012, 1, 1, 59, date(YDIFF + 2012, 2, 28), false, false},
+ {YDIFF + 2012, 1, 1, 60, date(YDIFF + 2012, 2, 29), false, false},
+ {YDIFF + 2012, 1, 1, 61, date(YDIFF + 2012, 3, 1), false, false},
+ {YDIFF + 2012, 1, 1, 365, date(YDIFF + 2012, 12, 30), false, false},
+ {YDIFF + 2012, 1, 1, 366, date(YDIFF + 2012, 12, 31), false, false},
+ {YDIFF + 2012, 1, 1, 367, date(YDIFF + 2013, 1, 1), false, false},
+ {YDIFF + 2012, 1, 1, 367 + 364, date(YDIFF + 2013, 12, 31), false, false},
+ {YDIFF + 2012, 1, 1, 367 + 365, date(YDIFF + 2014, 1, 1), false, false},
+
+ {YDIFF + 2012, 2, 0, 1, date(YDIFF + 2012, 1, 25), false, false},
+ {YDIFF + 2012, 2, 0, 7, date(YDIFF + 2012, 1, 31), false, false},
+ {YDIFF + 2012, 2, 1, 1, date(YDIFF + 2012, 2, 1), true, true},
+ {YDIFF + 2012, 2, 1, 7, date(YDIFF + 2012, 2, 7), true, true},
+ {YDIFF + 2012, 2, 2, 1, date(YDIFF + 2012, 2, 8), true, true},
+ {YDIFF + 2012, 2, 2, 7, date(YDIFF + 2012, 2, 14), true, true},
+ {YDIFF + 2012, 2, 3, 1, date(YDIFF + 2012, 2, 15), true, true},
+ {YDIFF + 2012, 2, 3, 7, date(YDIFF + 2012, 2, 21), true, true},
+ {YDIFF + 2012, 2, 4, 1, date(YDIFF + 2012, 2, 22), true, true},
+ {YDIFF + 2012, 2, 4, 7, date(YDIFF + 2012, 2, 28), true, true},
+ {YDIFF + 2012, 2, 5, 1, date(YDIFF + 2012, 2, 29), true, true},
+ {YDIFF + 2012, 2, 5, 2, date(YDIFF + 2012, 3, 1), true, false},
+ {YDIFF + 2012, 2, 5, 7, date(YDIFF + 2012, 3, 6), true, false},
+ {YDIFF + 2012, 2, 6, 1, date(YDIFF + 2012, 3, 7), false, false},
+ {YDIFF + 2012, 2, 6, 7, date(YDIFF + 2012, 3, 13), false, false},
+
+ {YDIFF + 2012, 12, 1, 1, date(YDIFF + 2012, 12, 1), true, true},
+ {YDIFF + 2012, 12, 5, 1, date(YDIFF + 2012, 12, 29), true, true},
+ {YDIFF + 2012, 12, 5, 2, date(YDIFF + 2012, 12, 30), true, true},
+ {YDIFF + 2012, 12, 5, 3, date(YDIFF + 2012, 12, 31), true, true},
+ {YDIFF + 2012, 12, 5, 4, date(YDIFF + 2013, 1, 1), true, false},
+ {YDIFF + 2012, 12, 5, 7, date(YDIFF + 2013, 1, 4), true, false},
+
+ {YDIFF + 2012, -12, 1, 1, date(YDIFF + 2010, 12, 1), false, false},
+ {YDIFF + 2012, -11, 1, 1, date(YDIFF + 2011, 1, 1), false, false},
+ {YDIFF + 2012, -1, 1, 1, date(YDIFF + 2011, 11, 1), false, false},
+ {YDIFF + 2012, 0, 1, 1, date(YDIFF + 2011, 12, 1), false, false},
+ {YDIFF + 2012, 1, 1, 1, date(YDIFF + 2012, 1, 1), true, true},
+ {YDIFF + 2012, 12, 1, 1, date(YDIFF + 2012, 12, 1), true, true},
+ {YDIFF + 2012, 13, 1, 1, date(YDIFF + 2013, 1, 1), false, false},
+ {YDIFF + 2012, 24, 1, 1, date(YDIFF + 2013, 12, 1), false, false},
+ {YDIFF + 2012, 25, 1, 1, date(YDIFF + 2014, 1, 1), false, false},
+
+ {YDIFF + 2011, 2, 1, 1, date(YDIFF + 2011, 2, 1), true, true},
+ {YDIFF + 2011, 2, 4, 7, date(YDIFF + 2011, 2, 28), true, true},
+ {YDIFF + 2011, 2, 5, 1, date(YDIFF + 2011, 3, 1), true, false},
+ };
+ }
+
+ @Test(dataProvider = "resolve_ymaa")
+ public void test_resolve_ymaa_lenient(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
+ fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ }
+
+ @Test(dataProvider = "resolve_ymaa")
+ public void test_resolve_ymaa_smart(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
+ fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
+ if (smart) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ @Test(dataProvider = "resolve_ymaa")
+ public void test_resolve_ymaa_strict(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
+ Map<TemporalField, Long> fieldValues = new HashMap<>();
+ fieldValues.put(ChronoField.YEAR, (long) y);
+ fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
+ fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
+ fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
+ if (strict) {
+ ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ assertEquals(date, expected);
+ assertEquals(fieldValues.size(), 0);
+ } else {
+ try {
+ ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
+ fail("Should have failed");
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ private static ThaiBuddhistDate date(int y, int m, int d) {
+ return ThaiBuddhistDate.of(y, m, d);
+ }
+
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/time/tck/java/time/format/TCKFormatStyle.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2012, 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * * Neither the name of JSR-310 nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package tck.java.time.format;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.FormatStyle;
+import java.time.temporal.Temporal;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Test.
+ */
+@Test
+public class TCKFormatStyle {
+
+ private static final ZoneId ZONEID_PARIS = ZoneId.of("Europe/Paris");
+ private static final ZoneId OFFSET_PTWO = ZoneOffset.of("+02:00");
+
+ //-----------------------------------------------------------------------
+ // valueOf()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_valueOf() {
+ for (FormatStyle style : FormatStyle.values()) {
+ assertEquals(FormatStyle.valueOf(style.name()), style);
+ }
+ }
+
+ @DataProvider(name="formatStyle")
+ Object[][] data_formatStyle() {
+ return new Object[][] {
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.FULL, "Tuesday, October 2, 2001 1:02:03 AM CEST Europe/Paris"},
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.LONG, "October 2, 2001 1:02:03 AM CEST Europe/Paris"},
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.MEDIUM, "Oct 2, 2001 1:02:03 AM Europe/Paris"},
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), ZONEID_PARIS), FormatStyle.SHORT, "10/2/01 1:02 AM Europe/Paris"},
+
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.FULL, "Tuesday, October 2, 2001 1:02:03 AM +02:00 +02:00"},
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.LONG, "October 2, 2001 1:02:03 AM +02:00 +02:00"},
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.MEDIUM, "Oct 2, 2001 1:02:03 AM +02:00"},
+ {ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 1, 2, 3), OFFSET_PTWO), FormatStyle.SHORT, "10/2/01 1:02 AM +02:00"},
+ };
+ }
+
+ @Test(dataProvider = "formatStyle")
+ public void test_formatStyle(Temporal temporal, FormatStyle style, String formattedStr) {
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ DateTimeFormatter formatter = builder.appendLocalized(style, style).appendLiteral(" ").appendZoneOrOffsetId().toFormatter();
+ assertEquals(formatter.format(temporal), formattedStr);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/time/tck/java/time/format/TCKResolverStyle.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2012, 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * * Neither the name of JSR-310 nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package tck.java.time.format;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import java.time.DateTimeException;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.ResolverStyle;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalAccessor;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Test.
+ */
+@Test
+public class TCKResolverStyle {
+
+ //-----------------------------------------------------------------------
+ // valueOf()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_valueOf() {
+ for (ResolverStyle style : ResolverStyle.values()) {
+ assertEquals(ResolverStyle.valueOf(style.name()), style);
+ }
+ }
+
+ @DataProvider(name="resolverStyle")
+ Object[][] data_resolverStyle() {
+ return new Object[][] {
+ {"2000/15/30", ResolverStyle.LENIENT, null, 2001, 3, 30},
+ {"2000/02/30", ResolverStyle.SMART, null, 2000, 2, 29},
+ {"2000/02/29", ResolverStyle.STRICT, null, 2000, 2, 29},
+
+ {"2000/15/30 CE", ResolverStyle.LENIENT, null, 2001, 3, 30},
+ {"2000/02/30 CE", ResolverStyle.SMART, null, 2000, 2, 29},
+ {"5/02/29 BCE", ResolverStyle.STRICT, null, 5, 2, 29},
+
+ {"4/02/29 BCE", ResolverStyle.STRICT, DateTimeException.class, -1, -1, -1},
+ {"2000/02/30 CE", ResolverStyle.STRICT, DateTimeException.class, -1, -1, -1},
+
+ };
+ }
+
+ @Test(dataProvider = "resolverStyle")
+ public void test_resolverStyle(String str, ResolverStyle style, Class<?> expectedEx, int year, int month, int day) {
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ builder.appendValue(ChronoField.YEAR_OF_ERA);
+ builder.appendLiteral("/");
+ builder.appendValue(ChronoField.MONTH_OF_YEAR);
+ builder.appendLiteral("/");
+ builder.appendValue(ChronoField.DAY_OF_MONTH);
+
+ Map<Long, String> eraMap = new HashMap<Long, String>();
+ eraMap.put(1L, "CE");
+ eraMap.put(0L, "BCE");
+ DateTimeFormatter optionalFormatter = new DateTimeFormatterBuilder().appendLiteral(" ").appendText(ChronoField.ERA, eraMap).toFormatter();
+
+ DateTimeFormatter formatter = builder.appendOptional(optionalFormatter).toFormatter();
+ formatter = formatter.withResolverStyle(style);
+ if (expectedEx == null) {
+ TemporalAccessor accessor = formatter.parse(str);
+ assertEquals(accessor.get(ChronoField.YEAR_OF_ERA), year);
+ assertEquals(accessor.get(ChronoField.MONTH_OF_YEAR), month);
+ assertEquals(accessor.get(ChronoField.DAY_OF_MONTH), day);
+ } else {
+ try {
+ formatter.parse(str);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(expectedEx.isInstance(ex));
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/time/tck/java/time/format/TCKSignStyle.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2012, 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * * Neither the name of JSR-310 nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package tck.java.time.format;
+
+import java.time.DateTimeException;
+import java.time.LocalDate;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.SignStyle;
+import java.time.temporal.ChronoField;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Test.
+ */
+@Test
+public class TCKSignStyle {
+
+ //-----------------------------------------------------------------------
+ // valueOf()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_valueOf() {
+ for (SignStyle style : SignStyle.values()) {
+ assertEquals(SignStyle.valueOf(style.name()), style);
+ }
+ }
+
+ @DataProvider(name="signStyle")
+ Object[][] data_signStyle() {
+ return new Object[][] {
+ {LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
+ {LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"},
+ {LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"},
+
+ {LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"},
+ {LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"},
+
+ {LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"},
+ {LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"},
+
+ {LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"},
+ {LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
+
+ {LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"},
+ {LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"},
+ {LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"},
+
+ {LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""},
+ {LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""},
+ {LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""},
+ {LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""},
+ {LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
+ };
+ }
+
+ @Test(dataProvider = "signStyle")
+ public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) {
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style)
+ .toFormatter();
+ formatter = formatter.withZone(ZoneOffset.UTC);
+ if (expectedEx == null) {
+ String output = formatter.format(localDate);
+ assertEquals(output, expectedStr);
+ } else {
+ try {
+ formatter.format(localDate);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(expectedEx.isInstance(ex));
+ }
+ }
+ }
+
+}
--- a/jdk/test/java/time/tck/java/time/format/TCKTextStyle.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/format/TCKTextStyle.java Thu Jul 25 20:30:58 2013 -0400
@@ -91,4 +91,14 @@
assertTrue(!TextStyle.NARROW.isStandalone());
}
+ //-----------------------------------------------------------------------
+ // valueOf()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_valueOf() {
+ for (TextStyle style : TextStyle.values()) {
+ assertEquals(TextStyle.valueOf(style.name()), style);
+ }
+ }
+
}
--- a/jdk/test/java/time/tck/java/time/format/TCKZoneIdPrinterParser.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/format/TCKZoneIdPrinterParser.java Thu Jul 25 20:30:58 2013 -0400
@@ -60,16 +60,20 @@
package tck.java.time.format;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
import java.text.ParsePosition;
+import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
import java.util.Locale;
+import java.util.Objects;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
@@ -148,43 +152,44 @@
@DataProvider(name="parseSuccess")
Object[][] data_parseSuccess() {
return new Object[][] {
- {"Z", 1, -1, ZoneOffset.UTC},
- {"UTC", 3, -1, ZoneOffset.UTC},
- {"UT", 2, -1, ZoneOffset.UTC},
- {"GMT", 3, -1, ZoneOffset.UTC},
- {"UTC0", 4, -1, ZoneOffset.UTC},
- {"UT0", 3, -1, ZoneOffset.UTC},
- {"GMT0", 4, -1, ZoneOffset.UTC},
+ {"Z", 1, -1, ZoneId.of("Z")},
+ {"UTC", 3, -1, ZoneId.of("UTC")},
+ {"UT", 2, -1, ZoneId.of("UT")},
+ {"GMT", 3, -1, ZoneId.of("GMT")},
{"+00:00", 6, -1, ZoneOffset.UTC},
- {"UTC+00:00", 9, -1, ZoneOffset.UTC},
- {"UT+00:00", 8, -1, ZoneOffset.UTC},
- {"GMT+00:00", 9, -1, ZoneOffset.UTC},
+ {"UTC+00:00", 9, -1, ZoneId.of("UTC")},
+ {"UT+00:00", 8, -1, ZoneId.of("UT")},
+ {"GMT+00:00", 9, -1, ZoneId.of("GMT")},
{"-00:00", 6, -1, ZoneOffset.UTC},
- {"UTC-00:00", 9, -1, ZoneOffset.UTC},
- {"UT-00:00", 8, -1, ZoneOffset.UTC},
- {"GMT-00:00", 9, -1, ZoneOffset.UTC},
+ {"UTC-00:00", 9, -1, ZoneId.of("UTC")},
+ {"UT-00:00", 8, -1, ZoneId.of("UT")},
+ {"GMT-00:00", 9, -1, ZoneId.of("GMT")},
{"+01:30", 6, -1, ZoneOffset.ofHoursMinutes(1, 30)},
- {"UTC+01:30", 9, -1, ZoneOffset.ofHoursMinutes(1, 30)},
- {"UT+02:30", 8, -1, ZoneOffset.ofHoursMinutes(2, 30)},
- {"GMT+03:30", 9, -1, ZoneOffset.ofHoursMinutes(3, 30)},
+ {"UTC+01:30", 9, -1, ZoneId.of("UTC+01:30")},
+ {"UT+02:30", 8, -1, ZoneId.of("UT+02:30")},
+ {"GMT+03:30", 9, -1, ZoneId.of("GMT+03:30")},
{"-01:30", 6, -1, ZoneOffset.ofHoursMinutes(-1, -30)},
- {"UTC-01:30", 9, -1, ZoneOffset.ofHoursMinutes(-1, -30)},
- {"UT-02:30", 8, -1, ZoneOffset.ofHoursMinutes(-2, -30)},
- {"GMT-03:30", 9, -1, ZoneOffset.ofHoursMinutes(-3, -30)},
+ {"UTC-01:30", 9, -1, ZoneId.of("UTC-01:30")},
+ {"UT-02:30", 8, -1, ZoneId.of("UT-02:30")},
+ {"GMT-03:30", 9, -1, ZoneId.of("GMT-03:30")},
// fallback to UTC
- {"UTC-01:WW", 3, -1, ZoneOffset.UTC},
- {"UT-02:WW", 2, -1, ZoneOffset.UTC},
- {"GMT-03:WW", 3, -1, ZoneOffset.UTC},
+ {"UTC-01:WW", 3, -1, ZoneId.of("UTC")},
+ {"UT-02:WW", 2, -1, ZoneId.of("UT")},
+ {"GMT-03:WW", 3, -1, ZoneId.of("GMT")},
{"Z0", 1, -1, ZoneOffset.UTC},
- {"UTC1", 3, -1, ZoneOffset.UTC},
+ {"UTC1", 3, -1, ZoneId.of("UTC")},
// Z not parsed as zero
- {"UTCZ", 3, -1, ZoneOffset.UTC},
- {"UTZ", 2, -1, ZoneOffset.UTC},
- {"GMTZ", 3, -1, ZoneOffset.UTC},
+ {"UTCZ", 3, -1, ZoneId.of("UTC")},
+ {"UTZ", 2, -1, ZoneId.of("UT")},
+ {"GMTZ", 3, -1, ZoneId.of("GMT")},
+
+ // 0 not parsed
+ {"UTC0", 3, -1, ZoneId.of("UTC")},
+ {"UT0", 2, -1, ZoneId.of("UT")},
// fail to parse
{"", 0, 0, null},
@@ -206,12 +211,12 @@
public void test_parseSuccess_plain(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) {
builder.appendZoneId();
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
- assertEquals(pos.getErrorIndex(), expectedErrorIndex);
- assertEquals(pos.getIndex(), expectedIndex);
+ assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + text);
+ assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + text);
if (expected != null) {
- assertEquals(parsed.query(TemporalQuery.zoneId()), expected);
- assertEquals(parsed.query(TemporalQuery.offset()), null);
- assertEquals(parsed.query(TemporalQuery.zone()), expected);
+ assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + text);
+ assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + text);
+ assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + text);
} else {
assertEquals(parsed, null);
}
@@ -221,13 +226,14 @@
public void test_parseSuccess_prefix(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) {
builder.appendZoneId();
pos.setIndex(3);
- TemporalAccessor parsed = builder.toFormatter().parseUnresolved("XXX" + text, pos);
- assertEquals(pos.getErrorIndex(), expectedErrorIndex >= 0 ? expectedErrorIndex + 3 : expectedErrorIndex);
- assertEquals(pos.getIndex(), expectedIndex + 3);
+ String prefixText = "XXX" + text;
+ TemporalAccessor parsed = builder.toFormatter().parseUnresolved(prefixText, pos);
+ assertEquals(pos.getErrorIndex(), expectedErrorIndex >= 0 ? expectedErrorIndex + 3 : expectedErrorIndex, "Incorrect error index parsing: " + prefixText);
+ assertEquals(pos.getIndex(), expectedIndex + 3, "Incorrect index parsing: " + prefixText);
if (expected != null) {
- assertEquals(parsed.query(TemporalQuery.zoneId()), expected);
- assertEquals(parsed.query(TemporalQuery.offset()), null);
- assertEquals(parsed.query(TemporalQuery.zone()), expected);
+ assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + prefixText);
+ assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + prefixText);
+ assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + prefixText);
} else {
assertEquals(parsed, null);
}
@@ -236,13 +242,14 @@
@Test(dataProvider="parseSuccess")
public void test_parseSuccess_suffix(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) {
builder.appendZoneId();
- TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text + "XXX", pos);
- assertEquals(pos.getErrorIndex(), expectedErrorIndex);
- assertEquals(pos.getIndex(), expectedIndex);
+ String suffixText = text + "XXX";
+ TemporalAccessor parsed = builder.toFormatter().parseUnresolved(suffixText, pos);
+ assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + suffixText);
+ assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + suffixText);
if (expected != null) {
- assertEquals(parsed.query(TemporalQuery.zoneId()), expected);
- assertEquals(parsed.query(TemporalQuery.offset()), null);
- assertEquals(parsed.query(TemporalQuery.zone()), expected);
+ assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + suffixText);
+ assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + suffixText);
+ assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + suffixText);
} else {
assertEquals(parsed, null);
}
@@ -251,15 +258,16 @@
@Test(dataProvider="parseSuccess")
public void test_parseSuccess_caseSensitive(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) {
builder.parseCaseSensitive().appendZoneId();
- TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text.toLowerCase(Locale.ENGLISH), pos);
+ String lcText = text.toLowerCase(Locale.ENGLISH);
+ TemporalAccessor parsed = builder.toFormatter().parseUnresolved(lcText, pos);
if (text.matches("[^A-Z]*[A-Z].*")) { // if input has letters
assertEquals(pos.getErrorIndex() >= 0, true);
assertEquals(pos.getIndex(), 0);
assertEquals(parsed, null);
} else {
// case sensitive made no difference
- assertEquals(pos.getIndex(), expectedIndex);
- assertEquals(pos.getErrorIndex(), expectedErrorIndex);
+ assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + lcText);
+ assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + lcText);
if (expected != null) {
assertEquals(parsed.query(TemporalQuery.zoneId()), expected);
assertEquals(parsed.query(TemporalQuery.offset()), null);
@@ -273,13 +281,15 @@
@Test(dataProvider="parseSuccess")
public void test_parseSuccess_caseInsensitive(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) {
builder.parseCaseInsensitive().appendZoneId();
- TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text.toLowerCase(Locale.ENGLISH), pos);
- assertEquals(pos.getErrorIndex(), expectedErrorIndex);
- assertEquals(pos.getIndex(), expectedIndex);
+ String lcText = text.toLowerCase(Locale.ENGLISH);
+ TemporalAccessor parsed = builder.toFormatter().parseUnresolved(lcText, pos);
+ assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + lcText);
+ assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + lcText);
if (expected != null) {
- assertEquals(parsed.query(TemporalQuery.zoneId()), expected);
- assertEquals(parsed.query(TemporalQuery.offset()), null);
- assertEquals(parsed.query(TemporalQuery.zone()), expected);
+ ZoneId zid = parsed.query(TemporalQuery.zoneId());
+ assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + lcText);
+ assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + lcText);
+ assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + lcText);
} else {
assertEquals(parsed, null);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/time/tck/java/time/temporal/TCKChronoField.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2012, 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * * Neither the name of JSR-310 nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package tck.java.time.temporal;
+
+import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
+import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
+import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
+import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
+import static java.time.temporal.ChronoField.AMPM_OF_DAY;
+import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
+import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
+import static java.time.temporal.ChronoField.DAY_OF_MONTH;
+import static java.time.temporal.ChronoField.DAY_OF_WEEK;
+import static java.time.temporal.ChronoField.DAY_OF_YEAR;
+import static java.time.temporal.ChronoField.EPOCH_DAY;
+import static java.time.temporal.ChronoField.HOUR_OF_DAY;
+import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
+import static java.time.temporal.ChronoField.MICRO_OF_DAY;
+import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
+import static java.time.temporal.ChronoField.MILLI_OF_DAY;
+import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
+import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
+import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
+import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
+import static java.time.temporal.ChronoField.NANO_OF_DAY;
+import static java.time.temporal.ChronoField.NANO_OF_SECOND;
+import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
+import static java.time.temporal.ChronoField.SECOND_OF_DAY;
+import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
+import static java.time.temporal.ChronoField.YEAR;
+import static java.time.temporal.ChronoField.YEAR_OF_ERA;
+import static java.time.temporal.ChronoField.ERA;
+import static java.time.temporal.ChronoUnit.DAYS;
+import static java.time.temporal.ChronoUnit.FOREVER;
+import static java.time.temporal.ChronoUnit.HOURS;
+import static java.time.temporal.ChronoUnit.MICROS;
+import static java.time.temporal.ChronoUnit.MILLIS;
+import static java.time.temporal.ChronoUnit.MINUTES;
+import static java.time.temporal.ChronoUnit.MONTHS;
+import static java.time.temporal.ChronoUnit.NANOS;
+import static java.time.temporal.ChronoUnit.SECONDS;
+import static java.time.temporal.ChronoUnit.WEEKS;
+import static java.time.temporal.ChronoUnit.YEARS;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.temporal.ChronoField;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAccessor;
+import java.time.temporal.ValueRange;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Test.
+ */
+@Test
+public class TCKChronoField {
+
+ //-----------------------------------------------------------------------
+ // getBaseUnit() and getRangeUnit()
+ //-----------------------------------------------------------------------
+ @DataProvider(name="fieldUnit")
+ Object[][] data_fieldUnit() {
+ return new Object[][] {
+ {YEAR, YEARS, FOREVER},
+ {MONTH_OF_YEAR, MONTHS, YEARS},
+ {DAY_OF_MONTH, DAYS, MONTHS},
+ {DAY_OF_WEEK, DAYS, WEEKS},
+ {DAY_OF_YEAR, DAYS, YEARS},
+ {HOUR_OF_DAY, HOURS, DAYS},
+ {MINUTE_OF_DAY, MINUTES, DAYS},
+ {MINUTE_OF_HOUR, MINUTES, HOURS},
+ {SECOND_OF_DAY, SECONDS, DAYS},
+ {SECOND_OF_MINUTE, SECONDS, MINUTES},
+ {MILLI_OF_DAY, MILLIS, DAYS},
+ {MILLI_OF_SECOND, MILLIS, SECONDS},
+ {MICRO_OF_SECOND, MICROS, SECONDS},
+ {MICRO_OF_DAY, MICROS, DAYS},
+ {NANO_OF_SECOND, NANOS, SECONDS},
+ {NANO_OF_DAY, NANOS, DAYS},
+
+ };
+ }
+
+ @Test(dataProvider = "fieldUnit")
+ public void test_getBaseUnit(ChronoField field, ChronoUnit baseUnit, ChronoUnit rangeUnit) {
+ assertEquals(field.getBaseUnit(), baseUnit);
+ assertEquals(field.getRangeUnit(), rangeUnit);
+ }
+
+ //-----------------------------------------------------------------------
+ // isDateBased() and isTimeBased()
+ //-----------------------------------------------------------------------
+ @DataProvider(name="fieldBased")
+ Object[][] data_fieldBased() {
+ return new Object[][] {
+ {DAY_OF_WEEK, true, false},
+ {ALIGNED_DAY_OF_WEEK_IN_MONTH, true, false},
+ {ALIGNED_DAY_OF_WEEK_IN_YEAR, true, false},
+ {DAY_OF_MONTH, true, false},
+ {DAY_OF_YEAR, true, false},
+ {EPOCH_DAY, true, false},
+ {ALIGNED_WEEK_OF_MONTH, true, false},
+ {ALIGNED_WEEK_OF_YEAR, true, false},
+ {MONTH_OF_YEAR, true, false},
+ {PROLEPTIC_MONTH, true, false},
+ {YEAR_OF_ERA, true, false},
+ {YEAR, true, false},
+ {ERA, true, false},
+
+ {AMPM_OF_DAY, false, true},
+ {CLOCK_HOUR_OF_DAY, false, true},
+ {HOUR_OF_DAY, false, true},
+ {CLOCK_HOUR_OF_AMPM, false, true},
+ {HOUR_OF_AMPM, false, true},
+ {MINUTE_OF_DAY, false, true},
+ {MINUTE_OF_HOUR, false, true},
+ {SECOND_OF_DAY, false, true},
+ {SECOND_OF_MINUTE, false, true},
+ {MILLI_OF_DAY, false, true},
+ {MILLI_OF_SECOND, false, true},
+ {MICRO_OF_DAY, false, true},
+ {MICRO_OF_SECOND, false, true},
+ {NANO_OF_DAY, false, true},
+ {NANO_OF_SECOND, false, true},
+ };
+ }
+
+ @Test(dataProvider = "fieldBased")
+ public void test_isDateBased(ChronoField field, boolean isDateBased, boolean isTimeBased) {
+ assertEquals(field.isDateBased(), isDateBased);
+ assertEquals(field.isTimeBased(), isTimeBased);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupportedBy(TemporalAccessor temporal) and getFrom(TemporalAccessor temporal)
+ //-----------------------------------------------------------------------
+ @DataProvider(name="fieldAndAccessor")
+ Object[][] data_fieldAndAccessor() {
+ return new Object[][] {
+ {YEAR, LocalDate.of(2000, 2, 29), true, 2000},
+ {YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2000},
+ {MONTH_OF_YEAR, LocalDate.of(2000, 2, 29), true, 2},
+ {MONTH_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2},
+ {DAY_OF_MONTH, LocalDate.of(2000, 2, 29), true, 29},
+ {DAY_OF_MONTH, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 29},
+ {DAY_OF_YEAR, LocalDate.of(2000, 2, 29), true, 60},
+ {DAY_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 60},
+
+ {HOUR_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5},
+ {HOUR_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5},
+
+ {MINUTE_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5*60 + 4},
+ {MINUTE_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5*60 + 4},
+ {MINUTE_OF_HOUR, LocalTime.of(5, 4, 3, 200), true, 4},
+ {MINUTE_OF_HOUR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 4},
+
+ {SECOND_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5*3600 + 4*60 + 3},
+ {SECOND_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5*3600 + 4*60 + 3},
+ {SECOND_OF_MINUTE, LocalTime.of(5, 4, 3, 200), true, 3},
+ {SECOND_OF_MINUTE, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 3},
+
+ {NANO_OF_SECOND, LocalTime.of(5, 4, 3, 200), true, 200},
+ {NANO_OF_SECOND, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 200},
+
+ {YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
+ {MONTH_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
+ {DAY_OF_MONTH, LocalTime.of(5, 4, 3, 200), false, -1},
+ {DAY_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
+ {HOUR_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
+ {MINUTE_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
+ {MINUTE_OF_HOUR, LocalDate.of(2000, 2, 29), false, -1},
+ {SECOND_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
+ {SECOND_OF_MINUTE, LocalDate.of(2000, 2, 29), false, -1},
+ {NANO_OF_SECOND, LocalDate.of(2000, 2, 29), false, -1},
+ };
+ }
+
+ @Test(dataProvider = "fieldAndAccessor")
+ public void test_supportedAccessor(ChronoField field, TemporalAccessor accessor, boolean isSupported, long value) {
+ assertEquals(field.isSupportedBy(accessor), isSupported);
+ if (isSupported) {
+ assertEquals(field.getFrom(accessor), value);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ // range() and rangeRefinedBy(TemporalAccessor temporal)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_range() {
+ assertEquals(MONTH_OF_YEAR.range(), ValueRange.of(1, 12));
+ assertEquals(MONTH_OF_YEAR.rangeRefinedBy(LocalDate.of(2000, 2, 29)), ValueRange.of(1, 12));
+
+ assertEquals(DAY_OF_MONTH.range(), ValueRange.of(1, 28, 31));
+ assertEquals(DAY_OF_MONTH.rangeRefinedBy(LocalDate.of(2000, 2, 29)), ValueRange.of(1, 29));
+ }
+
+ //-----------------------------------------------------------------------
+ // valueOf()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_valueOf() {
+ for (ChronoField field : ChronoField.values()) {
+ assertEquals(ChronoField.valueOf(field.name()), field);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/time/tck/java/time/temporal/TCKChronoUnit.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2012, 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * * Neither the name of JSR-310 nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package tck.java.time.temporal;
+
+import static java.time.temporal.ChronoUnit.CENTURIES;
+import static java.time.temporal.ChronoUnit.DAYS;
+import static java.time.temporal.ChronoUnit.DECADES;
+import static java.time.temporal.ChronoUnit.ERAS;
+import static java.time.temporal.ChronoUnit.FOREVER;
+import static java.time.temporal.ChronoUnit.HALF_DAYS;
+import static java.time.temporal.ChronoUnit.HOURS;
+import static java.time.temporal.ChronoUnit.MICROS;
+import static java.time.temporal.ChronoUnit.MILLENNIA;
+import static java.time.temporal.ChronoUnit.MILLIS;
+import static java.time.temporal.ChronoUnit.MINUTES;
+import static java.time.temporal.ChronoUnit.MONTHS;
+import static java.time.temporal.ChronoUnit.NANOS;
+import static java.time.temporal.ChronoUnit.SECONDS;
+import static java.time.temporal.ChronoUnit.WEEKS;
+import static java.time.temporal.ChronoUnit.YEARS;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.temporal.ChronoField;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.Temporal;
+import java.time.temporal.TemporalAccessor;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Test.
+ */
+@Test
+public class TCKChronoUnit {
+
+ //-----------------------------------------------------------------------
+ // isDateBased(), isTimeBased() and isDurationEstimated()
+ //-----------------------------------------------------------------------
+ @DataProvider(name="chronoUnit")
+ Object[][] data_chronoUnit() {
+ return new Object[][] {
+ {FOREVER, false, false, true},
+ {ERAS, true, false, true},
+ {MILLENNIA, true, false, true},
+ {CENTURIES, true, false, true},
+ {DECADES, true, false, true},
+ {YEARS, true, false, true},
+ {MONTHS, true, false, true},
+ {WEEKS, true, false, true},
+ {DAYS, true, false, true},
+
+ {HALF_DAYS, false, true, false},
+ {HOURS, false, true, false},
+ {MINUTES, false, true, false},
+ {SECONDS, false, true, false},
+ {MICROS, false, true, false},
+ {MILLIS, false, true, false},
+ {NANOS, false, true, false},
+
+ };
+ }
+
+ @Test(dataProvider = "chronoUnit")
+ public void test_unitType(ChronoUnit unit, boolean isDateBased, boolean isTimeBased, boolean isDurationEstimated) {
+ assertEquals(unit.isDateBased(), isDateBased);
+ assertEquals(unit.isTimeBased(), isTimeBased);
+ assertEquals(unit.isDurationEstimated(), isDurationEstimated);
+ }
+
+ //-----------------------------------------------------------------------
+ // isSupportedBy(), addTo() and between()
+ //-----------------------------------------------------------------------
+ @DataProvider(name="unitAndTemporal")
+ Object[][] data_unitAndTemporal() {
+ return new Object[][] {
+ {CENTURIES, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2100, 1, 10)},
+ {DECADES, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2010, 1, 10)},
+ {YEARS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2001, 1, 10)},
+ {MONTHS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 2, 10)},
+ {WEEKS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 1, 17)},
+ {DAYS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 1, 11)},
+
+ {HALF_DAYS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(13, 2, 3, 400)},
+ {HOURS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(2, 2, 3, 400)},
+ {MINUTES, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 3, 3, 400)},
+ {SECONDS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 4, 400)},
+ {MICROS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1000 + 400)},
+ {MILLIS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1000*1000 + 400)},
+ {NANOS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1 + 400)},
+
+ {CENTURIES, LocalTime.of(1, 2, 3, 400), false, 1, null},
+ {DECADES, LocalTime.of(1, 2, 3, 400), false, 1, null},
+ {YEARS, LocalTime.of(1, 2, 3, 400), false, 1, null},
+ {MONTHS, LocalTime.of(1, 2, 3, 400), false, 1, null},
+ {WEEKS, LocalTime.of(1, 2, 3, 400), false, 1, null},
+ {DAYS, LocalTime.of(1, 2, 3, 400), false, 1, null},
+
+ {HALF_DAYS, LocalDate.of(2000, 2, 29), false, 1, null},
+ {HOURS, LocalDate.of(2000, 2, 29), false, 1, null},
+ {MINUTES, LocalDate.of(2000, 2, 29), false, 1, null},
+ {SECONDS, LocalDate.of(2000, 2, 29), false, 1, null},
+ {MICROS, LocalDate.of(2000, 2, 29), false, 1, null},
+ {MILLIS, LocalDate.of(2000, 2, 29), false, 1, null},
+ {NANOS, LocalDate.of(2000, 2, 29), false, 1, null},
+
+ };
+ }
+
+ @Test(dataProvider = "unitAndTemporal")
+ public void test_unitAndTemporal(ChronoUnit unit, Temporal base, boolean isSupportedBy, long amount, Temporal target) {
+ assertEquals(unit.isSupportedBy(base), isSupportedBy);
+ if (isSupportedBy) {
+ Temporal result = unit.addTo(base, amount);
+ assertEquals(result, target);
+ assertEquals(unit.between(base, result), amount);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ // valueOf()
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_valueOf() {
+ for (ChronoUnit unit : ChronoUnit.values()) {
+ assertEquals(ChronoUnit.valueOf(unit.name()), unit);
+ }
+ }
+}
--- a/jdk/test/java/time/tck/java/time/temporal/TCKWeekFields.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/temporal/TCKWeekFields.java Thu Jul 25 20:30:58 2013 -0400
@@ -56,16 +56,22 @@
*/
package tck.java.time.temporal;
+import static java.time.format.ResolverStyle.LENIENT;
+import static java.time.format.ResolverStyle.SMART;
+import static java.time.format.ResolverStyle.STRICT;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
import static java.time.temporal.ChronoField.DAY_OF_YEAR;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.YEAR;
-
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
import java.io.IOException;
+import java.time.DateTimeException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@@ -376,14 +382,13 @@
TemporalField womField = week.weekOfMonth();
for (int i = 1; i <= 60; i++) {
- // Test that with dayOfWeek and Week of month it computes the date
DateTimeFormatter f = new DateTimeFormatterBuilder()
- .appendValue(YEAR).appendLiteral('-')
- .appendValue(MONTH_OF_YEAR).appendLiteral('-')
- .appendValue(womField).appendLiteral('-')
- .appendValue(DAY_OF_WEEK).toFormatter();
- String str = date.getYear() + "-" + date.getMonthValue() + "-" +
- date.get(womField) + "-" + date.get(DAY_OF_WEEK);
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(MONTH_OF_YEAR).appendLiteral(':')
+ .appendValue(womField).appendLiteral(':')
+ .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(SMART);
+ String str = date.getYear() + ":" + date.getMonthValue() + ":" +
+ date.get(womField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " ::" + str + "::" + i);
@@ -392,6 +397,52 @@
}
@Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWom_lenient(DayOfWeek firstDayOfWeek, int minDays) {
+ LocalDate date = LocalDate.of(2012, 12, 15);
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField womField = week.weekOfMonth();
+
+ for (int i = 1; i <= 60; i++) {
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(MONTH_OF_YEAR).appendLiteral(':')
+ .appendValue(womField).appendLiteral(':')
+ .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
+ int wom = date.get(womField);
+ int dow = date.get(DAY_OF_WEEK);
+ for (int j = wom - 10; j < wom + 10; j++) {
+ String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
+ LocalDate parsed = LocalDate.parse(str, f);
+ assertEquals(parsed, date.plusWeeks(j - wom), " ::" + str + ": :" + i + "::" + j);
+ }
+
+ date = date.plusDays(1);
+ }
+ }
+
+ @Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWom_strict(DayOfWeek firstDayOfWeek, int minDays) {
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField womField = week.weekOfMonth();
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(MONTH_OF_YEAR).appendLiteral(':')
+ .appendValue(womField).appendLiteral(':')
+ .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
+ String str = "2012:1:0:1";
+ try {
+ LocalDate date = LocalDate.parse(str, f);
+ assertEquals(date.getYear(), 2012);
+ assertEquals(date.getMonthValue(), 1);
+ assertEquals(date.get(womField), 0);
+ assertEquals(date.get(DAY_OF_WEEK), 1);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWomDow(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
@@ -399,14 +450,13 @@
TemporalField womField = week.weekOfMonth();
for (int i = 1; i <= 15; i++) {
- // Test that with dayOfWeek and Week of month it computes the date
DateTimeFormatter f = new DateTimeFormatterBuilder()
- .appendValue(YEAR).appendLiteral('-')
- .appendValue(MONTH_OF_YEAR).appendLiteral('-')
- .appendValue(womField).appendLiteral('-')
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(MONTH_OF_YEAR).appendLiteral(':')
+ .appendValue(womField).appendLiteral(':')
.appendValue(dowField).toFormatter();
- String str = date.getYear() + "-" + date.getMonthValue() + "-" +
- date.get(womField) + "-" + date.get(dowField);
+ String str = date.getYear() + ":" + date.getMonthValue() + ":" +
+ date.get(womField) + ":" + date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
@@ -415,20 +465,44 @@
}
@Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWomDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
+ LocalDate date = LocalDate.of(2012, 12, 15);
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField dowField = week.dayOfWeek();
+ TemporalField womField = week.weekOfMonth();
+
+ for (int i = 1; i <= 60; i++) {
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(MONTH_OF_YEAR).appendLiteral(':')
+ .appendValue(womField).appendLiteral(':')
+ .appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
+ int wom = date.get(womField);
+ int dow = date.get(dowField);
+ for (int j = wom - 10; j < wom + 10; j++) {
+ String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
+ LocalDate parsed = LocalDate.parse(str, f);
+ assertEquals(parsed, date.plusWeeks(j - wom), " ::" + str + ": :" + i + "::" + j);
+ }
+
+ date = date.plusDays(1);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoy(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
- // Test that with dayOfWeek and Week of month it computes the date
DateTimeFormatter f = new DateTimeFormatterBuilder()
- .appendValue(YEAR).appendLiteral('-')
- .appendValue(MONTH_OF_YEAR).appendLiteral('-')
- .appendValue(woyField).appendLiteral('-')
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(woyField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter();
- String str = date.getYear() + "-" + date.getMonthValue() + "-" +
- date.get(woyField) + "-" + date.get(DAY_OF_WEEK);
+ String str = date.getYear() + ":" +
+ date.get(woyField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
@@ -437,6 +511,49 @@
}
@Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWoy_lenient(DayOfWeek firstDayOfWeek, int minDays) {
+ LocalDate date = LocalDate.of(2012, 12, 15);
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField woyField = week.weekOfYear();
+
+ for (int i = 1; i <= 60; i++) {
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(woyField).appendLiteral(':')
+ .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
+ int woy = date.get(woyField);
+ int dow = date.get(DAY_OF_WEEK);
+ for (int j = woy - 60; j < woy + 60; j++) {
+ String str = date.getYear() + ":" + j + ":" + dow;
+ LocalDate parsed = LocalDate.parse(str, f);
+ assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
+ }
+
+ date = date.plusDays(1);
+ }
+ }
+
+ @Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWoy_strict(DayOfWeek firstDayOfWeek, int minDays) {
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField woyField = week.weekOfYear();
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(woyField).appendLiteral(':')
+ .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
+ String str = "2012:0:1";
+ try {
+ LocalDate date = LocalDate.parse(str, f);
+ assertEquals(date.getYear(), 2012);
+ assertEquals(date.get(woyField), 0);
+ assertEquals(date.get(DAY_OF_WEEK), 1);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoyDow(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
@@ -444,14 +561,13 @@
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
- // Test that with dayOfWeek and Week of month it computes the date
DateTimeFormatter f = new DateTimeFormatterBuilder()
- .appendValue(YEAR).appendLiteral('-')
- .appendValue(MONTH_OF_YEAR).appendLiteral('-')
- .appendValue(woyField).appendLiteral('-')
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(MONTH_OF_YEAR).appendLiteral(':')
+ .appendValue(woyField).appendLiteral(':')
.appendValue(dowField).toFormatter();
- String str = date.getYear() + "-" + date.getMonthValue() + "-" +
- date.get(woyField) + "-" + date.get(dowField);
+ String str = date.getYear() + ":" + date.getMonthValue() + ":" +
+ date.get(woyField) + ":" + date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
@@ -460,6 +576,31 @@
}
@Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWoyDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
+ LocalDate date = LocalDate.of(2012, 12, 15);
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField dowField = week.dayOfWeek();
+ TemporalField woyField = week.weekOfYear();
+
+ for (int i = 1; i <= 60; i++) {
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(YEAR).appendLiteral(':')
+ .appendValue(woyField).appendLiteral(':')
+ .appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
+ int woy = date.get(woyField);
+ int dow = date.get(dowField);
+ for (int j = woy - 60; j < woy + 60; j++) {
+ String str = date.getYear() + ":" + j + ":" + dow;
+ LocalDate parsed = LocalDate.parse(str, f);
+ assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
+ }
+
+ date = date.plusDays(1);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
@@ -467,12 +608,11 @@
TemporalField yowbyField = week.weekBasedYear();
for (int i = 1; i <= 60; i++) {
- // Test that with dayOfWeek, week of year and year of week-based-year it computes the date
DateTimeFormatter f = new DateTimeFormatterBuilder()
- .appendValue(yowbyField).appendLiteral('-')
- .appendValue(wowbyField).appendLiteral('-')
+ .appendValue(yowbyField).appendLiteral(':')
+ .appendValue(wowbyField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter();
- String str = date.get(yowbyField) + "-" + date.get(wowbyField) + "-" +
+ String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
@@ -482,6 +622,51 @@
}
@Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWoWBY_lenient(DayOfWeek firstDayOfWeek, int minDays) {
+ LocalDate date = LocalDate.of(2012, 12, 31);
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField wowbyField = week.weekOfWeekBasedYear();
+ TemporalField yowbyField = week.weekBasedYear();
+
+ for (int i = 1; i <= 60; i++) {
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(yowbyField).appendLiteral(':')
+ .appendValue(wowbyField).appendLiteral(':')
+ .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
+ int wowby = date.get(wowbyField);
+ int dow = date.get(DAY_OF_WEEK);
+ for (int j = wowby - 60; j < wowby + 60; j++) {
+ String str = date.get(yowbyField) + ":" + j + ":" + dow;
+ LocalDate parsed = LocalDate.parse(str, f);
+ assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
+ }
+
+ date = date.plusDays(1);
+ }
+ }
+
+ @Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWoWBY_strict(DayOfWeek firstDayOfWeek, int minDays) {
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField wowbyField = week.weekOfWeekBasedYear();
+ TemporalField yowbyField = week.weekBasedYear();
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(yowbyField).appendLiteral(':')
+ .appendValue(wowbyField).appendLiteral(':')
+ .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
+ String str = "2012:0:1";
+ try {
+ LocalDate date = LocalDate.parse(str, f);
+ assertEquals(date.get(yowbyField), 2012);
+ assertEquals(date.get(wowbyField), 0);
+ assertEquals(date.get(DAY_OF_WEEK), 1);
+ } catch (DateTimeException ex) {
+ // expected
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ @Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
@@ -490,12 +675,11 @@
TemporalField yowbyField = week.weekBasedYear();
for (int i = 1; i <= 60; i++) {
- // Test that with dayOfWeek, week of year and year of week-based-year it computes the date
DateTimeFormatter f = new DateTimeFormatterBuilder()
- .appendValue(yowbyField).appendLiteral('-')
- .appendValue(wowbyField).appendLiteral('-')
+ .appendValue(yowbyField).appendLiteral(':')
+ .appendValue(wowbyField).appendLiteral(':')
.appendValue(dowField).toFormatter();
- String str = date.get(yowbyField) + "-" + date.get(wowbyField) + "-" +
+ String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
@@ -504,6 +688,31 @@
}
}
+ @Test(dataProvider="weekFields")
+ public void test_parse_resolve_localizedWoWBYDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
+ LocalDate date = LocalDate.of(2012, 12, 31);
+ WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
+ TemporalField dowField = week.dayOfWeek();
+ TemporalField wowbyField = week.weekOfWeekBasedYear();
+ TemporalField yowbyField = week.weekBasedYear();
+
+ for (int i = 1; i <= 60; i++) {
+ DateTimeFormatter f = new DateTimeFormatterBuilder()
+ .appendValue(yowbyField).appendLiteral(':')
+ .appendValue(wowbyField).appendLiteral(':')
+ .appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
+ int wowby = date.get(wowbyField);
+ int dow = date.get(dowField);
+ for (int j = wowby - 60; j < wowby + 60; j++) {
+ String str = date.get(yowbyField) + ":" + j + ":" + dow;
+ LocalDate parsed = LocalDate.parse(str, f);
+ assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
+ }
+
+ date = date.plusDays(1);
+ }
+ }
+
//-----------------------------------------------------------------------
@Test(dataProvider="weekFields")
public void test_serializable_singleton(DayOfWeek firstDayOfWeek, int minDays) throws IOException, ClassNotFoundException {
@@ -587,4 +796,21 @@
assertEquals(date.get(yowbyField), wby);
}
+ //-----------------------------------------------------------------------
+ // equals() and hashCode().
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_equals() {
+ WeekFields weekDef_iso = WeekFields.ISO;
+ WeekFields weekDef_sundayStart = WeekFields.SUNDAY_START;
+
+ assertTrue(weekDef_iso.equals(WeekFields.of(DayOfWeek.MONDAY, 4)));
+ assertTrue(weekDef_sundayStart.equals(WeekFields.of(DayOfWeek.SUNDAY, 1)));
+ assertEquals(weekDef_iso.hashCode(), WeekFields.of(DayOfWeek.MONDAY, 4).hashCode());
+ assertEquals(weekDef_sundayStart.hashCode(), WeekFields.of(DayOfWeek.SUNDAY, 1).hashCode());
+
+ assertFalse(weekDef_iso.equals(weekDef_sundayStart));
+ assertNotEquals(weekDef_iso.hashCode(), weekDef_sundayStart.hashCode());
+ }
+
}
--- a/jdk/test/java/time/tck/java/time/zone/TCKZoneRules.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/tck/java/time/zone/TCKZoneRules.java Thu Jul 25 20:30:58 2013 -0400
@@ -75,6 +75,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
+import java.time.OffsetDateTime;
import java.time.Year;
import java.time.ZoneId;
import java.time.ZoneOffset;
@@ -83,6 +84,7 @@
import java.time.zone.ZoneOffsetTransitionRule;
import java.time.zone.ZoneOffsetTransitionRule.TimeDefinition;
import java.time.zone.ZoneRules;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -918,6 +920,65 @@
assertEquals(test.nextTransition(last.getInstant()), null);
}
+ //-----------------------------------------------------------------------
+ // Apia
+ //-----------------------------------------------------------------------
+ private ZoneRules pacificApia() {
+ return ZoneId.of("Pacific/Apia").getRules();
+ }
+
+ public void test_Apia_nextTransition_historic() {
+ ZoneRules test = pacificApia();
+ List<ZoneOffsetTransition> trans = test.getTransitions();
+
+ ZoneOffsetTransition first = trans.get(0);
+ assertEquals(test.nextTransition(first.getInstant().minusNanos(1)), first);
+
+ for (int i = 0; i < trans.size() - 1; i++) {
+ ZoneOffsetTransition cur = trans.get(i);
+ ZoneOffsetTransition next = trans.get(i + 1);
+
+ assertEquals(test.nextTransition(cur.getInstant()), next);
+ assertEquals(test.nextTransition(next.getInstant().minusNanos(1)), next);
+ }
+ }
+
+ public void test_Apia_jumpOverInternationalDateLine_M10_to_P14() {
+ // transition occurred at 2011-12-30T00:00-10:00
+ ZoneRules test = pacificApia();
+ Instant instantBefore = LocalDate.of(2011, 12, 27).atStartOfDay(ZoneOffset.UTC).toInstant();
+ ZoneOffsetTransition trans = test.nextTransition(instantBefore);
+ assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2011, 12, 30, 0, 0));
+ assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2011, 12, 31, 0, 0));
+ assertEquals(trans.isGap(), true);
+ assertEquals(trans.isOverlap(), false);
+ assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-10)), false);
+ assertEquals(trans.isValidOffset(ZoneOffset.ofHours(+14)), false);
+ assertEquals(trans.getDuration(), Duration.ofHours(24));
+ assertEquals(trans.getInstant(), LocalDateTime.of(2011, 12, 31, 0, 0).toInstant(ZoneOffset.ofHours(+14)));
+
+ ZonedDateTime zdt = ZonedDateTime.of(2011, 12, 29, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
+ assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(2011, 12, 31, 1, 0));
+ }
+
+ public void test_Apia_jumpForwardOverInternationalDateLine_P12_to_M12() {
+ // transition occurred at 1879-07-04T00:00+12:33:04
+ ZoneRules test = pacificApia();
+ Instant instantBefore = LocalDate.of(1879, 7, 2).atStartOfDay(ZoneOffset.UTC).toInstant();
+ ZoneOffsetTransition trans = test.nextTransition(instantBefore);
+ assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(1879, 7, 5, 0, 0));
+ assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(1879, 7, 4, 0, 0));
+ assertEquals(trans.isGap(), false);
+ assertEquals(trans.isOverlap(), true);
+ assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(+12, 33, 4)), true);
+ assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)), true);
+ assertEquals(trans.getDuration(), Duration.ofHours(-24));
+ assertEquals(trans.getInstant(), LocalDateTime.of(1879, 7, 4, 0, 0).toInstant(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)));
+
+ ZonedDateTime zdt = ZonedDateTime.of(1879, 7, 4, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
+ assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(1879, 7, 4, 1, 0, 0));
+ }
+
//-------------------------------------------------------------------------
@Test(expectedExceptions=UnsupportedOperationException.class)
public void test_getTransitions_immutable() {
@@ -932,6 +993,81 @@
}
//-----------------------------------------------------------------------
+ // of()
+ //-----------------------------------------------------------------------
+ public void test_of(){
+ //used for standard offset
+ ZoneOffset stdOffset1 = ZoneOffset.UTC;
+ ZoneOffset stdOffset2 = ZoneOffset.ofHours(1);
+ LocalDateTime time_of_stdOffsetTransition1 = LocalDateTime.of(2013, 1, 5, 1, 0);
+ ZoneOffsetTransition stdOffsetTransition1 = ZoneOffsetTransition.of(time_of_stdOffsetTransition1, stdOffset1, stdOffset2);
+ List<ZoneOffsetTransition> stdOffsetTransition_list = new ArrayList<ZoneOffsetTransition>();
+ stdOffsetTransition_list.add(stdOffsetTransition1);
+
+ //used for wall offset
+ ZoneOffset wallOffset1 = ZoneOffset.ofHours(2);
+ ZoneOffset wallOffset2 = ZoneOffset.ofHours(4);
+ ZoneOffset wallOffset3 = ZoneOffset.ofHours(7);
+
+ LocalDateTime time_of_wallOffsetTransition1 = LocalDateTime.of(2013, 2, 5, 1, 0);
+ LocalDateTime time_of_wallOffsetTransition2 = LocalDateTime.of(2013, 3, 5, 1, 0);
+ LocalDateTime time_of_wallOffsetTransition3 = LocalDateTime.of(2013, 10, 5, 1, 0);
+
+ ZoneOffsetTransition wallOffsetTransition1 = ZoneOffsetTransition.of(time_of_wallOffsetTransition1, wallOffset1, wallOffset2);
+ ZoneOffsetTransition wallOffsetTransition2 = ZoneOffsetTransition.of(time_of_wallOffsetTransition2, wallOffset2, wallOffset3);
+ ZoneOffsetTransition wallOffsetTransition3 = ZoneOffsetTransition.of(time_of_wallOffsetTransition3, wallOffset3, wallOffset1);
+
+ List<ZoneOffsetTransition> wallOffsetTransition_list = new ArrayList<ZoneOffsetTransition>();
+ wallOffsetTransition_list.add(wallOffsetTransition1);
+ wallOffsetTransition_list.add(wallOffsetTransition2);
+ wallOffsetTransition_list.add(wallOffsetTransition3);
+
+ //used for ZoneOffsetTransitionRule
+ ZoneOffset ruleOffset = ZoneOffset.ofHours(3);
+ ZoneOffsetTransitionRule.TimeDefinition timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.valueOf("WALL");
+ ZoneOffsetTransitionRule rule1 = ZoneOffsetTransitionRule.of(Month.FEBRUARY,
+ 2,
+ DayOfWeek.MONDAY,
+ LocalTime.of(1, 0),
+ false,
+ timeDefinition,
+ ZoneOffset.UTC,
+ ZoneOffset.UTC,
+ ruleOffset
+ );
+ List<ZoneOffsetTransitionRule> rule_list = new ArrayList<ZoneOffsetTransitionRule>();
+ rule_list.add(rule1);
+
+ //Begin verification
+ ZoneRules zoneRule = ZoneRules.of(stdOffset1,
+ wallOffset1,
+ stdOffsetTransition_list,
+ wallOffsetTransition_list,
+ rule_list
+ );
+
+ OffsetDateTime before_time_of_stdOffsetTransition1 = OffsetDateTime.of(time_of_stdOffsetTransition1, stdOffset1).minusSeconds(1);
+ OffsetDateTime after_time_of_stdOffsetTransition1 = OffsetDateTime.of(time_of_stdOffsetTransition1, stdOffset1).plusSeconds(1);;
+ assertEquals(zoneRule.getStandardOffset(before_time_of_stdOffsetTransition1.toInstant()), stdOffset1);
+ assertEquals(zoneRule.getStandardOffset(after_time_of_stdOffsetTransition1.toInstant()), stdOffset2);
+
+ OffsetDateTime before_time_of_wallOffsetTransition1 = OffsetDateTime.of(time_of_wallOffsetTransition1, wallOffset1).minusSeconds(1);
+ OffsetDateTime after_time_of_wallOffsetTransition1 = OffsetDateTime.of(time_of_wallOffsetTransition1, wallOffset1).plusSeconds(1);
+ assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition1.toInstant()), wallOffsetTransition1);
+ assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition1.toInstant()), wallOffsetTransition2);
+
+ OffsetDateTime before_time_of_wallOffsetTransition2 = OffsetDateTime.of(time_of_wallOffsetTransition2, wallOffset2).minusSeconds(1);
+ OffsetDateTime after_time_of_wallOffsetTransition2 = OffsetDateTime.of(time_of_wallOffsetTransition2, wallOffset2).plusSeconds(1);
+ assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition2.toInstant()), wallOffsetTransition2);
+ assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition2.toInstant()), wallOffsetTransition3);
+
+ OffsetDateTime before_time_of_wallOffsetTransition3 = OffsetDateTime.of(time_of_wallOffsetTransition3, wallOffset3).minusSeconds(1);
+ OffsetDateTime after_time_of_wallOffsetTransition3 = OffsetDateTime.of(time_of_wallOffsetTransition3, wallOffset3).plusSeconds(1);
+ assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition3.toInstant()), wallOffsetTransition3);
+ assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition3.toInstant()), rule1.createTransition(2014));
+ }
+
+ //-----------------------------------------------------------------------
// equals() / hashCode()
//-----------------------------------------------------------------------
public void test_equals() {
--- a/jdk/test/java/time/test/java/time/MockSimplePeriod.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/MockSimplePeriod.java Thu Jul 25 20:30:58 2013 -0400
@@ -176,7 +176,7 @@
@Override
public String toString() {
- return amount + " " + unit.getName();
+ return amount + " " + unit;
}
}
--- a/jdk/test/java/time/test/java/time/chrono/TestChronoLocalDate.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/chrono/TestChronoLocalDate.java Thu Jul 25 20:30:58 2013 -0400
@@ -60,7 +60,9 @@
import static org.testng.Assert.assertTrue;
import java.time.LocalDate;
+import java.time.LocalDateTime;
import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.ChronoLocalDateTime;
import java.time.chrono.Chronology;
import java.time.chrono.ThaiBuddhistChronology;
import java.time.chrono.ThaiBuddhistDate;
@@ -80,8 +82,8 @@
//-----------------------------------------------------------------------
public void test_date_comparator_checkGenerics_ISO() {
- List<ChronoLocalDate<LocalDate>> dates = new ArrayList<>();
- ChronoLocalDate<LocalDate> date = LocalDate.of(2013, 1, 1);
+ List<ChronoLocalDate> dates = new ArrayList<>();
+ ChronoLocalDate date = LocalDate.of(2013, 1, 1);
// Insert dates in order, no duplicates
dates.add(date.minus(10, ChronoUnit.YEARS));
@@ -96,55 +98,7 @@
dates.add(date.plus(1, ChronoUnit.YEARS));
dates.add(date.plus(10, ChronoUnit.YEARS));
- List<ChronoLocalDate<LocalDate>> copy = new ArrayList<>(dates);
- Collections.shuffle(copy);
- Collections.sort(copy, ChronoLocalDate.timeLineOrder());
- assertEquals(copy, dates);
- assertTrue(ChronoLocalDate.timeLineOrder().compare(copy.get(0), copy.get(1)) < 0);
- }
-
- public void test_date_comparator_checkGenerics_unknown() {
- List<ChronoLocalDate<?>> dates = new ArrayList<>();
- ChronoLocalDate<?> date = LocalDate.of(2013, 1, 1);
-
- // Insert dates in order, no duplicates
- dates.add(date.minus(10, ChronoUnit.YEARS));
- dates.add(date.minus(1, ChronoUnit.YEARS));
- dates.add(date.minus(1, ChronoUnit.MONTHS));
- dates.add(date.minus(1, ChronoUnit.WEEKS));
- dates.add(date.minus(1, ChronoUnit.DAYS));
- dates.add(date);
- dates.add(date.plus(1, ChronoUnit.DAYS));
- dates.add(date.plus(1, ChronoUnit.WEEKS));
- dates.add(date.plus(1, ChronoUnit.MONTHS));
- dates.add(date.plus(1, ChronoUnit.YEARS));
- dates.add(date.plus(10, ChronoUnit.YEARS));
-
- List<ChronoLocalDate<?>> copy = new ArrayList<>(dates);
- Collections.shuffle(copy);
- Collections.sort(copy, ChronoLocalDate.timeLineOrder());
- assertEquals(copy, dates);
- assertTrue(ChronoLocalDate.timeLineOrder().compare(copy.get(0), copy.get(1)) < 0);
- }
-
- public <D extends ChronoLocalDate<D>> void test_date_comparator_checkGenerics_unknownExtends() {
- List<ChronoLocalDate<D>> dates = new ArrayList<>();
- ChronoLocalDate<D> date = (ChronoLocalDate) LocalDate.of(2013, 1, 1); // TODO generics raw type
-
- // Insert dates in order, no duplicates
- dates.add(date.minus(10, ChronoUnit.YEARS));
- dates.add(date.minus(1, ChronoUnit.YEARS));
- dates.add(date.minus(1, ChronoUnit.MONTHS));
- dates.add(date.minus(1, ChronoUnit.WEEKS));
- dates.add(date.minus(1, ChronoUnit.DAYS));
- dates.add(date);
- dates.add(date.plus(1, ChronoUnit.DAYS));
- dates.add(date.plus(1, ChronoUnit.WEEKS));
- dates.add(date.plus(1, ChronoUnit.MONTHS));
- dates.add(date.plus(1, ChronoUnit.YEARS));
- dates.add(date.plus(10, ChronoUnit.YEARS));
-
- List<ChronoLocalDate<D>> copy = new ArrayList<>(dates);
+ List<ChronoLocalDate> copy = new ArrayList<>(dates);
Collections.shuffle(copy);
Collections.sort(copy, ChronoLocalDate.timeLineOrder());
assertEquals(copy, dates);
@@ -178,13 +132,12 @@
//-----------------------------------------------------------------------
public void test_date_checkGenerics_genericsMethod() {
Chronology chrono = ThaiBuddhistChronology.INSTANCE;
- ChronoLocalDate<?> date = chrono.dateNow();
- // date = processOK(date); // does not compile
+ ChronoLocalDate date = chrono.dateNow();
+ date = processOK(date);
date = processClassOK(ThaiBuddhistDate.class);
date = dateSupplier();
- // date = processWeird(date); // does not compile (correct)
- // date = processClassWeird(ThaiBuddhistDate.class); // does not compile (correct)
+ date = processClassWeird(ThaiBuddhistDate.class);
}
public void test_date_checkGenerics_genericsMethod_concreteType() {
@@ -195,12 +148,12 @@
date = processClassOK(ThaiBuddhistDate.class);
date = dateSupplier();
- // date = processWeird(date); // does not compile (correct)
// date = processClassWeird(ThaiBuddhistDate.class); // does not compile (correct)
}
- public <D extends ChronoLocalDate<D>> void test_date_checkGenerics_genericsMethod_withType() {
+ public <D extends ChronoLocalDate> void test_date_checkGenerics_genericsMethod_withType() {
Chronology chrono = ThaiBuddhistChronology.INSTANCE;
+ @SuppressWarnings("unchecked")
D date = (D) chrono.dateNow();
date = processOK(date);
// date = processClassOK(ThaiBuddhistDate.class); // does not compile (correct)
@@ -210,24 +163,40 @@
// date = processClassWeird(ThaiBuddhistDate.class); // does not compile (correct)
}
- private <D extends ChronoLocalDate<D>> D dateSupplier() {
- return (D) (ChronoLocalDate) ThaiBuddhistChronology.INSTANCE.dateNow(); // TODO raw types
+ @SuppressWarnings("unchecked")
+ private <D extends ChronoLocalDate> D dateSupplier() {
+ return (D) ThaiBuddhistChronology.INSTANCE.dateNow();
}
// decent generics signatures that need to work
- private <D extends ChronoLocalDate<D>> D processOK(D date) {
- return date;
+ @SuppressWarnings("unchecked")
+ private <D extends ChronoLocalDate> D processOK(D date) {
+ return (D) date.plus(1, ChronoUnit.DAYS);
}
- private <D extends ChronoLocalDate<D>> D processClassOK(Class<D> cls) {
+ private <D extends ChronoLocalDate> D processClassOK(Class<D> cls) {
return null;
}
// weird generics signatures that shouldn't really work
- private <D extends ChronoLocalDate<D>> ChronoLocalDate<D> processWeird(ChronoLocalDate<D> date) {
- return date;
- }
- private <D extends ChronoLocalDate<D>> ChronoLocalDate<D> processClassWeird(Class<D> cls) {
+ private <D extends ChronoLocalDate> ChronoLocalDate processClassWeird(Class<D> cls) {
return null;
}
+ public void test_date_checkGenerics_chronoLocalDateTime1() {
+ LocalDateTime now = LocalDateTime.now();
+ Chronology chrono = ThaiBuddhistChronology.INSTANCE;
+ ChronoLocalDateTime<?> ldt = chrono.localDateTime(now);
+ ldt = processCLDT(ldt);
+ }
+
+ public void test_date_checkGenerics_chronoLocalDateTime2() {
+ LocalDateTime now = LocalDateTime.now();
+ Chronology chrono = ThaiBuddhistChronology.INSTANCE;
+ ChronoLocalDateTime<? extends ChronoLocalDate> ldt = chrono.localDateTime(now);
+ ldt = processCLDT(ldt);
+ }
+
+ private <D extends ChronoLocalDate> ChronoLocalDateTime<D> processCLDT(ChronoLocalDateTime<D> dt) {
+ return dt;
+ }
}
--- a/jdk/test/java/time/test/java/time/chrono/TestExampleCode.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/chrono/TestExampleCode.java Thu Jul 25 20:30:58 2013 -0400
@@ -59,10 +59,14 @@
import static org.testng.Assert.assertEquals;
+import java.time.LocalDate;
import java.time.LocalTime;
+import java.time.ZoneId;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoZonedDateTime;
import java.time.chrono.Chronology;
+import java.time.chrono.HijrahChronology;
import java.time.chrono.HijrahDate;
import java.time.chrono.ThaiBuddhistDate;
import java.time.temporal.ChronoField;
@@ -82,7 +86,7 @@
@Test
public void test_chronoPackageExample() {
// Print the Thai Buddhist date
- ChronoLocalDate<?> now1 = Chronology.of("ThaiBuddhist").dateNow();
+ ChronoLocalDate now1 = Chronology.of("ThaiBuddhist").dateNow();
int day = now1.get(ChronoField.DAY_OF_MONTH);
int dow = now1.get(ChronoField.DAY_OF_WEEK);
int month = now1.get(ChronoField.MONTH_OF_YEAR);
@@ -93,15 +97,15 @@
// Enumerate the list of available calendars and print today for each
Set<Chronology> chronos = Chronology.getAvailableChronologies();
for (Chronology chrono : chronos) {
- ChronoLocalDate<?> date = chrono.dateNow();
+ ChronoLocalDate date = chrono.dateNow();
System.out.printf(" %20s: %s%n", chrono.getId(), date.toString());
}
// Print today's date and the last day of the year for the Thai Buddhist Calendar.
- ChronoLocalDate<?> first = now1
+ ChronoLocalDate first = now1
.with(ChronoField.DAY_OF_MONTH, 1)
.with(ChronoField.MONTH_OF_YEAR, 1);
- ChronoLocalDate<?> last = first
+ ChronoLocalDate last = first
.plus(1, ChronoUnit.YEARS)
.minus(1, ChronoUnit.DAYS);
System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(),
@@ -137,7 +141,7 @@
// Enumerate the list of available calendars and print today for each
Set<Chronology> chronos = Chronology.getAvailableChronologies();
for (Chronology chrono : chronos) {
- ChronoLocalDate<?> date = chrono.dateNow();
+ ChronoLocalDate date = chrono.dateNow();
System.out.printf(" %20s: %s%n", chrono.getId(), date.toString());
}
@@ -161,11 +165,31 @@
first, last);
}
+ void HijrahExample1() {
+ HijrahDate hd2 = HijrahChronology.INSTANCE.date(1200, 1, 1);
+
+ ChronoLocalDateTime<HijrahDate> hdt = hd2.atTime(LocalTime.MIDNIGHT);
+ ChronoZonedDateTime<HijrahDate> zhdt = hdt.atZone(ZoneId.of("GMT"));
+ HijrahDate hd3 = zhdt.toLocalDate();
+ ChronoLocalDateTime<HijrahDate> hdt2 = zhdt.toLocalDateTime();
+ HijrahDate hd4 = hdt2.toLocalDate();
+
+ HijrahDate hd5 = next(hd2);
+ }
+
+ void test_unknownChronologyWithDateTime() {
+ ChronoLocalDate date = LocalDate.now();
+ ChronoLocalDateTime<?> cldt = date.atTime(LocalTime.NOON);
+ ChronoLocalDate ld = cldt.toLocalDate();
+ ChronoLocalDateTime<?> noonTomorrow = tomorrowNoon(ld);
+ }
+
@Test
public void test_library() {
HijrahDate date = HijrahDate.now();
HijrahDate next = next(date);
ChronoLocalDateTime<HijrahDate> noonTomorrow = tomorrowNoon(date);
+ HijrahDate hd3 = noonTomorrow.toLocalDate();
System.out.printf(" now: %s, noon tomorrow: %s%n", date, noonTomorrow);
}
@@ -175,8 +199,9 @@
* @param date a specific date extending ChronoLocalDate
* @return a new date in the same chronology.
*/
- private <D extends ChronoLocalDate<D>> D next(D date) {
- return date.plus(1, ChronoUnit.DAYS);
+ @SuppressWarnings("unchecked")
+ private <D extends ChronoLocalDate> D next(D date) {
+ return (D) date.plus(1, ChronoUnit.DAYS);
}
/**
@@ -186,7 +211,8 @@
* @param date a specific date extending ChronoLocalDate
* @return a [@code ChronoLocalDateTime<D>} using the change chronology.
*/
- private <D extends ChronoLocalDate<D>> ChronoLocalDateTime<D> tomorrowNoon(D date) {
- return date.plus(1, ChronoUnit.DAYS).atTime(LocalTime.of(12, 0));
+ @SuppressWarnings("unchecked")
+ private <D extends ChronoLocalDate> ChronoLocalDateTime<D> tomorrowNoon(D date) {
+ return (ChronoLocalDateTime<D>) date.plus(1, ChronoUnit.DAYS).atTime(LocalTime.of(12, 0));
}
}
--- a/jdk/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java Thu Jul 25 20:30:58 2013 -0400
@@ -61,12 +61,15 @@
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.OffsetDateTime;
+import java.time.ZonedDateTime;
import java.time.ZoneOffset;
import java.time.chrono.JapaneseChronology;
+import java.time.chrono.JapaneseEra;
import java.time.chrono.JapaneseDate;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
+import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
@@ -85,7 +88,7 @@
@DataProvider(name="RangeVersusCalendar")
Object[][] provider_rangeVersusCalendar() {
return new Object[][] {
- {LocalDate.of(1868, 1, 1), LocalDate.of(2100, 1, 1)},
+ {LocalDate.of(1873, 1, 1), LocalDate.of(2100, 1, 1)},
};
}
@@ -118,4 +121,32 @@
}
}
+ //-----------------------------------------------------------------------
+ // Verify Japanese Calendar matches java.util.Calendar for number of days
+ // in years 1 and 2.
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_dayOfYearVsCalendar() {
+ Locale locale = Locale.forLanguageTag("ja-JP-u-ca-japanese");
+ Calendar cal = java.util.Calendar.getInstance(locale);
+
+ for (JapaneseEra era : JapaneseEra.values()) {
+ for (int year : new int[] {6, 7}) {
+ JapaneseDate jd = JapaneseChronology.INSTANCE.dateYearDay(era, year, 1);
+ OffsetDateTime jodt = OffsetDateTime.of(LocalDate.from(jd), LocalTime.MIN, ZoneOffset.UTC);
+ long millis = jodt.toInstant().toEpochMilli();
+ cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
+ cal.setTimeInMillis(millis);
+
+ assertEquals(jd.get(ChronoField.DAY_OF_YEAR), cal.get(Calendar.DAY_OF_YEAR),
+ "different DAY_OF_YEAR values in " + era + ", year: " + year);
+ assertEquals(jd.range(ChronoField.DAY_OF_YEAR).getMaximum(), cal.getActualMaximum(Calendar.DAY_OF_YEAR),
+ "different maximum for DAY_OF_YEAR in " + era + ", year: " + year);
+ assertEquals(jd.range(ChronoField.DAY_OF_YEAR).getMinimum(), cal.getActualMinimum(Calendar.DAY_OF_YEAR),
+ "different minimum for DAY_OF_YEAR in " + era + ", year: " + year);
+ }
+ }
+
+ }
+
}
--- a/jdk/test/java/time/test/java/time/chrono/TestJapaneseChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/chrono/TestJapaneseChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -47,9 +47,6 @@
Object[][] transitionData() {
return new Object[][] {
// Japanese era, yearOfEra, month, dayOfMonth, gregorianYear
- { JapaneseEra.SEIREKI, Year.MIN_VALUE, 1, 1, Year.MIN_VALUE },
- { JapaneseEra.SEIREKI, 1867, 12, 31, 1867 },
- { JapaneseEra.MEIJI, 1, 1, 25, 1868 }, // Note: the dates of Meiji 1 to 5 are incorrect
{ JapaneseEra.MEIJI, 6, 1, 1, 1873 },
// Meiji-Taisho transition isn't accurate. 1912-07-30 is the last day of Meiji
// and the first day of Taisho.
@@ -84,9 +81,10 @@
Object[][] rangeData() {
return new Object[][] {
// field, minSmallest, minLargest, maxSmallest, maxLargest
- { ChronoField.ERA, -999, -999, 2, 2},
- { ChronoField.YEAR_OF_ERA, -999999999, 1, 15, 999999999-1989 }, // depends on the current era
+ { ChronoField.ERA, -1, -1, 2, 2},
+ { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-1989 }, // depends on the current era
{ ChronoField.DAY_OF_YEAR, 1, 1, 7, 366},
+ { ChronoField.YEAR, 1873, 1873, 999999999, 999999999},
};
}
@@ -94,9 +92,6 @@
Object[][] invalidDatesData() {
return new Object[][] {
// Japanese era, yearOfEra, month, dayOfMonth
- { JapaneseEra.SEIREKI, Year.MIN_VALUE - 1, 1, 1 },
- { JapaneseEra.SEIREKI, 1855, 2, 29 },
- { JapaneseEra.SEIREKI, 1868, 1, 25 },
{ JapaneseEra.MEIJI, 6, 2, 29 },
{ JapaneseEra.MEIJI, 45, 7, 30 },
{ JapaneseEra.MEIJI, 46, 1, 1 },
@@ -118,8 +113,6 @@
Object[][] invalidEraYearData() {
return new Object[][] {
// Japanese era, yearOfEra
- { JapaneseEra.SEIREKI, Year.MIN_VALUE - 1 },
- { JapaneseEra.SEIREKI, 2012 },
{ JapaneseEra.MEIJI, -1 },
{ JapaneseEra.MEIJI, 0 },
{ JapaneseEra.MEIJI, 46 },
--- a/jdk/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Thu Jul 25 20:30:58 2013 -0400
@@ -28,27 +28,57 @@
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.YEAR;
+import static java.time.temporal.ChronoField.DAY_OF_YEAR;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.time.DateTimeException;
+import java.time.DayOfWeek;
import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.Period;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoZonedDateTime;
import java.time.chrono.Chronology;
import java.time.chrono.HijrahChronology;
import java.time.chrono.HijrahDate;
+import java.time.chrono.JapaneseChronology;
+import java.time.chrono.JapaneseDate;
+import java.time.chrono.MinguoChronology;
+import java.time.chrono.MinguoDate;
+import java.time.chrono.ThaiBuddhistChronology;
+import java.time.chrono.ThaiBuddhistDate;
+import java.time.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalAdjuster;
import java.time.temporal.ValueRange;
+import java.time.temporal.WeekFields;
+import java.util.Locale;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
- * Tests for the Umm alQura chronology and data
+ * Tests for the Umm alQura chronology and data.
+ * Note: The dates used for testing are just a sample of calendar data.
*/
@Test
public class TestUmmAlQuraChronology {
+ private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
+ private static final ZoneId ZONE_RIYADH = ZoneId.of("Asia/Riyadh");
+
+ // Test for HijrahChronology Aliases
@Test
public void test_aliases() {
HijrahChronology hc = (HijrahChronology) Chronology.of("Hijrah");
@@ -57,49 +87,43 @@
assertEquals(hc, HijrahChronology.INSTANCE, "Alias for Hijrah-umalqura");
}
- //-----------------------------------------------------------------------
- // regular data factory for Umm alQura dates and the corresponding ISO dates
- //-----------------------------------------------------------------------
- @DataProvider(name = "UmmalQuraVsISODates")
- Object[][] data_of_ummalqura() {
- return new Object[][]{
-
- //{1318, 01, 01, 1900, 04, 30},
- //{1318, 01, 02, 1900, 05, 01},
+ // Test to check if the exception is thrown for an incorrect chronology id
+ @Test(expectedExceptions=DateTimeException.class)
+ public void test_badChronology() {
+ Chronology test = Chronology.of("Hijrah-ummalqura");
+ }
- //{1318, 12, 29, 1901, 04, 18},
- //{1319, 01, 01, 1901, 04, 19},
-
- //{1433, 12, 29, 2012, 11, 14},
- //{1434, 01, 01, 2012, 11, 15},
-
- {1434, 02, 18, 2012, 12, 31},
- {1434, 02, 19, 2013, 01, 01},
-
- //{1502, 12, 30, 2079, 10, 25},
- // not in Umm alQura data {1503, 01, 01, 2079, 10, 26},
-
- // not in Umm alQura data {1503, 06, 28, 2080, 04, 18},
- // not in Umm alQura data ~/ws/Downloads
+ //--------------------------------------------------------------------------
+ // regular data factory for Umm alQura dates and the corresponding ISO dates
+ //--------------------------------------------------------------------------
+ @DataProvider(name = "UmmAlQuraVsISODates")
+ Object[][] data_UmmAlQuraVsISODates() {
+ return new Object[][] {
+ {HijrahDate.of(1318, 1, 1), LocalDate.of(1900, 04, 30)},
+ {HijrahDate.of(1318, 12, 29), LocalDate.of(1901, 04, 19)},
+ {HijrahDate.of(1319, 01, 01), LocalDate.of(1901, 04, 20)},
+ {HijrahDate.of(1433, 12, 29), LocalDate.of(2012, 11, 14)},
+ {HijrahDate.of(1434, 01, 01), LocalDate.of(2012, 11, 15)},
+ {HijrahDate.of(1434, 02, 18), LocalDate.of(2012, 12, 31)},
+ {HijrahDate.of(1502, 12, 29), LocalDate.of(2079, 10, 25)},
};
}
- @Test(dataProvider="UmmalQuraVsISODates")
- public void Test_UmmAlQuraDatesVsISO(int h_year, int h_month, int h_day, int iso_year, int iso_month, int iso_day) {
- HijrahDate hd = HijrahDate.of(h_year, h_month, h_day);
- LocalDate ld = LocalDate.of(iso_year, iso_month, iso_day);
+ // Test to verify the epoch days for given Hijrah & ISO date instances
+ @Test(dataProvider="UmmAlQuraVsISODates")
+ public void Test_UmmAlQuraVsISODates(HijrahDate hd, LocalDate ld) {
assertEquals(hd.toEpochDay(), ld.toEpochDay(), "Umm alQura date and ISO date should have same epochDay");
}
-
+ // UmmAlQura chronology ranges for year, month and days for the HijrahChronology
@Test
public void Test_UmmAlQuraChronoRange() {
HijrahChronology chrono = HijrahChronology.INSTANCE;
ValueRange year = chrono.range(YEAR);
- assertEquals(year.getMinimum(), 1432, "Minimum year");
- assertEquals(year.getLargestMinimum(), 1432, "Largest minimum year");
- assertEquals(year.getMaximum(), 1435, "Largest year");
- assertEquals(year.getSmallestMaximum(), 1435, "Smallest Maximum year");
+ assertEquals(year.getMinimum(), 1300, "Minimum year");
+ assertEquals(year.getLargestMinimum(), 1300, "Largest minimum year");
+ assertEquals(year.getMaximum(), 1600, "Largest year");
+ assertEquals(year.getSmallestMaximum(), 1600, "Smallest Maximum year");
ValueRange month = chrono.range(MONTH_OF_YEAR);
assertEquals(month.getMinimum(), 1, "Minimum month");
@@ -118,13 +142,17 @@
// regular data factory for dates and the corresponding range values
//-----------------------------------------------------------------------
@DataProvider(name = "dates")
- Object[][] data_of_calendars() {
+ Object[][] data_dates() {
return new Object[][]{
- {HijrahDate.of(1434, 5, 1), 1432, 1435, 1, 12, 1, 29, 30},
- {HijrahDate.of(1434, 6, 1), 1432, 1435, 1, 12, 1, 30, 30},
+ {HijrahDate.of(1300, 5, 1), 1300, 1600, 1, 12, 1, 30, 30},
+ {HijrahDate.of(1300, 6, 1), 1300, 1600, 1, 12, 1, 29, 30},
+ {HijrahDate.of(1434, 12, 1), 1300, 1600, 1, 12, 1, 29, 30},
+ {HijrahDate.of(1500, 4, 1), 1300, 1600, 1, 12, 1, 30, 30},
+ {HijrahDate.of(1600, 6, 1), 1300, 1600, 1, 12, 1, 29, 30},
};
}
+ // Test to verify the min/max field ranges for given dates
@Test(dataProvider="dates")
public void Test_UmmAlQuraRanges(HijrahDate date,
int minYear, int maxYear,
@@ -163,6 +191,7 @@
}
+ // Check the date limits
@Test
public void test_hijrahDateLimits() {
HijrahChronology chrono = HijrahChronology.INSTANCE;
@@ -193,33 +222,547 @@
}
}
- @DataProvider(name="badDates")
- Object[][] data_badDates() {
+ // Data provider to verify the dateYearDay() method
+ @DataProvider(name="dateYearDay")
+ Object[][] data_dateYearDay() {
return new Object[][] {
- {1317, 12, 29},
- {1317, 12, 30},
+ {HijrahChronology.INSTANCE.dateYearDay(1434, 42), HijrahChronology.INSTANCE.date(1434, 02, 13)},
+ {HijrahChronology.INSTANCE.dateYearDay(1330, 354), HijrahChronology.INSTANCE.date(1330, 12, 29)},
+ {HijrahChronology.INSTANCE.dateYearDay(1600, 1), HijrahChronology.INSTANCE.date(1600, 1, 1)},
+ {HijrahChronology.INSTANCE.dateYearDay(1400, 175), HijrahChronology.INSTANCE.date(1400, 6, 28)},
+ {HijrahChronology.INSTANCE.dateYearDay(1520, 190), HijrahChronology.INSTANCE.date(1520, 7, 13)},
+ {HijrahChronology.INSTANCE.dateYearDay(1521, 112), HijrahChronology.INSTANCE.date(1521, 4, 25)},
+ };
+ }
+
+ // Test to verify the dateYearDay() method
+ @Test(dataProvider="dateYearDay")
+ public void test_DateYearDay(ChronoLocalDate date1, ChronoLocalDate date2) {
+ assertEquals(date1, date2);
+ }
+
+ //-----------------------------------------------------------------------
+ // HijrahDate.with(DAY_OF_YEAR, n)
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_getDayOfYear() {
+ HijrahDate hd1 = HijrahChronology.INSTANCE.dateYearDay(1434, 1);
+ for (int i = 1; i <= hd1.lengthOfYear(); i++) {
+ HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1434, i);
+ int doy = hd.get(DAY_OF_YEAR);
+ assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i);
+ }
+ }
+
+ @Test
+ public void test_withDayOfYear() {
+ HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1434, 1);
+ for (int i = 1; i <= hd.lengthOfYear(); i++) {
+ HijrahDate hd2 = hd.with(DAY_OF_YEAR, i);
+ int doy = hd2.get(DAY_OF_YEAR);
+ assertEquals(doy, i, "with(DAY_OF_YEAR) incorrect for " + i + " " + hd2);
+ }
+ }
+
+ @Test(expectedExceptions=java.time.DateTimeException.class)
+ public void test_withDayOfYearTooSmall() {
+ HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1435, 1);
+ HijrahDate hd2 = hd.with(DAY_OF_YEAR, 0);
+ }
+
+ @Test(expectedExceptions=java.time.DateTimeException.class)
+ public void test_withDayOfYearTooLarge() {
+ HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1435, 1);
+ HijrahDate hd2 = hd.with(DAY_OF_YEAR, hd.lengthOfYear() + 1);
+ }
+
+ // Test to verify the with() method with ChronoField is set to DAY_OF_WEEK
+ @Test
+ public void test_adjustWithDayOfWeek() {
+ assertEquals(HijrahChronology.INSTANCE.date(1320, 1, 15).with(ChronoField.DAY_OF_WEEK, 4), HijrahDate.of(1320, 1, 15));
+ assertEquals(HijrahChronology.INSTANCE.date(1421, 11, 15).with(ChronoField.DAY_OF_WEEK, 1), HijrahDate.of(1421, 11, 11));
+ assertEquals(HijrahChronology.INSTANCE.date(1529, 7, 18).with(ChronoField.DAY_OF_WEEK, 6), HijrahDate.of(1529, 7, 20));
+ assertEquals(HijrahChronology.INSTANCE.date(1534, 2, 10).with(ChronoField.DAY_OF_WEEK, 5), HijrahDate.of(1534, 2, 12));
+ assertEquals(HijrahChronology.INSTANCE.date(1552, 4, 1).with(ChronoField.DAY_OF_WEEK, 2), HijrahDate.of(1552, 3, 26));
+ }
+
+ // Test to verify the with() method with ChronoField is set to DAY_OF_MONTH
+ @Test
+ public void test_adjustWithDayOfMonth() {
+ assertEquals(HijrahChronology.INSTANCE.date(1320, 1, 15).with(ChronoField.DAY_OF_MONTH, 2), HijrahDate.of(1320, 1, 2));
+ assertEquals(HijrahChronology.INSTANCE.date(1421, 11, 15).with(ChronoField.DAY_OF_MONTH, 9), HijrahDate.of(1421, 11, 9));
+ assertEquals(HijrahChronology.INSTANCE.date(1529, 7, 18).with(ChronoField.DAY_OF_MONTH, 13), HijrahDate.of(1529, 7, 13));
+ assertEquals(HijrahChronology.INSTANCE.date(1534, 12, 10).with(ChronoField.DAY_OF_MONTH, 29), HijrahDate.of(1534, 12, 29));
+ assertEquals(HijrahChronology.INSTANCE.date(1552, 4, 1).with(ChronoField.DAY_OF_MONTH, 6), HijrahDate.of(1552, 4, 6));
+ }
+
+ // Test to verify the with() method with ChronoField is set to DAY_OF_YEAR
+ @Test
+ public void test_adjustWithDayOfYear() {
+ assertEquals(HijrahChronology.INSTANCE.date(1320, 1, 15).with(ChronoField.DAY_OF_YEAR, 24), HijrahDate.of(1320, 1, 24));
+ assertEquals(HijrahChronology.INSTANCE.date(1421, 11, 15).with(ChronoField.DAY_OF_YEAR, 135), HijrahDate.of(1421, 5, 18));
+ assertEquals(HijrahChronology.INSTANCE.date(1529, 7, 18).with(ChronoField.DAY_OF_YEAR, 64), HijrahDate.of(1529, 3, 5));
+ assertEquals(HijrahChronology.INSTANCE.date(1534, 2, 10).with(ChronoField.DAY_OF_YEAR, 354), HijrahDate.of(1534, 12, 29));
+ assertEquals(HijrahChronology.INSTANCE.date(1552, 4, 1).with(ChronoField.DAY_OF_YEAR, 291), HijrahDate.of(1552, 10, 26));
+ }
+
+ // Data provider to get the difference between two dates in terms of days, months and years
+ @DataProvider(name="datesForDiff")
+ Object[][] data_datesForDiffs() {
+ return new Object[][] {
+ {HijrahDate.of(1350, 5, 15), HijrahDate.of(1351, 12, 29), 574, 19, 1},
+ {HijrahDate.of(1434, 5, 1), HijrahDate.of(1434,6, 12), 40, 1, 0},
+ {HijrahDate.of(1436, 1, 1), HijrahDate.of(1475, 12, 29), 14173, 479, 39},
+ {HijrahDate.of(1500, 6, 12), HijrahDate.of(1551, 7, 12), 18102, 613, 51},
+ {HijrahDate.of(1550, 3, 11), HijrahDate.of(1551, 4, 11), 384, 13, 1},
+ };
+ }
+
+ // Test to verify the difference between two given dates in terms of days, months and years
+ @Test(dataProvider="datesForDiff")
+ public void test_diffBetweenDates(ChronoLocalDate from, ChronoLocalDate to, long days, long months, long years) {
+ assertEquals(from.until(to, ChronoUnit.DAYS), days);
+ assertEquals(from.until(to, ChronoUnit.MONTHS), months);
+ assertEquals(from.until(to, ChronoUnit.YEARS), years);
+ }
+
+ // Data provider to get the difference between two dates as a period
+ @DataProvider(name="datesForPeriod")
+ Object[][] data_Period() {
+ return new Object[][] {
+ {HijrahDate.of(1350, 5, 15), HijrahDate.of(1434, 7, 20), Period.of(84, 2, 5)},
+ {HijrahDate.of(1403, 5, 28), HijrahDate.of(1434, 7, 20), Period.of(31, 1, 22)},
+ {HijrahDate.of(1434, 7, 20), HijrahDate.of(1484, 2, 15), Period.of(49, 6, 24)},
+ {HijrahDate.of(1500, 6, 12), HijrahDate.of(1450, 4, 21), Period.of(-50, -1, -20)},
+ {HijrahDate.of(1549, 3, 11), HijrahDate.of(1550, 3, 10), Period.of(0, 11, 28)},
+ };
+ }
+
+ // Test to get the Period between two given dates
+ @Test(dataProvider="datesForPeriod")
+ public void test_until(HijrahDate h1, HijrahDate h2, Period p) {
+ Period period = h1.until(h2);
+ assertEquals(period, p);
+ }
- {1320, 1, 29 + 1},
- {1320, 2, 30 + 1},
- {1320, 3, 29 + 1},
- {1320, 4, 29 + 1},
- {1320, 5, 30 + 1},
- {1320, 6, 29 + 1},
- {1320, 7, 30 + 1},
- {1320, 8, 30 + 1},
- {1320, 9, 29 + 1},
- {1320, 10, 30 + 1},
- {1320, 11, 30 + 1},
- {1320, 12, 30 + 1},
+ // Test to get the Period between dates in different chronologies
+ @Test(dataProvider="datesForPeriod")
+ public void test_periodUntilDiffChrono(HijrahDate h1, HijrahDate h2, Period p) {
+ MinguoDate m = MinguoChronology.INSTANCE.date(h2);
+ Period period = h1.until(m);
+ assertEquals(period, p);
+ }
+
+ // Test to get the adjusted date from a given date using TemporalAdjuster methods
+ @Test
+ public void test_temporalDayAdjustments() {
+ HijrahDate date = HijrahDate.of(1554, 7, 21);
+ assertEquals(date.with(TemporalAdjuster.firstDayOfMonth()), HijrahDate.of(1554, 7, 1));
+ assertEquals(date.with(TemporalAdjuster.lastDayOfMonth()), HijrahDate.of(1554, 7, 29));
+ assertEquals(date.with(TemporalAdjuster.firstDayOfNextMonth()), HijrahDate.of(1554, 8, 1));
+ assertEquals(date.with(TemporalAdjuster.firstDayOfNextYear()), HijrahDate.of(1555, 1, 1));
+ assertEquals(date.with(TemporalAdjuster.firstDayOfYear()), HijrahDate.of(1554, 1, 1));
+ assertEquals(date.with(TemporalAdjuster.lastDayOfYear()), HijrahDate.of(1554, 12, 30));
+ }
+
+ // Data provider for string representation of the date instances
+ @DataProvider(name="toString")
+ Object[][] data_toString() {
+ return new Object[][] {
+ {HijrahChronology.INSTANCE.date(1320, 1, 1), "Hijrah-umalqura AH 1320-01-01"},
+ {HijrahChronology.INSTANCE.date(1500, 10, 28), "Hijrah-umalqura AH 1500-10-28"},
+ {HijrahChronology.INSTANCE.date(1500, 10, 29), "Hijrah-umalqura AH 1500-10-29"},
+ {HijrahChronology.INSTANCE.date(1434, 12, 5), "Hijrah-umalqura AH 1434-12-05"},
+ {HijrahChronology.INSTANCE.date(1434, 12, 6), "Hijrah-umalqura AH 1434-12-06"},
+ };
+ }
+
+ // Test to verify the returned string value of a given date instance
+ @Test(dataProvider="toString")
+ public void test_toString(ChronoLocalDate hijrahDate, String expected) {
+ assertEquals(hijrahDate.toString(), expected);
+ }
+
+ // Data provider for maximum number of days
+ @DataProvider(name="monthDays")
+ Object[][] data_monthDays() {
+ return new Object[][] {
+ {1432, 1, 29},
+ {1432, 4, 30},
+ {1433, 12, 29},
+ {1434, 1, 29},
+ {1435, 8, 29},
+ {1435, 9, 30},
+ };
+ }
+
+ // Test to verify the maximum number of days by adding one month to a given date
+ @Test (dataProvider="monthDays")
+ public void test_valueRange_monthDays(int year, int month, int maxlength) {
+ ChronoLocalDate date = HijrahChronology.INSTANCE.date(year, month, 1);
+ ValueRange range = null;
+ for (int i=1; i<=12; i++) {
+ range = date.range(ChronoField.DAY_OF_MONTH);
+ date = date.plus(1, ChronoUnit.MONTHS);
+ assertEquals(range.getMaximum(), month, maxlength);
+ }
+ }
+
+ // Test to get the last day of the month by adjusting the date with lastDayOfMonth() method
+ @Test(dataProvider="monthDays")
+ public void test_lastDayOfMonth(int year, int month, int numDays) {
+ HijrahDate hDate = HijrahChronology.INSTANCE.date(year, month, 1);
+ hDate = hDate.with(TemporalAdjuster.lastDayOfMonth());
+ assertEquals(hDate.get(ChronoField.DAY_OF_MONTH), numDays);
+ }
+
+ // Data provider for the 12 islamic month names in a formatted date
+ @DataProvider(name="patternMonthNames")
+ Object[][] data_patternMonthNames() {
+ return new Object[][] {
+ {1434, 1, 1, "01 AH Thu Muharram 1434"},
+ {1434, 2, 1, "01 AH Fri Safar 1434"},
+ {1434, 3, 1, "01 AH Sun Rabi\u02bb I 1434"},//the actual month name is Rabi Al-Awwal, but the locale data contains short form.
+ {1434, 4, 1, "01 AH Mon Rabi\u02bb II 1434"},//the actual month name is Rabi Al-Akhar, but the locale data contains short form.
+ {1434, 5, 1, "01 AH Wed Jumada I 1434"},//the actual month name is Jumada Al-Awwal, but the locale data contains short form.
+ {1434, 6, 1, "01 AH Thu Jumada II 1434"},//the actual month name is Jumada Al-Akhar, but the locale data contains short form.
+ {1434, 7, 1, "01 AH Sat Rajab 1434"},
+ {1434, 8, 1, "01 AH Mon Sha\u02bbban 1434"},
+ {1434, 9, 1, "01 AH Tue Ramadan 1434"},
+ {1434, 10, 1, "01 AH Thu Shawwal 1434"},
+ {1434, 11, 1, "01 AH Sat Dhu\u02bbl-Qi\u02bbdah 1434"},
+ {1434, 12, 1, "01 AH Sun Dhu\u02bbl-Hijjah 1434"},
+ };
+ }
+
+ // Test to verify the formatted dates
+ @Test(dataProvider="patternMonthNames")
+ public void test_ofPattern(int year, int month, int day, String expected) {
+ DateTimeFormatter test = DateTimeFormatter.ofPattern("dd G E MMMM yyyy");
+ assertEquals(test.format(HijrahDate.of(year, month, day)), expected);
+ }
+
+ // Data provider for localized dates
+ @DataProvider(name="chronoDateTimes")
+ Object[][] data_chronodatetimes() {
+ return new Object[][] {
+ {1432, 12, 29, "Safar 1, 1434 AH"},
+ {1433, 1, 30, "Safar 30, 1434 AH"},
+ {1434, 6, 30, "Rajab 30, 1435 AH"},
+ };
+ }
+
+ // Test to verify the localized dates using ofLocalizedDate() method
+ @Test(dataProvider="chronoDateTimes")
+ public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
+ HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
+ ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
+ hdt = hdt.plus(1, ChronoUnit.YEARS);
+ hdt = hdt.plus(1, ChronoUnit.MONTHS);
+ hdt = hdt.plus(1, ChronoUnit.DAYS);
+ hdt = hdt.plus(1, ChronoUnit.HOURS);
+ hdt = hdt.plus(1, ChronoUnit.MINUTES);
+ hdt = hdt.plus(1, ChronoUnit.SECONDS);
+ DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.forLanguageTag("en-US"));
+ assertEquals(df.format(hdt), expected);
+ }
+
+ // Data provider to get the day of the week in a given date
+ // The day of the week varies if the week starts with a saturday or sunday
+ @DataProvider(name="dayOfWeek")
+ Object[][] data_dayOfweek() {
+ return new Object[][] {
+ {HijrahDate.of(1434, 6, 24), 1, 7},
+ {HijrahDate.of(1432, 9, 3), 5, 4},
+ {HijrahDate.of(1334, 12, 29), 7, 6},
+ {HijrahDate.of(1354, 5, 24), 1, 7},
+ {HijrahDate.of(1465, 10, 2), 2, 1},
};
}
- @Test(dataProvider="badDates", expectedExceptions=DateTimeException.class)
- public void test_badDates(int year, int month, int dom) {
- HijrahChronology.INSTANCE.date(year, month, dom);
+ // Test to get the day of the week based on a Saturday/Sunday as the first day of the week
+ @Test(dataProvider="dayOfWeek")
+ public void test_dayOfWeek(HijrahDate date, int satStart, int sunStart) {
+ assertEquals(date.get(WeekFields.of(DayOfWeek.SATURDAY, 7).dayOfWeek()), satStart);
+ assertEquals(date.get(WeekFields.of(DayOfWeek.SUNDAY, 7).dayOfWeek()), sunStart);
+ }
+
+ // Data sample to get the epoch days of a date instance
+ @DataProvider(name="epochDays")
+ Object[][] data_epochdays() {
+ return new Object[][] {
+ {1332, -20486},
+ {1334, -19777},
+ {1336, -19068},
+ {1432, 14950},
+ {1434, 15659},
+ {1534, 51096},
+ {1535, 51450},
+ };
+ }
+
+ // Test to verify the number of epoch days of a date instance
+ @Test(dataProvider="epochDays")
+ public void test_epochDays(int y, long epoch) {
+ HijrahDate date = HijrahDate.of(y, 1, 1);
+ assertEquals(date.toEpochDay(), epoch);
+ }
+
+ // Data provider to verify whether a given hijrah year is a leap year or not
+ @DataProvider(name="leapYears")
+ Object[][] data_leapyears() {
+ return new Object[][] {
+ {1302, true},
+ {1305, false},
+ {1315, false},
+ {1534, false},
+ {1411, true},
+ {1429, false},
+ {1433, true},
+ {1443, true},
+ };
+ }
+
+ // Test to verify whether a given hijrah year is a leap year or not
+ @Test(dataProvider="leapYears")
+ public void test_leapYears(int y, boolean leapyear) {
+ HijrahDate date = HijrahDate.of(y, 1, 1);
+ assertEquals(date.isLeapYear(), leapyear);
+ }
+
+ // Date samples to convert HijrahDate to LocalDate and vice versa
+ @DataProvider(name="samples")
+ Object[][] data_samples() {
+ return new Object[][] {
+ {HijrahChronology.INSTANCE.date(1319, 12, 30), LocalDate.of(1902, 4, 9)},
+ {HijrahChronology.INSTANCE.date(1320, 1, 1), LocalDate.of(1902, 4, 10)},
+ {HijrahChronology.INSTANCE.date(1321, 12, 30), LocalDate.of(1904, 3, 18)},
+ {HijrahChronology.INSTANCE.date(1433, 7, 29), LocalDate.of(2012, 6, 19)},
+ {HijrahChronology.INSTANCE.date(1434, 10, 12), LocalDate.of(2013, 8, 19)},
+ {HijrahChronology.INSTANCE.date(1500, 3, 3), LocalDate.of(2077, 1, 28)},
+ };
+ }
+
+ // Test to get LocalDate instance from a given HijrahDate
+ @Test(dataProvider="samples")
+ public void test_toLocalDate(ChronoLocalDate hijrahDate, LocalDate iso) {
+ assertEquals(LocalDate.from(hijrahDate), iso);
+ }
+
+ // Test to adjust HijrahDate with a given LocalDate
+ @Test(dataProvider="samples")
+ public void test_adjust_toLocalDate(ChronoLocalDate hijrahDate, LocalDate iso) {
+ assertEquals(hijrahDate.with(iso), hijrahDate);
+ }
+
+ // Test to get a HijrahDate from a calendrical
+ @Test(dataProvider="samples")
+ public void test_fromCalendrical(ChronoLocalDate hijrahDate, LocalDate iso) {
+ assertEquals(HijrahChronology.INSTANCE.date(iso), hijrahDate);
+ }
+
+ // Test to verify the day of week of a given HijrahDate and LocalDate
+ @Test(dataProvider="samples")
+ public void test_dayOfWeekEqualIsoDayOfWeek(ChronoLocalDate hijrahDate, LocalDate iso) {
+ assertEquals(hijrahDate.get(ChronoField.DAY_OF_WEEK), iso.get(ChronoField.DAY_OF_WEEK), "Hijrah day of week should be same as ISO day of week");
+ }
+
+ // Test to get the local date by applying the MIN adjustment with hijrah date
+ @Test(dataProvider="samples")
+ public void test_LocalDate_adjustToHijrahDate(ChronoLocalDate hijrahDate, LocalDate localDate) {
+ LocalDate test = LocalDate.MIN.with(hijrahDate);
+ assertEquals(test, localDate);
+ }
+
+ // Test to get the local date time by applying the MIN adjustment with hijrah date
+ @Test(dataProvider="samples")
+ public void test_LocalDateTime_adjustToHijrahDate(ChronoLocalDate hijrahDate, LocalDate localDate) {
+ LocalDateTime test = LocalDateTime.MIN.with(hijrahDate);
+ assertEquals(test, LocalDateTime.of(localDate, LocalTime.MIDNIGHT));
+ }
+
+ // Sample dates for comparison
+ @DataProvider(name="datesForComparison")
+ Object[][] data_datesForComparison() {
+ return new Object[][] {
+ {HijrahChronology.INSTANCE.date(1434, 6, 26), LocalDate.of(2013, 5, 5), -1, 1},
+ {HijrahChronology.INSTANCE.date(1433, 4, 15), LocalDate.of(2012, 3, 15), 1, -1},
+ {HijrahChronology.INSTANCE.date(1432, 5, 21), LocalDate.of(2011, 4, 22), -1, 1},
+ {HijrahChronology.INSTANCE.date(1433, 7, 29), LocalDate.of(2012, 6, 2), -1, 1},
+ {HijrahChronology.INSTANCE.date(1434, 10, 12), LocalDate.of(2013, 8, 2), -1, 1},
+ };
+ }
+
+ // Test to compare dates in both forward and reverse order
+ @Test(dataProvider="datesForComparison")
+ public void test_compareDates(HijrahDate hdate, LocalDate ldate, int result1, int result2) {
+ assertEquals(ldate.compareTo(hdate), result1);
+ assertEquals(hdate.compareTo(ldate), result2);
+ }
+
+ // Test to verify the values of various chrono fields for a given hijrah date instance
+ @Test
+ public void test_chronoFields() {
+ ChronoLocalDate hdate = HijrahChronology.INSTANCE.date(1434, 6, 28);
+ assertEquals(hdate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), 3);
+ assertEquals(hdate.get(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), 7);
+ assertEquals(hdate.get(ChronoField.ALIGNED_WEEK_OF_MONTH), 4);
+ assertEquals(hdate.get(ChronoField.ALIGNED_WEEK_OF_YEAR), 25);
+ assertEquals(hdate.get(ChronoField.ERA), 1);
+ assertEquals(hdate.get(ChronoField.YEAR_OF_ERA), 1434);
+ assertEquals(hdate.get(ChronoField.MONTH_OF_YEAR), 6);
+ assertEquals(hdate.get(ChronoField.DAY_OF_MONTH), 28);
+ assertEquals(hdate.get(ChronoField.DAY_OF_WEEK), 3);
+ assertEquals(hdate.get(ChronoField.DAY_OF_YEAR), 175);
}
- void printRange(ValueRange range, Object obj, ChronoField field) {
- System.err.printf(" range: min: %d, max: %d; of: %s, field: %s%n", range.getMinimum(), range.getMaximum(), obj.toString(), field.toString());
+ // Test to verify the returned hijrah date after adjusting the day of week as Saturday
+ @Test
+ public void test_adjustInto() {
+ assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1434, 6, 28)), HijrahDate.of(1434, 7, 1));
+ assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1432, 4, 13)), HijrahDate.of(1432, 4, 14));
+ assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1433, 11, 29)), HijrahDate.of(1433, 12, 4));
+ assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1434, 5, 10)), HijrahDate.of(1434, 5, 11));
+ assertEquals(DayOfWeek.SATURDAY.adjustInto(HijrahDate.of(1434, 9, 11)), HijrahDate.of(1434, 9, 12));
+ }
+
+ //-----------------------------------------------------------------------
+ // zonedDateTime(TemporalAccessor)
+ //-----------------------------------------------------------------------
+ @DataProvider(name="zonedDateTime")
+ Object[][] data_zonedDateTime() {
+ return new Object[][] {
+ {ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
+ {OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
+ {LocalDateTime.of(2012, 2, 29, 2, 7), null, null, DateTimeException.class},
+ {JapaneseDate.of(2012, 2, 29), null, null, DateTimeException.class},
+ {ThaiBuddhistDate.of(2012 + 543, 2, 29), null, null, DateTimeException.class},
+ {LocalDate.of(2012, 2, 29), null, null, DateTimeException.class},
+ {LocalTime.of(20, 30, 29, 0), null, null, DateTimeException.class},
+ };
+ }
+
+ // Test to check the zoned date times
+ @Test(dataProvider="zonedDateTime")
+ public void test_zonedDateTime(TemporalAccessor accessor, HijrahDate expectedDate, LocalTime expectedTime, Class<?> expectedEx) {
+ if (expectedEx == null) {
+ ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(accessor);
+ assertEquals(result.toLocalDate(), expectedDate);
+ assertEquals(HijrahDate.from(accessor), expectedDate);
+ assertEquals(result.toLocalTime(), expectedTime);
+
+ } else {
+ try {
+ ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(accessor);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(expectedEx.isInstance(ex));
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ // zonedDateTime(Instant, ZoneId )
+ //-----------------------------------------------------------------------
+ @Test
+ public void test_Instant_zonedDateTime() {
+ OffsetDateTime offsetDateTime = OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO);
+ ZonedDateTime zonedDateTime = ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH);
+
+ ChronoZonedDateTime<HijrahDate> result = HijrahChronology.INSTANCE.zonedDateTime(offsetDateTime.toInstant(), offsetDateTime.getOffset());
+ assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
+ assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
+
+ result = HijrahChronology.INSTANCE.zonedDateTime(zonedDateTime.toInstant(), zonedDateTime.getOffset());
+ assertEquals(result.toLocalDate(), HijrahChronology.INSTANCE.date(1433, 4, 7));
+ assertEquals(result.toLocalTime(), LocalTime.of(2, 7, 1, 1));
+ }
+
+ //-----------------------------------------------------------------------
+ // localDateTime()
+ //-----------------------------------------------------------------------
+ @DataProvider(name="localDateTime")
+ Object[][] data_localDateTime() {
+ return new Object[][] {
+ {LocalDateTime.of(2012, 2, 29, 2, 7), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7), null},
+ {ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
+ {OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
+ {JapaneseDate.of(2012, 2, 29), null, null, DateTimeException.class},
+ {ThaiBuddhistDate.of(2012 + 543, 2, 29), null, null, DateTimeException.class},
+ {LocalDate.of(2012, 2, 29), null, null, DateTimeException.class},
+ {LocalTime.of(20, 30, 29, 0), null, null, DateTimeException.class},
+ };
+ }
+
+ // Test to verify local date time values from various date instances defined in the localDateTime data provider
+ @Test(dataProvider="localDateTime")
+ public void test_localDateTime(TemporalAccessor accessor, HijrahDate expectedDate, LocalTime expectedTime, Class<?> expectedEx) {
+ if (expectedEx == null) {
+ ChronoLocalDateTime<HijrahDate> result = HijrahChronology.INSTANCE.localDateTime(accessor);
+ assertEquals(result.toLocalDate(), expectedDate);
+ assertEquals(HijrahDate.from(accessor), expectedDate);
+ assertEquals(result.toLocalTime(), expectedTime);
+ } else {
+ try {
+ ChronoLocalDateTime<HijrahDate> result = HijrahChronology.INSTANCE.localDateTime(accessor);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(expectedEx.isInstance(ex));
+ }
+ }
+ }
+
+ // Sample Hijrah & Minguo Dates
+ @DataProvider(name="hijrahToMinguo")
+ Object[][] data_hijrahToMinguo() {
+ return new Object[][] {
+ {HijrahDate.of(1350,5,15), MinguoDate.of(20,9,28)},
+ {HijrahDate.of(1434,5,1), MinguoDate.of(102,3,13)},
+ {HijrahDate.of(1436,1,1), MinguoDate.of(103,10,25)},
+ {HijrahDate.of(1500,6,12), MinguoDate.of(166,5,5)},
+ {HijrahDate.of(1550,3,11), MinguoDate.of(214,8,11)},
+ };
+ }
+
+ // Test to verify the date conversion from Hijrah to Minguo chronology
+ @Test(dataProvider="hijrahToMinguo")
+ public void test_hijrahToMinguo(HijrahDate hijrah, MinguoDate minguo) {
+ assertEquals(MinguoChronology.INSTANCE.date(hijrah), minguo);
+ }
+
+ // Sample Hijrah & Thai Dates
+ @DataProvider(name="hijrahToThai")
+ Object[][] data_hijrahToThai() {
+ return new Object[][] {
+ {HijrahDate.of(1350,5,15), ThaiBuddhistDate.of(2474,9,28)},
+ {HijrahDate.of(1434,5,1), ThaiBuddhistDate.of(2556,3,13)},
+ {HijrahDate.of(1436,1,1), ThaiBuddhistDate.of(2557,10,25)},
+ {HijrahDate.of(1500,6,12), ThaiBuddhistDate.of(2620,5,5)},
+ {HijrahDate.of(1550,3,11), ThaiBuddhistDate.of(2668,8,11)},
+ };
+ }
+
+ // Test to verify the date conversion from Hijrah to Thai chronology
+ @Test(dataProvider="hijrahToThai")
+ public void test_hijrahToThai(HijrahDate hijrah, ThaiBuddhistDate thai) {
+ assertEquals(ThaiBuddhistChronology.INSTANCE.date(hijrah), thai);
+ }
+
+ // Sample Hijrah & Japanese Dates
+ @DataProvider(name="hijrahToJapanese")
+ Object[][] data_hijrahToJapanese() {
+ return new Object[][] {
+ {HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"},
+ {HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"},
+ {HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"},
+ {HijrahDate.of(1500,6,12), "Japanese Heisei 89-05-05"},
+ {HijrahDate.of(1550,3,11), "Japanese Heisei 137-08-11"},
+ };
+ }
+
+ // Test to verify the date conversion from Hijrah to Japanese chronology
+ @Test(dataProvider="hijrahToJapanese")
+ public void test_hijrahToJapanese(HijrahDate hijrah, String japanese) {
+ assertEquals(JapaneseChronology.INSTANCE.date(hijrah).toString(), japanese);
}
}
--- a/jdk/test/java/time/test/java/time/format/TestDateTimeTextProvider.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/format/TestDateTimeTextProvider.java Thu Jul 25 20:30:58 2013 -0400
@@ -131,18 +131,18 @@
{MONTH_OF_YEAR, 11, TextStyle.SHORT, enUS, "Nov"},
{MONTH_OF_YEAR, 12, TextStyle.SHORT, enUS, "Dec"},
- {MONTH_OF_YEAR, 1, TextStyle.SHORT, ptBR, "Jan"},
- {MONTH_OF_YEAR, 2, TextStyle.SHORT, ptBR, "Fev"},
- {MONTH_OF_YEAR, 3, TextStyle.SHORT, ptBR, "Mar"},
- {MONTH_OF_YEAR, 4, TextStyle.SHORT, ptBR, "Abr"},
- {MONTH_OF_YEAR, 5, TextStyle.SHORT, ptBR, "Mai"},
- {MONTH_OF_YEAR, 6, TextStyle.SHORT, ptBR, "Jun"},
- {MONTH_OF_YEAR, 7, TextStyle.SHORT, ptBR, "Jul"},
- {MONTH_OF_YEAR, 8, TextStyle.SHORT, ptBR, "Ago"},
- {MONTH_OF_YEAR, 9, TextStyle.SHORT, ptBR, "Set"},
- {MONTH_OF_YEAR, 10, TextStyle.SHORT, ptBR, "Out"},
- {MONTH_OF_YEAR, 11, TextStyle.SHORT, ptBR, "Nov"},
- {MONTH_OF_YEAR, 12, TextStyle.SHORT, ptBR, "Dez"},
+ {MONTH_OF_YEAR, 1, TextStyle.SHORT, ptBR, "jan"},
+ {MONTH_OF_YEAR, 2, TextStyle.SHORT, ptBR, "fev"},
+ {MONTH_OF_YEAR, 3, TextStyle.SHORT, ptBR, "mar"},
+ {MONTH_OF_YEAR, 4, TextStyle.SHORT, ptBR, "abr"},
+ {MONTH_OF_YEAR, 5, TextStyle.SHORT, ptBR, "mai"},
+ {MONTH_OF_YEAR, 6, TextStyle.SHORT, ptBR, "jun"},
+ {MONTH_OF_YEAR, 7, TextStyle.SHORT, ptBR, "jul"},
+ {MONTH_OF_YEAR, 8, TextStyle.SHORT, ptBR, "ago"},
+ {MONTH_OF_YEAR, 9, TextStyle.SHORT, ptBR, "set"},
+ {MONTH_OF_YEAR, 10, TextStyle.SHORT, ptBR, "out"},
+ {MONTH_OF_YEAR, 11, TextStyle.SHORT, ptBR, "nov"},
+ {MONTH_OF_YEAR, 12, TextStyle.SHORT, ptBR, "dez"},
{MONTH_OF_YEAR, 1, TextStyle.FULL, enUS, "January"},
{MONTH_OF_YEAR, 2, TextStyle.FULL, enUS, "February"},
--- a/jdk/test/java/time/test/java/time/format/TestNonIsoFormatter.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/format/TestNonIsoFormatter.java Thu Jul 25 20:30:58 2013 -0400
@@ -126,7 +126,7 @@
@Test(dataProvider="format_data")
public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale,
- ChronoLocalDate<?> date, String expected) {
+ ChronoLocalDate date, String expected) {
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
.withChronology(chrono).withLocale(formatLocale)
.withDecimalStyle(DecimalStyle.of(numberingLocale));
@@ -136,12 +136,12 @@
@Test(dataProvider="format_data")
public void test_parseLocalizedText(Chronology chrono, Locale formatLocale, Locale numberingLocale,
- ChronoLocalDate<?> expected, String text) {
+ ChronoLocalDate expected, String text) {
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
.withChronology(chrono).withLocale(formatLocale)
.withDecimalStyle(DecimalStyle.of(numberingLocale));
TemporalAccessor temporal = dtf.parse(text);
- ChronoLocalDate<?> date = chrono.date(temporal);
+ ChronoLocalDate date = chrono.date(temporal);
assertEquals(date, expected);
}
--- a/jdk/test/java/time/test/java/time/format/TestNumberPrinter.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/format/TestNumberPrinter.java Thu Jul 25 20:30:58 2013 -0400
@@ -191,7 +191,7 @@
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result == null || value < 0) {
- assertEquals(ex.getMessage().contains(DAY_OF_MONTH.getName()), true);
+ assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
} else {
throw ex;
}
@@ -210,7 +210,7 @@
if (result != null) {
throw ex;
}
- assertEquals(ex.getMessage().contains(DAY_OF_MONTH.getName()), true);
+ assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
@@ -226,7 +226,7 @@
if (result != null) {
throw ex;
}
- assertEquals(ex.getMessage().contains(DAY_OF_MONTH.getName()), true);
+ assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
@@ -242,7 +242,7 @@
if (result != null) {
throw ex;
}
- assertEquals(ex.getMessage().contains(DAY_OF_MONTH.getName()), true);
+ assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
@@ -262,7 +262,7 @@
if (result != null) {
throw ex;
}
- assertEquals(ex.getMessage().contains(DAY_OF_MONTH.getName()), true);
+ assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
--- a/jdk/test/java/time/test/java/time/format/TestReducedPrinter.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/format/TestReducedPrinter.java Thu Jul 25 20:30:58 2013 -0400
@@ -185,7 +185,7 @@
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result == null || value < 0) {
- assertEquals(ex.getMessage().contains(YEAR.getName()), true);
+ assertEquals(ex.getMessage().contains(YEAR.toString()), true);
} else {
throw ex;
}
--- a/jdk/test/java/time/test/java/time/temporal/MockFieldNoValue.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/temporal/MockFieldNoValue.java Thu Jul 25 20:30:58 2013 -0400
@@ -77,11 +77,6 @@
INSTANCE;
@Override
- public String getName() {
- return null;
- }
-
- @Override
public TemporalUnit getBaseUnit() {
return WEEKS;
}
@@ -96,6 +91,16 @@
return ValueRange.of(1, 20);
}
+ @Override
+ public boolean isDateBased() {
+ return false;
+ }
+
+ @Override
+ public boolean isTimeBased() {
+ return false;
+ }
+
//-----------------------------------------------------------------------
@Override
public boolean isSupportedBy(TemporalAccessor temporal) {
@@ -117,4 +122,9 @@
throw new DateTimeException("Mock");
}
+ @Override
+ public String toString() {
+ return null;
+ }
+
}
--- a/jdk/test/java/time/test/java/time/temporal/MockFieldValue.java Thu Jul 25 20:12:14 2013 -0400
+++ b/jdk/test/java/time/test/java/time/temporal/MockFieldValue.java Thu Jul 25 20:30:58 2013 -0400
@@ -89,7 +89,7 @@
if (isSupported(field)) {
return field.range();
}
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName());
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/xml/jaxp/parsers/8021148/JAXPSAXParserTest.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8021148
+ * @summary test that JAXPSAXParser works even if referenced directly
+ * @run main/othervm JAXPSAXParserTest
+ */
+import java.io.StringReader;
+import java.io.StringWriter;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+/**
+ * test that JAXPSAXParser works even if referenced directly as
+ * NetBeans did. **Note that JAXPSAXParser is an internal implementation, this
+ * may therefore change.
+ *
+ * @author huizhe.wang@oracle.com
+ */
+public class JAXPSAXParserTest extends TestBase {
+
+ public JAXPSAXParserTest(String name) {
+ super(name);
+ }
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ JAXPSAXParserTest test = new JAXPSAXParserTest("JAXP 1.5 regression");
+ test.setUp();
+ test.testTransform();
+ test.tearDown();
+ }
+
+ public final void testTransform() {
+ String data =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ + "<r>\n"
+ + " <e/>\n"
+ + "</r>\n";
+ String IDENTITY_XSLT_WITH_INDENT = // #5064280 workaround
+ "<xsl:stylesheet version='1.0' "
+ + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' "
+ + "xmlns:xalan='http://xml.apache.org/xslt' "
+ + "exclude-result-prefixes='xalan'>"
+ + "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>"
+ + "<xsl:template match='@*|node()'>"
+ + "<xsl:copy>"
+ + "<xsl:apply-templates select='@*|node()'/>"
+ + "</xsl:copy>"
+ + "</xsl:template>"
+ + "</xsl:stylesheet>";
+ try {
+ //Skip the default XMLReader
+ System.setProperty("org.xml.sax.driver", "com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser");
+
+ StringWriter sw = new StringWriter();
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer(new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
+ Result result = new StreamResult(sw);
+ t.transform(new StreamSource(new StringReader(data)), result);
+ success("JAXPSAXParserTest passed");
+ } catch (Exception e) {
+ /**
+ * JAXPSAXParser throws NullPointerException since the jaxp 1.5 security
+ * manager is not initialized when JAXPSAXParser is instantiated using
+ * the default constructor.
+ */
+ fail(e.toString());
+ } finally {
+ System.clearProperty("org.xml.sax.driver");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/xml/jaxp/parsers/8021148/TestBase.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.security.Policy;
+
+/**
+ *
+ *
+ * @author huizhe.wang@oracle.com
+ */
+public class TestBase {
+ String filePath;
+ boolean hasSM;
+ String curDir;
+ Policy origPolicy;
+
+ String testName;
+ static String errMessage;
+
+ int passed = 0, failed = 0;
+
+ /**
+ * Creates a new instance of StreamReader
+ */
+ public TestBase(String name) {
+ testName = name;
+ }
+
+ //junit @Override
+ protected void setUp() {
+ if (System.getSecurityManager() != null) {
+ hasSM = true;
+ System.setSecurityManager(null);
+ }
+
+ filePath = System.getProperty("test.src");
+ if (filePath == null) {
+ //current directory
+ filePath = System.getProperty("user.dir");
+ }
+ origPolicy = Policy.getPolicy();
+
+ }
+
+ //junit @Override
+ public void tearDown() {
+ // turn off security manager and restore policy
+ System.setSecurityManager(null);
+ Policy.setPolicy(origPolicy);
+ if (hasSM) {
+ System.setSecurityManager(new SecurityManager());
+ }
+ System.out.println("\nNumber of tests passed: " + passed);
+ System.out.println("Number of tests failed: " + failed + "\n");
+
+ if (errMessage != null ) {
+ throw new RuntimeException(errMessage);
+ }
+ }
+
+ void fail(String errMsg) {
+ if (errMessage == null) {
+ errMessage = errMsg;
+ } else {
+ errMessage = errMessage + "\n" + errMsg;
+ }
+ failed++;
+ }
+
+ void success(String msg) {
+ passed++;
+ System.out.println(msg);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/pkcs/pkcs9/UnstructuredName.java Thu Jul 25 20:30:58 2013 -0400
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8016916
+ * @summary UnstructuredName should support DirectoryString
+ */
+
+import java.util.Base64;
+import sun.security.pkcs10.PKCS10;
+
+public class UnstructuredName {
+
+ // Certificate request with an Unstructured Name attribute
+ static String csrStr =
+ "MIIBtjCCAR8CAQAwEzERMA8GA1UEAxMIdGVzdE5hbWUwgZ8wDQYJKoZIhvcNAQEB\n" +
+ "BQADgY0AMIGJAoGBAMTEIVCsM8IIhvsbzn6AwQFX5C8RGAWIrL6P5XEr1z+bvHx3\n" +
+ "XhPD4tWLCR6CTKq0lTlo+QKKct7MUY7pdKShajpyYD+1YLgEve0nNd4r5kVUeoHe\n" +
+ "CyIZoImONgAlmVD7M8IJjz2Vg84WVVjkHK67H5qt7Agi1hUnFGmRbJ8rbL7jAgMB\n" +
+ "AAGgYzAXBgkqhkiG9w0BCQcxChMIcGFzc3dvcmQwHAYJKoZIhvcNAQkCMQ8TDW9w\n" +
+ "dGlvbmFsIG5hbWUwKgYJKoZIhvcNAQkOMR0wGzAMBgNVHRMBAf8EAjAAMAsGA1Ud\n" +
+ "DwQEAwIGQDANBgkqhkiG9w0BAQUFAAOBgQBc7ldGSmyCjMU+ssjglCimqknCVdig\n" +
+ "N8FsI/aNRgLqf+eXKWZOxl1v3GB9HCXWDtqOnHd6AJKFpGtK0bqRu7bIncYIiQ1a\n" +
+ "P1NW4Kup8d1fTPhw6xgYtxeHvUxRa2y4IXskPUYqp05HavfNZxmcJ5mZOLtgiDIC\n" +
+ "I3J80saqEUQKqQ==";
+
+ public static void main(String[] args) throws Exception {
+ PKCS10 req = new PKCS10(Base64.getMimeDecoder().decode(csrStr));
+
+ // If PKCS9Attribute did not accept the PrintableString ASN.1 tag,
+ // this would fail with an IOException
+ Object attr = req.getAttributes().getAttribute("1.2.840.113549.1.9.2");
+
+ // Check that the attribute exists
+ if (attr == null) {
+ throw new Exception("Attribute should not be null.");
+ }
+
+ System.out.println("Test passed.");
+ }
+}