added BitmapTileLayer, and TileSource interface from mapsforge
This commit is contained in:
48
src/org/oscim/utils/IOUtils.java
Normal file
48
src/org/oscim/utils/IOUtils.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.utils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A utility class with IO-specific helper methods.
|
||||
*/
|
||||
public final class IOUtils {
|
||||
private static final Logger LOGGER = Logger.getLogger(IOUtils.class.getName());
|
||||
|
||||
/**
|
||||
* Invokes the {@link Closeable#close()} method on the given object. If an {@link IOException} occurs during the
|
||||
* method call, it will be caught and logged on level {@link Level#WARNING}.
|
||||
*
|
||||
* @param closeable
|
||||
* the data source which should be closed (may be null).
|
||||
*/
|
||||
public static void closeQuietly(Closeable closeable) {
|
||||
try {
|
||||
if (closeable != null) {
|
||||
closeable.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.FINE, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private IOUtils() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
@@ -21,26 +21,45 @@ public abstract class SyncPool<T extends Inlist<T>> {
|
||||
|
||||
protected T pool;
|
||||
|
||||
public SyncPool(){
|
||||
public SyncPool() {
|
||||
maxFill = 100;
|
||||
fill = 0;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
public SyncPool(int maxItemsInPool) {
|
||||
maxFill = maxItemsInPool;
|
||||
fill = 0;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getFill() {
|
||||
return fill;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param items number of initial items
|
||||
*/
|
||||
public void init(int items){
|
||||
public void init(int items) {
|
||||
count = items;
|
||||
fill = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item set initial state
|
||||
*/
|
||||
protected void clearItem(T item) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item release resources
|
||||
*/
|
||||
protected void clearItem(T item) {
|
||||
protected void freeItem(T item) {
|
||||
|
||||
}
|
||||
|
||||
@@ -59,7 +78,8 @@ public abstract class SyncPool<T extends Inlist<T>> {
|
||||
item.next = pool;
|
||||
pool = item;
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
freeItem(item);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
@@ -68,69 +88,36 @@ public abstract class SyncPool<T extends Inlist<T>> {
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
if (fill > maxFill)
|
||||
while (item != null) {
|
||||
clearItem(item);
|
||||
if (fill > maxFill) {
|
||||
while (item != null) {
|
||||
clearItem(item);
|
||||
freeItem(item);
|
||||
count--;
|
||||
|
||||
item = item.next;
|
||||
count--;
|
||||
}
|
||||
|
||||
if (item == null)
|
||||
item = item.next;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
while (item != null) {
|
||||
T next = item.next;
|
||||
|
||||
clearItem(item);
|
||||
fill++;
|
||||
|
||||
item.next = pool;
|
||||
pool = item;
|
||||
fill++;
|
||||
|
||||
item = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove 'item' from 'list' and add back to pool
|
||||
public T release(T list, T item) {
|
||||
if (item == null)
|
||||
return list;
|
||||
|
||||
T ret = list;
|
||||
|
||||
clearItem(item);
|
||||
|
||||
if (item == list) {
|
||||
ret = item.next;
|
||||
} else {
|
||||
for (T prev = list, it = list.next; it != null; it = it.next) {
|
||||
if (it == item) {
|
||||
prev.next = it.next;
|
||||
}
|
||||
prev = it;
|
||||
}
|
||||
}
|
||||
|
||||
if (fill < maxFill) {
|
||||
synchronized (this) {
|
||||
fill++;
|
||||
|
||||
item.next = pool;
|
||||
pool = item;
|
||||
}
|
||||
} else{
|
||||
count--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
|
||||
synchronized (this) {
|
||||
if (pool == null){
|
||||
if (pool == null) {
|
||||
count++;
|
||||
return createItem();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user