List of usage examples for java.lang Long compareTo
public int compareTo(Long anotherLong)
From source file:me.geenee.conf.SampleDataConfiguration.java
/** * Generates random set of tags.//w w w.ja v a 2s . co m * @return Set of tags. * @checkstyle ParameterNameCheck (25 lines) */ private Set<Tag> randomTags() { final int amount = this.random(1, TAGS_AMOUNT); final Set<Tag> result = new TreeSet<>(new Comparator<Tag>() { @Override public int compare(final Tag o1, final Tag o2) { Long first = Long.MIN_VALUE; Long second = Long.MIN_VALUE; if (o1 != null) { first = o1.getId(); } if (o2 != null) { second = o2.getId(); } return first.compareTo(second); } }); for (int idx = 0; idx < amount; ++idx) { result.add(this.tags.findOne((long) this.random(1, TAGS_AMOUNT))); } return result; }
From source file:org.kuali.mobility.push.dao.DeviceDaoImplTest.java
@Test @DirtiesContext//from www. j a va2s .com public void testSaveDeviceWithUpdate() { Device device = getDao().findDeviceByDeviceId("deviceIdA"); assertTrue("Failed to find deviceIdA", device != null); Calendar cal = Calendar.getInstance(); device.setPostedTimestamp(new Timestamp(cal.getTimeInMillis())); Long originalId = device.getId(); getDao().saveDevice(device); assertTrue("Device id changed with update and should not have.", originalId.compareTo(device.getId()) == 0); }
From source file:org.kuali.mobility.push.dao.DeviceDaoImplTest.java
@Test @DirtiesContext//from ww w. ja va 2 s. c o m public void testRegisterDeviceWithUpdate() { Device device = getDao().findDeviceByDeviceId("deviceIdA"); assertTrue("Failed to find deviceIdA", device != null); Calendar cal = Calendar.getInstance(); device.setPostedTimestamp(new Timestamp(cal.getTimeInMillis())); Long originalId = device.getId(); getDao().saveDevice(device); assertTrue("Device id changed with update and should not have.", originalId.compareTo(device.getId()) == 0); }
From source file:cz.muni.fi.mir.tools.Tools.java
/** * Method checks whether ID is valid or not. Valid IDs are not null and greater than zero. * @param id to be checked/* ww w .j av a 2 s. c om*/ * @throws IllegalArgumentException if ID is null or lower than one. */ public void checkID(Long id) throws IllegalArgumentException { if (id == null) { throw new IllegalArgumentException("ERROR: Given input id is null, therefore it's not valid"); } if (id.compareTo(new Long(1)) < 0) { throw new IllegalArgumentException("ERROR: GIven input id is lower than 1, therefore it's not valid"); } }
From source file:io.github.data4all.util.Gallery.java
/** * Lists the timestamp of all images in this gallery. * /*w w w . ja v a 2s. c o m*/ * @return An array with timestamps */ public long[] getImages() { final File[] files = this.getImageFiles(); final Long[] timestamps = new Long[files.length]; for (int i = 0; i < files.length; i++) { final File f = files[i]; timestamps[i] = Long.parseLong(f.getName().replace(ENDING_JPEG, "")); } final List<Long> asList = Arrays.asList(timestamps); Collections.sort(asList, new Comparator<Long>() { @Override public int compare(Long lhs, Long rhs) { return rhs.compareTo(lhs); } }); final long[] result = new long[asList.size()]; for (int i = 0; i < asList.size(); i++) { result[i] = asList.get(i); } return result; }
From source file:org.opendatakit.common.persistence.engine.gae.QueryImpl.java
final static synchronized void updateCostLoggingThreshold(DatastoreImpl datastore) { Log logger = LogFactory.getLog(QueryImpl.class); long currentTime = System.currentTimeMillis(); if (milliLastCheck + ACTIVE_COST_LOGGING_CHECK_INTERVAL < currentTime) { milliLastCheck = currentTime;// update early in case an exception is // thrown... try {/*from ww w . j a v a 2 s.c om*/ com.google.appengine.api.datastore.Query query = new Query("_COST_LOGGING_"); PreparedQuery pq = datastore.getDatastoreService().prepare(query); logger.debug("costLogging fetch."); List<com.google.appengine.api.datastore.Entity> eList = pq .asList(FetchOptions.Builder.withDefaults()); datastore.recordQueryUsage("_COST_LOGGING_", eList.size()); if (eList.isEmpty()) { costLoggingMinimumMegacyclesThreshold = 10 * 1200; // 10 seconds... logger.warn("writing 10-second cost logging threshold record"); com.google.appengine.api.datastore.Entity e = new com.google.appengine.api.datastore.Entity( "_COST_LOGGING_", "T" + WebUtils.iso8601Date(new Date())); e.setProperty("COST_LOGGING_MEGACYCLE_THRESHOLD", 10 * 1200); // 10 // seconds... e.setProperty("LAST_UPDATE_DATE", new Date()); datastore.getDatastoreService().put(e); } else { Long newValue = null; for (com.google.appengine.api.datastore.Entity e : eList) { Object o = e.getProperty("COST_LOGGING_MEGACYCLE_THRESHOLD"); if (o != null) { if (o instanceof Long) { Long l = (Long) o; if (newValue == null || newValue.compareTo(l) > 0) { newValue = l; } else { logger.warn("deleting superceded logging threshold record"); datastore.getDatastoreService().delete(e.getKey()); } } else if (o instanceof Integer) { Integer i = (Integer) o; Long l = Long.valueOf(i); if (newValue == null || newValue.compareTo(l) > 0) { newValue = l; } else { logger.warn("deleting superceded logging threshold record"); datastore.getDatastoreService().delete(e.getKey()); } } else if (o instanceof String) { String s = (String) o; try { Long l = Long.parseLong(s); if (newValue == null || newValue.compareTo(l) > 0) { newValue = l; } else { logger.warn("deleting superceded logging threshold record"); datastore.getDatastoreService().delete(e.getKey()); } } catch (NumberFormatException ex) { logger.warn("deleting superceded logging threshold record"); datastore.getDatastoreService().delete(e.getKey()); } } else { logger.warn("deleting superceded logging threshold record"); datastore.getDatastoreService().delete(e.getKey()); } } } if (newValue == null) { logger.warn("resetting cost logging to 10 second (12000 megacycle) threshold"); costLoggingMinimumMegacyclesThreshold = 10 * 1200; // 10 seconds... } else if (costLoggingMinimumMegacyclesThreshold != newValue.longValue()) { logger.warn("changing cost logging to " + newValue + " megacycle threshold"); costLoggingMinimumMegacyclesThreshold = newValue; } } } catch (Exception e) { e.printStackTrace(); logger.error("exception while updating cost logging threshold: " + e.getMessage()); } } }
From source file:org.nuxeo.ecm.webapp.seam.NuxeoSeamHotReloader.java
/** * Returns true if reload service has sent a runtime flush event since given timestamp. * * @since 5.6//from w w w . j ava 2s. c o m * @param cacheTimestamp * @see ReloadService#lastFlushed() */ public boolean shouldResetCache(Long cacheTimestamp) { if (cacheTimestamp == null) { return true; } Long serviceTimestamp = getCurrentCacheTimestamp(); if (serviceTimestamp == null) { return false; } if (cacheTimestamp.compareTo(serviceTimestamp) < 0) { return true; } return false; }
From source file:org.nuxeo.ecm.webapp.seam.NuxeoSeamHotReloader.java
/** * Returns true if given service has changed since given timestamp. * * @since 5.6//from www. j av a 2 s . c o m * @param service * @param cacheTimestamp * @see TimestampedService */ public boolean shouldResetCache(TimestampedService service, Long cacheTimestamp) { if (cacheTimestamp == null || service == null) { return true; } Long serviceTimestamp = service.getLastModified(); if (serviceTimestamp == null) { return false; } if (cacheTimestamp.compareTo(serviceTimestamp) < 0) { return true; } return false; }
From source file:org.kuali.mobility.file.dao.FileDaoImplTest.java
@Test @Transactional(TransactionMode.ROLLBACK) public void testFileDao() { File file = new File(); try {/* www. jav a 2 s . co m*/ InputStream in = this.getClass().getClassLoader().getResourceAsStream(FILE_NAME); byte[] inputFile = IOUtils.toByteArray(in); file.setBytes(inputFile); file.setFileSize(inputFile.length); } catch (IOException ioe) { LOG.error(ioe.getLocalizedMessage(), ioe); } file.setFileName(FILE_NAME); file.setContentType(CONTENT_TYPE); file.setPostedTimestamp(new Timestamp(Calendar.getInstance().getTimeInMillis())); assertTrue("File has an ID and should not have.", file.getId() == null); Long fileId = getDao().saveFile(file); LOG.debug("New file id is: " + fileId); assertTrue("Could not save file.", fileId != null && fileId.intValue() > 0); file.setContentType("text/xml"); Long fileId2 = getDao().saveFile(file); assertTrue("File was inserted again, not updated.", fileId.compareTo(fileId2) == 0); File lookupFile = getDao().findFileById(fileId); assertTrue("Failed to find file for ID " + fileId, lookupFile != null); List<File> listOfFiles = getDao().findFilesByName(FILE_NAME); assertTrue("Failed to find files for name " + FILE_NAME, listOfFiles != null && listOfFiles.size() == 1); List<File> allFiles = getDao().findAllFiles(); assertTrue("Failed to find all files.", allFiles != null && allFiles.size() == 1); File fileToRemove = allFiles.get(0); boolean didRemove = getDao().removeFile(fileToRemove); assertTrue("Failed to remove file ID " + fileToRemove.getId(), didRemove); allFiles = getDao().findAllFiles(); assertTrue("Found files and should not have.", allFiles == null || allFiles.size() == 0); didRemove = getDao().removeFile(null); assertFalse("Removed a null file. How is that possible?", didRemove); Long nullId = getDao().saveFile(null); assertTrue("Saved a null file. How is that possible?", nullId == null); }
From source file:org.apache.flume.client.avro.TestReliableSpoolingFileEventReader.java
@Test public void testLargeNumberOfFilesYOUNGEST() throws IOException { templateTestForLargeNumberOfFiles(ConsumeOrder.YOUNGEST, new Comparator<Long>() { @Override//from w ww .ja v a2s. co m public int compare(Long o1, Long o2) { return o2.compareTo(o1); } }, 1000); }