List of usage examples for java.util.concurrent TimeUnit HOURS
TimeUnit HOURS
To view the source code for java.util.concurrent TimeUnit HOURS.
Click Source Link
From source file:org.dllearner.algorithms.qtl.qald.QALDExperiment.java
private Query rewriteForVirtuosoDateLiteralBug(Query query) { QueryUtils queryUtils = new QueryUtils(); Set<Triple> triplePatterns = queryUtils.extractTriplePattern(query); Set<Triple> newTriplePatterns = new TreeSet<>((Comparator<Triple>) (o1, o2) -> { return ComparisonChain.start().compare(o1.getSubject().toString(), o2.getSubject().toString()) .compare(o1.getPredicate().toString(), o2.getPredicate().toString()) .compare(o1.getObject().toString(), o2.getObject().toString()).result(); });//w ww . jav a 2 s .c o m List<ElementFilter> filters = new ArrayList<>(); int cnt = 0; // <s p o> for (Iterator<Triple> iter = triplePatterns.iterator(); iter.hasNext();) { Triple tp = iter.next(); if (tp.getObject().isLiteral()) { RDFDatatype dt = tp.getObject().getLiteralDatatype(); if (dt != null && dt instanceof XSDAbstractDateTimeType) { iter.remove(); // new triple pattern <s p ?var> Node objectVar = NodeFactory.createVariable("date" + cnt++); newTriplePatterns.add(Triple.create(tp.getSubject(), tp.getPredicate(), objectVar)); // add FILTER(STR(?var) = lexicalform(o)) String lit = tp.getObject().getLiteralLexicalForm(); Object literalValue = tp.getObject().getLiteralValue(); Expr filterExpr = new E_Equals(new E_Str(new ExprVar(objectVar)), NodeValue.makeString(lit)); if (literalValue instanceof XSDDateTime) { Calendar calendar = ((XSDDateTime) literalValue).asCalendar(); Date date = new Date(calendar.getTimeInMillis() + TimeUnit.HOURS.toMillis(2)); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); String inActiveDate = format1.format(date); filterExpr = new E_LogicalOr(filterExpr, new E_Equals(new E_Str(new ExprVar(objectVar)), NodeValue.makeString(inActiveDate))); } ElementFilter filter = new ElementFilter(filterExpr); filters.add(filter); } } } newTriplePatterns.addAll(triplePatterns); Query q = new Query(); q.addProjectVars(query.getProjectVars()); ElementTriplesBlock tripleBlock = new ElementTriplesBlock(); for (Triple triple : newTriplePatterns) { tripleBlock.addTriple(triple); } ElementGroup eg = new ElementGroup(); eg.addElement(tripleBlock); for (ElementFilter filter : filters) { eg.addElementFilter(filter); } q.setQuerySelectType(); q.setDistinct(true); q.setQueryPattern(eg); return q; }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static String formatTotalDuration(long totalDuration, boolean inMilliseconds) { long millis = totalDuration; if (!inMilliseconds) { millis = totalDuration * 1000;/* www .j a va 2s.c o m*/ } long hours = TimeUnit.MILLISECONDS.toHours(millis); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(hours); long seconds = TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(hours * 60 + minutes); if (hours >= 10) { return String.format("%02d:%02d:%02d", hours, minutes, seconds); } else if (hours > 0) { return String.format("%d:%02d:%02d", hours, minutes, seconds); } else if (minutes >= 10) { return String.format("%02d:%02d", minutes, seconds); } else if (minutes > 0) { return String.format("%d:%02d", minutes, seconds); } else { return String.format("0:%02d", seconds); } }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionComparisons() { final long twoHoursAgo = (System.currentTimeMillis() - TimeUnit.HOURS.toMillis(2)); AbstractGemFireOperationsSessionRepository.GemFireSession sessionOne = new AbstractGemFireOperationsSessionRepository.GemFireSession( mockSession("1", twoHoursAgo, MAX_INACTIVE_INTERVAL_IN_SECONDS)); AbstractGemFireOperationsSessionRepository.GemFireSession sessionTwo = new AbstractGemFireOperationsSessionRepository.GemFireSession( "2"); assertThat(sessionOne.getCreationTime()).isEqualTo(twoHoursAgo); assertThat(sessionTwo.getCreationTime()).isGreaterThan(twoHoursAgo); assertThat(sessionOne.compareTo(sessionTwo)).isLessThan(0); assertThat(sessionOne.compareTo(sessionOne)).isEqualTo(0); assertThat(sessionTwo.compareTo(sessionOne)).isGreaterThan(0); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.java
@Test public void testRetention() throws Exception { ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle()); ManagedLedgerConfig config = new ManagedLedgerConfig(); config.setRetentionSizeInMB(10);/*www. j a v a 2 s . co m*/ config.setMaxEntriesPerLedger(1); config.setRetentionTime(1, TimeUnit.HOURS); ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open("retention_test_ledger", config); ManagedCursor c1 = ml.openCursor("c1"); ml.addEntry("iamaverylongmessagethatshouldberetained".getBytes()); c1.skipEntries(1, IndividualDeletedEntries.Exclude); ml.close(); // reopen ml ml = (ManagedLedgerImpl) factory.open("retention_test_ledger", config); c1 = ml.openCursor("c1"); ml.addEntry("shortmessage".getBytes()); c1.skipEntries(1, IndividualDeletedEntries.Exclude); ml.close(); assertTrue(ml.getLedgersInfoAsList().size() > 1); assertTrue(ml.getTotalSize() > "shortmessage".getBytes().length); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.java
@Test public void testInfiniteRetention() throws Exception { ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle()); ManagedLedgerConfig config = new ManagedLedgerConfig(); config.setRetentionSizeInMB(-1);/*from w ww.j a va 2s. c om*/ config.setRetentionTime(-1, TimeUnit.HOURS); config.setMaxEntriesPerLedger(1); ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open("retention_test_ledger", config); ManagedCursor c1 = ml.openCursor("c1"); ml.addEntry("iamaverylongmessagethatshouldberetained".getBytes()); c1.skipEntries(1, IndividualDeletedEntries.Exclude); ml.close(); // reopen ml ml = (ManagedLedgerImpl) factory.open("retention_test_ledger", config); c1 = ml.openCursor("c1"); ml.addEntry("shortmessage".getBytes()); c1.skipEntries(1, IndividualDeletedEntries.Exclude); ml.close(); assertTrue(ml.getLedgersInfoAsList().size() > 1); assertTrue(ml.getTotalSize() > "shortmessage".getBytes().length); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.java
@Test public void testTimestampOnWorkingLedger() throws Exception { ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle()); ManagedLedgerConfig conf = new ManagedLedgerConfig(); conf.setMaxEntriesPerLedger(1);//from ww w. j ava 2 s. com conf.setRetentionSizeInMB(10); conf.setRetentionTime(1, TimeUnit.HOURS); ManagedLedgerImpl ml = (ManagedLedgerImpl) factory.open("my_test_ledger", conf); ml.openCursor("c1"); ml.addEntry("msg1".getBytes()); Iterator<LedgerInfo> iter = ml.getLedgersInfoAsList().iterator(); long ts = -1; while (iter.hasNext()) { LedgerInfo i = iter.next(); if (iter.hasNext()) { assertTrue(ts <= i.getTimestamp(), i.toString()); ts = i.getTimestamp(); } else { // the last timestamp can be // 0 if it is still opened // >0 if it is closed after the addEntry see OpAddEntry#addComplete() assertTrue(i.getTimestamp() == 0 || ts <= i.getTimestamp(), i.toString()); } } ml.addEntry("msg02".getBytes()); ml.close(); // Thread.sleep(1000); iter = ml.getLedgersInfoAsList().iterator(); ts = -1; while (iter.hasNext()) { LedgerInfo i = iter.next(); if (iter.hasNext()) { assertTrue(ts <= i.getTimestamp(), i.toString()); ts = i.getTimestamp(); } else { assertTrue(i.getTimestamp() > 0, "well closed LedgerInfo should set a timestamp > 0"); } } }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerTest.java
@Test public void testBackwardCompatiblityForMeta() throws Exception { final ManagedLedgerInfo[] storedMLInfo = new ManagedLedgerInfo[3]; final Stat[] versions = new Stat[1]; ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle()); ManagedLedgerConfig conf = new ManagedLedgerConfig(); conf.setMaxEntriesPerLedger(1);//from www. j av a 2 s . com conf.setRetentionSizeInMB(10); conf.setRetentionTime(1, TimeUnit.HOURS); ManagedLedger ml = factory.open("backward_test_ledger", conf); ml.openCursor("c1"); ml.addEntry("msg1".getBytes()); ml.addEntry("msg2".getBytes()); ml.close(); MetaStore store = new MetaStoreImplZookeeper(zkc, executor); CountDownLatch l1 = new CountDownLatch(1); // obtain the ledger info store.getManagedLedgerInfo("backward_test_ledger", false, new MetaStoreCallback<ManagedLedgerInfo>() { @Override public void operationComplete(ManagedLedgerInfo result, Stat version) { storedMLInfo[0] = result; versions[0] = version; l1.countDown(); } @Override public void operationFailed(MetaStoreException e) { fail("on get ManagedLedgerInfo backward_test_ledger"); } }); l1.await(); ManagedLedgerInfo.Builder builder1 = ManagedLedgerInfo.newBuilder(); // simulate test for old ledger with no timestampl for (LedgerInfo info : storedMLInfo[0].getLedgerInfoList()) { LedgerInfo noTimestamp = ManagedLedgerInfo.LedgerInfo.newBuilder().mergeFrom(info).clearTimestamp() .build(); assertFalse(noTimestamp.hasTimestamp(), "expected old version info with no timestamp"); builder1.addLedgerInfo(noTimestamp); } storedMLInfo[1] = builder1.build(); // test timestamp on new ledger CountDownLatch l2 = new CountDownLatch(1); store.asyncUpdateLedgerIds("backward_test_ledger", storedMLInfo[1], versions[0], new MetaStoreCallback<Void>() { @Override public void operationComplete(Void result, Stat version) { l2.countDown(); } @Override public void operationFailed(MetaStoreException e) { fail("on asyncUpdateLedgerIds"); } }); // verify that after update ledgers have timestamp ManagedLedgerImpl newVersionLedger = (ManagedLedgerImpl) factory.open("backward_test_ledger", conf); List<LedgerInfo> mlInfo = newVersionLedger.getLedgersInfoAsList(); assertTrue(mlInfo.stream().allMatch(new Predicate<LedgerInfo>() { @Override public boolean test(LedgerInfo ledgerInfo) { return ledgerInfo.hasTimestamp(); } })); }
From source file:net.bashtech.geobot.Channel.java
public static String getDurationBreakdown(long millis) { if (millis < 0) { throw new IllegalArgumentException("Duration must be greater than zero!"); }// w w w . j a va 2s .c o m long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); StringBuilder sb = new StringBuilder(64); if (days > 0) { sb.append(days); sb.append(" days, "); } if (hours < 10) sb.append(0); sb.append(hours); sb.append(" hours, "); if (minutes < 10) sb.append(0); sb.append(minutes); sb.append(" minutes, and "); if (seconds < 10) sb.append(0); sb.append(seconds); sb.append(" seconds."); return (sb.toString()); }
From source file:tv.phantombot.PhantomBot.java
private void doCheckPhantomBotUpdate() { ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); service.scheduleAtFixedRate(() -> { Thread.currentThread().setName("tv.phantombot.PhantomBot::doCheckPhantomBotUpdate"); String[] newVersionInfo = GitHubAPIv3.instance().CheckNewRelease(); if (newVersionInfo != null) { try { Thread.sleep(6000); print(""); print("New PhantomBot Release Detected: " + newVersionInfo[0]); print("Release Changelog: https://github.com/PhantomBot/PhantomBot/releases/" + newVersionInfo[0]); print("Download Link: " + newVersionInfo[1]); print("A reminder will be provided in 24 hours!"); print(""); } catch (InterruptedException ex) { com.gmt2001.Console.err.printStackTrace(ex); }// w w w .ja v a2 s .c o m if (webEnabled) { dataStore.set("settings", "newrelease_info", newVersionInfo[0] + "|" + newVersionInfo[1]); } } else { dataStore.del("settings", "newrelease_info"); } }, 0, 24, TimeUnit.HOURS); }
From source file:tv.phantombot.PhantomBot.java
/** * Backup the database, keeping so many days. */// w w w . j a v a2s.c o m private void doBackupSQLiteDB() { if (!dataStoreType.equals("sqlite3store")) { return; } ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); service.scheduleAtFixedRate(() -> { Thread.currentThread().setName("tv.phantombot.PhantomBot::doBackupSQLiteDB"); SimpleDateFormat datefmt = new SimpleDateFormat("ddMMyyyy.hhmmss"); datefmt.setTimeZone(TimeZone.getTimeZone(timeZone)); String timestamp = datefmt.format(new Date()); dataStore.backupSQLite3("phantombot.auto.backup." + timestamp + ".db"); try { Iterator dirIterator = FileUtils.iterateFiles(new File("./dbbackup"), new WildcardFileFilter("phantombot.auto.*"), null); while (dirIterator.hasNext()) { File backupFile = (File) dirIterator.next(); if (FileUtils.isFileOlder(backupFile, (System.currentTimeMillis() - (long) (backupSQLiteKeepDays * 864e5)))) { FileUtils.deleteQuietly(backupFile); } } } catch (Exception ex) { com.gmt2001.Console.err.println("Failed to clean up database backup directory: " + ex.getMessage()); } }, 0, backupSQLiteHourFrequency, TimeUnit.HOURS); }