use of java.time.Instant in project sonarqube by SonarSource.
the class DefaultIssue method truncateToSeconds.
@CheckForNull
private static Date truncateToSeconds(@Nullable Date d) {
if (d == null) {
return null;
}
Instant instant = d.toInstant();
instant = instant.truncatedTo(ChronoUnit.SECONDS);
return Date.from(instant);
}
use of java.time.Instant in project VocabHunter by VocabHunter.
the class SessionWordsToolImpl method timedCollect.
private static <T extends List<?>> T timedCollect(final String type, final Supplier<T> s, final Path file) {
Instant start = Instant.now();
T words = s.get();
Instant end = Instant.now();
Duration duration = Duration.between(start, end);
String filename = FileNameTool.filename(file);
LOG.info("Read filter file and found {} words marked as {} in {}ms ({})", words.size(), type, duration.toMillis(), filename);
return words;
}
use of java.time.Instant in project VocabHunter by VocabHunter.
the class FileStreamer method analyse.
public AnalysisResult analyse(final Path file) {
Instant start = Instant.now();
List<String> stream = lines(file);
String filename = FileNameTool.filename(file);
AnalysisResult result = analyser.analyse(stream, filename);
int count = result.getOrderedUses().size();
Instant end = Instant.now();
Duration duration = Duration.between(start, end);
LOG.info("Analysed text and found {} words in {}ms ({})", count, duration.toMillis(), filename);
return result;
}
use of java.time.Instant in project alchemy-test by SirWellington.
the class TestClassInjectors method inflateInstant.
private static void inflateInstant(FrameworkField field, Object target) throws IllegalArgumentException, IllegalAccessException {
GenerateInstant annotation = field.getAnnotation(GenerateInstant.class);
checkNotNull(annotation, "missing annotation");
AlchemyGenerator<Instant> generator = GenerateInstant.Values.createGeneratorFor(annotation);
Instant value = generator.get();
inflate(field, target, value);
}
use of java.time.Instant in project alchemy-test by SirWellington.
the class GenerateInstantTest method testValue.
@Test
public void testValue() {
System.out.println("testValue");
AlchemyGenerator<Instant> generator = GenerateInstant.Values.createGeneratorFor(annotation);
assertThat(generator, notNullValue());
Instant now = Instant.now();
Instant result = generator.get();
assertThat(result, notNullValue());
switch(type) {
case FUTURE:
assertThat(result.isAfter(now), is(true));
break;
case PAST:
assertThat(result.isBefore(now), is(true));
break;
case RANGE:
assertThat(result.toEpochMilli(), greaterThanOrEqualTo(startTime.toEpochMilli()));
assertThat(result.toEpochMilli(), lessThan(endTime.toEpochMilli()));
break;
case PRESENT:
long marginOfErrorMillis = 50;
assertThat(result.toEpochMilli(), greaterThanOrEqualTo(now.toEpochMilli() - marginOfErrorMillis));
assertThat(result.toEpochMilli(), lessThanOrEqualTo(now.toEpochMilli() + marginOfErrorMillis));
break;
}
}
Aggregations