/** * Checks if the specified field is supported. * * <p>This checks if this offset 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 {@code * OFFSET_SECONDS} field returns true. 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 offset, false if not */ @Override public boolean isSupported(TemporalField field) { if (field instanceof ChronoField) { return field == OFFSET_SECONDS; } return field != null && field.isSupportedBy(this); }
/** * Gets the value of the specified field from this offset as a {@code long}. * * <p>This queries this offset for the value for the specified field. If it is not possible to * return the value, because the field is not supported or for some other reason, an exception is * thrown. * * <p>If the field is a {@link ChronoField} then the query is implemented here. The {@code * OFFSET_SECONDS} field returns the value of the offset. All other {@code ChronoField} instances * will throw an {@code UnsupportedTemporalTypeException}. * * <p>If the field is not a {@code ChronoField}, then the result of this method is obtained by * invoking {@code TemporalField.getFrom(TemporalAccessor)} passing {@code this} as the argument. * Whether the value can be obtained, and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained * @throws UnsupportedTemporalTypeException if the field is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override public long getLong(TemporalField field) { if (field == OFFSET_SECONDS) { return totalSeconds; } else if (field instanceof ChronoField) { throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }