工作闲暇时间,将做工程过程中重要的代码片段珍藏起来,下边代码段是关于Java对大量无序数据获取前N个的的代码,希望对大家有帮助。
···
public class LimitStorageList
{
public LimitStorageList()
{ }
public LimitStorageList(long maxTopN, List<KeyCountPair> list)
{
this.maxTopN = maxTopN;
this.topNList = list;
}
void put(KeyCountPair keyCountPair)
{
{
int index = isExist(keyCountPair);
{
topNList.add(keyCountPair);
insertSort(topNList);
}
else
{
topNList.remove(keyCountPair);
topNList.add(keyCountPair);
insertSort(topNList);
}
}
else
{
{
int index = isExist(keyCountPair);
{
topNList.set(topNList.size() - 1, keyCountPair);
insertSort(topNList);
}
else
{
topNList.remove(keyCountPair);
topNList.a