当前位置: 首页>>代码示例>>Java>>正文


Java ChronoUnit.SECONDS属性代码示例

本文整理汇总了Java中java.time.temporal.ChronoUnit.SECONDS属性的典型用法代码示例。如果您正苦于以下问题:Java ChronoUnit.SECONDS属性的具体用法?Java ChronoUnit.SECONDS怎么用?Java ChronoUnit.SECONDS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.time.temporal.ChronoUnit的用法示例。


在下文中一共展示了ChronoUnit.SECONDS属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toChronoUnit

/**
 * To chrono unit.
 *
 * @param tu the tu
 * @return the chrono unit
 */
public static ChronoUnit toChronoUnit(final TimeUnit tu) {
    if (tu == null) {
        return null;
    }
    switch (tu) {
        case DAYS:
            return ChronoUnit.DAYS;
        case HOURS:
            return ChronoUnit.HOURS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        default:
            return null;
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:29,代码来源:DateTimeUtils.java

示例2: chronoUnit

/**
 * Converts a {@code TimeUnit} to a {@code ChronoUnit}.
 * <p>
 * This handles the seven units declared in {@code TimeUnit}.
 *
 * @param unit  the unit to convert, not null
 * @return the converted unit, not null
 */
private static ChronoUnit chronoUnit(final TimeUnit unit) {
    Objects.requireNonNull(unit, "unit");
    switch (unit) {
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case HOURS:
            return ChronoUnit.HOURS;
        case DAYS:
            return ChronoUnit.DAYS;
        default:
            throw new IllegalArgumentException("Unknown TimeUnit constant");
    }
}
 
开发者ID:groupon,项目名称:jtier-ctx,代码行数:29,代码来源:Life.java

示例3: toChronoUnit

private static ChronoUnit toChronoUnit(TimeUnit unit) { 
    Objects.requireNonNull(unit, "unit"); 
    switch (unit) { 
        case NANOSECONDS: 
            return ChronoUnit.NANOS; 
        case MICROSECONDS: 
            return ChronoUnit.MICROS; 
        case MILLISECONDS: 
            return ChronoUnit.MILLIS; 
        case SECONDS: 
            return ChronoUnit.SECONDS; 
        case MINUTES: 
            return ChronoUnit.MINUTES; 
        case HOURS: 
            return ChronoUnit.HOURS; 
        case DAYS: 
            return ChronoUnit.DAYS; 
        default: 
            throw new IllegalArgumentException("Unknown TimeUnit constant"); 
    } 
}
 
开发者ID:vsilaev,项目名称:tascalate-concurrent,代码行数:21,代码来源:Timeouts.java

示例4: parseDuration

static Duration parseDuration(String input) {
  if (input.startsWith("P") || input.startsWith("-P") || input.startsWith("+P")) {
    return Duration.parse(input);
  }

  String[] parts = splitNumericAndChar(input);
  String numberString = parts[0];
  String originalUnitString = parts[1];
  String unitString = originalUnitString;

  if (numberString.length() == 0) {
    throw new IllegalArgumentException(String.format("No number in duration value '%s'", input));
  }

  if (unitString.length() > 2 && !unitString.endsWith("s")) {
    unitString = unitString + "s";
  }

  ChronoUnit units;
  switch (unitString) {
    case "ns":
      units = ChronoUnit.NANOS;
      break;
    case "us":
      units = ChronoUnit.MICROS;
      break;
    case "":
    case "ms":
      units = ChronoUnit.MILLIS;
      break;
    case "s":
      units = ChronoUnit.SECONDS;
      break;
    case "m":
      units = ChronoUnit.MINUTES;
      break;
    case "h":
      units = ChronoUnit.HOURS;
      break;
    case "d":
      units = ChronoUnit.DAYS;
      break;
    default:
      throw new IllegalArgumentException(
          String.format("Could not parse time unit '%s' (try ns, us, ms, s, m, h, d)", originalUnitString));
  }

  return Duration.of(Long.parseLong(numberString), units);
}
 
开发者ID:scalecube,项目名称:config,代码行数:49,代码来源:DurationParser.java

示例5: getParentChronoUnit

/**
 * Returns the parent ChronoUnit for the given ChronoUnit.
 *
 * @param chronoUnit desired ChronoUnit
 * @return parent ChronoUnit of the given ChronoUnit
 */
@NotNull
public static ChronoUnit getParentChronoUnit(@NotNull ChronoUnit chronoUnit) {
    switch (requireNonNull(chronoUnit)) {
        case NANOS:
            return ChronoUnit.SECONDS;
        case MICROS:
            return ChronoUnit.SECONDS;
        case MILLIS:
            return ChronoUnit.SECONDS;
        case SECONDS:
            return ChronoUnit.MINUTES;
        case MINUTES:
            return ChronoUnit.HOURS;
        case HOURS:
            return ChronoUnit.DAYS;
        case DAYS:
            return ChronoUnit.WEEKS;
        case WEEKS:
            return ChronoUnit.MONTHS;
        case MONTHS:
            return ChronoUnit.YEARS;
        case YEARS:
            return ChronoUnit.DECADES;
        case DECADES:
            return ChronoUnit.CENTURIES;
        case CENTURIES:
            return ChronoUnit.ERAS;
        default:
            throw new UnsupportedOperationException("Unsupported chrono unit: " + chronoUnit);
    }
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:37,代码来源:ChronoScale.java

示例6: getChildChronoUnit

/**
 * Returns the child ChronoUnit for the given ChronoUnit.
 *
 * @param chronoUnit desired ChronoUnit
 * @return child ChronoUnit of the given ChronoUnit
 */
@NotNull
public static ChronoUnit getChildChronoUnit(@NotNull ChronoUnit chronoUnit) {
    switch (requireNonNull(chronoUnit)) {
        case MICROS:
            return ChronoUnit.NANOS;
        case MILLIS:
            return ChronoUnit.MICROS;
        case SECONDS:
            return ChronoUnit.MILLIS;
        case MINUTES:
            return ChronoUnit.SECONDS;
        case HOURS:
            return ChronoUnit.MINUTES;
        case DAYS:
            return ChronoUnit.HOURS;
        case WEEKS:
            return ChronoUnit.DAYS;
        case MONTHS:
            return ChronoUnit.WEEKS;
        case YEARS:
            return ChronoUnit.MONTHS;
        case DECADES:
            return ChronoUnit.YEARS;
        case MILLENNIA:
            return ChronoUnit.DECADES;
        case ERAS:
            return ChronoUnit.MILLENNIA;
        default:
            throw new UnsupportedOperationException("Unsupported chrono unit: " + chronoUnit);
    }
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:37,代码来源:ChronoScale.java

示例7: RollingFileWriter

/**
 * Create a RollingFileWriter as specified
 *
 * @param directory Path where the log files will be created
 * @param name Base name to use for log files
 * @param zone Time zone of timestamps on rolling file names
 * @param minuteRotation If true, rotate logs every minute, if false rotate every hour
 */
RollingFileWriter(Path directory, String name, TimeZone zone, boolean minuteRotation)
{
    if (directory == null) {
        throw new IllegalArgumentException("Directory required");
    }
    if (name == null) {
        throw new IllegalArgumentException("File base name required");
    }
    if (zone == null) {
        throw new IllegalArgumentException("Time zone required");
    }

    this.directory = directory;
    this.baseName = name;
    this.timeZone = zone.toZoneId();

    final String formatPattern = (minuteRotation ? ".yyyy-MM-dd-HH-mm" : ".yyyy-MM-dd-HH");
    this.format = DateTimeFormatter.ofPattern(formatPattern);

    if (minuteRotation) {
        rollInterval = ChronoUnit.SECONDS;
    } else {
        rollInterval = ChronoUnit.HOURS;
    }

    // Set to roll immediately on first write, to ensure file is created
    this.rollAt = Instant.now().truncatedTo(rollInterval);
}
 
开发者ID:awslabs,项目名称:swage,代码行数:36,代码来源:RollingFileWriter.java

示例8: BlackjackManager

public BlackjackManager(AbstractCommand cmd, String prefix, IChannel channel, IUser author) {
	super(cmd, prefix, channel, author);
	this.rateLimiter = new RateLimiter(1, 2, ChronoUnit.SECONDS);
	this.players = Collections.synchronizedList(new ArrayList<>());
	this.dealerCards = new ArrayList<>();
	this.message = new UpdateableMessage(channel);
}
 
开发者ID:Shadorc,项目名称:Shadbot,代码行数:7,代码来源:BlackjackManager.java

示例9: HangmanManager

public HangmanManager(AbstractCommand cmd, String prefix, IChannel channel, IUser author, Difficulty difficulty) {
	super(cmd, prefix, channel, author);
	this.rateLimiter = new RateLimiter(2, 2, ChronoUnit.SECONDS);
	this.message = new UpdateableMessage(channel);
	this.word = HangmanCmd.getWord(difficulty);
	this.charsTested = new ArrayList<>();
	this.failsCount = 0;
}
 
开发者ID:Shadorc,项目名称:Shadbot,代码行数:8,代码来源:HangmanManager.java

示例10: test

@Override
@Bulkhead(value = 5)
@Retry(retryOn =
{ BulkheadException.class }, delay = 1, delayUnit = ChronoUnit.SECONDS, maxRetries = 20, maxDuration=999999)
public Future test(BackendTestDelegate action) throws InterruptedException {
    Utils.log("in business method of bean " + this.getClass().getName());
    return action.perform();
}
 
开发者ID:eclipse,项目名称:microprofile-fault-tolerance,代码行数:8,代码来源:Bulkhead5MethodSynchronousRetry20Bean.java

示例11: test

@Override
@Bulkhead(waitingTaskQueue = 5, value = 5)
@Asynchronous
@Retry(retryOn =
{ BulkheadException.class }, delay = 1, delayUnit = ChronoUnit.SECONDS, maxRetries = 10, maxDuration=999999)
public Future test(BackendTestDelegate action) throws InterruptedException {
    Utils.log("in business method of bean " + this.getClass().getName());
    return action.perform();
}
 
开发者ID:eclipse,项目名称:microprofile-fault-tolerance,代码行数:9,代码来源:Bulkhead55MethodAsynchronousRetryBean.java

示例12: serviceD

/**
 * serviceD specifies a Timeout longer than the default, at 2 
 * seconds 
 * @param timeToSleepInMillis  How long should the execution take in millis
 * @return null or exception is raised
 */
@Timeout(value = 2, unit = ChronoUnit.SECONDS)
public Connection serviceD(long timeToSleepInMillis) {
    try {
        Thread.sleep(timeToSleepInMillis);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
开发者ID:eclipse,项目名称:microprofile-fault-tolerance,代码行数:17,代码来源:TimeoutClient.java

示例13: truncatedTo

/**
 * Returns a copy of this {@code Duration} truncated to the specified unit.
 * <p>
 * Truncating the duration returns a copy of the original with conceptual fields
 * smaller than the specified unit set to zero.
 * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will
 * round down to the nearest minute, setting the seconds and nanoseconds to zero.
 * <p>
 * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
 * that divides into the length of a standard day without remainder.
 * This includes all supplied time units on {@link ChronoUnit} and
 * {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param unit the unit to truncate to, not null
 * @return a {@code Duration} based on this duration with the time truncated, not null
 * @throws DateTimeException if the unit is invalid for truncation
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @since 9
 */
public Duration truncatedTo(TemporalUnit unit) {
    Objects.requireNonNull(unit, "unit");
    if (unit == ChronoUnit.SECONDS && (seconds >= 0 || nanos == 0)) {
        return new Duration(seconds, 0);
    } else if (unit == ChronoUnit.NANOS) {
        return this;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) {
        throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }
    long dur = unitDur.toNanos();
    if ((LocalTime.NANOS_PER_DAY % dur) != 0) {
        throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
    }
    long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
    long result = (nod / dur) * dur ;
    return plusNanos(result - nod);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:Duration.java

示例14: serviceC

/**
 * Max retries is configured to 90 but the max duration is 1 second with a durationUnit of seconds
 * specified.
 *  
 * Once the duration is reached, no more retries should be performed.
 */
@Retry(maxRetries = 90, maxDuration= 1, durationUnit = ChronoUnit.SECONDS)
public void serviceC() {
    counterForInvokingServiceC ++;
    writingService();
}
 
开发者ID:eclipse,项目名称:microprofile-fault-tolerance,代码行数:11,代码来源:RetryClientForMaxRetries.java


注:本文中的java.time.temporal.ChronoUnit.SECONDS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。