/** * Copy constructor. * @param other */ public Rankings(Rankings other) { this(other.maxSize()); updateWith(other); }
public void updateWith(Rankable r) { synchronized (rankedItems) { addOrReplace(r); rerank(); shrinkRankingsIfNeeded(); } }
/** * Return the current (total) counts of all tracked objects, then advance the window. * <p/> * Whenever this method is called, we consider the counts of the current sliding window to be available to and * successfully processed "upstream" (i.e. by the caller). Knowing this we will start counting any subsequent * objects within the next "chunk" of the sliding window. * * @return The current (total) counts of all tracked objects. */ public Map<T, Long> getCountsThenAdvanceWindow() { Map<T, Long> counts = objCounter.getCounts(); objCounter.wipeZeros(); objCounter.wipeSlot(tailSlot); advanceHead(); return counts; }
public void updateWith(Rankings other) { for (Rankable r : other.getRankings()) { updateWith(r); } }
public SlidingWindowCounter(int windowLengthInSlots) { if (windowLengthInSlots < 2) { throw new IllegalArgumentException( "Window length in slots must be at least two (you requested " + windowLengthInSlots + ")"); } this.windowLengthInSlots = windowLengthInSlots; this.objCounter = new SlotBasedCounter<T>(this.windowLengthInSlots); this.headSlot = 0; this.tailSlot = slotAfter(headSlot); }
@Override void updateRankingsWithTuple(Tuple tuple) { Rankable rankable = RankableObjectWithFields.from(tuple); super.getRankings().updateWith(rankable); }
/** * Creates a (defensive) copy of itself. */ public Rankings copy() { return new Rankings(this); } }
private void advanceHead() { headSlot = tailSlot; tailSlot = slotAfter(tailSlot); }
private boolean shouldBeRemovedFromCounter(T obj) { return computeTotalCount(obj) == 0; }
public void incrementCount(T obj) { objCounter.incrementCount(obj, headSlot); }
public void markAsModified() { updateLastModifiedTime(); }
public void updateWith(Rankable r) { synchronized (rankedItems) { addOrReplace(r); rerank(); shrinkRankingsIfNeeded(); } }
/** * Copy constructor. * * @param other */ public Rankings(Rankings other) { this(other.maxSize()); updateWith(other); }
public void updateWith(Rankings other) { for (Rankable r : other.getRankings()) { updateWith(r); } }
public SlidingWindowCounter(int windowLengthInSlots) { if (windowLengthInSlots < 2) { throw new IllegalArgumentException( "Window length in slots must be at least two (you requested " + windowLengthInSlots + ")"); } this.windowLengthInSlots = windowLengthInSlots; this.objCounter = new SlotBasedCounter<T>(this.windowLengthInSlots); this.headSlot = 0; this.tailSlot = slotAfter(headSlot); }
@Override void updateRankingsWithTuple(Tuple tuple) { Rankable rankable = RankableObjectWithFields.from(tuple); super.getRankings().updateWith(rankable); }
/** * Creates a (defensive) copy of itself. */ public Rankings copy() { return new Rankings(this); } }
private void advanceHead() { headSlot = tailSlot; tailSlot = slotAfter(tailSlot); }