/** * The returned defensive copy is only "somewhat" defensive. We do, for instance, return a defensive copy of the * enclosing List instance, and we do try to defensively copy any contained Rankable objects, too. However, the * contract of {@link org.apache.storm.starter.tools.Rankable#copy()} does not guarantee that any Object's embedded within * a Rankable will be defensively copied, too. * * @return a somewhat defensive copy of ranked items */ public List<Rankable> getRankings() { List<Rankable> copy = Lists.newLinkedList(); for (Rankable r : rankedItems) { copy.add(r.copy()); } return ImmutableList.copyOf(copy); }
/** * Removes ranking entries that have a count of zero. */ public void pruneZeroCounts() { int i = 0; while (i < rankedItems.size()) { if (rankedItems.get(i).getCount() == 0) { rankedItems.remove(i); } else { i++; } } }
@Override public void execute(Tuple input, BasicOutputCollector basicOutputCollector) { Rankings rankings = (Rankings) input.getValueByField("rankings"); /** * TODO:此处2个步骤的操作应该合并成一个lua操作,不过考虑到更新频率低,并且设置了globalGrouping,已经不存在并发状况了 */ hashOperations.getOperations().delete(WORD_COUNT_TOP_N_REAL_TIME_KEY); rankings.getRankings().forEach(rankable -> { String word = (String) rankable.getObject(); long count = rankable.getCount(); hashOperations.put(WORD_COUNT_TOP_N_REAL_TIME_KEY, word, count); }); }
/** * Removes ranking entries that have a count of zero. */ public void pruneZeroCounts() { int i = 0; while (i < rankedItems.size()) { if (rankedItems.get(i).getCount() == 0) { rankedItems.remove(i); } else { i++; } } }
/** * The returned defensive copy is only "somewhat" defensive. We do, for * instance, return a defensive copy of the enclosing List instance, and we * do try to defensively copy any contained Rankable objects, too. However, * the contract of {@link org.apache.storm.starter.tools.Rankable#copy()} * does not guarantee that any Object's embedded within a Rankable will be * defensively copied, too. * * @return a somewhat defensive copy of ranked items */ public List<Rankable> getRankings() { List<Rankable> copy = Lists.newLinkedList(); for (Rankable r : rankedItems) { copy.add(r.copy()); } return ImmutableList.copyOf(copy); }
@Override public int compareTo(Rankable other) { long delta = this.getCount() - other.getCount(); if (delta > 0) { return 1; } else if (delta < 0) { return -1; } else { return 0; } }
/** * The returned defensive copy is only "somewhat" defensive. We do, for instance, return a defensive copy of the * enclosing List instance, and we do try to defensively copy any contained Rankable objects, too. However, the * contract of {@link Rankable#copy()} does not guarantee that any Object's embedded within * a Rankable will be defensively copied, too. * * @return a somewhat defensive copy of ranked items */ public List<Rankable> getRankings() { List<Rankable> copy = Lists.newLinkedList(); for (Rankable r: rankedItems) { copy.add(r.copy()); } return ImmutableList.copyOf(copy); }
@Override public int compareTo(Rankable other) { long delta = this.getCount() - other.getCount(); if (delta > 0) { return 1; } else if (delta < 0) { return -1; } else { return 0; } }
/** * Removes ranking entries that have a count of zero. */ public void pruneZeroCounts() { int i = 0; while (i < rankedItems.size()) { if (rankedItems.get(i).getCount() == 0) { rankedItems.remove(i); } else { i++; } } }
@Override public int compareTo(Rankable other) { long delta = this.getCount() - other.getCount(); if (delta > 0) { return 1; } else if (delta < 0) { return -1; } else { return 0; } }