List of usage examples for java.lang Long compare
public static int compare(long x, long y)
From source file:org.ng200.openolympus.services.TestingService.java
@Autowired public TestingService(final SolutionService solutionService, final SolutionRepository solutionRepository, final UserRepository userRepository, final VerdictRepository verdictRepository, final StorageService storageService, final TaskContainerCache taskContainerCache) { super();/* w w w . j av a 2 s . c o m*/ this.verdictRepository = verdictRepository; this.taskContainerCache = taskContainerCache; this.dataProvider.setParameter("storageService", storageService); final HashSet<Verdict> alreadyScheduledJobs = new HashSet<>(); this.verdictCheckSchedulingExecutorService.scheduleAtFixedRate(() -> { this.logInAsSystem(); solutionService.getPendingVerdicts().stream() .filter((verdict) -> !alreadyScheduledJobs.contains(verdict)).sorted((l, r) -> { if (l.isViewableWhenContestRunning() != r.isViewableWhenContestRunning()) { // Schedule base tests first return Boolean.compare(r.isViewableWhenContestRunning(), l.isViewableWhenContestRunning()); } return Long.compare(l.getId(), r.getId()); }).forEach((verdict) -> { alreadyScheduledJobs.add(verdict); this.processVerdict(verdict); }); }, 0, 100, TimeUnit.MILLISECONDS); }
From source file:io.horizondb.model.core.fields.TimestampField.java
/** * {@inheritDoc}/*from ww w .ja va2 s.c o m*/ */ @Override public int compareTo(Field other) { return Long.compare(this.sourceTimestamp, other.getTimestampIn(this.sourceUnit)); }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtTargetResourceTest.java
@Test @Description("Ensures that actions list is in exptected order.") public void getActionStatusReturnsCorrectType() throws Exception { final int limitSize = 2; final String knownTargetId = "targetId"; final List<Action> actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actions.get(0).getId()) .status(Status.FINISHED).message("test")); final PageRequest pageRequest = PageRequest.of(0, 1000, Direction.ASC, ActionFields.ID.getFieldName()); final Action action = deploymentManagement.findActionsByTarget(knownTargetId, pageRequest).getContent() .get(0);/*from ww w . j a v a 2s .co m*/ final ActionStatus status = deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getContent() .stream().sorted((e1, e2) -> Long.compare(e2.getId(), e1.getId())).collect(Collectors.toList()) .get(0); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actions.get(0).getId() + "/status") .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:DESC")) .andExpect(status().isOk()).andDo(MockMvcResultPrinter.print()) .andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(3))) .andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize))) .andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize))) .andExpect(jsonPath("content.[0].id", equalTo(status.getId().intValue()))) .andExpect(jsonPath("content.[0].type", equalTo("finished"))) .andExpect(jsonPath("content.[0].messages", hasSize(1))) .andExpect(jsonPath("content.[0].reportedAt", equalTo(status.getCreatedAt()))) .andExpect(jsonPath("content.[1].type", equalTo("canceling"))); }
From source file:org.efaps.admin.AbstractAdminObject.java
/** * Adds a new event to this AdminObject. * * @param _eventtype Eventtype class name to add * @param _eventdef EventDefinition to add * @see #events//from w ww . j a v a 2s .c o m * @throws CacheReloadException on error */ public void addEvent(final EventType _eventtype, final EventDefinition _eventdef) throws CacheReloadException { List<EventDefinition> evenList = this.events.get(_eventtype); if (evenList == null) { evenList = new ArrayList<>(); this.events.put(_eventtype, evenList); } if (!evenList.contains(_eventdef)) { evenList.add(_eventdef); } // if there are more than one event they must be sorted by their index // position if (evenList.size() > 1) { Collections.sort(evenList, new Comparator<EventDefinition>() { @Override public int compare(final EventDefinition _eventDef0, final EventDefinition _eventDef1) { return Long.compare(_eventDef0.getIndexPos(), _eventDef1.getIndexPos()); } }); } setDirty(); }
From source file:com.siemens.sw360.datahandler.common.CommonUtils.java
@NotNull public static Comparator<ModerationRequest> compareByTimeStampDescending() { return new Comparator<ModerationRequest>() { @Override/*from w w w .j av a 2s. c om*/ public int compare(ModerationRequest o1, ModerationRequest o2) { return Long.compare(o2.getTimestamp(), o1.getTimestamp()); } }; }
From source file:org.alex73.osm.monitors.export.ExportOutput.java
public void finishUpdate() { Collections.sort(queue, new Comparator<IOsmObject>() { @Override/* w w w. j a v a2s. c om*/ public int compare(IOsmObject o1, IOsmObject o2) { int r = o1.getType() - o2.getType(); if (r == 0) { r = Long.compare(o1.getId(), o2.getId()); } return r; } }); }
From source file:org.apache.falcon.snapshots.replication.HdfsSnapshotReplicator.java
private String findLatestReplicatedSnapshot(DistributedFileSystem sourceFs, DistributedFileSystem targetFs, String sourceDir, String targetDir) throws FalconException { try {// w w w .j a va 2 s . c o m FileStatus[] sourceSnapshots = sourceFs.listStatus(new Path(getSnapshotDir(sourceDir))); Set<String> sourceSnapshotNames = new HashSet<String>(); for (FileStatus snapshot : sourceSnapshots) { sourceSnapshotNames.add(snapshot.getPath().getName()); } FileStatus[] targetSnapshots = targetFs.listStatus(new Path(getSnapshotDir(targetDir))); if (targetSnapshots.length > 0) { //sort target snapshots in desc order of creation time. Arrays.sort(targetSnapshots, new Comparator<FileStatus>() { @Override public int compare(FileStatus f1, FileStatus f2) { return Long.compare(f2.getModificationTime(), f1.getModificationTime()); } }); // get most recent snapshot name that exists in source. for (int i = 0; i < targetSnapshots.length; i++) { String name = targetSnapshots[i].getPath().getName(); if (sourceSnapshotNames.contains(name)) { return name; } } // If control reaches here, // there are snapshots on target, but none are replicated from source. Return null. } // No target snapshots, return null return null; } catch (IOException e) { LOG.error("Unable to find latest snapshot on targetDir {} {}", targetDir, e.getMessage()); throw new FalconException("Unable to find latest snapshot on targetDir " + targetDir, e); } }
From source file:org.brutusin.rpc.client.http.HttpEndpoint.java
private static Map<String, InputStream> sortFiles(final Map<String, InputStream> files) { if (files == null) { return null; }/* w ww. j a v a 2 s . c om*/ Comparator<String> comparator = new Comparator<String>() { public int compare(String s1, String s2) { if (s1.equals(s2)) { return 0; } InputStream f1 = files.get(s1); InputStream f2 = files.get(s2); if (f1 == null || !(f1 instanceof MetaDataInputStream) || ((MetaDataInputStream) f1).getLength() == null) { return -1; } if (f2 == null || !(f2 instanceof MetaDataInputStream) || ((MetaDataInputStream) f2).getLength() == null) { return 1; } return Long.compare(((MetaDataInputStream) f1).getLength(), ((MetaDataInputStream) f2).getLength()); } }; Map<String, InputStream> ret = new TreeMap<String, InputStream>(comparator); ret.putAll(files); return ret; }
From source file:backup.namenode.NameNodeBackupBlockCheckProcessor.java
public static void checkAllBlocks(BackupReportWriter writer, ExtendedBlockEnum<Addresses> nnEnum, ExtendedBlockEnum<NullWritable> buEnum, BackupStoreDeleter deleter, int backupRequestBatchSize, DataNodeBackupRPCLookup rpcLookup) throws Exception { nnEnum.next();/* ww w . j av a 2 s . co m*/ buEnum.next(); List<ExtendedBlockWithAddress> backupBatch = new ArrayList<>(); try { while (true) { if (buEnum.current() == null && nnEnum.current() == null) { return; } else if (buEnum.current() == null) { backupAll(writer, nnEnum, backupRequestBatchSize, rpcLookup); return; } else if (nnEnum.current() == null) { deleteAllFromBackupStore(writer, buEnum, deleter); return; } ExtendedBlock nn = nnEnum.current(); ExtendedBlock bu = buEnum.current(); if (nn.equals(bu)) { nnEnum.next(); buEnum.next(); // nothing to do continue; } int compare = Long.compare(nn.getBlockId(), bu.getBlockId()); if (compare == 0) { // Blocks not equal but block ids present in both reports. Backup. writer.deleteBackupBlock(bu); try { deleter.deleteBlock(bu); } catch (Exception e) { LOG.error("Unknown error while trying to delete block " + bu, e); writer.deleteBackupBlockError(bu); } backupBlock(writer, backupBatch, nnEnum, backupRequestBatchSize, rpcLookup); nnEnum.next(); buEnum.next(); } else if (compare < 0) { // nn 123, bu 124 // Missing backup block. Backup. backupBlock(writer, backupBatch, nnEnum, backupRequestBatchSize, rpcLookup); nnEnum.next(); } else { // nn 125, bu 124 // Missing namenode block. Remove from backup. try { writer.deleteBackupBlock(bu); deleter.deleteBlock(bu); } catch (Exception e) { LOG.error("Unknown error while trying to delete block " + bu, e); writer.deleteBackupBlockError(bu); } buEnum.next(); } } } finally { if (backupBatch.size() > 0) { writeBackupRequests(writer, backupBatch, rpcLookup); backupBatch.clear(); } } }
From source file:org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager.java
/** * Returns all update delta files of specified Segment. * * @param segmentId//from www . j a va2 s. c om * @return * @throws Exception */ public List<String> getUpdateDeltaFiles(final String segmentId) { List<String> updatedDeltaFilesList = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); String endTimeStamp = ""; String startTimeStamp = ""; String segmentPath = CarbonTablePath.getSegmentPath(identifier.getTablePath(), segmentId); CarbonFile segDir = FileFactory.getCarbonFile(segmentPath, FileFactory.getFileType(segmentPath)); for (LoadMetadataDetails eachSeg : segmentDetails) { if (eachSeg.getLoadName().equalsIgnoreCase(segmentId)) { // if the segment is found then take the start and end time stamp. startTimeStamp = eachSeg.getUpdateDeltaStartTimestamp(); endTimeStamp = eachSeg.getUpdateDeltaEndTimestamp(); } } // if start timestamp is empty then no update delta is found. so return empty list. if (startTimeStamp.isEmpty()) { return updatedDeltaFilesList; } final Long endTimeStampFinal = CarbonUpdateUtil.getTimeStampAsLong(endTimeStamp); final Long startTimeStampFinal = CarbonUpdateUtil.getTimeStampAsLong(startTimeStamp); // else scan the segment for the delta files with the respective timestamp. CarbonFile[] files = segDir.listFiles(new CarbonFileFilter() { @Override public boolean accept(CarbonFile pathName) { String fileName = pathName.getName(); if (fileName.endsWith(CarbonCommonConstants.UPDATE_DELTA_FILE_EXT)) { String firstPart = fileName.substring(0, fileName.indexOf('.')); long timestamp = Long.parseLong(firstPart.substring( firstPart.lastIndexOf(CarbonCommonConstants.HYPHEN) + 1, firstPart.length())); if (Long.compare(timestamp, endTimeStampFinal) <= 0 && Long.compare(timestamp, startTimeStampFinal) >= 0) { // if marked for delete then it is invalid. if (!isBlockValid(segmentId, fileName)) { return false; } return true; } } return false; } }); for (CarbonFile cfile : files) { updatedDeltaFilesList.add(cfile.getCanonicalPath()); } return updatedDeltaFilesList; }