List of usage examples for java.lang Long compare
public static int compare(long x, long y)
From source file:org.apache.sentry.tests.e2e.dbprovider.TestConcurrentClients.java
/** * Test when concurrent HS2 clients talking to server, * Privileges are correctly created and updated. * @throws Exception/*from w w w . j av a 2s . c om*/ */ @Test public void testConccurentHS2Client() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(NUM_OF_THREADS); final TestRuntimeState state = new TestRuntimeState(); for (int i = 0; i < NUM_OF_TASKS; i++) { executor.execute(new Runnable() { @Override public void run() { LOGGER.info("Starting tests: create role, show role, create db and tbl, and create partitions"); if (state.failed) { return; } try { Long startTime = System.currentTimeMillis(); Long elapsedTime = 0L; while (Long.compare(elapsedTime, HS2_CLIENT_TEST_DURATION_MS) <= 0) { String randStr = randomString(5); String test_role = "test_role_" + randStr; String test_db = "test_db_" + randStr; String test_tb = "test_tb_" + randStr; LOGGER.info("Start to test sentry with hs2 client with role " + test_role); adminCreateRole(test_role); adminShowRole(test_role); createDbTb(ADMIN1, test_db, test_tb); adminGrant(test_db, test_tb, test_role, USERGROUP1); createPartition(USER1_1, test_db, test_tb); adminCleanUp(test_db, test_role); elapsedTime = System.currentTimeMillis() - startTime; LOGGER.info("elapsedTime = " + elapsedTime); } state.setNumSuccess(); } catch (Exception e) { LOGGER.error("Exception: " + e); state.setFirstException(e); } } }); } executor.shutdown(); while (!executor.isTerminated()) { Thread.sleep(1000); //millisecond } Throwable ex = state.getFirstException(); assertFalse(ex == null ? "Test failed" : ex.toString(), state.failed); assertEquals(NUM_OF_TASKS, state.getNumSuccess()); }
From source file:com.rascarlo.aurdroid.ui.SearchResultFragment.java
private List<SearchResult> getSortedList(List<SearchResult> searchResultList) { switch (sortOder) { case AurdroidConstants.SORT_BY_PACKAGE_NAME: Collections.sort(searchResultList, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName())); break;/*from w w w . j a v a 2 s.co m*/ case AurdroidConstants.SORT_BY_VOTES: Collections.sort(searchResultList, (o1, o2) -> Long.compare(Long.parseLong(o2.getNumVotes()), Long.parseLong(o1.getNumVotes()))); break; case AurdroidConstants.SORT_BY_POPULARITY: Collections.sort(searchResultList, (o1, o2) -> Double.compare(Double.parseDouble(o2.getPopularity()), Double.parseDouble(o1.getPopularity()))); break; case AurdroidConstants.SORT_BY_LAST_UPDATED: Collections.sort(searchResultList, (o1, o2) -> Long.compare(Long.parseLong(o2.getLastModified()), Long.parseLong(o1.getLastModified()))); break; case AurdroidConstants.SORT_BY_FIRST_SUBMITTED: Collections.sort(searchResultList, (o1, o2) -> Long.compare(Long.parseLong(o1.getFirstSubmitted()), Long.parseLong(o2.getFirstSubmitted()))); break; default: Collections.sort(searchResultList, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName())); break; } return searchResultList; }
From source file:edu.kit.dama.mdm.dataworkflow.ExecutionEnvironmentConfiguration.java
/** * Check whether this execution environment is applicable for executing the * provided configuration. The check will compare the provided * ExecutionEnvironmentProperties with the required ones defined in the * DataWorkflowConfiguration. True is returned, if the environment provides * all required properties.//from w ww . java2s .c o m * * @param pConfiguration The configuration to check. * * @return TRUE if all required properties are provided. */ public boolean canExecute(DataWorkflowTaskConfiguration pConfiguration) { Set<? extends IDefaultEnvironmentProperty> required = pConfiguration.getRequiredEnvironmentProperties(); boolean result = true; for (final IDefaultEnvironmentProperty property : required) { IDefaultEnvironmentProperty providedProperty = (IDefaultEnvironmentProperty) CollectionUtils .find(providedEnvironmentProperties, new Predicate() { @Override public boolean evaluate(Object o) { return Long.compare(((IDefaultEnvironmentProperty) o).getId(), property.getId()) == 0; } }); if (providedProperty == null) { //not applicable ... Log this LOGGER.error( "Execution environment with id {} cannot handle task configuration with id {}. Property {} not supported.", getId(), pConfiguration.getId(), property); result = false; break; } } //all available return result; }
From source file:org.hawkular.alerts.api.model.data.Data.java
@Override public int compareTo(Data o) { int c = this.tenantId.compareTo(o.tenantId); if (0 != c)// w w w .j a v a 2 s.c o m return c; c = this.source.compareTo(o.source); if (0 != c) return c; c = this.id.compareTo(o.id); if (0 != c) return c; return Long.compare(this.timestamp, o.timestamp); }
From source file:main.java.edu.isistan.genCom.redSocial.RedSocial.java
/** * Gets a collection of instances of Investigadores by Id * // w w w.j a va 2 s.c o m * @param nodeIds * @return Node instances */ public List<Investigador> getNodos(Long[] nodeIds) { List<Investigador> nodes = new ArrayList<>(); List<Long> nodeList = Arrays.asList(nodeIds); for (Investigador investigador : getNodos()) { for (Long id : nodeList) { if (Long.compare(investigador.getInvestigadorId(), id) == 0) { nodes.add(investigador); } } } return nodes; }
From source file:com.streamsets.pipeline.stage.origin.hdfs.spooler.HdfsFileSystem.java
public Comparator<WrappedFile> getComparator(boolean useLastModified) { return new Comparator<WrappedFile>() { @Override//from www . j a v a2 s . c o m public int compare(WrappedFile file1, WrappedFile file2) { try { if (useLastModified) { // if comparing with folder last modified timestamp, always return true if (file2.toString().isEmpty()) { return 1; } if (!exists(file1)) { return 1; } long mtime1 = getLastModifiedTime(file1); file1.getCustomMetadata().putIfAbsent(HeaderAttributeConstants.LAST_MODIFIED_TIME, mtime1); long mtime2 = getLastModifiedTime(file2); file2.getCustomMetadata().putIfAbsent(HeaderAttributeConstants.LAST_MODIFIED_TIME, mtime2); int compares = Long.compare(mtime1, mtime2); if (compares != 0) { return compares; } } return file1.getFileName().compareTo(file2.getFileName()); } catch (IOException ex) { LOG.error("Could not sort files due to IO Exception", ex); throw new RuntimeException(ex); } } }; }
From source file:org.apache.kylin.provision.BuildIIWithStream.java
private List<String[]> getSortedRows(HiveTableReader reader, final int tsCol) throws IOException { List<String[]> unsorted = Lists.newArrayList(); while (reader.next()) { unsorted.add(reader.getRow());//from w ww.j av a2 s . c om } Collections.sort(unsorted, new Comparator<String[]>() { @Override public int compare(String[] o1, String[] o2) { long t1 = DateFormat.stringToMillis(o1[tsCol]); long t2 = DateFormat.stringToMillis(o2[tsCol]); return Long.compare(t1, t2); } }); return unsorted; }
From source file:org.apache.accumulo.core.client.summary.CountingSummarizer.java
@Override public Combiner combiner(SummarizerConfiguration sc) { init(sc);//from ww w . ja va 2 s . c o m return (summary1, summary2) -> { for (String key : ALL_STATS) { summary1.merge(key, summary2.getOrDefault(key, 0L), Long::sum); } for (Entry<String, Long> entry : summary2.entrySet()) { String k2 = entry.getKey(); Long v2 = entry.getValue(); if (k2.startsWith(COUNTER_STAT_PREFIX)) { summary1.merge(k2, v2, Long::sum); } } if (summary1.size() - ALL_STATS.length > maxCounters) { // find the keys with the lowest counts to remove List<String> keysToRemove = summary1.entrySet().stream() .filter(e -> e.getKey().startsWith(COUNTER_STAT_PREFIX)) // filter out non counters .sorted((e1, e2) -> Long.compare(e2.getValue(), e1.getValue())) // sort descending by // count .skip(maxCounters) // skip most frequent .map(Entry::getKey).collect(Collectors.toList()); // collect the least frequent // counters in a list long removedCount = 0; for (String key : keysToRemove) { removedCount += summary1.remove(key); } summary1.merge(TOO_MANY_STAT, removedCount, Long::sum); } }; }
From source file:com.seleniumtests.reporter.reporters.SeleniumTestsReporter2.java
/** * Generate summary report for all test methods * @param suites/*from w w w.ja v a 2s . c om*/ * @param suiteName * @param map * @return map containing test results */ public Map<ITestContext, List<ITestResult>> generateSuiteSummaryReport(final List<ISuite> suites) { // build result list for each TestNG test Map<ITestContext, List<ITestResult>> methodResultsMap = new LinkedHashMap<>(); for (ISuite suite : suites) { Map<String, ISuiteResult> tests = suite.getResults(); for (ISuiteResult r : tests.values()) { ITestContext context = r.getTestContext(); List<ITestResult> resultList = new ArrayList<>(); Collection<ITestResult> methodResults = new ArrayList<>(); methodResults.addAll(context.getFailedTests().getAllResults()); methodResults.addAll(context.getPassedTests().getAllResults()); methodResults.addAll(context.getSkippedTests().getAllResults()); methodResults = methodResults.stream() .sorted((r1, r2) -> Long.compare(r1.getStartMillis(), r2.getStartMillis())) .collect(Collectors.toList()); for (ITestResult result : methodResults) { SeleniumTestsContext testContext = (SeleniumTestsContext) result .getAttribute(SeleniumRobotTestListener.TEST_CONTEXT); String fileName; if (testContext != null) { fileName = testContext.getRelativeOutputDir() + "/TestReport.html"; } else { fileName = getTestName(result) + "/TestReport.html"; } result.setAttribute(METHOD_RESULT_FILE_NAME, fileName); result.setAttribute(SeleniumRobotLogger.UNIQUE_METHOD_NAME, getTestName(result)); } resultList.addAll(methodResults); methodResultsMap.put(context, resultList); } } try { VelocityEngine ve = initVelocityEngine(); Template t = ve.getTemplate("/reporter/templates/report.part.suiteSummary.vm"); VelocityContext context = new VelocityContext(); context.put("tests", methodResultsMap); context.put("steps", TestLogging.getTestsSteps()); StringWriter writer = new StringWriter(); t.merge(context, writer); mOut.write(writer.toString()); } catch (Exception e) { generationErrorMessage = "generateSuiteSummaryReport error:" + e.getMessage(); logger.error("generateSuiteSummaryReport error: ", e); } return methodResultsMap; }
From source file:com.mirth.connect.connectors.file.FileReceiver.java
public void sortFiles(FileInfo[] files) { String sortAttribute = connectorProperties.getSortBy(); if (sortAttribute.equals(FileReceiverProperties.SORT_BY_DATE)) { Arrays.sort(files, new Comparator<FileInfo>() { public int compare(FileInfo file1, FileInfo file2) { return Long.compare(file1.getLastModified(), file2.getLastModified()); }/* w w w. j a va2 s. c o m*/ }); } else if (sortAttribute.equals(FileReceiverProperties.SORT_BY_SIZE)) { Arrays.sort(files, new Comparator<FileInfo>() { public int compare(FileInfo file1, FileInfo file2) { return Long.compare(file1.getSize(), file2.getSize()); } }); } else { Arrays.sort(files, new Comparator<FileInfo>() { public int compare(FileInfo file1, FileInfo file2) { return file1.getName().compareToIgnoreCase(file2.getName()); } }); } }