List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:com.linkedin.pinot.broker.broker.helix.ClusterChangeMediator.java
public ClusterChangeMediator(HelixExternalViewBasedRouting helixExternalViewBasedRouting, final BrokerMetrics brokerMetrics) { _helixExternalViewBasedRouting = helixExternalViewBasedRouting; // Simple thread that polls every 10 seconds to check if there are any cluster updates to apply _deferredClusterUpdater = new Thread("Deferred cluster state updater") { @Override// www . j a va 2s. c om public void run() { while (true) { try { // Wait for at least one update Pair<UpdateType, Long> firstUpdate = _clusterChangeQueue.take(); // Update the queue time metrics long queueTime = System.currentTimeMillis() - firstUpdate.getValue(); brokerMetrics.addTimedValue(BrokerTimer.ROUTING_TABLE_UPDATE_QUEUE_TIME, queueTime, TimeUnit.MILLISECONDS); // Take all other updates also present List<Pair<UpdateType, Long>> allUpdates = new ArrayList<>(); allUpdates.add(firstUpdate); _clusterChangeQueue.drainTo(allUpdates); // Gather all update types boolean externalViewUpdated = false; boolean instanceConfigUpdated = false; for (Pair<UpdateType, Long> update : allUpdates) { if (update.getKey() == UpdateType.EXTERNAL_VIEW) { externalViewUpdated = true; } else if (update.getKey() == UpdateType.INSTANCE_CONFIG) { instanceConfigUpdated = true; } } if (externalViewUpdated) { try { _helixExternalViewBasedRouting.processExternalViewChange(); } catch (Exception e) { LOGGER.warn("Caught exception while updating external view", e); } } if (instanceConfigUpdated) { try { _helixExternalViewBasedRouting.processInstanceConfigChange(); } catch (Exception e) { LOGGER.warn("Caught exception while processing instance config", e); } } } catch (InterruptedException e) { LOGGER.warn("Was interrupted while waiting for a cluster change", e); break; } } LOGGER.warn("Stopping deferred cluster state update thread"); _deferredClusterUpdater = null; } }; _deferredClusterUpdater.start(); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForDays() { int numberOfDays = 3; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusDays(numberOfDays); Pair<String, Integer> dayPair = PeriodUtils.period(start, end); assertEquals(DAYS_LABEL, dayPair.getKey()); assertEquals(numberOfDays, (int) dayPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForOneWeek() { int numberOfWeeks = 1; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusWeeks(numberOfWeeks); Pair<String, Integer> weekPair = PeriodUtils.period(start, end); assertEquals(WEEK_LABEL, weekPair.getKey()); assertEquals(numberOfWeeks, (int) weekPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForOneHour() { int numberOfHours = 1; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusHours(numberOfHours); Pair<String, Integer> hourPair = PeriodUtils.period(start, end); assertEquals(HOUR_LABEL, hourPair.getKey()); assertEquals(numberOfHours, (int) hourPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForOneYear() { int numberOfYears = 1; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusYears(numberOfYears); Pair<String, Integer> yearsPair = PeriodUtils.period(start, end); assertEquals(YEAR_LABEL, yearsPair.getKey()); assertEquals(numberOfYears, (int) yearsPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForWeeks() { int numberOfWeeks = 3; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusWeeks(numberOfWeeks); Pair<String, Integer> weekPair = PeriodUtils.period(start, end); assertEquals(WEEKS_LABEL, weekPair.getKey()); assertEquals(numberOfWeeks, (int) weekPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForHours() { int numberOfHours = 23; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusHours(numberOfHours); Pair<String, Integer> hourPair = PeriodUtils.period(start, end); assertEquals(HOURS_LABEL, hourPair.getKey()); assertEquals(numberOfHours, (int) hourPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForYears() { int numberOfYears = 3; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusYears(numberOfYears); Pair<String, Integer> yearsPair = PeriodUtils.period(start, end); assertEquals(YEARS_LABEL, yearsPair.getKey()); assertEquals(numberOfYears, (int) yearsPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForOneMonth() { int numberOfMonths = 1; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusMonths(numberOfMonths); Pair<String, Integer> monthPair = PeriodUtils.period(start, end); assertEquals(MONTH_LABEL, monthPair.getKey()); assertEquals(numberOfMonths, (int) monthPair.getValue()); }
From source file:hu.ppke.itk.nlpg.purepos.POSTagger.java
@Override public List<ISentence> tagSentence(List<String> sentence, int maxRes) { sentence = preprocessSentence(sentence); List<Pair<List<Integer>, Double>> tagList = decoder.decode(sentence, maxRes); List<ISentence> ret = new ArrayList<ISentence>(); for (Pair<List<Integer>, Double> tags : tagList) { List<IToken> tokens = merge(sentence, tags.getKey()); Sentence sent = new Sentence(tokens); sent.setScore(tags.getValue());//from w w w .jav a 2 s. com ret.add(sent); } return ret; }