List of usage examples for java.lang Long compare
public static int compare(long x, long y)
From source file:org.apache.tez.history.parser.datamodel.VertexInfo.java
/** * Get first task to start//from w w w .j a v a2s .c o m * * @return TaskInfo */ public final TaskInfo getFirstTaskToStart() { List<TaskInfo> taskInfoList = Lists.newLinkedList(taskInfoMap.values()); if (taskInfoList.size() == 0) { return null; } Collections.sort(taskInfoList, new Comparator<TaskInfo>() { @Override public int compare(TaskInfo o1, TaskInfo o2) { return Long.compare(o1.getStartTimeInterval(), o2.getStartTimeInterval()); } }); return taskInfoList.get(0); }
From source file:edu.kit.dama.staging.services.impl.ingest.IngestInformationServiceLocal.java
private List<StagingProcessor> mergeStagingProcessors(Collection<StagingProcessor> assignedProcessors, List<StagingProcessor> defaultProcessors) { LOGGER.debug("Checking default staging processors."); if (assignedProcessors == null || assignedProcessors.isEmpty()) { //return defaultProcessors (can't be null, so we do not have to check result) LOGGER.debug("No staging processors assigned, using only default processors."); return defaultProcessors; }/*from w w w .jav a2 s. c o m*/ LOGGER.debug("Adding all assigned processors to result list."); List<StagingProcessor> result = new ArrayList<>(assignedProcessors); if (defaultProcessors == null || defaultProcessors.isEmpty()) { //return empty list LOGGER.debug("No default processors provided, using only assigned processors."); return result; } LOGGER.debug("Merging {} existing and {} default processor(s)", assignedProcessors.size(), defaultProcessors.size()); for (final StagingProcessor processor : defaultProcessors) { LOGGER.debug("Searching for default processor with id {}", processor.getUniqueIdentifier()); StagingProcessor exists = (StagingProcessor) CollectionUtils.find(assignedProcessors, new Predicate() { @Override public boolean evaluate(Object o) { return Long.compare(((StagingProcessor) o).getId(), processor.getId()) == 0; } }); if (exists == null) { LOGGER.debug("Default processor with id {} is not assigned, yet. Adding it.", processor.getId()); //add as it not exists result.add(processor); } } return result; }
From source file:org.apache.hadoop.tools.HadoopArchiveLogs.java
@VisibleForTesting void checkMaxEligible() { // If we have too many eligible apps, remove the newest ones first if (maxEligible > 0 && eligibleApplications.size() > maxEligible) { if (verbose) { LOG.info("Too many applications (" + eligibleApplications.size() + " > " + maxEligible + ")"); }// w w w.j a v a 2s .com List<AppInfo> sortedApplications = new ArrayList<AppInfo>(eligibleApplications); Collections.sort(sortedApplications, new Comparator<AppInfo>() { @Override public int compare(AppInfo o1, AppInfo o2) { int lCompare = Long.compare(o1.getFinishTime(), o2.getFinishTime()); if (lCompare == 0) { return o1.getAppId().compareTo(o2.getAppId()); } return lCompare; } }); for (int i = maxEligible; i < sortedApplications.size(); i++) { if (verbose) { LOG.info("Removing " + sortedApplications.get(i)); } eligibleApplications.remove(sortedApplications.get(i)); } } }
From source file:org.apache.carbondata.core.statusmanager.SegmentUpdateStatusManager.java
/** * Return all delta file for a block./* w w w.j a va2 s.c o m*/ * @param segmentId * @param blockName * @return */ public CarbonFile[] getDeleteDeltaFilesList(final Segment segmentId, final String blockName) { String segmentPath = CarbonTablePath.getSegmentPath(identifier.getTablePath(), segmentId.getSegmentNo()); CarbonFile segDir = FileFactory.getCarbonFile(segmentPath, FileFactory.getFileType(segmentPath)); for (SegmentUpdateDetails block : updateDetails) { if ((block.getBlockName().equalsIgnoreCase(blockName)) && (block.getSegmentName().equalsIgnoreCase(segmentId.getSegmentNo())) && !CarbonUpdateUtil.isBlockInvalid((block.getSegmentStatus()))) { final long deltaStartTimestamp = getStartTimeOfDeltaFile( CarbonCommonConstants.DELETE_DELTA_FILE_EXT, block); final long deltaEndTimeStamp = getEndTimeOfDeltaFile(CarbonCommonConstants.DELETE_DELTA_FILE_EXT, block); return segDir.listFiles(new CarbonFileFilter() { @Override public boolean accept(CarbonFile pathName) { String fileName = pathName.getName(); if (fileName.endsWith(CarbonCommonConstants.DELETE_DELTA_FILE_EXT) && pathName.getSize() > 0) { String firstPart = fileName.substring(0, fileName.indexOf('.')); String blkName = firstPart.substring(0, firstPart.lastIndexOf("-")); long timestamp = Long.parseLong( firstPart.substring(firstPart.lastIndexOf("-") + 1, firstPart.length())); if (blockName.equals(blkName) && (Long.compare(timestamp, deltaEndTimeStamp) <= 0) && (Long.compare(timestamp, deltaStartTimestamp) >= 0)) { return true; } } return false; } }); } } return null; }
From source file:org.apache.tez.history.parser.datamodel.VertexInfo.java
/** * Get last task to finish//from w ww. j a v a2 s. com * * @return TaskInfo */ public final TaskInfo getLastTaskToFinish() { List<TaskInfo> taskInfoList = Lists.newLinkedList(taskInfoMap.values()); if (taskInfoList.size() == 0) { return null; } Collections.sort(taskInfoList, new Comparator<TaskInfo>() { @Override public int compare(TaskInfo o1, TaskInfo o2) { return -1 * Long.compare(o1.getFinishTimeInterval(), o2.getFinishTimeInterval()); } }); return taskInfoList.get(0); }
From source file:com.github.braully.graph.BatchExecuteOperation.java
static List<File> sortFileArrayBySize(File[] files) { List<File> fileList = new ArrayList<>(Arrays.asList(files)); Collections.sort(fileList, new Comparator<File>() { public int compare(File t, File t1) { int ret = 0; try { if (t != null && t1 != null) { String tname = t.getName().toLowerCase(); String t1name = t1.getName().toLowerCase(); if (tname.contains("binary") || tname.contains("-00-ref") || tname.contains("hull_number_java")) { tname = "a" + tname; }/* w w w . j a v a 2 s . c om*/ if (t1name.contains("binary") || t1name.contains("-00-ref") || t1name.contains("hull_number_java")) { t1name = "a" + t1name; } ret = Long.compare(t.length(), t1.length()); } } catch (Exception e) { } return ret; } }); return fileList; }
From source file:org.apache.tez.history.parser.datamodel.VertexInfo.java
private Ordering<TaskInfo> orderingOnTimeTaken() { return Ordering.from(new Comparator<TaskInfo>() { @Override// w w w . j a v a 2 s. c o m public int compare(TaskInfo o1, TaskInfo o2) { return Long.compare(o1.getTimeTaken(), o2.getTimeTaken()); } }); }
From source file:org.apache.tez.history.parser.datamodel.VertexInfo.java
private Ordering<TaskInfo> orderingOnStartTime() { return Ordering.from(new Comparator<TaskInfo>() { @Override/* w w w . j a v a 2s . co m*/ public int compare(TaskInfo o1, TaskInfo o2) { return Long.compare(o1.getStartTimeInterval(), o2.getStartTimeInterval()); } }); }
From source file:org.apache.tez.history.parser.datamodel.VertexInfo.java
private Ordering<TaskAttemptInfo> orderingOnAttemptStartTime() { return Ordering.from(new Comparator<TaskAttemptInfo>() { @Override/*from ww w . j a va 2 s . c om*/ public int compare(TaskAttemptInfo o1, TaskAttemptInfo o2) { return Long.compare(o1.getStartTimeInterval(), o2.getStartTimeInterval()); } }); }
From source file:com.replaymod.replaystudio.filter.SquashFilter.java
@Override public void onEnd(PacketStream stream, long timestamp) { List<PacketData> result = new ArrayList<>(); result.addAll(unhandled);/*from w w w. j av a 2 s .co m*/ result.addAll(currentWorld); result.addAll(currentWindow); result.addAll(closeWindows); result.addAll(mainInventoryChanges.values()); if (mainInventory != null) { result.add(mainInventory); } if (joinGame != null) { ServerJoinGamePacket org = (ServerJoinGamePacket) joinGame.getPacket(); Packet packet = new ServerJoinGamePacket(org.getEntityId(), org.getHardcore(), gameMode, dimension, difficulty, org.getMaxPlayers(), worldType, reducedDebugInfo); result.add(new PacketData(joinGame.getTime(), packet)); } else if (respawn != null) { Packet packet = new ServerRespawnPacket(dimension, difficulty, gameMode, worldType); result.add(new PacketData(respawn.getTime(), packet)); } else { if (difficulty != null) { result.add(new PacketData(lastTimestamp, new ServerDifficultyPacket(difficulty))); } if (gameMode != null) { Packet packet = new ServerNotifyClientPacket(ClientNotification.CHANGE_GAMEMODE, gameMode); result.add(new PacketData(lastTimestamp, packet)); } } if (experience != null) { result.add(new PacketData(lastTimestamp, experience)); } if (abilities != null) { result.add(new PacketData(lastTimestamp, abilities)); } for (Map.Entry<Integer, Entity> e : entities.entrySet()) { Entity entity = e.getValue(); FOR_PACKETS: for (PacketData data : entity.packets) { Packet packet = data.getPacket(); Integer id = PacketUtils.getEntityId(packet); if (id == -1) { // Multiple entities List<Integer> allIds = PacketUtils.getEntityIds(packet); for (int i : allIds) { if (!entities.containsKey(i)) { // Other entity doesn't exist continue FOR_PACKETS; } } } result.add(data); } if (entity.loc != null) { result.add(new PacketData(entity.lastTimestamp, entity.loc.toServerEntityTeleportPacket(e.getKey(), entity.onGround))); } while (entity.dx != 0 && entity.dy != 0 && entity.dz != 0) { long mx = within(entity.dx, POS_MIN, POS_MAX); long my = within(entity.dy, POS_MIN, POS_MAX); long mz = within(entity.dz, POS_MIN, POS_MAX); entity.dx -= mx; entity.dy -= my; entity.dz -= mz; ServerEntityPositionPacket p = new ServerEntityPositionPacket(e.getKey(), mx / 32d, my / 32d, mz / 32d, entity.onGround); result.add(new PacketData(entity.lastTimestamp, p)); } if (entity.yaw != null && entity.pitch != null) { ServerEntityRotationPacket p = new ServerEntityRotationPacket(e.getKey(), entity.yaw, entity.pitch, entity.onGround); result.add(new PacketData(entity.lastTimestamp, p)); } } for (Map.Entry<Long, Long> e : unloadedChunks.entrySet()) { int x = ChunkData.longToX(e.getKey()); int z = ChunkData.longToZ(e.getKey()); result.add(new PacketData(e.getValue(), new ServerChunkDataPacket(x, z))); } for (ChunkData chunk : chunks.values()) { Packet packet = new ServerChunkDataPacket(chunk.x, chunk.z, chunk.changes, chunk.biomeData); result.add(new PacketData(chunk.firstAppearance, packet)); for (Map<Short, MutablePair<Long, BlockChangeRecord>> e : chunk.blockChanges) { if (e != null) { for (MutablePair<Long, BlockChangeRecord> pair : e.values()) { result.add(new PacketData(pair.getLeft(), new ServerBlockChangePacket(pair.getRight()))); } } } } Collections.sort(result, (e1, e2) -> Long.compare(e1.getTime(), e2.getTime())); for (PacketData data : result) { add(stream, timestamp, data.getPacket()); } for (Team team : teams.values()) { String[] added = team.added.toArray(new String[team.added.size()]); String[] removed = team.added.toArray(new String[team.removed.size()]); if (team.status == Team.Status.CREATED) { add(stream, timestamp, new ServerTeamPacket(team.name, team.displayName, team.prefix, team.suffix, team.friendlyFire, team.seeingFriendlyInvisibles, team.nameTagVisibility, team.color, added)); } else if (team.status == Team.Status.UPDATED) { if (team.color != null) { add(stream, timestamp, new ServerTeamPacket(team.name, team.displayName, team.prefix, team.suffix, team.friendlyFire, team.seeingFriendlyInvisibles, team.nameTagVisibility, team.color)); } if (added.length > 0) { add(stream, timestamp, new ServerTeamPacket(team.name, TeamAction.ADD_PLAYER, added)); } if (removed.length > 0) { add(stream, timestamp, new ServerTeamPacket(team.name, TeamAction.REMOVE_PLAYER, removed)); } } else if (team.status == Team.Status.REMOVED) { add(stream, timestamp, new ServerTeamPacket(team.name)); } } for (ServerMapDataPacket packet : maps.values()) { add(stream, timestamp, packet); } }