List of usage examples for java.lang Long compare
public static int compare(long x, long y)
From source file:com.coinblesk.client.wallet.Outputs.java
private synchronized void refreshOutputs() { adapter.getItems().clear();/* w w w .j av a 2s .c o m*/ adapter.getItems().addAll(walletServiceBinder.getUnspentInstantOutputs()); Collections.sort(adapter.getItems(), new Comparator<TransactionOutput>() { @Override public int compare(TransactionOutput lhs, TransactionOutput rhs) { Sha256Hash lhsHash = lhs.getParentTransactionHash(); Sha256Hash rhsHash = lhs.getParentTransactionHash(); if (lhsHash != null && rhsHash != null) { int hashCmp = lhsHash.toString().compareTo(rhsHash.toString()); if (hashCmp != 0) return hashCmp; else return Long.compare(lhs.getIndex(), rhs.getIndex()); } else if (lhsHash != null) return -1; else if (rhsHash != null) return 1; else return 0; } }); adapter.notifyDataSetChanged(); }
From source file:org.apache.ranger.plugin.geo.RangerGeolocationData.java
@Override public int compareToRange(final Long ip) { int ret = Long.compare(fromIPAddress, ip.longValue()); if (ret < 0) { ret = Long.compare(toIPAddress, ip.longValue()); if (ret > 0) { ret = 0;//from w w w. j a v a2 s .c om } } return ret; }
From source file:org.apache.falcon.snapshots.retention.HdfsSnapshotEvictor.java
protected static void evictSnapshots(DistributedFileSystem fs, String dirName, String ageLimit, int numSnapshots) throws FalconException { try {//w ww .j a v a 2s. c om LOG.info("Started evicting snapshots on dir {}{} using policy {}, agelimit {}, numSnapshot {}", fs.getUri(), dirName, ageLimit, numSnapshots); long evictionTime = System.currentTimeMillis() - EvictionHelper.evalExpressionToMilliSeconds(ageLimit); dirName = StringUtils.removeEnd(dirName, Path.SEPARATOR); String snapshotDir = dirName + Path.SEPARATOR + HdfsSnapshotUtil.SNAPSHOT_DIR_PREFIX + Path.SEPARATOR; FileStatus[] snapshots = fs.listStatus(new Path(snapshotDir)); if (snapshots.length <= numSnapshots) { // no eviction needed return; } // Sort by last modified time, ascending order. Arrays.sort(snapshots, new Comparator<FileStatus>() { @Override public int compare(FileStatus f1, FileStatus f2) { return Long.compare(f1.getModificationTime(), f2.getModificationTime()); } }); for (int i = 0; i < (snapshots.length - numSnapshots); i++) { // delete if older than ageLimit while retaining numSnapshots if (snapshots[i].getModificationTime() < evictionTime) { fs.deleteSnapshot(new Path(dirName), snapshots[i].getPath().getName()); } } } catch (ELException ele) { LOG.warn("Unable to parse retention age limit {} {}", ageLimit, ele.getMessage()); throw new FalconException("Unable to parse retention age limit " + ageLimit, ele); } catch (IOException ioe) { LOG.warn("Unable to evict snapshots from dir {} {}", dirName, ioe); throw new FalconException("Unable to evict snapshots from dir " + dirName, ioe); } }
From source file:org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureTree.java
private WALProcedureTree(Map<Long, Entry> procMap) { List<Entry> rootEntries = buildTree(procMap); for (Entry rootEntry : rootEntries) { checkReady(rootEntry, procMap);//from w w w .ja va 2 s .c o m } checkOrphan(procMap); Comparator<ProtoAndProc> cmp = (p1, p2) -> Long.compare(p1.proto.getProcId(), p2.proto.getProcId()); Collections.sort(validProcs, cmp); Collections.sort(corruptedProcs, cmp); }
From source file:io.dockstore.webservice.core.Tag.java
@Override public int compareTo(Tag o) { return Long.compare(super.getId(), o.getId()); }
From source file:mailbox.EmailHandler.java
private static void handleMessages(final IMAPFolder folder, List<Message> messages) { // Sort messages by uid; If they are not sorted, it is possible to miss // a email as a followed example: ////from w ww . j a va 2s. c om // 1. Yobi fetches two messages with uid of 1, 3 and 2. // 2. Yobi handles a message with uid of 1 and update lastseenuid to 1. // 3. Yobi handles a message with uid of 3 and update lastseenuid to 3. // 4. **Yobi Shutdown Abnormally** // 5. The system administrator restarts Yobi. // 6. Yobi fetches messages with uid larger than 3, the value of the // lastseenuid; It means that **the message with uid of 2 will be // never handled!** Collections.sort(messages, new Comparator<Message>() { @Override public int compare(Message m1, Message m2) { try { return Long.compare(folder.getUID(m1), folder.getUID(m2)); } catch (MessagingException e) { play.Logger.warn("Failed to compare uids of " + m1 + " and " + m2 + " while sorting messages by the uid; " + "There is some remote chance of loss of " + "mail requests."); return 0; } } }); for (Message msg : messages) { handleMessage((IMAPMessage) msg); } }
From source file:com.freiheit.fuava.sftp.util.FilenameUtil.java
/** * Compares two timestamps extracted from the names of the product group * data./* w ww. j a va2s . c o m*/ * * @param timestamp1 * first timestamp to compare * @param timestamp2 * second timestamp to compare * @return returns -1 if timestamp1 < timestamp2, 0 if they are equal and 1 * if timestamp1 > timestamp2 */ public static int compareTimestamps(final String timestamp1, final String timestamp2) { return Long.compare(timestampToLong(timestamp1), timestampToLong(timestamp2)); }
From source file:eu.comsode.unifiedviews.plugins.transformer.generatedtorelational.GeneratedToRelational.java
@Override protected void innerExecute() throws DPUException { Connection conn = null;//from www . j av a2 s .com try { createOutputTable(); //Retrieves data from CKAN resource fillInputTableFromCKAN(); LOG.debug("{} records retrieved from CKAN.", inputFromCkan.size()); Collections.sort(inputFromCkan, new Comparator<GenTableRow>() { @Override public int compare(GenTableRow o1, GenTableRow o2) { return Long.compare(o1.id, o2.id); } }); this.output.addExistingDatabaseTable(GENERATED_TABLE_NAME.toUpperCase(), GENERATED_TABLE_NAME.toUpperCase()); //If there are no data on input, create first row, else update table in CKAN if (inputFromCkan.size() == 0) { LOG.debug("No input table found!"); String dateToInsert = fmt.format(new Date()); String insertIntoQuery = String.format("INSERT INTO %s VALUES (0, '%s');", GENERATED_TABLE_NAME, dateToInsert); LOG.debug("Inserting first data to Output table with query: " + insertIntoQuery); DatabaseHelper.executeUpdate(insertIntoQuery, output); } else { Integer todayInt = Integer.decode(intFmt.format(new Date())); PreparedStatement psInsert = null; PreparedStatement ps = null; int counter = 0; conn = output.getDatabaseConnection(); //Iterate throgh data retrieved from CKAN for (GenTableRow currentRow : inputFromCkan) { counter++; Integer lastRunInt = Integer .decode(currentRow.data.substring(0, 10).replaceAll("-", "").trim()); LOG.debug(String.format("Last run date is: %d, today is: %d", lastRunInt, todayInt)); //If the record is not deleted and it is from previous day, delete it if (currentRow.deletedTimestamp != null) { //Create new record in database if (counter == inputFromCkan.size() && lastRunInt.compareTo(todayInt) < 0) { LOG.debug("Starting to insert record."); String dateToInsert = fmt.format(new Date()); String insertIntoQuery = String.format("INSERT INTO %s VALUES (%d,'%s');", GENERATED_TABLE_NAME, currentRow.id + 1, dateToInsert); LOG.debug("Inserting data to Output table with query: " + insertIntoQuery); DatabaseHelper.executeUpdate(insertIntoQuery, output); } LOG.debug("Commiting changes in output table."); conn.commit(); continue; } else if (lastRunInt.compareTo(todayInt) < 0) { if (counter == inputFromCkan.size() && lastRunInt.compareTo(todayInt) < 0) { LOG.debug("Starting to insert record."); String dateToInsert = fmt.format(new Date()); String insertIntoQuery = String.format("INSERT INTO %s VALUES (%d,'%s');", GENERATED_TABLE_NAME, currentRow.id + 1, dateToInsert); LOG.debug("Inserting data to Output table with query: " + insertIntoQuery); DatabaseHelper.executeUpdate(insertIntoQuery, output); } LOG.debug("Commiting changes in output table."); conn.commit(); continue; } String insertRecQuery = insertRecordForPrepStmt(GENERATED_TABLE_NAME, currentRow.id, currentRow.data); LOG.debug("Executing query: {}", insertRecQuery); psInsert = conn.prepareStatement(insertRecQuery); psInsert.execute(); conn.commit(); //If record is created today, update it if (lastRunInt.compareTo(todayInt) == 0 && currentRow.deletedTimestamp == null) { LOG.debug("Starting to update records."); String queryModify = updateModifyRecordForPrepStmt(GENERATED_TABLE_NAME.toUpperCase(), "data", fmt.format(new Date())); ps = conn.prepareStatement(queryModify); ps.setLong(1, currentRow.id); LOG.debug("Executing query: {} for ID: {}", queryModify, currentRow.id.toString()); ps.execute(); } LOG.debug("Commiting changes in output table."); conn.commit(); } } this.faultTolerance.execute(new FaultTolerance.Action() { @Override public void action() throws Exception { eu.unifiedviews.helpers.dataunit.resource.Resource resource = ResourceHelpers .getResource(GeneratedToRelational.this.output, GENERATED_TABLE_NAME); Date now = new Date(); resource.setCreated(now); resource.setLast_modified(now); ResourceHelpers.setResource(GeneratedToRelational.this.output, GENERATED_TABLE_NAME, resource); } }); } catch (DataUnitException | SQLException ex) { ContextUtils.sendError(this.ctx, "errors.dpu.failed", ex, "errors.dpu.failed"); return; } finally { DatabaseHelper.tryCloseConnection(conn); } }
From source file:org.apache.hadoop.hbase.regionserver.MetricsUserSourceImpl.java
@Override public int compareTo(MetricsUserSource source) { if (source == null) { return -1; }//w w w . j a v a2 s . c o m if (!(source instanceof MetricsUserSourceImpl)) { return -1; } MetricsUserSourceImpl impl = (MetricsUserSourceImpl) source; return Long.compare(hashCode, impl.hashCode); }
From source file:io.fabric8.jenkins.openshiftsync.BuildWatcher.java
public synchronized static void onInitialBuilds(BuildList buildList) { List<Build> items = buildList.getItems(); if (items != null) { Collections.sort(items, new Comparator<Build>() { @Override/*from w ww . ja va 2 s . com*/ public int compare(Build b1, Build b2) { return Long.compare( Long.parseLong( b1.getMetadata().getAnnotations().get(OPENSHIFT_ANNOTATIONS_BUILD_NUMBER)), Long.parseLong( b2.getMetadata().getAnnotations().get(OPENSHIFT_ANNOTATIONS_BUILD_NUMBER))); } }); // We need to sort the builds into their build configs so we can handle build run policies correctly. Map<String, BuildConfig> buildConfigMap = new HashMap<>(); Map<BuildConfig, List<Build>> buildConfigBuildMap = new HashMap<>(items.size()); for (Build b : items) { String buildConfigName = b.getStatus().getConfig().getName(); if (StringUtils.isEmpty(buildConfigName)) { continue; } String namespace = b.getMetadata().getNamespace(); String bcMapKey = namespace + "/" + buildConfigName; BuildConfig bc = buildConfigMap.get(bcMapKey); if (bc == null) { bc = getOpenShiftClient().buildConfigs().inNamespace(namespace).withName(buildConfigName).get(); if (bc == null) { continue; } buildConfigMap.put(bcMapKey, bc); } List<Build> bcBuilds = buildConfigBuildMap.get(bc); if (bcBuilds == null) { bcBuilds = new ArrayList<>(); buildConfigBuildMap.put(bc, bcBuilds); } bcBuilds.add(b); } // Now handle the builds. for (Map.Entry<BuildConfig, List<Build>> buildConfigBuilds : buildConfigBuildMap.entrySet()) { BuildConfig bc = buildConfigBuilds.getKey(); if (bc.getMetadata() == null) { // Should never happen but let's be safe... continue; } WorkflowJob job = getJobFromBuildConfig(bc); if (job == null) { continue; } BuildConfigProjectProperty bcp = job.getProperty(BuildConfigProjectProperty.class); if (bcp == null) { continue; } List<Build> builds = buildConfigBuilds.getValue(); handleBuildList(job, builds, bcp); } } }