com.jamonapi.utils
Class NExtremeBufferHolder

java.lang.Object
  extended by com.jamonapi.utils.NExtremeBufferHolder
All Implemented Interfaces:
BufferHolder, java.util.Comparator
Direct Known Subclasses:
NExtremeArrayBufferHolder

public class NExtremeBufferHolder
extends java.lang.Object
implements BufferHolder, java.util.Comparator

Buffer used to keep the last N recent values based on the comparator. Note the Comparator must be thread safe.

Author:
steve souza

Constructor Summary
NExtremeBufferHolder(boolean naturalOrder)
           
NExtremeBufferHolder(java.util.Comparator comparator)
           
 
Method Summary
 void add(java.lang.Object replaceWithObj)
          Add the passed object to the array if BufferList is not full or shouldReplaceWith returns true
 int compare(java.lang.Object newObj, java.lang.Object existingObj)
          Method used by the comparator interface.
 BufferHolder copy()
          return a usable copy of the BufferHolder
 java.util.List getCollection()
          Get the underlying collection
 java.util.Comparator getComparator()
           
 java.util.List getOrderedCollection()
          Get the Collection in sorted order
 void remove(java.lang.Object replaceWithObj)
          Remove the smallest element from the BufferList if the buffer is full and shouldReplaceWith(...) returns true.
 void setCollection(java.util.List list)
           
 void setComparator(java.util.Comparator comparator)
           
 boolean shouldReplaceWith(java.lang.Object replaceWithObj)
          Returns true if this object is greater than the smallest value in the buffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

NExtremeBufferHolder

public NExtremeBufferHolder(java.util.Comparator comparator)

NExtremeBufferHolder

public NExtremeBufferHolder(boolean naturalOrder)
Method Detail

getCollection

public java.util.List getCollection()
Description copied from interface: BufferHolder
Get the underlying collection

Specified by:
getCollection in interface BufferHolder

setComparator

public void setComparator(java.util.Comparator comparator)

getComparator

public java.util.Comparator getComparator()

compare

public int compare(java.lang.Object newObj,
                   java.lang.Object existingObj)
Method used by the comparator interface.

o1 < o2 - returns a negative integer
o1==o2 - returns zero
o1>o2 - returns a postitive integer

Iterate through all columns that should be compared (in the proper order) and call the Comparator for each of the column elements. Note the column value is always the first argument and the comparison value is always the second

Specified by:
compare in interface java.util.Comparator

add

public void add(java.lang.Object replaceWithObj)
Description copied from interface: BufferHolder
Add the passed object to the array if BufferList is not full or shouldReplaceWith returns true

Specified by:
add in interface BufferHolder

remove

public void remove(java.lang.Object replaceWithObj)
Description copied from interface: BufferHolder
Remove the smallest element from the BufferList if the buffer is full and shouldReplaceWith(...) returns true.

Specified by:
remove in interface BufferHolder

shouldReplaceWith

public boolean shouldReplaceWith(java.lang.Object replaceWithObj)
Description copied from interface: BufferHolder
Returns true if this object is greater than the smallest value in the buffer

Specified by:
shouldReplaceWith in interface BufferHolder

getOrderedCollection

public java.util.List getOrderedCollection()
Description copied from interface: BufferHolder
Get the Collection in sorted order

Specified by:
getOrderedCollection in interface BufferHolder

setCollection

public void setCollection(java.util.List list)
Specified by:
setCollection in interface BufferHolder

copy

public BufferHolder copy()
Description copied from interface: BufferHolder
return a usable copy of the BufferHolder

Specified by:
copy in interface BufferHolder