本文整理汇总了Java中java.time.jdk8.Jdk7Methods类的典型用法代码示例。如果您正苦于以下问题:Java Jdk7Methods类的具体用法?Java Jdk7Methods怎么用?Java Jdk7Methods使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Jdk7Methods类属于java.time.jdk8包,在下文中一共展示了Jdk7Methods类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareTo
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Compares this {@code LocalTime} to another time.
* <p>
* The comparison is based on the time-line position of the local times within a day. It is
* "consistent with equals", as defined by {@link Comparable}.
*
* @param other the other time to compare to, not null
* @return the comparator value, negative if less, positive if greater
* @throws NullPointerException if {@code other} is null
*/
@Override
public int compareTo(LocalTime other) {
int cmp = Jdk7Methods.Integer_compare(this.hour, other.hour);
if (cmp == 0) {
cmp = Jdk7Methods.Integer_compare(this.minute, other.minute);
if (cmp == 0) {
cmp = Jdk7Methods.Integer_compare(this.second, other.second);
if (cmp == 0) {
cmp = Jdk7Methods.Integer_compare(this.nano, other.nano);
}
}
}
return cmp;
}
示例2: 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);
}
示例3: appendValue
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Appends the value of a date-time field to the formatter providing full control over printing.
* <p>
* The value of the field will be output during a print. If the value cannot be obtained then an exception
* will be thrown.
* <p>
* This method provides full control of the numeric formatting, including zero-padding and the
* positive/negative sign.
* <p>
* The parser for a variable width value normally behaves greedily, accepting as many digits as possible.
* This behavior can be affected by 'adjacent value parsing'. See {@link #appendValue(DateTimeField, int)}
* for full details.
*
* @param field the field to append, not null
* @param minWidth the minimum field width of the printed field, from 1 to 19
* @param maxWidth the maximum field width of the printed field, from 1 to 19
* @param signStyle the positive/negative output style, not null
* @return this, for chaining, not null
* @throws IllegalArgumentException if the widths are invalid
*/
public DateTimeFormatterBuilder appendValue(DateTimeField field, int minWidth, int maxWidth, SignStyle signStyle) {
if (minWidth == maxWidth && signStyle == SignStyle.NOT_NEGATIVE) {
return appendValue(field, maxWidth);
}
Jdk7Methods.Objects_requireNonNull(field, "field");
Jdk7Methods.Objects_requireNonNull(signStyle, "signStyle");
if (minWidth < 1 || minWidth > 19) {
throw new IllegalArgumentException("The minimum width must be from 1 to 19 inclusive but was " + minWidth);
}
if (maxWidth < 1 || maxWidth > 19) {
throw new IllegalArgumentException("The maximum width must be from 1 to 19 inclusive but was " + maxWidth);
}
if (maxWidth < minWidth) {
throw new IllegalArgumentException("The maximum width must exceed or equal the minimum width but " + maxWidth
+ " < " + minWidth);
}
NumberPrinterParser pp = new NumberPrinterParser(field, minWidth, maxWidth, signStyle);
if (minWidth == maxWidth) {
appendInternal(pp);
} else {
this.active.valueParserIndex = appendInternal(pp);
}
return this;
}
示例4: parseToBuilder
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Parses the text to a builder.
* <p>
* This parses to a {@code DateTimeBuilder} ensuring that the text is fully parsed. This method throws
* {@link DateTimeParseException} if unable to parse, or some other {@code DateTimeException} if another
* date/time problem occurs.
*
* @param text the text to parse, not null
* @return the engine representing the result of the parse, not null
* @throws DateTimeParseException if the parse fails
* @throws DateTimeException if there is a date/time problem
*/
public DateTimeBuilder parseToBuilder(CharSequence text) {
Jdk7Methods.Objects_requireNonNull(text, "text");
String str = text.toString(); // parsing whole String, so this makes sense
ParsePosition pos = new ParsePosition(0);
DateTimeBuilder result = parseToBuilder(str, pos);
if (result == null || pos.getErrorIndex() >= 0 || pos.getIndex() < str.length()) {
String abbr = str.toString();
if (abbr.length() > 64) {
abbr = abbr.substring(0, 64) + "...";
}
if (pos.getErrorIndex() >= 0) {
throw new DateTimeParseException("Text '" + abbr + "' could not be parsed at index " + pos.getErrorIndex(),
str, pos.getErrorIndex());
} else {
throw new DateTimeParseException("Text '" + abbr + "' could not be parsed, unparsed text found at index "
+ pos.getIndex(), str, pos.getIndex());
}
}
return result;
}
示例5: 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);
}
示例6: FractionPrinterParser
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Constructor.
*
* @param field the field to output, not null
* @param minWidth the minimum width to output, from 0 to 9
* @param maxWidth the maximum width to output, from 0 to 9
* @param decimalPoint whether to output the localized decimal point symbol
*/
public FractionPrinterParser(DateTimeField field, int minWidth, int maxWidth, boolean decimalPoint) {
Jdk7Methods.Objects_requireNonNull(field, "field");
if (field.range().isFixed() == false) {
throw new IllegalArgumentException("Field must have a fixed set of values: " + field.getName());
}
if (minWidth < 0 || minWidth > 9) {
throw new IllegalArgumentException("Minimum width must be from 0 to 9 inclusive but was " + minWidth);
}
if (maxWidth < 1 || maxWidth > 9) {
throw new IllegalArgumentException("Maximum width must be from 1 to 9 inclusive but was " + maxWidth);
}
if (maxWidth < minWidth) {
throw new IllegalArgumentException("Maximum width must exceed or equal the minimum width but " + maxWidth
+ " < " + minWidth);
}
this.field = field;
this.minWidth = minWidth;
this.maxWidth = maxWidth;
this.decimalPoint = decimalPoint;
}
示例7: ofLocale
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Obtains an instance of {@code Chrono} from a locale.
* <p>
* The locale can be used to identify a calendar. This uses {@link Locale#getUnicodeLocaleType(String)} to
* obtain the "ca" key to identify the calendar system.
* <p>
* If the locale does not contain calendar system information, the standard ISO calendar system is used.
*
* @param locale the locale to use to obtain the calendar system, not null
* @return the calendar system associated with the locale, not null
* @throws DateTimeException if the locale-specified calendar cannot be found
*/
public static Chrono<?> ofLocale(Locale locale) {
Jdk7Methods.Objects_requireNonNull(locale, "locale");
String type = locale.getUnicodeLocaleType("ca");
if (type == null) {
return ISOChrono.INSTANCE;
} else if ("iso".equals(type) || "iso8601".equals(type)) {
return ISOChrono.INSTANCE;
} else {
Chrono<?> chrono = CHRONOS_BY_TYPE.get(type);
if (chrono == null) {
throw new DateTimeException("Unknown calendar system: " + type);
}
return chrono;
}
}
示例8: 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);
}
示例9: plus
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Returns a copy of this period with the specified period added.
* <p>
* The specified unit must be one of the supported units from {@link ChronoUnit}, {@code YEARS},
* {@code MONTHS} or {@code DAYS} or be a time unit with an {@link PeriodUnit#isDurationEstimated() exact
* duration}. Other units throw an exception.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param amount the amount to add, positive or negative
* @param unit the unit that the amount is expressed in, not null
* @return a {@code Period} based on this period with the requested amount added, not null
* @throws ArithmeticException if numeric overflow occurs
*/
public Period plus(long amount, PeriodUnit unit) {
Jdk7Methods.Objects_requireNonNull(unit, "unit");
if (unit instanceof ChronoUnit) {
if (unit == YEARS || unit == MONTHS || unit == DAYS || unit.isDurationEstimated() == false) {
if (amount == 0) {
return this;
}
switch ((ChronoUnit) unit) {
case NANOS:
return plusNanos(amount);
case MICROS:
return plusNanos(Jdk8Methods.safeMultiply(amount, 1000L));
case MILLIS:
return plusNanos(Jdk8Methods.safeMultiply(amount, 1000000L));
case SECONDS:
return plusSeconds(amount);
case MINUTES:
return plusMinutes(amount);
case HOURS:
return plusHours(amount);
case HALF_DAYS:
return plusNanos(Jdk8Methods.safeMultiply(amount, 12 * NANOS_PER_HOUR));
case DAYS:
return plusDays(amount);
case MONTHS:
return plusMonths(amount);
case YEARS:
return plusYears(amount);
default :
throw new DateTimeException("Unsupported unit: " + unit.getName());
}
}
}
if (unit.isDurationEstimated()) {
throw new DateTimeException("Unsupported unit: " + unit.getName());
}
return plusNanos(Duration.of(amount, unit).toNanos());
}
示例10: plus
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Returns a copy of this duration with the specified duration added.
* <p>
* The duration amount is measured in terms of the specified unit. Only a subset of units are accepted by
* this method. The unit must either have an {@link PeriodUnit#isDurationEstimated() exact duration} or be
* {@link ChronoUnit#DAYS} which is treated as 24 hours. Other units throw an exception.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param amountToAdd the amount of the period, measured in terms of the unit, positive or negative
* @param unit the unit that the period is measured in, must have an exact duration, not null
* @return a {@code Duration} based on this duration with the specified duration added, not null
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration plus(long amountToAdd, PeriodUnit unit) {
Jdk7Methods.Objects_requireNonNull(unit, "unit");
if (unit == DAYS) {
return plus(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY), 0);
}
if (unit.isDurationEstimated()) {
throw new DateTimeException("Unit must not have an estimated duration");
}
if (amountToAdd == 0) {
return this;
}
if (unit instanceof ChronoUnit) {
switch ((ChronoUnit) unit) {
case NANOS:
return plusNanos(amountToAdd);
case MICROS:
return plusSeconds((amountToAdd / (1000000L * 1000)) * 1000).plusNanos(
(amountToAdd % (1000000L * 1000)) * 1000);
case MILLIS:
return plusMillis(amountToAdd);
case SECONDS:
return plusSeconds(amountToAdd);
}
return plusSeconds(Jdk8Methods.safeMultiply(unit.getDuration().seconds, amountToAdd));
}
Duration duration = unit.getDuration().multipliedBy(amountToAdd);
return plusSeconds(duration.getSeconds()).plusNanos(duration.getNano());
}
示例11: compareTo
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Compares this duration to the specified {@code Duration}.
* <p>
* The comparison is based on the total length of the durations. It is "consistent with equals", as defined
* by {@link Comparable}.
*
* @param otherDuration the other duration to compare to, not null
* @return the comparator value, negative if less, positive if greater
*/
@Override
public int compareTo(Duration otherDuration) {
int cmp = Jdk7Methods.Long_compare(this.seconds, otherDuration.seconds);
if (cmp != 0) {
return cmp;
}
return this.nanos - otherDuration.nanos;
}
示例12: 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 = rules.getOffset(localDateTime); // 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);
}
示例13: of
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Obtains an instance of {@code WeekDefinition} appropriate for a locale.
* <p>
* This will look up appropriate values from the provider of localization data.
*
* @param locale the locale to use, not null
* @return the week-definition, not null
*/
public static WeekDefinition of(Locale locale) {
Jdk7Methods.Objects_requireNonNull(locale, "locale");
DayOfWeek dow = DayOfWeek.MONDAY;
if ("US".equals(locale.getCountry())) {
dow = DayOfWeek.SUNDAY;
}
int minDays = 4; // ISO-08601 // gcal.getMinimalDaysInFirstWeek();
return WeekDefinition.of(dow, minDays);
}
示例14: 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;
}
示例15: getFieldValue
import java.time.jdk8.Jdk7Methods; //导入依赖的package包/类
/**
* Gets the value of the specified field from the builder.
*
* @param field the field to query in the field-value map, not null
* @return the value of the field, may be out of range
* @throws DateTimeException if the field is not present
*/
public long getFieldValue(DateTimeField field) {
Jdk7Methods.Objects_requireNonNull(field, "field");
Long value = getFieldValue0(field);
if (value == null) {
throw new DateTimeException("Field not found: " + field);
}
return value;
}