/**   
 * License Agreement for OpenSearchServer
 *
 * Copyright (C) 2014 Emmanuel Keller / Jaeksoft
 * 
 * http://www.open-search-server.com
 * 
 * This file is part of OpenSearchServer.
 *
 * OpenSearchServer is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 * OpenSearchServer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenSearchServer. 
 *  If not, see <http://www.gnu.org/licenses/>.
 **/

package com.jaeksoft.searchlib.index.osse.memory;

import java.io.Closeable;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.TreeMap;

public abstract class AbstractBuffer<T extends BufferItemInterface> implements
		Closeable {

	private long reused;
	private TreeMap<Long, ArrayDeque<T>> available;

	public AbstractBuffer() {
		available = new TreeMap<Long, ArrayDeque<T>>();
		reused = 0;
	}

	@Override
	final public void close() {
		System.out.println(this.getClass().getName() + " RELEASE "
				+ available.size() + " " + reused);
		available.clear();
		reused = 0;
	}

	protected abstract T newBufferItem(final long size);

	@SuppressWarnings("unchecked")
	final public T getNewBufferItem(final long size) {
		Map.Entry<Long, ArrayDeque<T>> entry = available.ceilingEntry(size);
		if (entry == null)
			return newBufferItem(size);
		ArrayDeque<T> memoryQue = entry.getValue();
		if (memoryQue.isEmpty())
			return newBufferItem(size);
		reused++;
		return (T) memoryQue.poll().reset();
	}

	final void closed(T bufferItem) {
		final long size = bufferItem.getSize();
		ArrayDeque<T> memoryQue = available.get(size);
		if (memoryQue == null) {
			memoryQue = new ArrayDeque<T>();
			available.put(size, memoryQue);
		}
		memoryQue.offer(bufferItem);
	}

}

@@ -1108,30 +1108,8 @@
  %7B%0A%0A
-%09private long reused;%0A
 %09pri
@@ -1153,16 +1153,16 @@
 ilable;%0A
+
 %0A%09public
@@ -1227,38 +1227,24 @@
 eque%3CT%3E%3E();%0A
-%09%09reused = 0;%0A
 %09%7D%0A%0A%09@Overri
@@ -1279,109 +1279,8 @@
 ) %7B%0A
-%09%09System.out.println(this.getClass().getName() + %22 RELEASE %22%0A%09%09%09%09+ available.size() + %22 %22 + reused);%0A
 %09%09av
@@ -1300,22 +1300,8 @@
 ();%0A
-%09%09reused = 0;%0A
 %09%7D%0A%0A
@@ -1670,20 +1670,8 @@
 e);%0A
-%09%09reused++;%0A
 %09%09re

Remove non useful logs