From 08a9ca4293e846597c78755340e41fd984c7976a Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Sun, 21 Apr 2013 23:01:38 +0200 Subject: [PATCH] merge Query- and OpenResult into IMapDatabase --- src/org/oscim/database/IMapDatabase.java | 68 ++++++++++ src/org/oscim/database/IMapTileData.java | 19 --- src/org/oscim/database/OpenResult.java | 75 ----------- src/org/oscim/database/QueryResult.java | 22 ---- .../oscim/database/mapfile/MapDatabase.java | 2 - .../mapfile/header/MapFileHeader.java | 2 +- .../mapfile/header/OptionalFields.java | 2 +- .../mapfile/header/RequiredFields.java | 2 +- .../oscim/database/oscimap/MapDatabase.java | 2 - src/org/oscim/database/pbmap/MapDatabase.java | 2 - src/org/oscim/database/test/MapDatabase.java | 118 +++++++++--------- src/org/oscim/generator/JobTile.java | 4 - 12 files changed, 132 insertions(+), 186 deletions(-) delete mode 100644 src/org/oscim/database/IMapTileData.java delete mode 100644 src/org/oscim/database/OpenResult.java delete mode 100644 src/org/oscim/database/QueryResult.java diff --git a/src/org/oscim/database/IMapDatabase.java b/src/org/oscim/database/IMapDatabase.java index f010a311..8bea5626 100644 --- a/src/org/oscim/database/IMapDatabase.java +++ b/src/org/oscim/database/IMapDatabase.java @@ -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(); + } + } + } diff --git a/src/org/oscim/database/IMapTileData.java b/src/org/oscim/database/IMapTileData.java deleted file mode 100644 index 9703fff6..00000000 --- a/src/org/oscim/database/IMapTileData.java +++ /dev/null @@ -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 . - */ -package org.oscim.database; - -public interface IMapTileData { - -} diff --git a/src/org/oscim/database/OpenResult.java b/src/org/oscim/database/OpenResult.java deleted file mode 100644 index a94d0b01..00000000 --- a/src/org/oscim/database/OpenResult.java +++ /dev/null @@ -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 . - */ -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(); - } -} diff --git a/src/org/oscim/database/QueryResult.java b/src/org/oscim/database/QueryResult.java deleted file mode 100644 index 504eab1b..00000000 --- a/src/org/oscim/database/QueryResult.java +++ /dev/null @@ -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 . - */ -package org.oscim.database; - -public enum QueryResult { - SUCCESS, - FAILED, - TILE_NOT_FOUND, - DELAYED, -} diff --git a/src/org/oscim/database/mapfile/MapDatabase.java b/src/org/oscim/database/mapfile/MapDatabase.java index a58108e8..793b6709 100644 --- a/src/org/oscim/database/mapfile/MapDatabase.java +++ b/src/org/oscim/database/mapfile/MapDatabase.java @@ -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; diff --git a/src/org/oscim/database/mapfile/header/MapFileHeader.java b/src/org/oscim/database/mapfile/header/MapFileHeader.java index 37504b79..65d15949 100644 --- a/src/org/oscim/database/mapfile/header/MapFileHeader.java +++ b/src/org/oscim/database/mapfile/header/MapFileHeader.java @@ -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; /** diff --git a/src/org/oscim/database/mapfile/header/OptionalFields.java b/src/org/oscim/database/mapfile/header/OptionalFields.java index 89ea9e50..84fadd48 100644 --- a/src/org/oscim/database/mapfile/header/OptionalFields.java +++ b/src/org/oscim/database/mapfile/header/OptionalFields.java @@ -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 { diff --git a/src/org/oscim/database/mapfile/header/RequiredFields.java b/src/org/oscim/database/mapfile/header/RequiredFields.java index 97097bfb..fd4f8659 100644 --- a/src/org/oscim/database/mapfile/header/RequiredFields.java +++ b/src/org/oscim/database/mapfile/header/RequiredFields.java @@ -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 { diff --git a/src/org/oscim/database/oscimap/MapDatabase.java b/src/org/oscim/database/oscimap/MapDatabase.java index 473721c2..3aefb0d5 100644 --- a/src/org/oscim/database/oscimap/MapDatabase.java +++ b/src/org/oscim/database/oscimap/MapDatabase.java @@ -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; diff --git a/src/org/oscim/database/pbmap/MapDatabase.java b/src/org/oscim/database/pbmap/MapDatabase.java index 6b111c44..737afb5a 100644 --- a/src/org/oscim/database/pbmap/MapDatabase.java +++ b/src/org/oscim/database/pbmap/MapDatabase.java @@ -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; diff --git a/src/org/oscim/database/test/MapDatabase.java b/src/org/oscim/database/test/MapDatabase.java index ae6e44e7..8a682ff8 100644 --- a/src/org/oscim/database/test/MapDatabase.java +++ b/src/org/oscim/database/test/MapDatabase.java @@ -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; + /** * * @@ -47,8 +46,8 @@ public class MapDatabase implements IMapDatabase { new Tag("admin_level", "2") }; private final Tag[] mTagsPlace = { - new Tag("place", "city"), - null + new Tag("place", "city"), + null }; private final MapInfo mMapInfo = @@ -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,68 +102,69 @@ public class MapDatabase implements IMapDatabase { e.set(mTags, 0, GEOM_POLY); mapDatabaseCallback.renderElement(e); - //-------------- - e.clear(); + if (renderWays) { + e.clear(); - // middle horizontal - e.startLine(); - e.addPoint(0, size / 2); - e.addPoint(size, size / 2); + // middle horizontal + e.startLine(); + e.addPoint(0, size / 2); + e.addPoint(size, size / 2); - // center up - e.startLine(); - e.addPoint(size / 2, -size / 2); - e.addPoint(size / 2, size / 2); + // center up + e.startLine(); + e.addPoint(size / 2, -size / 2); + e.addPoint(size / 2, size / 2); - // center down - e.startLine(); - e.addPoint(size / 2, size / 2); - e.addPoint(size / 2, size / 2 + size); + // center down + e.startLine(); + e.addPoint(size / 2, size / 2); + e.addPoint(size / 2, size / 2 + size); - e.set(mTagsWay, 0, GEOM_LINE); - mapDatabaseCallback.renderElement(e); + e.set(mTagsWay, 0, GEOM_LINE); + mapDatabaseCallback.renderElement(e); - //-------------- - e.clear(); - // left-top to center - e.startLine(); - e.addPoint(size / 2, size / 2); - e.addPoint(10, 10); + e.clear(); + // left-top to center + e.startLine(); + e.addPoint(size / 2, size / 2); + e.addPoint(10, 10); - e.startLine(); - e.addPoint(0, 10); - e.addPoint(size, 10); + e.startLine(); + e.addPoint(0, 10); + e.addPoint(size, 10); - e.startLine(); - e.addPoint(10, 0); - e.addPoint(10, size); + e.startLine(); + e.addPoint(10, 0); + e.addPoint(10, size); - e.set(mTagsWay, 1, GEOM_LINE); - mapDatabaseCallback.renderElement(e); - - //-------------- - e.clear(); - e.startPolygon(); - float r = size / 2; - - for (int i = 0; i < 360; i += 4) { - double d = Math.toRadians(i); - e.addPoint(r + (float) Math.cos(d) * (r - 40), - r + (float) Math.sin(d) * (r - 40)); + e.set(mTagsWay, 1, GEOM_LINE); + mapDatabaseCallback.renderElement(e); } - e.set(mTagsBoundary, 1, GEOM_LINE); - mapDatabaseCallback.renderElement(e); + if (renderBoundary) { + e.clear(); + e.startPolygon(); + float r = size / 2; - //-------------- - e.clear(); - e.startPoints(); - e.addPoint(size/2, size/2); + for (int i = 0; i < 360; i += 4) { + double d = Math.toRadians(i); + e.addPoint(r + (float) Math.cos(d) * (r - 40), + r + (float) Math.sin(d) * (r - 40)); + } - mTagsPlace[1] = new Tag("name", tile.toString()); - e.set(mTagsPlace, 0, GEOM_POINT); - mapDatabaseCallback.renderElement(e); + e.set(mTagsBoundary, 1, GEOM_LINE); + mapDatabaseCallback.renderElement(e); + } + if (renderPlace) { + e.clear(); + e.startPoints(); + 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; } diff --git a/src/org/oscim/generator/JobTile.java b/src/org/oscim/generator/JobTile.java index b3314009..f4bc4ca9 100644 --- a/src/org/oscim/generator/JobTile.java +++ b/src/org/oscim/generator/JobTile.java @@ -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();