本文整理汇总了Java中java.time.jdk8.Jdk7Methods.Objects_requireNonNull方法的典型用法代码示例。如果您正苦于以下问题:Java Jdk7Methods.Objects_requireNonNull方法的具体用法?Java Jdk7Methods.Objects_requireNonNull怎么用?Java Jdk7Methods.Objects_requireNonNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.jdk8.Jdk7Methods
的用法示例。
在下文中一共展示了Jdk7Methods.Objects_requireNonNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ofStrict
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code ZonedDateTime} strictly validating the combination of local date-time,
* offset and zone ID.
* <p>
* This creates a zoned date-time ensuring that the offset is valid for the local date-time according to the
* rules of the specified zone. If the offset is invalid, an exception is thrown.
*
* @param localDateTime the local date-time, not null
* @param offset the zone offset, not null
* @param zone the time-zone, not null
* @return the zoned date-time, not null
*/
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Jdk7Methods.Objects_requireNonNull(localDateTime, "localDateTime");
Jdk7Methods.Objects_requireNonNull(offset, "offset");
Jdk7Methods.Objects_requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
// ZoneOffsetTransition trans = rules.getTransition(localDateTime);
// if (trans != null && trans.isGap()) {
// // error message says daylight savings for simplicity
// // even though there are other kinds of gaps
// throw new DateTimeException("LocalDateTime '" + localDateTime + "' does not exist in zone '" + zone
// + "' due to a gap in the local time-line, typically caused by daylight savings");
// }
// throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
// localDateTime
// + "' in zone '" + zone + "'");
}
return new ZonedDateTime(localDateTime, offset, zone);
}
示例2: ofInstant
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code OffsetTime} from an {@code Instant} and zone ID.
* <p>
* This creates an offset time with the same instant as that specified. Finding the offset from
* UTC/Greenwich is simple as there is only one valid offset for each instant.
* <p>
* The date component of the instant is dropped during the conversion. This means that the conversion can
* never fail due to the instant being out of the valid range of dates.
*
* @param instant the instant to create the time from, not null
* @param zone the time-zone, which may be an offset, not null
* @return the offset time, not null
*/
public static OffsetTime ofInstant(Instant instant, ZoneId zone) {
Jdk7Methods.Objects_requireNonNull(instant, "instant");
Jdk7Methods.Objects_requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
long secsOfDay = instant.getEpochSecond() % SECONDS_PER_DAY;
secsOfDay = (secsOfDay + offset.getTotalSeconds()) % SECONDS_PER_DAY;
if (secsOfDay < 0) {
secsOfDay += SECONDS_PER_DAY;
}
LocalTime time = LocalTime.ofSecondOfDay(secsOfDay, instant.getNano());
return new OffsetTime(time, offset);
}
示例3: WeekDefinition
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Creates an instance of the definition.
*
* @param firstDayOfWeek the first day of the week, not null
* @param minimalDaysInFirstWeek the minimal number of days in the first week, from 1 to 7
* @throws IllegalArgumentException if the minimal days value is invalid
*/
private WeekDefinition(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek) {
Jdk7Methods.Objects_requireNonNull(firstDayOfWeek, "firstDayOfWeek");
if (minimalDaysInFirstWeek < 1 || minimalDaysInFirstWeek > 7) {
throw new IllegalArgumentException("Minimal number of days is invalid");
}
this.firstDayOfWeek = firstDayOfWeek;
this.minimalDays = minimalDaysInFirstWeek;
}
示例4: ofInstant
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code OffsetDate} from an {@code Instant} and zone ID.
* <p>
* This creates an offset date with the same instant as midnight at the start of day of the instant
* specified. Finding the offset from UTC/Greenwich is simple as there is only one valid offset for each
* instant.
*
* @param instant the instant to create the time from, not null
* @param zone the time-zone, which may be an offset, not null
* @return the offset time, not null
*/
public static OffsetDate ofInstant(Instant instant, ZoneId zone) {
Jdk7Methods.Objects_requireNonNull(instant, "instant");
Jdk7Methods.Objects_requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
long epochSec = instant.getEpochSecond() + offset.getTotalSeconds(); // overflow caught later
long epochDay = Jdk8Methods.floorDiv(epochSec, SECONDS_PER_DAY);
LocalDate date = LocalDate.ofEpochDay(epochDay);
return new OffsetDate(date, offset);
}
示例5: ChronoDateTimeImpl
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param date the date part of the date-time, not null
* @param time the time part of the date-time, not null
*/
private ChronoDateTimeImpl(ChronoLocalDate<C> date, LocalTime time) {
Jdk7Methods.Objects_requireNonNull(date, "date");
Jdk7Methods.Objects_requireNonNull(time, "time");
this.date = date;
this.time = time;
}
示例6: ofLocal
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code ZonedDateTime} from a local date-time using the preferred offset if
* possible.
* <p>
* The local date-time is resolved to a single instant on the time-line. This is achieved by finding a valid
* offset from UTC/Greenwich for the local date-time as defined by the {@link ZoneRules rules} of the zone
* ID.
* <p>
* In most cases, there is only one valid offset for a local date-time. In the case of an overlap, where
* clocks are set back, there are two valid offsets. If the preferred offset is one of the valid offsets
* then it is used. Otherwise the earlier valid offset is used, typically corresponding to "summer".
* <p>
* In the case of a gap, where clocks jump forward, there is no valid offset. Instead, the local date-time
* is adjusted to be later by the length of the gap. For a typical one hour daylight savings change, the
* local date-time will be moved one hour later into the offset typically corresponding to "summer".
*
* @param localDateTime the local date-time, not null
* @param zone the time-zone, not null
* @param preferredOffset the zone offset, null if no preference
* @return the zoned date-time, not null
*/
public static ZonedDateTime ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
Jdk7Methods.Objects_requireNonNull(localDateTime, "localDateTime");
Jdk7Methods.Objects_requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset) {
return new ZonedDateTime(localDateTime, (ZoneOffset) zone, zone);
}
ZoneRules rules = zone.getRules();
List<ZoneOffset> validOffsets = rules.getValidOffsets(localDateTime);
ZoneOffset offset;
if (validOffsets.size() == 1) {
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
} else {
if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
offset = preferredOffset;
} else {
offset = Jdk7Methods.Objects_requireNonNull(validOffsets.get(0), "offset"); // protect against bad
// ZoneRules
}
}
return new ZonedDateTime(localDateTime, offset, zone);
}
示例7: removeFieldValue
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Removes a field-value pair from the builder.
* <p>
* This removes a field, which must exist, from the builder. See
* {@link #removeFieldValues(DateTimeField...)} for a version which does not throw an exception
*
* @param field the field to remove, not null
* @return the previous value of the field
* @throws DateTimeException if the field is not found
*/
public long removeFieldValue(DateTimeField field) {
Jdk7Methods.Objects_requireNonNull(field, "field");
Long value = null;
if (field instanceof ChronoField) {
value = this.standardFields.remove(field);
} else if (this.otherFields != null) {
value = this.otherFields.remove(field);
}
if (value == null) {
throw new DateTimeException("Field not found: " + field);
}
return value;
}
示例8: appendInternal
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Appends a printer and/or parser to the internal list handling padding.
*
* @param pp the printer-parser to add, not null
* @return the index into the active parsers list
*/
private int appendInternal(DateTimePrinterParser pp) {
Jdk7Methods.Objects_requireNonNull(pp, "pp");
if (this.active.padNextWidth > 0) {
if (pp != null) {
pp = new PadPrinterParserDecorator(pp, this.active.padNextWidth, this.active.padNextChar);
}
this.active.padNextWidth = 0;
this.active.padNextChar = 0;
}
this.active.printerParsers.add(pp);
this.active.valueParserIndex = -1;
return this.active.printerParsers.size() - 1;
}
示例9: atStartOfDay
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Returns a zoned date-time from this date at the earliest valid time according to the rules in the
* time-zone.
* <p>
* Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified
* zone, thus the local date-time may not be midnight.
* <p>
* In most cases, there is only one valid offset for a local date-time. In the case of an overlap, there are
* two valid offsets, and the earlier one is used, corresponding to the first occurrence of midnight on the
* date. In the case of a gap, the zoned date-time will represent the instant just after the gap.
* <p>
* If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
* <p>
* To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)} followed by
* {@link LocalDateTime#atZone(ZoneId)}.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param zoneId the zone ID to use, not null
* @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
*/
public ZonedDateTime atStartOfDay(ZoneId zoneId) {
Jdk7Methods.Objects_requireNonNull(zoneId, "zoneId");
// need to handle case where there is a gap from 11:30 to 00:30
// standard ZDT factory would result in 01:00 rather than 00:30
LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
// if (zoneId instanceof ZoneOffset == false) {
// ZoneRules rules = zoneId.getRules();
// ZoneOffsetTransition trans = rules.getTransition(ldt);
// if (trans != null && trans.isGap()) {
// ldt = trans.getDateTimeAfter();
// }
// }
return ZonedDateTime.of(ldt, zoneId);
}
示例10: setDateTime
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Sets the date-time being output.
*
* @param dateTime the date-time object, not null
*/
void setDateTime(DateTimeAccessor dateTime) {
Jdk7Methods.Objects_requireNonNull(dateTime, "dateTime");
this.dateTime = dateTime;
}
示例11: atStartOfDay
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Returns a zoned date-time from this date at the earliest valid time according to the rules in the
* time-zone.
* <p>
* Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified
* zone, thus the local date-time may not be midnight.
* <p>
* In most cases, there is only one valid offset for a local date-time. In the case of an overlap, there are
* two valid offsets, and the earlier one is used, corresponding to the first occurrence of midnight on the
* date. In the case of a gap, the zoned date-time will represent the instant just after the gap.
* <p>
* If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
* <p>
* To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)} followed by
* {@link LocalDateTime#atZone(ZoneId)}.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param zoneId the zone ID to use, not null
* @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
*/
public ZonedDateTime atStartOfDay(ZoneId zoneId) {
Jdk7Methods.Objects_requireNonNull(zoneId, "zoneId");
// need to handle case where there is a gap from 11:30 to 00:30
// standard ZDT factory would result in 01:00 rather than 00:30
LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
if (zoneId instanceof ZoneOffset == false) {
ZoneRules rules = zoneId.getRules();
ZoneOffsetTransition trans = rules.getTransition(ldt);
if (trans != null && trans.isGap()) {
ldt = trans.getDateTimeAfter();
}
}
return ZonedDateTime.of(ldt, zoneId);
}
示例12: from
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code Chrono} from a date-time object.
* <p>
* A {@code DateTimeAccessor} represents some form of date and time information. This factory converts the
* arbitrary date-time object to an instance of {@code Chrono}. If the specified date-time object does not
* have a chronology, {@link ISOChrono} is returned.
*
* @param dateTime the date-time to convert, not null
* @return the chronology, not null
* @throws DateTimeException if unable to convert to an {@code Chrono}
*/
public static Chrono<?> from(DateTimeAccessor dateTime) {
Jdk7Methods.Objects_requireNonNull(dateTime, "dateTime");
Chrono<?> obj = dateTime.query(Query.CHRONO);
return (obj != null ? obj : ISOChrono.INSTANCE);
}
示例13: fixed
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Gets a clock that always returns the same instant.
* <p>
* This clock simply returns the specified instant. As such, it is not a clock in the conventional sense.
* The main use case for this is in testing, where the fixed clock ensures tests are not dependent on the
* current clock.
* <p>
* The returned implementation is immutable, thread-safe and {@code Serializable}.
*
* @param fixedInstant the instant to use as the clock, not null
* @param zone the time-zone to use to convert the instant to date-time, not null
* @return a clock that always returns the same instant, not null
*/
public static Clock fixed(Instant fixedInstant, ZoneId zone) {
Jdk7Methods.Objects_requireNonNull(fixedInstant, "fixedInstant");
Jdk7Methods.Objects_requireNonNull(zone, "zone");
return new FixedClock(fixedInstant, zone);
}
示例14: ofLenient
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code ZonedDateTime} leniently, for advanced use cases, allowing any combination
* of local date-time, offset and zone ID.
* <p>
* This creates a zoned date-time with no checks other than no nulls. This means that the resulting zoned
* date-time may have an offset that is in conflict with the zone ID.
* <p>
* This method is intended for advanced use cases. For example, consider the case where a zoned date-time
* with valid fields is created and then stored in a database or serialization-based store. At some later
* point, the object is then re-loaded. However, between those points in time, the government that defined
* the time-zone has changed the rules, such that the originally stored local date-time now does not occur.
* This method can be used to create the object in an "invalid" state, despite the change in rules.
*
* @param localDateTime the local date-time, not null
* @param offset the zone offset, not null
* @param zone the time-zone, not null
* @return the zoned date-time, not null
*/
private static ZonedDateTime ofLenient(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Jdk7Methods.Objects_requireNonNull(localDateTime, "localDateTime");
Jdk7Methods.Objects_requireNonNull(offset, "offset");
Jdk7Methods.Objects_requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset && offset.equals(zone) == false) {
throw new IllegalArgumentException("ZoneId must match ZoneOffset");
}
return new ZonedDateTime(localDateTime, offset, zone);
}
示例15: of
import java.time.jdk8.Jdk7Methods; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code LocalDateTime} from a date and time.
*
* @param date the local date, not null
* @param time the local time, not null
* @return the local date-time, not null
*/
public static LocalDateTime of(LocalDate date, LocalTime time) {
Jdk7Methods.Objects_requireNonNull(date, "date");
Jdk7Methods.Objects_requireNonNull(time, "time");
return new LocalDateTime(date, time);
}