< prev index next >

src/java.base/share/classes/java/time/format/DateTimePrintContext.java

Print this page




 285      */
 286     <R> R getValue(TemporalQuery<R> query) {
 287         R result = temporal.query(query);
 288         if (result == null && optional == 0) {
 289             throw new DateTimeException("Unable to extract " +
 290                     query + " from temporal " + temporal);
 291         }
 292         return result;
 293     }
 294 
 295     /**
 296      * Gets the value of the specified field.
 297      * <p>
 298      * This will return the value for the specified field.
 299      *
 300      * @param field  the field to find, not null
 301      * @return the value, null if not found and optional is true
 302      * @throws DateTimeException if the field is not available and the section is not optional
 303      */
 304     Long getValue(TemporalField field) {
 305         try {
 306             return temporal.getLong(field);
 307         } catch (DateTimeException ex) {
 308             if (optional > 0) {
 309                 return null;
 310             }
 311             throw ex;
 312         }
 313     }
 314 
 315     //-----------------------------------------------------------------------
 316     /**
 317      * Returns a string version of the context for debugging.
 318      *
 319      * @return a string representation of the context, not null
 320      */
 321     @Override
 322     public String toString() {
 323         return temporal.toString();
 324     }
 325 
 326 }


 285      */
 286     <R> R getValue(TemporalQuery<R> query) {
 287         R result = temporal.query(query);
 288         if (result == null && optional == 0) {
 289             throw new DateTimeException("Unable to extract " +
 290                     query + " from temporal " + temporal);
 291         }
 292         return result;
 293     }
 294 
 295     /**
 296      * Gets the value of the specified field.
 297      * <p>
 298      * This will return the value for the specified field.
 299      *
 300      * @param field  the field to find, not null
 301      * @return the value, null if not found and optional is true
 302      * @throws DateTimeException if the field is not available and the section is not optional
 303      */
 304     Long getValue(TemporalField field) {
 305         if (optional == 0) {
 306             return temporal.getLong(field);
 307         } else {
 308             return temporal.isSupported(field) ? temporal.getLong(field) : null;



 309         }
 310     }
 311 
 312     //-----------------------------------------------------------------------
 313     /**
 314      * Returns a string version of the context for debugging.
 315      *
 316      * @return a string representation of the context, not null
 317      */
 318     @Override
 319     public String toString() {
 320         return temporal.toString();
 321     }
 322 
 323 }
< prev index next >