merge Query- and OpenResult into IMapDatabase

This commit is contained in:
Hannes Janetzek 2013-04-21 23:01:38 +02:00
parent c14b14fd11
commit 08a9ca4293
12 changed files with 132 additions and 186 deletions

View File

@ -70,4 +70,72 @@ public interface IMapDatabase {
*/
public abstract void cancel();
public static enum QueryResult {
SUCCESS,
FAILED,
TILE_NOT_FOUND,
DELAYED,
}
/**
* A FileOpenResult is a simple DTO which is returned by
* IMapDatabase#open().
*/
public static class OpenResult {
/**
* Singleton for a FileOpenResult instance with {@code success=true}.
*/
public static final OpenResult SUCCESS = new OpenResult();
private final String errorMessage;
private final boolean success;
/**
* @param errorMessage
* a textual message describing the error, must not be null.
*/
public OpenResult(String errorMessage) {
if (errorMessage == null) {
throw new IllegalArgumentException("error message must not be null");
}
this.success = false;
this.errorMessage = errorMessage;
}
/**
*
*/
public OpenResult() {
this.success = true;
this.errorMessage = null;
}
/**
* @return a textual error description (might be null).
*/
public String getErrorMessage() {
return this.errorMessage;
}
/**
* @return true if the file could be opened successfully, false
* otherwise.
*/
public boolean isSuccess() {
return this.success;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("FileOpenResult [success=");
stringBuilder.append(this.success);
stringBuilder.append(", errorMessage=");
stringBuilder.append(this.errorMessage);
stringBuilder.append("]");
return stringBuilder.toString();
}
}
}

View File

@ -1,19 +0,0 @@
/*
* 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.database;
public interface IMapTileData {
}

View File

@ -1,75 +0,0 @@
/*
* 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.database;
/**
* A FileOpenResult is a simple DTO which is returned by
* IMapDatabase#openFile(File).
*/
public class OpenResult {
/**
* Singleton for a FileOpenResult instance with {@code success=true}.
*/
public static final OpenResult SUCCESS = new OpenResult();
private final String errorMessage;
private final boolean success;
/**
* @param errorMessage
* a textual message describing the error, must not be null.
*/
public OpenResult(String errorMessage) {
if (errorMessage == null) {
throw new IllegalArgumentException("error message must not be null");
}
this.success = false;
this.errorMessage = errorMessage;
}
/**
*
*/
public OpenResult() {
this.success = true;
this.errorMessage = null;
}
/**
* @return a textual error description (might be null).
*/
public String getErrorMessage() {
return this.errorMessage;
}
/**
* @return true if the file could be opened successfully, false otherwise.
*/
public boolean isSuccess() {
return this.success;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("FileOpenResult [success=");
stringBuilder.append(this.success);
stringBuilder.append(", errorMessage=");
stringBuilder.append(this.errorMessage);
stringBuilder.append("]");
return stringBuilder.toString();
}
}

View File

@ -1,22 +0,0 @@
/*
* 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.database;
public enum QueryResult {
SUCCESS,
FAILED,
TILE_NOT_FOUND,
DELAYED,
}

View File

@ -24,8 +24,6 @@ import org.oscim.core.Tile;
import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.database.mapfile.header.MapFileHeader;
import org.oscim.database.mapfile.header.MapFileInfo;
import org.oscim.database.mapfile.header.SubFileParameter;

View File

@ -16,7 +16,7 @@ package org.oscim.database.mapfile.header;
import java.io.IOException;
import org.oscim.database.OpenResult;
import org.oscim.database.IMapDatabase.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
/**

View File

@ -15,7 +15,7 @@
package org.oscim.database.mapfile.header;
import org.oscim.core.GeoPoint;
import org.oscim.database.OpenResult;
import org.oscim.database.IMapDatabase.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
final class OptionalFields {

View File

@ -18,7 +18,7 @@ import java.io.IOException;
import org.oscim.core.BoundingBox;
import org.oscim.core.Tag;
import org.oscim.database.OpenResult;
import org.oscim.database.IMapDatabase.OpenResult;
import org.oscim.database.mapfile.ReadBuffer;
final class RequiredFields {

View File

@ -30,8 +30,6 @@ import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapInfo;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.generator.JobTile;
import android.os.Environment;

View File

@ -43,8 +43,6 @@ import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapInfo;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.generator.JobTile;
import android.os.Environment;

View File

@ -26,9 +26,8 @@ import org.oscim.database.IMapDatabase;
import org.oscim.database.IMapDatabaseCallback;
import org.oscim.database.MapInfo;
import org.oscim.database.MapOptions;
import org.oscim.database.OpenResult;
import org.oscim.database.QueryResult;
import org.oscim.generator.JobTile;
/**
*
*
@ -64,6 +63,10 @@ public class MapDatabase implements IMapDatabase {
mElem = new MapElement();
}
private final boolean renderWays = false;
private final boolean renderBoundary = false;
private final boolean renderPlace = false;
@Override
public QueryResult executeQuery(JobTile tile,
IMapDatabaseCallback mapDatabaseCallback) {
@ -85,10 +88,10 @@ public class MapDatabase implements IMapDatabase {
e.addPoint(x2, y2);
e.addPoint(x1, y2);
y1 = 40;
y2 = size - 40;
x1 = 40;
x2 = size - 40;
y1 = 5;
y2 = size - 5;
x1 = 5;
x2 = size - 5;
e.startHole();
e.addPoint(x1, y1);
@ -99,7 +102,7 @@ public class MapDatabase implements IMapDatabase {
e.set(mTags, 0, GEOM_POLY);
mapDatabaseCallback.renderElement(e);
//--------------
if (renderWays) {
e.clear();
// middle horizontal
@ -120,7 +123,6 @@ public class MapDatabase implements IMapDatabase {
e.set(mTagsWay, 0, GEOM_LINE);
mapDatabaseCallback.renderElement(e);
//--------------
e.clear();
// left-top to center
e.startLine();
@ -137,8 +139,9 @@ public class MapDatabase implements IMapDatabase {
e.set(mTagsWay, 1, GEOM_LINE);
mapDatabaseCallback.renderElement(e);
}
//--------------
if (renderBoundary) {
e.clear();
e.startPolygon();
float r = size / 2;
@ -151,16 +154,17 @@ public class MapDatabase implements IMapDatabase {
e.set(mTagsBoundary, 1, GEOM_LINE);
mapDatabaseCallback.renderElement(e);
}
//--------------
if (renderPlace) {
e.clear();
e.startPoints();
e.addPoint(size/2, size/2);
e.addPoint(size / 2, size / 2);
mTagsPlace[1] = new Tag("name", tile.toString());
e.set(mTagsPlace, 0, GEOM_POINT);
mapDatabaseCallback.renderElement(e);
}
return QueryResult.SUCCESS;
}

View File

@ -17,10 +17,6 @@ package org.oscim.generator;
import org.oscim.core.Tile;
import android.util.Log;
/**
* @author Hannes Janetzek
*/
public class JobTile extends Tile {
private final static String TAG = JobTile.class.getName();