private void deleteTableMappings(StyleMappingDao mappingDao,
                                     String featureTable) {
        if (mappingDao != null) {
            Long featureContentsId = contentsId.getId(featureTable);
            if (featureContentsId != null) {
                mappingDao.deleteByBaseId(featureContentsId);
            }
        }
    }

private void deleteTableMappings ( StyleMappingDao mappingDao , String featureTable ) { if ( mappingDao != null ) { Long featureContentsId = contentsId . getId ( featureTable ) ; if ( featureContentsId != null ) { mappingDao . deleteByBaseId ( featureContentsId ) ; } } }

Delete the table style mappings

@param mappingDao   mapping dao
@param featureTable feature table


private void deleteTableMapping(StyleMappingDao mappingDao,
                                    String featureTable, GeometryType geometryType) {
        if (mappingDao != null) {
            Long featureContentsId = contentsId.getId(featureTable);
            if (featureContentsId != null) {
                mappingDao.deleteByBaseId(featureContentsId, geometryType);
            }
        }
    }

private void deleteTableMapping ( StyleMappingDao mappingDao , String featureTable , GeometryType geometryType ) { if ( mappingDao != null ) { Long featureContentsId = contentsId . getId ( featureTable ) ; if ( featureContentsId != null ) { mappingDao . deleteByBaseId ( featureContentsId , geometryType ) ; } } }

Delete the table style mapping with the geometry type value

@param mappingDao   mapping dao
@param featureTable feature table
@param geometryType geometry type


private void deleteMapping(StyleMappingDao mappingDao, long featureId,
                               GeometryType geometryType) {
        if (mappingDao != null) {
            mappingDao.deleteByBaseId(featureId, geometryType);
        }
    }

private void deleteMapping ( StyleMappingDao mappingDao , long featureId , GeometryType geometryType ) { if ( mappingDao != null ) { mappingDao . deleteByBaseId ( featureId , geometryType ) ; } }

Delete the style mapping with the geometry type value

@param mappingDao   mapping dao
@param featureId    feature id
@param geometryType geometry type


public List<Long> getAllTableStyleIds(String featureTable) {
        List<Long> styleIds = null;
        StyleMappingDao mappingDao = getTableStyleMappingDao(featureTable);
        if (mappingDao != null) {
            styleIds = mappingDao.uniqueRelatedIds();
        }
        return styleIds;
    }

public List < Long > getAllTableStyleIds ( String featureTable ) { List < Long > styleIds = null ; StyleMappingDao mappingDao = getTableStyleMappingDao ( featureTable ) ; if ( mappingDao != null ) { styleIds = mappingDao . uniqueRelatedIds ( ) ; } return styleIds ; }

Get all the unique style row ids the table maps to

@param featureTable feature table
@return style row ids


public List<Long> getAllTableIconIds(String featureTable) {
        List<Long> iconIds = null;
        StyleMappingDao mappingDao = getTableIconMappingDao(featureTable);
        if (mappingDao != null) {
            iconIds = mappingDao.uniqueRelatedIds();
        }
        return iconIds;
    }

public List < Long > getAllTableIconIds ( String featureTable ) { List < Long > iconIds = null ; StyleMappingDao mappingDao = getTableIconMappingDao ( featureTable ) ; if ( mappingDao != null ) { iconIds = mappingDao . uniqueRelatedIds ( ) ; } return iconIds ; }

Get all the unique icon row ids the table maps to

@param featureTable feature table
@return icon row ids


public List<Long> getAllStyleIds(String featureTable) {
        List<Long> styleIds = null;
        StyleMappingDao mappingDao = getStyleMappingDao(featureTable);
        if (mappingDao != null) {
            styleIds = mappingDao.uniqueRelatedIds();
        }
        return styleIds;
    }

public List < Long > getAllStyleIds ( String featureTable ) { List < Long > styleIds = null ; StyleMappingDao mappingDao = getStyleMappingDao ( featureTable ) ; if ( mappingDao != null ) { styleIds = mappingDao . uniqueRelatedIds ( ) ; } return styleIds ; }

Get all the unique style row ids the features map to

@param featureTable feature table
@return style row ids


public List<Long> getAllIconIds(String featureTable) {
        List<Long> iconIds = null;
        StyleMappingDao mappingDao = getIconMappingDao(featureTable);
        if (mappingDao != null) {
            iconIds = mappingDao.uniqueRelatedIds();
        }
        return iconIds;
    }

public List < Long > getAllIconIds ( String featureTable ) { List < Long > iconIds = null ; StyleMappingDao mappingDao = getIconMappingDao ( featureTable ) ; if ( mappingDao != null ) { iconIds = mappingDao . uniqueRelatedIds ( ) ; } return iconIds ; }

Get all the unique icon row ids the features map to

@param featureTable feature table
@return icon row ids


public byte[] getImageBytes() {
        byte[] bytes = null;
        if (imageBytes != null) {
            bytes = imageBytes;
        } else if (outputStream != null) {
            bytes = outputStream.toByteArray();
        }
        return bytes;
    }

public byte [ ] getImageBytes ( ) { byte [ ] bytes = null ; if ( imageBytes != null ) { bytes = imageBytes ; } else if ( outputStream != null ) { bytes = outputStream . toByteArray ( ) ; } return bytes ; }

Get the image bytes

@return image bytes


public void flushStream() {
        if (outputStream != null) {
            if (imageBytes == null) {
                imageBytes = outputStream.toByteArray();
            }
            try {
                outputStream.close();
            } catch (IOException e) {
                Log.w(CoverageDataPngImage.class.getSimpleName(), "Failed to close output stream", e);
            }
        }
    }

public
void
flushStream
(
)
{
if
(
outputStream
!=
)
{
if
(
imageBytes
==
)
{
imageBytes
=
outputStream
.
toByteArray
(
)
;
}
try
{
outputStream
.
close
(
)
;
}
catch
(
IOException
e
)
{
Log
.
w
(
CoverageDataPngImage
.
class
.
getSimpleName
(
)
,
"Failed to close output stream"
,
e
)
;
}
}
}

Flush the output stream and set the image bytes, close the stream

Flush the output stream and set the image bytes close the stream


public int getPixel(int x, int y) {
        int pixel = -1;
        if (pixels == null) {
            readPixels();
        }
        if (pixels != null) {
            pixel = pixels[y][x];
        } else {
            throw new GeoPackageException("Could not retrieve pixel value");
        }
        return pixel;
    }

public
int
getPixel
(
int
x
,
int
y
)
{
int
pixel
=
1
;
if
(
pixels
==
)
{
readPixels
(
)
;
}
if
(
pixels
!=
)
{
pixel
=
pixels
[
y
]
[
x
]
;
}
else
{
throw
new
GeoPackageException
(
"Could not retrieve pixel value"
)
;
}
return
pixel
;
}

Get the pixel at the coordinate

@param x x coordinate
@param y y coordinate
@return pixel value


private void readPixels() {
        if (reader != null) {
            pixels = new int[reader.imgInfo.rows][reader.imgInfo.cols];
            int rowCount = 0;
            while (reader.hasMoreRows()) {
                ImageLineInt row = reader.readRowInt();
                int[] columnValues = new int[reader.imgInfo.cols];
                System.arraycopy(row.getScanline(), 0, columnValues, 0, columnValues.length);
                pixels[rowCount++] = columnValues;
            }
            reader.close();
        }
    }

private void readPixels ( ) { if ( reader != null ) { pixels = new int [ reader . imgInfo . rows ] [ reader . imgInfo . cols ] ; int rowCount = 0 ; while ( reader . hasMoreRows ( ) ) { ImageLineInt row = reader . readRowInt ( ) ; int [ ] columnValues = new int [ reader . imgInfo . cols ] ; System . arraycopy ( row . getScanline ( ) , 0 , columnValues , 0 , columnValues . length ) ; pixels [ rowCount ++ ] = columnValues ; } reader . close ( ) ; } }


private boolean drawFeature(int zoom, BoundingBox boundingBox, BoundingBox expandedBoundingBox, ProjectionTransform transform, FeatureTileCanvas canvas, FeatureRow row) {

        boolean drawn = false;

        try {
            GeoPackageGeometryData geomData = row.getGeometry();
            if (geomData != null) {
                Geometry geometry = geomData.getGeometry();
                if (geometry != null) {

                    GeometryEnvelope envelope = geomData.getOrBuildEnvelope();
                    BoundingBox geometryBoundingBox = new BoundingBox(envelope);
                    BoundingBox transformedBoundingBox = geometryBoundingBox.transform(transform);

                    if (expandedBoundingBox.intersects(transformedBoundingBox, true)) {

                        double simplifyTolerance = TileBoundingBoxUtils.toleranceDistance(zoom, tileWidth, tileHeight);
                        drawn = drawShape(simplifyTolerance, boundingBox, transform, canvas, row, geometry);

                    }
                }
            }
        } catch (Exception e) {
            Log.e(DefaultFeatureTiles.class.getSimpleName(), "Failed to draw feature in tile. Table: "
                    + featureDao.getTableName(), e);
        }

        return drawn;
    }

Draw the feature on the canvas

@param zoom                zoom level
@param boundingBox         bounding box
@param expandedBoundingBox expanded bounding box
@param transform           projection transform
@param canvas              feature tile canvas
@param row                 feature row
@return true if at least one feature was drawn


private boolean drawLinePath(FeatureTileCanvas canvas, Path path, FeatureStyle featureStyle) {

        Canvas lineCanvas = canvas.getLineCanvas();

        Paint pathPaint = getLinePaint(featureStyle);
        lineCanvas.drawPath(path, pathPaint);

        return true;
    }

private boolean drawLinePath ( FeatureTileCanvas canvas , Path path , FeatureStyle featureStyle ) { Canvas lineCanvas = canvas . getLineCanvas ( ) ; Paint pathPaint = getLinePaint ( featureStyle ) ; lineCanvas . drawPath ( path , pathPaint ) ; return true ; }

Draw the line path on the canvas

@param canvas       canvas
@param path         path
@param featureStyle feature style
@return true if drawn


private boolean drawPolygonPath(FeatureTileCanvas canvas, Path path, FeatureStyle featureStyle) {

        Canvas polygonCanvas = canvas.getPolygonCanvas();

        Paint fillPaint = getPolygonFillPaint(featureStyle);
        if (fillPaint != null) {
            path.setFillType(Path.FillType.EVEN_ODD);
            polygonCanvas.drawPath(path, fillPaint);
        }

        Paint pathPaint = getPolygonPaint(featureStyle);
        polygonCanvas.drawPath(path, pathPaint);

        return true;
    }

private boolean drawPolygonPath ( FeatureTileCanvas canvas , Path path , FeatureStyle featureStyle ) { Canvas polygonCanvas = canvas . getPolygonCanvas ( ) ; Paint fillPaint = getPolygonFillPaint ( featureStyle ) ; if ( fillPaint != null ) { path . setFillType ( Path . FillType . EVEN_ODD ) ; polygonCanvas . drawPath ( path , fillPaint ) ; } Paint pathPaint = getPolygonPaint ( featureStyle ) ; polygonCanvas . drawPath ( path , pathPaint ) ; return true ; }

Draw the path on the canvas

@param canvas       canvas
@param path         path
@param featureStyle feature style


private void addLineString(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, LineString lineString) {

        List<Point> points = lineString.getPoints();

        if (points.size() >= 2) {

            // Try to simplify the number of points in the LineString
            points = simplifyPoints(simplifyTolerance, points);

            for (int i = 0; i < points.size(); i++) {
                Point point = points.get(i);
                Point webMercatorPoint = transform.transform(point);
                float x = TileBoundingBoxUtils.getXPixel(tileWidth, boundingBox,
                        webMercatorPoint.getX());
                float y = TileBoundingBoxUtils.getYPixel(tileHeight, boundingBox,
                        webMercatorPoint.getY());
                if (i == 0) {
                    path.moveTo(x, y);
                } else {
                    path.lineTo(x, y);
                }
            }
        }
    }

Add the linestring to the path

@param simplifyTolerance simplify tolerance in meters
@param boundingBox       bounding box
@param transform         projection transform
@param path              path
@param lineString        line string


private void addPolygon(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, Polygon polygon) {
        List<LineString> rings = polygon.getRings();
        if (!rings.isEmpty()) {

            // Add the polygon points
            LineString polygonLineString = rings.get(0);
            List<Point> polygonPoints = polygonLineString.getPoints();
            if (polygonPoints.size() >= 2) {
                addRing(simplifyTolerance, boundingBox, transform, path, polygonPoints);

                // Add the holes
                for (int i = 1; i < rings.size(); i++) {
                    LineString holeLineString = rings.get(i);
                    List<Point> holePoints = holeLineString.getPoints();
                    if (holePoints.size() >= 2) {
                        addRing(simplifyTolerance, boundingBox, transform, path, holePoints);
                    }
                }
            }
        }
    }

private
void
addPolygon
(
double
simplifyTolerance
,
BoundingBox
boundingBox
,
ProjectionTransform
transform
,
Path
path
,
Polygon
polygon
)
{
List
<
LineString
>
rings
=
polygon
.
getRings
(
)
;
if
(
!
rings
.
isEmpty
(
)
)
{
// Add the polygon points
LineString
polygonLineString
=
rings
.
get
(
0
)
;
List
<
Point
>
polygonPoints
=
polygonLineString
.
getPoints
(
)
;
if
(
polygonPoints
.
size
(
)
>=
2
)
{
addRing
(
simplifyTolerance
,
boundingBox
,
transform
,
path
,
polygonPoints
)
;
// Add the holes
for
(
int
i
=
1
;
i
<
rings
.
size
(
)
;
i
++
)
{
LineString
holeLineString
=
rings
.
get
(
i
)
;
List
<
Point
>
holePoints
=
holeLineString
.
getPoints
(
)
;
if
(
holePoints
.
size
(
)
>=
2
)
{
addRing
(
simplifyTolerance
,
boundingBox
,
transform
,
path
,
holePoints
)
;
}
}
}
}
}

Add the polygon on the canvas

@param simplifyTolerance simplify tolerance in meters
@param boundingBox       bounding box
@param transform         projection transform
@param path              path
@param polygon           polygon


public FeatureCache getCache(String tableName) {
        FeatureCache cache = tableCache.get(tableName);
        if (cache == null) {
            cache = new FeatureCache(maxCacheSize);
            tableCache.put(tableName, cache);
        }
        return cache;
    }

public FeatureCache getCache ( String tableName ) { FeatureCache cache = tableCache . get ( tableName ) ; if ( cache == null ) { cache = new FeatureCache ( maxCacheSize ) ; tableCache . put ( tableName , cache ) ; } return cache ; }

Get or create a feature row cache for the table name

@param tableName feature table name
@return feature row cache


public FeatureRow remove(FeatureRow featureRow) {
        return remove(featureRow.getTable().getTableName(), featureRow.getId());
    }

public FeatureRow remove ( FeatureRow featureRow ) { return remove ( featureRow . getTable ( ) . getTableName ( ) , featureRow . getId ( ) ) ; }

Remove the cached feature row

@param featureRow feature row
@return removed feature row or null


public void clearAndResize(int maxCacheSize) {
        setMaxCacheSize(maxCacheSize);
        for (FeatureCache cache : tableCache.values()) {
            cache.clearAndResize(maxCacheSize);
        }
    }

public void clearAndResize ( int maxCacheSize ) { setMaxCacheSize ( maxCacheSize ) ; for ( FeatureCache cache : tableCache . values ( ) ) { cache . clearAndResize ( maxCacheSize ) ; } }

Clear and resize all caches and update the max cache size

@param maxCacheSize max cache size


public Styles getCachedTableStyles() {

        Styles styles = cachedTableFeatureStyles.getStyles();

        if (styles == null) {
            synchronized (cachedTableFeatureStyles) {
                styles = cachedTableFeatureStyles.getStyles();
                if (styles == null) {
                    styles = getTableStyles();
                    if (styles == null) {
                        styles = new Styles();
                    }
                    cachedTableFeatureStyles.setStyles(styles);
                }
            }
        }

        if (styles.isEmpty()) {
            styles = null;
        }

        return styles;
    }

public Styles getCachedTableStyles ( ) { Styles styles = cachedTableFeatureStyles . getStyles ( ) ; if ( styles == null ) { synchronized ( cachedTableFeatureStyles ) { styles = cachedTableFeatureStyles . getStyles ( ) ; if ( styles == null ) { styles = getTableStyles ( ) ; if ( styles == null ) { styles = new Styles ( ) ; } cachedTableFeatureStyles . setStyles ( styles ) ; } } } if ( styles . isEmpty ( ) ) { styles = null ; } return styles ; }

Get the cached table styles, querying and caching if needed

@return cached table styles

Get the cached table styles querying and caching if needed


public Icons getCachedTableIcons() {

        Icons icons = cachedTableFeatureStyles.getIcons();

        if (icons == null) {
            synchronized (cachedTableFeatureStyles) {
                icons = cachedTableFeatureStyles.getIcons();
                if (icons == null) {
                    icons = getTableIcons();
                    if (icons == null) {
                        icons = new Icons();
                    }
                    cachedTableFeatureStyles.setIcons(icons);
                }
            }
        }

        if (icons.isEmpty()) {
            icons = null;
        }

        return icons;
    }

public Icons getCachedTableIcons ( ) { Icons icons = cachedTableFeatureStyles . getIcons ( ) ; if ( icons == null ) { synchronized ( cachedTableFeatureStyles ) { icons = cachedTableFeatureStyles . getIcons ( ) ; if ( icons == null ) { icons = getTableIcons ( ) ; if ( icons == null ) { icons = new Icons ( ) ; } cachedTableFeatureStyles . setIcons ( icons ) ; } } } if ( icons . isEmpty ( ) ) { icons = null ; } return icons ; }

Get the cached table icons, querying and caching if needed

@return cached table icons

Get the cached table icons querying and caching if needed


public RTreeIndexTableDao getTableDao(FeatureDao featureDao) {

        GeoPackageConnection connection = getGeoPackage().getConnection();
        UserCustomConnection userDb = new UserCustomConnection(connection);
        UserCustomTable userCustomTable = getRTreeTable(featureDao.getTable());
        UserCustomDao userCustomDao = new UserCustomDao(geoPackage.getName(),
                connection, userDb, userCustomTable);

        return new RTreeIndexTableDao(this, userCustomDao, featureDao);
    }

public RTreeIndexTableDao getTableDao ( FeatureDao featureDao ) { GeoPackageConnection connection = getGeoPackage ( ) . getConnection ( ) ; UserCustomConnection userDb = new UserCustomConnection ( connection ) ; UserCustomTable userCustomTable = getRTreeTable ( featureDao . getTable ( ) ) ; UserCustomDao userCustomDao = new UserCustomDao ( geoPackage . getName ( ) , connection , userDb , userCustomTable ) ; return new RTreeIndexTableDao ( this , userCustomDao , featureDao ) ; }

Get a RTree Index Table DAO for the feature dao

@param featureDao feature DAO
@return RTree Index Table DAO
@since 3.1.0


public void setWidth(Double width) {
        if (width != null && width < 0.0) {
            throw new GeoPackageException(
                    "Width must be greater than or equal to 0.0, invalid value: "
                            + width);
        }
        setValue(getWidthColumnIndex(), width);
    }

Set the width

@param width Icon display width, when null use actual icon width


public void setHeight(Double height) {
        if (height != null && height < 0.0) {
            throw new GeoPackageException(
                    "Height must be greater than or equal to 0.0, invalid value: "
                            + height);
        }
        setValue(getHeightColumnIndex(), height);
    }

Set the height

@param height Icon display height, when null use actual icon height


public double[] getDerivedDimensions() {

        Double width = getWidth();
        Double height = getHeight();

        if (width == null || height == null) {

            BitmapFactory.Options options = getDataBounds();
            int dataWidth = options.outWidth;
            int dataHeight = options.outHeight;

            if (width == null) {
                width = (double) dataWidth;

                if (height != null) {
                    width *= (height / dataHeight);
                }
            }

            if (height == null) {
                height = (double) dataHeight;

                if (width != null) {
                    height *= (width / dataWidth);
                }
            }

        }

        return new double[]{width, height};
    }

public double [ ] getDerivedDimensions ( ) { Double width = getWidth ( ) ; Double height = getHeight ( ) ; if ( width == null || height == null ) { BitmapFactory . Options options = getDataBounds ( ) ; int dataWidth = options . outWidth ; int dataHeight = options . outHeight ; if ( width == null ) { width = ( double ) dataWidth ; if ( height != null ) { width *= ( height / dataHeight ) ; } } if ( height == null ) { height = ( double ) dataHeight ; if ( width != null ) { height *= ( width / dataWidth ) ; } } } return new double [ ] { width , height } ; }

Get the derived width and height from the values and icon data, scaled as
needed

@return derived dimensions array with two values, width at index 0, height at index 1

Get the derived width and height from the values and icon data scaled as needed


public static float tileDensity(float density, int tileWidth, int tileHeight) {
        return tileDensity(density, Math.min(tileWidth, tileHeight));
    }

public static float tileDensity ( float density , int tileWidth , int tileHeight ) { return tileDensity ( density , Math . min ( tileWidth , tileHeight ) ) ; }

Get the tile density based upon the display density scale and tile dimensions

@param density    display density: {@link android.util.DisplayMetrics#density}
@param tileWidth  tile width
@param tileHeight tile height
@return tile density


private void readBlobValue(UserRow row, UserColumn column) {

        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        try {

            byte[] blobChunk = new byte[]{0};
            for (int i = 1; blobChunk.length > 0; i += CHUNK_SIZE) {
                if (i > 1) {
                    byteStream.write(blobChunk);
                }
                blobChunk = new byte[]{};
                String query = "select substr(" +
                        CoreSQLUtils.quoteWrap(column.getName()) + ", " + i + ", " + CHUNK_SIZE + ") from "
                        + CoreSQLUtils.quoteWrap(dao.getTableName()) + " where "
                        + CoreSQLUtils.quoteWrap(row.getPkColumn().getName()) + " = " + row.getId();
                Cursor blobCursor = dao.getDatabaseConnection().getDb().rawQuery(query, null);
                try {
                    if (blobCursor.moveToNext()) {
                        blobChunk = blobCursor.getBlob(0);
                    }
                } finally {
                    blobCursor.close();
                }
            }
            byte[] blob = byteStream.toByteArray();
            row.setValue(column.getIndex(), blob);

        } catch (IOException e) {
            Log.e(UserInvalidCursor.class.getSimpleName(), "Failed to read large blob value. Table: "
                    + dao.getTableName() + ", Column: " + column.getName() + ", Position: " + getPosition(), e);
        } finally {
            IOUtils.closeQuietly(byteStream);
        }
    }

Read the blob column value in chunks

@param row    user row
@param column user blob column


public static UserCustomTable readTable(GeoPackageConnection connection,
                                            String tableName) {
        UserCustomTableReader tableReader = new UserCustomTableReader(tableName);
        UserCustomTable customTable = tableReader.readTable(new UserCustomWrapperConnection(connection));
        return customTable;
    }

public static UserCustomTable readTable ( GeoPackageConnection connection , String tableName ) { UserCustomTableReader tableReader = new UserCustomTableReader ( tableName ) ; UserCustomTable customTable = tableReader . readTable ( new UserCustomWrapperConnection ( connection ) ) ; return customTable ; }

Read the table

@param connection GeoPackage connection
@param tableName  table name
@return table


public Color getColorOrDefault() {
        Color color = getColor();
        if (color == null) {
            color = new Color();
        }
        return color;
    }

public Color getColorOrDefault ( ) { Color color = getColor ( ) ; if ( color == null ) { color = new Color ( ) ; } return color ; }

Get the color or default value

@return color


private String validateColor(String color) {
        String validated = color;
        if (color != null) {
            if (!color.startsWith("#")) {
                validated = "#" + color;
            }
            if (!colorPattern.matcher(validated).matches()) {
                throw new GeoPackageException(
                        "Color must be in hex format #RRGGBB or #RGB, invalid value: "
                                + color);
            }
            validated = validated.toUpperCase();
        }
        return validated;
    }

Validate and adjust the color value

@param color color


private Color createColor(String hexColor, Double opacity) {
        Color color = null;
        if (hexColor != null || opacity != null) {
            color = new Color();
            if (hexColor != null) {
                color.setColor(hexColor);
            }
            if (opacity != null) {
                color.setOpacity(opacity.floatValue());
            }
        }
        return color;
    }

private Color createColor ( String hexColor , Double opacity ) { Color color = null ; if ( hexColor != null || opacity != null ) { color = new Color ( ) ; if ( hexColor != null ) { color . setColor ( hexColor ) ; } if ( opacity != null ) { color . setOpacity ( opacity . floatValue ( ) ) ; } } return color ; }

Create a color from the hex color and opacity

@param hexColor hex color
@param opacity  opacity
@return color or null


public static GeoPackageManager getManager(Context context) {
        Thread.currentThread().setContextClassLoader(GeoPackageManager.class.getClassLoader());
        return new GeoPackageManagerImpl(context);
    }

public static GeoPackageManager getManager ( Context context ) { Thread . currentThread ( ) . setContextClassLoader ( GeoPackageManager . class . getClassLoader ( ) ) ; return new GeoPackageManagerImpl ( context ) ; }

Get a GeoPackage Manager

@param context context
@return GeoPackage manager


public void setProgress(GeoPackageProgress progress) {
        featureTableIndex.setProgress(progress);
        featureIndexer.setProgress(progress);
        rTreeIndexTableDao.setProgress(progress);
    }

public void setProgress ( GeoPackageProgress progress ) { featureTableIndex . setProgress ( progress ) ; featureIndexer . setProgress ( progress ) ; rTreeIndexTableDao . setProgress ( progress ) ; }

Set the GeoPackage Progress

@param progress GeoPackage progress


public int index(boolean force, List<FeatureIndexType> types) {
        int count = 0;
        for (FeatureIndexType type : types) {
            int typeCount = index(type, force);
            count = Math.max(count, typeCount);
        }
        return count;
    }

public int index ( boolean force , List < FeatureIndexType > types ) { int count = 0 ; for ( FeatureIndexType type : types ) { int typeCount = index ( type , force ) ; count = Math . max ( count , typeCount ) ; } return count ; }

Index the feature tables for the index types

@param force true to force re-indexing
@param types feature index types
@return largest count of indexed features
@since 2.0.0


public boolean index(FeatureRow row, List<FeatureIndexType> types) {
        boolean indexed = false;
        for (FeatureIndexType type : types) {
            if (index(type, row)) {
                indexed = true;
            }
        }
        return indexed;
    }

public boolean index ( FeatureRow row , List < FeatureIndexType > types ) { boolean indexed = false ; for ( FeatureIndexType type : types ) { if ( index ( type , row ) ) { indexed = true ; } } return indexed ; }

Index the feature row for the index types.
This method assumes that indexing has been completed and
maintained as the last indexed time is updated.

@param row   feature row to index
@param types feature index types
@return true if indexed from any type
@since 2.0.0

Index the feature row for the index types . This method assumes that indexing has been completed and maintained as the last indexed time is updated .


public boolean deleteIndex(Collection<FeatureIndexType> types) {
        boolean deleted = false;
        for (FeatureIndexType type : types) {
            if (deleteIndex(type)) {
                deleted = true;
            }
        }
        return deleted;
    }

public boolean deleteIndex ( Collection < FeatureIndexType > types ) { boolean deleted = false ; for ( FeatureIndexType type : types ) { if ( deleteIndex ( type ) ) { deleted = true ; } } return deleted ; }

Delete the feature index from the index types

@param types feature index types
@return true if deleted from any type
@since 2.0.0


public boolean deleteIndex(FeatureRow row, List<FeatureIndexType> types) {
        boolean deleted = false;
        for (FeatureIndexType type : types) {
            if (deleteIndex(type, row)) {
                deleted = true;
            }
        }
        return deleted;
    }

public boolean deleteIndex ( FeatureRow row , List < FeatureIndexType > types ) { boolean deleted = false ; for ( FeatureIndexType type : types ) { if ( deleteIndex ( type , row ) ) { deleted = true ; } } return deleted ; }

Delete the feature index for the feature row from the index types

@param row   feature row
@param types feature index types
@return true if deleted from any type
@since 2.0.0


public boolean deleteIndex(long geomId, List<FeatureIndexType> types) {
        boolean deleted = false;
        for (FeatureIndexType type : types) {
            if (deleteIndex(type, geomId)) {
                deleted = true;
            }
        }
        return deleted;
    }

public boolean deleteIndex ( long geomId , List < FeatureIndexType > types ) { boolean deleted = false ; for ( FeatureIndexType type : types ) { if ( deleteIndex ( type , geomId ) ) { deleted = true ; } } return deleted ; }

Delete the feature index for the geometry id from the index types

@param geomId geometry id
@param types  feature index types
@return true if deleted from any type
@since 2.0.0


public boolean deleteIndex(FeatureIndexType type, long geomId) {
        if (type == null) {
            throw new GeoPackageException("FeatureIndexType is required to delete index");
        }
        boolean deleted = false;
        switch (type) {
            case GEOPACKAGE:
                deleted = featureTableIndex.deleteIndex(geomId) > 0;
                break;
            case METADATA:
                deleted = featureIndexer.deleteIndex(geomId);
                break;
            case RTREE:
                // Updated by triggers, ignore for RTree
                deleted = true;
                break;
            default:
                throw new GeoPackageException("Unsupported FeatureIndexType: " + type);
        }
        return deleted;
    }

Delete the feature index for the geometry id

@param type   feature index type
@param geomId geometry id
@return true if deleted


public boolean isIndexed() {
        boolean indexed = false;
        for (FeatureIndexType type : indexLocationQueryOrder) {
            indexed = isIndexed(type);
            if (indexed) {
                break;
            }
        }
        return indexed;
    }

public boolean isIndexed ( ) { boolean indexed = false ; for ( FeatureIndexType type : indexLocationQueryOrder ) { indexed = isIndexed ( type ) ; if ( indexed ) { break ; } } return indexed ; }

Determine if the feature table is indexed

@return true if indexed


public List<FeatureIndexType> getIndexedTypes() {
        List<FeatureIndexType> indexed = new ArrayList<>();
        for (FeatureIndexType type : indexLocationQueryOrder) {
            if (isIndexed(type)) {
                indexed.add(type);
            }
        }
        return indexed;
    }

public List < FeatureIndexType > getIndexedTypes ( ) { List < FeatureIndexType > indexed = new ArrayList <> ( ) ; for ( FeatureIndexType type : indexLocationQueryOrder ) { if ( isIndexed ( type ) ) { indexed . add ( type ) ; } } return indexed ; }

Get the indexed types that are currently indexed

@return indexed types
@since 2.0.0


public FeatureIndexResults query() {
        FeatureIndexResults results = null;
        switch (getIndexedType()) {
            case GEOPACKAGE:
                long count = featureTableIndex.count();
                CloseableIterator<GeometryIndex> geometryIndices = featureTableIndex.query();
                results = new FeatureIndexGeoPackageResults(featureTableIndex, count, geometryIndices);
                break;
            case METADATA:
                Cursor geometryMetadata = featureIndexer.query();
                results = new FeatureIndexMetadataResults(featureIndexer, geometryMetadata);
                break;
            case RTREE:
                UserCustomCursor cursor = rTreeIndexTableDao.queryForAll();
                results = new FeatureIndexRTreeResults(rTreeIndexTableDao,
                        cursor);
                break;
            default:
                FeatureCursor featureCursor = featureDao.queryForAll();
                results = new FeatureIndexFeatureResults(featureCursor);
        }
        return results;
    }

public FeatureIndexResults query ( ) { FeatureIndexResults results = null ; switch ( getIndexedType ( ) ) { case GEOPACKAGE : long count = featureTableIndex . count ( ) ; CloseableIterator < GeometryIndex > geometryIndices = featureTableIndex . query ( ) ; results = new FeatureIndexGeoPackageResults ( featureTableIndex , count , geometryIndices ) ; break ; case METADATA : Cursor geometryMetadata = featureIndexer . query ( ) ; results = new FeatureIndexMetadataResults ( featureIndexer , geometryMetadata ) ; break ; case RTREE : UserCustomCursor cursor = rTreeIndexTableDao . queryForAll ( ) ; results = new FeatureIndexRTreeResults ( rTreeIndexTableDao , cursor ) ; break ; default : FeatureCursor featureCursor = featureDao . queryForAll ( ) ; results = new FeatureIndexFeatureResults ( featureCursor ) ; } return results ; }

Query for all feature index results

@return feature index results, close when done


public long count() {
        long count = 0;
        switch (getIndexedType()) {
            case GEOPACKAGE:
                count = featureTableIndex.count();
                break;
            case METADATA:
                count = featureIndexer.count();
                break;
            case RTREE:
                count = rTreeIndexTableDao.count();
                break;
            default:
                count = manualFeatureQuery.countWithGeometries();
        }
        return count;
    }

public long count ( ) { long count = 0 ; switch ( getIndexedType ( ) ) { case GEOPACKAGE : count = featureTableIndex . count ( ) ; break ; case METADATA : count = featureIndexer . count ( ) ; break ; case RTREE : count = rTreeIndexTableDao . count ( ) ; break ; default : count = manualFeatureQuery . countWithGeometries ( ) ; } return count ; }

Query for all feature index count

@return count


public BoundingBox getBoundingBox() {
        BoundingBox bounds = null;
        switch (getIndexedType()) {
            case GEOPACKAGE:
                bounds = featureTableIndex.getBoundingBox();
                break;
            case METADATA:
                bounds = featureIndexer.getBoundingBox();
                break;
            case RTREE:
                bounds = rTreeIndexTableDao.getBoundingBox();
                break;
            default:
                bounds = manualFeatureQuery.getBoundingBox();
        }
        return bounds;
    }

public BoundingBox getBoundingBox ( ) { BoundingBox bounds = null ; switch ( getIndexedType ( ) ) { case GEOPACKAGE : bounds = featureTableIndex . getBoundingBox ( ) ; break ; case METADATA : bounds = featureIndexer . getBoundingBox ( ) ; break ; case RTREE : bounds = rTreeIndexTableDao . getBoundingBox ( ) ; break ; default : bounds = manualFeatureQuery . getBoundingBox ( ) ; } return bounds ; }

Query for the feature index bounds

@return bounding box


public FeatureIndexResults query(BoundingBox boundingBox, Projection projection) {
        FeatureIndexResults results = null;
        switch (getIndexedType()) {
            case GEOPACKAGE:
                long count = featureTableIndex.count(boundingBox, projection);
                CloseableIterator<GeometryIndex> geometryIndices = featureTableIndex.query(boundingBox, projection);
                results = new FeatureIndexGeoPackageResults(featureTableIndex, count, geometryIndices);
                break;
            case METADATA:
                Cursor geometryMetadata = featureIndexer.query(boundingBox, projection);
                results = new FeatureIndexMetadataResults(featureIndexer, geometryMetadata);
                break;
            case RTREE:
                UserCustomCursor cursor = rTreeIndexTableDao.query(
                        boundingBox, projection);
                results = new FeatureIndexRTreeResults(rTreeIndexTableDao,
                        cursor);
                break;
            default:
                results = manualFeatureQuery.query(boundingBox, projection);
        }
        return results;
    }

public FeatureIndexResults query ( BoundingBox boundingBox , Projection projection ) { FeatureIndexResults results = null ; switch ( getIndexedType ( ) ) { case GEOPACKAGE : long count = featureTableIndex . count ( boundingBox , projection ) ; CloseableIterator < GeometryIndex > geometryIndices = featureTableIndex . query ( boundingBox , projection ) ; results = new FeatureIndexGeoPackageResults ( featureTableIndex , count , geometryIndices ) ; break ; case METADATA : Cursor geometryMetadata = featureIndexer . query ( boundingBox , projection ) ; results = new FeatureIndexMetadataResults ( featureIndexer , geometryMetadata ) ; break ; case RTREE : UserCustomCursor cursor = rTreeIndexTableDao . query ( boundingBox , projection ) ; results = new FeatureIndexRTreeResults ( rTreeIndexTableDao , cursor ) ; break ; default : results = manualFeatureQuery . query ( boundingBox , projection ) ; } return results ; }

Query for feature index results within the bounding box in
the provided projection

@param boundingBox bounding box
@param projection  projection
@return feature index results, close when done


private FeatureIndexType getIndexedType() {

        FeatureIndexType indexType = FeatureIndexType.NONE;

        // Check for an indexed type
        for (FeatureIndexType type : indexLocationQueryOrder) {
            if (isIndexed(type)) {
                indexType = type;
                break;
            }
        }

        return indexType;
    }

private
FeatureIndexType
getIndexedType
(
)
{
FeatureIndexType
indexType
=
FeatureIndexType
.
;
// Check for an indexed type
for
(
FeatureIndexType
type
:
indexLocationQueryOrder
)
{
if
(
isIndexed
(
type
)
)
{
indexType
=
type
;
break
;
}
}
return
indexType
;
}

Get the indexed type or throw an error if not indexed


public static File getInternalFile(Context context, String filePath) {
        File internalFile = null;
        if (filePath != null) {
            internalFile = new File(context.getFilesDir(), filePath);
        } else {
            internalFile = context.getFilesDir();
        }
        return internalFile;
    }

public static File getInternalFile ( Context context , String filePath ) { File internalFile = null ; if ( filePath != null ) { internalFile = new File ( context . getFilesDir ( ) , filePath ) ; } else { internalFile = context . getFilesDir ( ) ; } return internalFile ; }

Get the internal storage file for the file path

@param context  context
@param filePath file path
@return file


public static String getInternalFilePath(Context context, String filePath) {
        return getInternalFile(context, filePath).getAbsolutePath();
    }

public static String getInternalFilePath ( Context context , String filePath ) { return getInternalFile ( context , filePath ) . getAbsolutePath ( ) ; }

Get the internal storage patch for the file path

@param context  context
@param filePath file path
@return file path


public GeometryType getGeometryType() {
        GeometryType geometryType = null;
        String geometryTypeName = getGeometryTypeName();
        if (geometryTypeName != null) {
            geometryType = GeometryType.fromName(geometryTypeName);
        }
        return geometryType;
    }

public GeometryType getGeometryType ( ) { GeometryType geometryType = null ; String geometryTypeName = getGeometryTypeName ( ) ; if ( geometryTypeName != null ) { geometryType = GeometryType . fromName ( geometryTypeName ) ; } return geometryType ; }

Get the geometry type

@return geometry type


public void setGeometryType(GeometryType geometryType) {
        String geometryTypeName = null;
        if (geometryType != null) {
            geometryTypeName = geometryType.getName();
        }
        setValue(getGeometryTypeNameColumnIndex(), geometryTypeName);
    }

public void setGeometryType ( GeometryType geometryType ) { String geometryTypeName = null ; if ( geometryType != null ) { geometryTypeName = geometryType . getName ( ) ; } setValue ( getGeometryTypeNameColumnIndex ( ) , geometryTypeName ) ; }

Set the geometry type

@param geometryType geometry type


private boolean hasBoundingBox(String url) {

        String replacedUrl = replaceBoundingBox(url, boundingBox);
        boolean hasBoundingBox = !replacedUrl.equals(url);

        return hasBoundingBox;
    }

private boolean hasBoundingBox ( String url ) { String replacedUrl = replaceBoundingBox ( url , boundingBox ) ; boolean hasBoundingBox = ! replacedUrl . equals ( url ) ; return hasBoundingBox ; }

Determine if the url has bounding box variables

@param url
@return


private String replaceXYZ(String url, int z, long x, long y) {

        url = url.replaceAll(
                context.getString(R.string.tile_generator_variable_z),
                String.valueOf(z));
        url = url.replaceAll(
                context.getString(R.string.tile_generator_variable_x),
                String.valueOf(x));
        url = url.replaceAll(
                context.getString(R.string.tile_generator_variable_y),
                String.valueOf(y));
        return url;
    }

private String replaceXYZ ( String url , int z , long x , long y ) { url = url . replaceAll ( context . getString ( R . string . tile_generator_variable_z ) , String . valueOf ( z ) ) ; url = url . replaceAll ( context . getString ( R . string . tile_generator_variable_x ) , String . valueOf ( x ) ) ; url = url . replaceAll ( context . getString ( R . string . tile_generator_variable_y ) , String . valueOf ( y ) ) ; return url ; }

Replace x, y, and z in the url

@param url
@param z
@param x
@param y
@return


private boolean hasXYZ(String url) {

        String replacedUrl = replaceXYZ(url, 0, 0, 0);
        boolean hasXYZ = !replacedUrl.equals(url);

        return hasXYZ;
    }

private boolean hasXYZ ( String url ) { String replacedUrl = replaceXYZ ( url , 0 , 0 , 0 ) ; boolean hasXYZ = ! replacedUrl . equals ( url ) ; return hasXYZ ; }

Determine if the url has x, y, or z variables

@param url
@return

Determine if the url has x y or z variables


private String replaceBoundingBox(String url, int z, long x, long y) {

        BoundingBox boundingBox = TileBoundingBoxUtils.getProjectedBoundingBox(
                projection, x, y, z);

        url = replaceBoundingBox(url, boundingBox);

        return url;
    }

private String replaceBoundingBox ( String url , int z , long x , long y ) { BoundingBox boundingBox = TileBoundingBoxUtils . getProjectedBoundingBox ( projection , x , y , z ) ; url = replaceBoundingBox ( url , boundingBox ) ; return url ; }

Replace the bounding box coordinates in the url

@param url
@param z
@param x
@param y
@return


private String replaceBoundingBox(String url, BoundingBox boundingBox) {

        url = url.replaceAll(
                context.getString(R.string.tile_generator_variable_min_lat),
                String.valueOf(boundingBox.getMinLatitude()));
        url = url.replaceAll(
                context.getString(R.string.tile_generator_variable_max_lat),
                String.valueOf(boundingBox.getMaxLatitude()));
        url = url.replaceAll(
                context.getString(R.string.tile_generator_variable_min_lon),
                String.valueOf(boundingBox.getMinLongitude()));
        url = url.replaceAll(
                context.getString(R.string.tile_generator_variable_max_lon),
                String.valueOf(boundingBox.getMaxLongitude()));

        return url;
    }

private String replaceBoundingBox ( String url , BoundingBox boundingBox ) { url = url . replaceAll ( context . getString ( R . string . tile_generator_variable_min_lat ) , String . valueOf ( boundingBox . getMinLatitude ( ) ) ) ; url = url . replaceAll ( context . getString ( R . string . tile_generator_variable_max_lat ) , String . valueOf ( boundingBox . getMaxLatitude ( ) ) ) ; url = url . replaceAll ( context . getString ( R . string . tile_generator_variable_min_lon ) , String . valueOf ( boundingBox . getMinLongitude ( ) ) ) ; url = url . replaceAll ( context . getString ( R . string . tile_generator_variable_max_lon ) , String . valueOf ( boundingBox . getMaxLongitude ( ) ) ) ; return url ; }

Replace the url parts with the bounding box

@param url
@param boundingBox
@return


public GeoPackageGeometryData getGeometry() {

        GeoPackageGeometryData geometry = null;

        int columnIndex = getTable().getGeometryColumnIndex();
        int type = getType(columnIndex);

        if (type != FIELD_TYPE_NULL) {
            byte[] geometryBytes = getBlob(columnIndex);

            if (geometryBytes != null) {
                geometry = new GeoPackageGeometryData(geometryBytes);
            }
        }

        return geometry;
    }

public GeoPackageGeometryData getGeometry ( ) { GeoPackageGeometryData geometry = null ; int columnIndex = getTable ( ) . getGeometryColumnIndex ( ) ; int type = getType ( columnIndex ) ; if ( type != FIELD_TYPE_NULL ) { byte [ ] geometryBytes = getBlob ( columnIndex ) ; if ( geometryBytes != null ) { geometry = new GeoPackageGeometryData ( geometryBytes ) ; } } return geometry ; }


private boolean index(long geoPackageId, FeatureRow row, boolean possibleUpdate) {

        boolean indexed = false;

        GeoPackageGeometryData geomData = row.getGeometry();
        if (geomData != null) {

            // Get the envelope
            GeometryEnvelope envelope = geomData.getEnvelope();

            // If no envelope, build one from the geometry
            if (envelope == null) {
                Geometry geometry = geomData.getGeometry();
                if (geometry != null) {
                    envelope = GeometryEnvelopeBuilder.buildEnvelope(geometry);
                }
            }

            // Create the new index row
            if (envelope != null) {
                GeometryMetadata metadata = geometryMetadataDataSource.populate(geoPackageId, featureDao.getTableName(), row.getId(), envelope);
                if (possibleUpdate) {
                    geometryMetadataDataSource.createOrUpdate(metadata);
                } else {
                    geometryMetadataDataSource.create(metadata);
                }
                indexed = true;
            }
        }

        return indexed;
    }

Index the feature row

@param geoPackageId   GeoPackage id
@param row            feature row
@param possibleUpdate possible update flag
@return true if indexed


private void updateLastIndexed(GeoPackageMetadataDb db, long geoPackageId) {

        long indexedTime = (new Date()).getTime();

        TableMetadataDataSource ds = new TableMetadataDataSource(db);
        if (!ds.updateLastIndexed(geoPackageId, featureDao.getTableName(), indexedTime)) {
            throw new GeoPackageException("Failed to update last indexed time. Table: GeoPackage Id: "
                    + geoPackageId + ", Table: " + featureDao.getTableName() + ", Last Indexed: " + indexedTime);
        }

    }

Update the least indexed time

@param db           metadata db
@param geoPackageId GeoPackage id


public boolean deleteIndex() {
        TableMetadataDataSource tableMetadataDataSource = new TableMetadataDataSource(db);
        boolean deleted = tableMetadataDataSource.delete(featureDao.getDatabase(), featureDao.getTableName());
        return deleted;
    }

public boolean deleteIndex ( ) { TableMetadataDataSource tableMetadataDataSource = new TableMetadataDataSource ( db ) ; boolean deleted = tableMetadataDataSource . delete ( featureDao . getDatabase ( ) , featureDao . getTableName ( ) ) ; return deleted ; }

Delete the feature table index

@return true if index deleted
@since 1.1.0


public boolean deleteIndex(long geomId) {
        boolean deleted = geometryMetadataDataSource.delete(
                featureDao.getDatabase(), featureDao.getTableName(), geomId);
        return deleted;
    }

public boolean deleteIndex ( long geomId ) { boolean deleted = geometryMetadataDataSource . delete ( featureDao . getDatabase ( ) , featureDao . getTableName ( ) , geomId ) ; return deleted ; }

Delete the index for the geometry id

@param geomId geometry id
@return true if deleted


public boolean isIndexed() {

        boolean indexed = false;

        Date lastIndexed = getLastIndexed();
        if (lastIndexed != null) {
            Contents contents = featureDao.getGeometryColumns().getContents();
            Date lastChange = contents.getLastChange();
            indexed = lastIndexed.equals(lastChange) || lastIndexed.after(lastChange);
        }

        return indexed;
    }

public boolean isIndexed ( ) { boolean indexed = false ; Date lastIndexed = getLastIndexed ( ) ; if ( lastIndexed != null ) { Contents contents = featureDao . getGeometryColumns ( ) . getContents ( ) ; Date lastChange = contents . getLastChange ( ) ; indexed = lastIndexed . equals ( lastChange ) || lastIndexed . after ( lastChange ) ; } return indexed ; }

Determine if the database table is indexed after database modifications

@return true if indexed


public Cursor query() {
        Cursor cursor = geometryMetadataDataSource.query(featureDao.getDatabase(), featureDao.getTableName());
        return cursor;
    }

public Cursor query ( ) { Cursor cursor = geometryMetadataDataSource . query ( featureDao . getDatabase ( ) , featureDao . getTableName ( ) ) ; return cursor ; }

Query for all Geometry Metadata

@return geometry metadata cursor
@since 1.1.0


public Cursor query(BoundingBox boundingBox) {
        Cursor cursor = geometryMetadataDataSource.query(featureDao.getDatabase(), featureDao.getTableName(), boundingBox);
        return cursor;
    }

public Cursor query ( BoundingBox boundingBox ) { Cursor cursor = geometryMetadataDataSource . query ( featureDao . getDatabase ( ) , featureDao . getTableName ( ) , boundingBox ) ; return cursor ; }

Query for Geometry Metadata within the bounding box, projected
correctly

@param boundingBox bounding box
@return geometry metadata cursor
@since 1.1.0

Query for Geometry Metadata within the bounding box projected correctly


public int count(BoundingBox boundingBox) {
        int count = geometryMetadataDataSource.count(featureDao.getDatabase(), featureDao.getTableName(), boundingBox);
        return count;
    }

public int count ( BoundingBox boundingBox ) { int count = geometryMetadataDataSource . count ( featureDao . getDatabase ( ) , featureDao . getTableName ( ) , boundingBox ) ; return count ; }

Query for Geometry Metadata count within the bounding box, projected
correctly

@param boundingBox bounding box
@return count
@since 1.1.0

Query for Geometry Metadata count within the bounding box projected correctly


public Cursor query(GeometryEnvelope envelope) {
        Cursor cursor = geometryMetadataDataSource.query(featureDao.getDatabase(), featureDao.getTableName(), envelope);
        return cursor;
    }

public Cursor query ( GeometryEnvelope envelope ) { Cursor cursor = geometryMetadataDataSource . query ( featureDao . getDatabase ( ) , featureDao . getTableName ( ) , envelope ) ; return cursor ; }

Query for Geometry Metadata within the Geometry Envelope

@param envelope geometry envelope
@return geometry metadata cursor
@since 1.1.0


public int count(GeometryEnvelope envelope) {
        int count = geometryMetadataDataSource.count(featureDao.getDatabase(), featureDao.getTableName(), envelope);
        return count;
    }

public int count ( GeometryEnvelope envelope ) { int count = geometryMetadataDataSource . count ( featureDao . getDatabase ( ) , featureDao . getTableName ( ) , envelope ) ; return count ; }

Query for Geometry Metadata count within the Geometry Envelope

@param envelope geometry envelope
@return count
@since 1.1.0


public Cursor query(BoundingBox boundingBox,
                        Projection projection) {

        BoundingBox featureBoundingBox = getFeatureBoundingBox(boundingBox,
                projection);

        Cursor cursor = query(featureBoundingBox);

        return cursor;
    }

public Cursor query ( BoundingBox boundingBox , Projection projection ) { BoundingBox featureBoundingBox = getFeatureBoundingBox ( boundingBox , projection ) ; Cursor cursor = query ( featureBoundingBox ) ; return cursor ; }

Query for Geometry Metadata within the bounding box in
the provided projection

@param boundingBox bounding box
@param projection  projection of the provided bounding box
@return geometry metadata cursor
@since 1.1.0


public long count(BoundingBox boundingBox, Projection projection) {

        BoundingBox featureBoundingBox = getFeatureBoundingBox(boundingBox,
                projection);

        long count = count(featureBoundingBox);

        return count;
    }

public long count ( BoundingBox boundingBox , Projection projection ) { BoundingBox featureBoundingBox = getFeatureBoundingBox ( boundingBox , projection ) ; long count = count ( featureBoundingBox ) ; return count ; }

Query for Geometry Metadata count within the bounding box in
the provided projection

@param boundingBox bounding box
@param projection  projection of the provided bounding box
@return count
@since 1.1.0


private BoundingBox getFeatureBoundingBox(BoundingBox boundingBox,
                                              Projection projection) {
        ProjectionTransform projectionTransform = projection
                .getTransformation(featureDao.getProjection());
        BoundingBox featureBoundingBox = boundingBox
                .transform(projectionTransform);
        return featureBoundingBox;
    }

private BoundingBox getFeatureBoundingBox ( BoundingBox boundingBox , Projection projection ) { ProjectionTransform projectionTransform = projection . getTransformation ( featureDao . getProjection ( ) ) ; BoundingBox featureBoundingBox = boundingBox . transform ( projectionTransform ) ; return featureBoundingBox ; }

Get the bounding box in the feature projection from the bounding box in
the provided projection

@param boundingBox bounding box
@param projection  projection
@return feature projected bounding box


public GeometryMetadata getGeometryMetadata(Cursor cursor) {
        GeometryMetadata geometryMetadata = GeometryMetadataDataSource.createGeometryMetadata(cursor);
        return geometryMetadata;
    }

public GeometryMetadata getGeometryMetadata ( Cursor cursor ) { GeometryMetadata geometryMetadata = GeometryMetadataDataSource . createGeometryMetadata ( cursor ) ; return geometryMetadata ; }

Get the Geometry Metadata for the current place in the cursor

@param cursor cursor
@return geometry metadata
@since 1.1.0


public FeatureRow getFeatureRow(Cursor cursor) {
        GeometryMetadata geometryMetadata = getGeometryMetadata(cursor);
        FeatureRow featureRow = getFeatureRow(geometryMetadata);
        return featureRow;
    }

public FeatureRow getFeatureRow ( Cursor cursor ) { GeometryMetadata geometryMetadata = getGeometryMetadata ( cursor ) ; FeatureRow featureRow = getFeatureRow ( geometryMetadata ) ; return featureRow ; }

Get the feature row for the current place in the cursor

@param cursor cursor
@return feature row
@since 1.1.0


public FeatureRow getFeatureRow(GeometryMetadata geometryMetadata) {

        long geomId = geometryMetadata.getId();

        // Get the row or lock for reading
        FeatureRow row = featureRowSync.getRowOrLock(geomId);
        if (row == null) {
            // Query for the row and set in the sync
            try {
                row = featureDao.queryForIdRow(geomId);
            } finally {
                featureRowSync.setRow(geomId, row);
            }
        }

        return row;
    }

Get the feature row for the Geometry Metadata

@param geometryMetadata geometry metadata
@return feature row
@since 1.1.0


public List<TileDao> getTileDaosForFeatureTable(String featureTable) {

        List<TileDao> tileDaos = new ArrayList<TileDao>();

        List<String> tileTables = getTileTablesForFeatureTable(featureTable);
        for (String tileTable : tileTables) {
            if (geoPackage.isTileTable(tileTable)) {
                TileDao tileDao = geoPackage.getTileDao(tileTable);
                tileDaos.add(tileDao);
            }
        }

        return tileDaos;
    }

public List < TileDao > getTileDaosForFeatureTable ( String featureTable ) { List < TileDao > tileDaos = new ArrayList < TileDao > ( ) ; List < String > tileTables = getTileTablesForFeatureTable ( featureTable ) ; for ( String tileTable : tileTables ) { if ( geoPackage . isTileTable ( tileTable ) ) { TileDao tileDao = geoPackage . getTileDao ( tileTable ) ; tileDaos . add ( tileDao ) ; } } return tileDaos ; }

Query for the tile tables linked to a feature table and return tile DAOs
to those tables

@param featureTable feature table
@return tiles DAOs


public List<FeatureDao> getFeatureDaosForTileTable(String tileTable) {

        List<FeatureDao> featureDaos = new ArrayList<FeatureDao>();

        List<String> featureTables = getFeatureTablesForTileTable(tileTable);
        for (String featureTable : featureTables) {
            if (geoPackage.isFeatureTable(featureTable)) {
                FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
                featureDaos.add(featureDao);
            }
        }

        return featureDaos;
    }

public List < FeatureDao > getFeatureDaosForTileTable ( String tileTable ) { List < FeatureDao > featureDaos = new ArrayList < FeatureDao > ( ) ; List < String > featureTables = getFeatureTablesForTileTable ( tileTable ) ; for ( String featureTable : featureTables ) { if ( geoPackage . isFeatureTable ( featureTable ) ) { FeatureDao featureDao = geoPackage . getFeatureDao ( featureTable ) ; featureDaos . add ( featureDao ) ; } } return featureDaos ; }

Query for the feature tables linked to a tile table and return feature
DAOs to those tables

@param tileTable tile table
@return feature DAOs


private static BoundingBox getBoundingBox(GeoPackage geoPackage,
                                              FeatureTiles featureTiles, BoundingBox boundingBox,
                                              Projection projection) {

        String tableName = featureTiles.getFeatureDao().getTableName();
        boolean manualQuery = boundingBox == null;
        BoundingBox featureBoundingBox = geoPackage.getBoundingBox(projection,
                tableName, manualQuery);
        if (featureBoundingBox != null) {
            if (boundingBox == null) {
                boundingBox = featureBoundingBox;
            } else {
                boundingBox = boundingBox.overlap(featureBoundingBox);
            }
        }

        if (boundingBox != null) {
            boundingBox = featureTiles.expandBoundingBox(boundingBox,
                    projection);
        }

        return boundingBox;
    }

private static BoundingBox getBoundingBox ( GeoPackage geoPackage , FeatureTiles featureTiles , BoundingBox boundingBox , Projection projection ) { String tableName = featureTiles . getFeatureDao ( ) . getTableName ( ) ; boolean manualQuery = boundingBox == null ; BoundingBox featureBoundingBox = geoPackage . getBoundingBox ( projection , tableName , manualQuery ) ; if ( featureBoundingBox != null ) { if ( boundingBox == null ) { boundingBox = featureBoundingBox ; } else { boundingBox = boundingBox . overlap ( featureBoundingBox ) ; } } if ( boundingBox != null ) { boundingBox = featureTiles . expandBoundingBox ( boundingBox , projection ) ; } return boundingBox ; }

Get the bounding box for the feature tile generator, from the provided
and from the feature table

@param geoPackage   GeoPackage
@param featureTiles feature tiles
@param boundingBox  bounding box
@param projection   projection
@return bounding box

Get the bounding box for the feature tile generator from the provided and from the feature table


public UserCustomCursor queryByIds(long baseId, long relatedId) {
        return query(buildWhereIds(baseId, relatedId),
                buildWhereIdsArgs(baseId, relatedId));
    }

public UserCustomCursor queryByIds ( long baseId , long relatedId ) { return query ( buildWhereIds ( baseId , relatedId ) , buildWhereIdsArgs ( baseId , relatedId ) ) ; }

Query by both base id and related id

@param baseId    base id
@param relatedId related id
@return cursor


public List<Long> uniqueBaseIds() {
        return querySingleColumnTypedResults(
                "SELECT DISTINCT " + CoreSQLUtils.quoteWrap(UserMappingTable.COLUMN_BASE_ID) + " FROM "
                        + CoreSQLUtils.quoteWrap(getTableName()), null);
    }

public
List
<
Long
>
uniqueBaseIds
(
)
{
return
querySingleColumnTypedResults
(
"SELECT DISTINCT "
+
CoreSQLUtils
.
quoteWrap
(
UserMappingTable
.
COLUMN_BASE_ID
)
+
" FROM "
+
CoreSQLUtils
.
quoteWrap
(
getTableName
(
)
)
,
)
;
}

Get the unique base ids

@return list of unique base ids
@since 3.2.0


public List<Long> uniqueRelatedIds() {
        return querySingleColumnTypedResults(
                "SELECT DISTINCT " + CoreSQLUtils.quoteWrap(UserMappingTable.COLUMN_RELATED_ID) + " FROM "
                        + CoreSQLUtils.quoteWrap(getTableName()), null);
    }

public
List
<
Long
>
uniqueRelatedIds
(
)
{
return
querySingleColumnTypedResults
(
"SELECT DISTINCT "
+
CoreSQLUtils
.
quoteWrap
(
UserMappingTable
.
COLUMN_RELATED_ID
)
+
" FROM "
+
CoreSQLUtils
.
quoteWrap
(
getTableName
(
)
)
,
)
;
}

Get the unique related ids

@return list of unique related ids
@since 3.2.0


public int deleteByBaseId(long baseId) {

        StringBuilder where = new StringBuilder();
        where.append(buildWhere(UserMappingTable.COLUMN_BASE_ID, baseId));

        String[] whereArgs = buildWhereArgs(new Object[]{baseId});

        int deleted = delete(where.toString(), whereArgs);

        return deleted;
    }

public int deleteByBaseId ( long baseId ) { StringBuilder where = new StringBuilder ( ) ; where . append ( buildWhere ( UserMappingTable . COLUMN_BASE_ID , baseId ) ) ; String [ ] whereArgs = buildWhereArgs ( new Object [ ] { baseId } ) ; int deleted = delete ( where . toString ( ) , whereArgs ) ; return deleted ; }

Delete user mappings by base id

@param baseId base id
@return rows deleted


public int deleteByRelatedId(long relatedId) {

        StringBuilder where = new StringBuilder();
        where.append(buildWhere(UserMappingTable.COLUMN_RELATED_ID, relatedId));

        String[] whereArgs = buildWhereArgs(new Object[]{relatedId});

        int deleted = delete(where.toString(), whereArgs);

        return deleted;
    }

public int deleteByRelatedId ( long relatedId ) { StringBuilder where = new StringBuilder ( ) ; where . append ( buildWhere ( UserMappingTable . COLUMN_RELATED_ID , relatedId ) ) ; String [ ] whereArgs = buildWhereArgs ( new Object [ ] { relatedId } ) ; int deleted = delete ( where . toString ( ) , whereArgs ) ; return deleted ; }

Delete user mappings by related id

@param relatedId related id
@return rows deleted


public int deleteByIds(long baseId, long relatedId) {
        return delete(buildWhereIds(baseId, relatedId),
                buildWhereIdsArgs(baseId, relatedId));
    }

public int deleteByIds ( long baseId , long relatedId ) { return delete ( buildWhereIds ( baseId , relatedId ) , buildWhereIdsArgs ( baseId , relatedId ) ) ; }

Delete user mappings by both base id and related id

@param baseId    base id
@param relatedId related id
@return rows deleted


private String buildWhereIds(long baseId, long relatedId) {

        StringBuilder where = new StringBuilder();
        where.append(buildWhere(UserMappingTable.COLUMN_BASE_ID, baseId));
        where.append(" AND ");
        where.append(buildWhere(UserMappingTable.COLUMN_RELATED_ID, relatedId));

        return where.toString();
    }

private
String
buildWhereIds
(
long
baseId
,
long
relatedId
)
{
StringBuilder
where
=
new
StringBuilder
(
)
;
where
.
append
(
buildWhere
(
UserMappingTable
.
COLUMN_BASE_ID
,
baseId
)
)
;
where
.
append
(
" AND "
)
;
where
.
append
(
buildWhere
(
UserMappingTable
.
COLUMN_RELATED_ID
,
relatedId
)
)
;
return
where
.
toString
(
)
;
}

Build the where ids clause

@param baseId    base id
@param relatedId related id
@return where clause


public void create(GeoPackageMetadata metadata) {
        ContentValues values = new ContentValues();
        values.put(GeoPackageMetadata.COLUMN_NAME, metadata.getName());
        values.put(GeoPackageMetadata.COLUMN_EXTERNAL_PATH, metadata.getExternalPath());
        long insertId = db.insert(
                GeoPackageMetadata.TABLE_NAME, null,
                values);
        if (insertId == -1) {
            throw new GeoPackageException(
                    "Failed to insert GeoPackage metadata. Name: "
                            + metadata.getName() + ", External Path: "
                            + metadata.getExternalPath());
        }
        metadata.setId(insertId);
    }

Create a new GeoPackage metadata

@param metadata GeoPackage metadata


public boolean delete(String database) {

        GeoPackageMetadata metadata = get(database);
        if (metadata != null) {
            TableMetadataDataSource tableDs = new TableMetadataDataSource(db);
            tableDs.delete(metadata.getId());
        }

        String whereClause = GeoPackageMetadata.COLUMN_NAME + " = ?";
        String[] whereArgs = new String[]{database};
        int deleteCount = db.delete(
                GeoPackageMetadata.TABLE_NAME,
                whereClause, whereArgs);
        return deleteCount > 0;
    }

public
boolean
delete
(
String
database
)
{
GeoPackageMetadata
metadata
=
get
(
database
)
;
if
(
metadata
!=
)
{
TableMetadataDataSource
tableDs
=
new
TableMetadataDataSource
(
db
)
;
tableDs
.
delete
(
metadata
.
getId
(
)
)
;
}
String
whereClause
=
GeoPackageMetadata
.
COLUMN_NAME
+
" = ?"
;
String
[
]
whereArgs
=
new
String
[
]
{
database
}
;
int
deleteCount
=
db
.
delete
(
GeoPackageMetadata
.
TABLE_NAME
,
whereClause
,
whereArgs
)
;
return
deleteCount
>
0
;
}

Delete the database

@param database database name
@return deleted flag


public boolean rename(GeoPackageMetadata metadata, String newName) {
        boolean renamed = rename(metadata.getName(), newName);
        if (renamed) {
            metadata.setName(newName);
        }
        return renamed;
    }

public boolean rename ( GeoPackageMetadata metadata , String newName ) { boolean renamed = rename ( metadata . getName ( ) , newName ) ; if ( renamed ) { metadata . setName ( newName ) ; } return renamed ; }

Rename the GeoPackage metadata to the new name

@param metadata GeoPackage metadata
@param newName  new name
@return renamed flag


public boolean rename(String name, String newName) {
        String whereClause = GeoPackageMetadata.COLUMN_NAME + " = ?";
        String[] whereArgs = new String[]{name};
        ContentValues values = new ContentValues();
        values.put(GeoPackageMetadata.COLUMN_NAME, newName);
        int updateCount = db.update(
                GeoPackageMetadata.TABLE_NAME, values,
                whereClause, whereArgs);
        return updateCount > 0;
    }

public
boolean
rename
(
String
name
,
String
newName
)
{
String
whereClause
=
GeoPackageMetadata
.
COLUMN_NAME
+
" = ?"
;
String
[
]
whereArgs
=
new
String
[
]
{
name
}
;
ContentValues
values
=
new
ContentValues
(
)
;
values
.
put
(
GeoPackageMetadata
.
COLUMN_NAME
,
newName
)
;
int
updateCount
=
db
.
update
(
GeoPackageMetadata
.
TABLE_NAME
,
values
,
whereClause
,
whereArgs
)
;
return
updateCount
>
0
;
}

Rename the GeoPackage name to the new name

@param name    GeoPackage name
@param newName new name
@return renamed flag


public List<GeoPackageMetadata> getAll() {
        List<GeoPackageMetadata> allMetadata = new ArrayList<GeoPackageMetadata>();

        Cursor cursor = db.query(
                GeoPackageMetadata.TABLE_NAME,
                GeoPackageMetadata.COLUMNS, null, null, null, null, null);
        try {
            while (cursor.moveToNext()) {
                GeoPackageMetadata metadata = createGeoPackageMetadata(cursor);
                allMetadata.add(metadata);
            }
        } finally {
            cursor.close();
        }
        return allMetadata;
    }

public List < GeoPackageMetadata > getAll ( ) { List < GeoPackageMetadata > allMetadata = new ArrayList < GeoPackageMetadata > ( ) ; Cursor cursor = db . query ( GeoPackageMetadata . TABLE_NAME , GeoPackageMetadata . COLUMNS , null , null , null , null , null ) ; try { while ( cursor . moveToNext ( ) ) { GeoPackageMetadata metadata = createGeoPackageMetadata ( cursor ) ; allMetadata . add ( metadata ) ; } } finally { cursor . close ( ) ; } return allMetadata ; }

Get all GeoPackage metadata

@return all GeoPackage metadata


public GeoPackageMetadata get(String database) {
        GeoPackageMetadata metadata = null;
        String selection = GeoPackageMetadata.COLUMN_NAME + " = ?";
        String[] selectionArgs = new String[]{database};
        Cursor cursor = db.query(
                GeoPackageMetadata.TABLE_NAME,
                GeoPackageMetadata.COLUMNS, selection, selectionArgs, null, null, null);
        try {
            if (cursor.moveToNext()) {
                metadata = createGeoPackageMetadata(cursor);
            }
        } finally {
            cursor.close();
        }
        return metadata;
    }

public
GeoPackageMetadata
get
(
String
database
)
{
GeoPackageMetadata
metadata
=
;
String
selection
=
GeoPackageMetadata
.
COLUMN_NAME
+
" = ?"
;
String
[
]
selectionArgs
=
new
String
[
]
{
database
}
;
Cursor
cursor
=
db
.
query
(
GeoPackageMetadata
.
TABLE_NAME
,
GeoPackageMetadata
.
COLUMNS
,
selection
,
selectionArgs
,
,
,
)
;
try
{
if
(
cursor
.
moveToNext
(
)
)
{
metadata
=
createGeoPackageMetadata
(
cursor
)
;
}
}
finally
{
cursor
.
close
(
)
;
}
return
metadata
;
}

Get GeoPackage metadata by name

@param database database name
@return GeoPackage metadata


public GeoPackageMetadata get(long id) {
        GeoPackageMetadata metadata = null;
        String selection = GeoPackageMetadata.COLUMN_ID + " = ?";
        String[] selectionArgs = new String[]{String.valueOf(id)};
        Cursor cursor = db.query(
                GeoPackageMetadata.TABLE_NAME,
                GeoPackageMetadata.COLUMNS, selection, selectionArgs, null, null, null);
        try {
            if (cursor.moveToNext()) {
                metadata = createGeoPackageMetadata(cursor);
            }
        } finally {
            cursor.close();
        }
        return metadata;
    }

public
GeoPackageMetadata
get
(
long
id
)
{
GeoPackageMetadata
metadata
=
;
String
selection
=
GeoPackageMetadata
.
COLUMN_ID
+
" = ?"
;
String
[
]
selectionArgs
=
new
String
[
]
{
String
.
valueOf
(
id
)
}
;
Cursor
cursor
=
db
.
query
(
GeoPackageMetadata
.
TABLE_NAME
,
GeoPackageMetadata
.
COLUMNS
,
selection
,
selectionArgs
,
,
,
)
;
try
{
if
(
cursor
.
moveToNext
(
)
)
{
metadata
=
createGeoPackageMetadata
(
cursor
)
;
}
}
finally
{
cursor
.
close
(
)
;
}
return
metadata
;
}

Get GeoPackage metadata by id

@param id id
@return GeoPackage metadata


public GeoPackageMetadata getOrCreate(String geoPackage) {
        GeoPackageMetadata metadata = get(geoPackage);

        if (metadata == null) {
            metadata = new GeoPackageMetadata();
            metadata.setName(geoPackage);
            create(metadata);
        }

        return metadata;
    }

public GeoPackageMetadata getOrCreate ( String geoPackage ) { GeoPackageMetadata metadata = get ( geoPackage ) ; if ( metadata == null ) { metadata = new GeoPackageMetadata ( ) ; metadata . setName ( geoPackage ) ; create ( metadata ) ; } return metadata ; }

Get GeoPackage metadata or create it if it does not exist

@param geoPackage GeoPackage name
@return GeoPackage metadata


public boolean isExternal(String database) {
        GeoPackageMetadata metadata = get(database);
        return get(database) != null && metadata.getExternalPath() != null;
    }

public boolean isExternal ( String database ) { GeoPackageMetadata metadata = get ( database ) ; return get ( database ) != null && metadata . getExternalPath ( ) != null ; }

Determine if the GeoPackage is external

@param database database name
@return external flag


public GeoPackageMetadata getExternalAtPath(String path) {
        GeoPackageMetadata metadata = null;
        String selection = GeoPackageMetadata.COLUMN_EXTERNAL_PATH + " = ?";
        String[] selectionArgs = new String[]{path};
        Cursor cursor = db.query(
                GeoPackageMetadata.TABLE_NAME,
                GeoPackageMetadata.COLUMNS, selection, selectionArgs, null, null, null);
        try {
            if (cursor.moveToNext()) {
                metadata = createGeoPackageMetadata(cursor);
            }
        } finally {
            cursor.close();
        }
        return metadata;
    }

public
GeoPackageMetadata
getExternalAtPath
(
String
path
)
{
GeoPackageMetadata
metadata
=
;
String
selection
=
GeoPackageMetadata
.
COLUMN_EXTERNAL_PATH
+
" = ?"
;
String
[
]
selectionArgs
=
new
String
[
]
{
path
}
;
Cursor
cursor
=
db
.
query
(
GeoPackageMetadata
.
TABLE_NAME
,
GeoPackageMetadata
.
COLUMNS
,
selection
,
selectionArgs
,
,
,
)
;
try
{
if
(
cursor
.
moveToNext
(
)
)
{
metadata
=
createGeoPackageMetadata
(
cursor
)
;
}
}
finally
{
cursor
.
close
(
)
;
}
return
metadata
;
}

Get external GeoPackage metadata by external path

@param path path
@return GeoPackage metadata


public List<String> getMetadataWhereNameLike(String like, String sortColumn) {
        return getMetadataWhereNameLike(like, sortColumn, false);
    }

public List < String > getMetadataWhereNameLike ( String like , String sortColumn ) { return getMetadataWhereNameLike ( like , sortColumn , false ) ; }

Get metadata where the name is like

@param like       like argument
@param sortColumn sort by column
@return metadata names
@since 1.2.7


public List<String> getMetadataWhereNameNotLike(String notLike, String sortColumn) {
        return getMetadataWhereNameLike(notLike, sortColumn, true);
    }

public List < String > getMetadataWhereNameNotLike ( String notLike , String sortColumn ) { return getMetadataWhereNameLike ( notLike , sortColumn , true ) ; }

Get metadata where the name is not like

@param notLike    not like argument
@param sortColumn sort by column
@return metadata names
@since 1.2.7


private List<String> getMetadataWhereNameLike(String like, String sortColumn, boolean notLike) {
        List<String> names = new ArrayList<>();
        StringBuilder where = new StringBuilder(GeoPackageMetadata.COLUMN_NAME);
        if (notLike) {
            where.append(" not");
        }
        where.append(" like ?");
        String[] whereArgs = new String[]{like};
        Cursor cursor = db.query(GeoPackageMetadata.TABLE_NAME, new String[]{GeoPackageMetadata.COLUMN_NAME}, where.toString(), whereArgs, null, null, sortColumn);
        try {
            while (cursor.moveToNext()) {
                names.add(cursor.getString(0));
            }
        } finally {
            cursor.close();
        }
        return names;
    }

private
List
<
String
>
getMetadataWhereNameLike
(
String
like
,
String
sortColumn
,
boolean
notLike
)
{
List
<
String
>
names
=
new
ArrayList
<>
(
)
;
StringBuilder
where
=
new
StringBuilder
(
GeoPackageMetadata
.
COLUMN_NAME
)
;
if
(
notLike
)
{
where
.
append
(
" not"
)
;
}
where
.
append
(
" like ?"
)
;
String
[
]
whereArgs
=
new
String
[
]
{
like
}
;
Cursor
cursor
=
db
.
query
(
GeoPackageMetadata
.
TABLE_NAME
,
new
String
[
]
{
GeoPackageMetadata
.
COLUMN_NAME
}
,
where
.
toString
(
)
,
whereArgs
,
,
,
sortColumn
)
;
try
{
while
(
cursor
.
moveToNext
(
)
)
{
names
.
add
(
cursor
.
getString
(
0
)
)
;
}
}
finally
{
cursor
.
close
(
)
;
}
return
names
;
}

Get metadata where the name is like or not like

@param like       like or not like argument
@param sortColumn sort by column
@param notLike    true if a not like query
@return metadata names


private GeoPackageMetadata createGeoPackageMetadata(Cursor cursor) {
        GeoPackageMetadata metadata = new GeoPackageMetadata();
        metadata.setId(cursor.getLong(0));
        metadata.setName(cursor.getString(1));
        metadata.setExternalPath(cursor.getString(2));
        return metadata;
    }

private GeoPackageMetadata createGeoPackageMetadata ( Cursor cursor ) { GeoPackageMetadata metadata = new GeoPackageMetadata ( ) ; metadata . setId ( cursor . getLong ( 0 ) ) ; metadata . setName ( cursor . getString ( 1 ) ) ; metadata . setExternalPath ( cursor . getString ( 2 ) ) ; return metadata ; }

Create a GeoPackage metadata from the current cursor location

@param cursor cursor
@return GeoPackage metadata


public View onViewCreated(View view, Context context, AttributeSet attrs) {
    if (view == null) {
      return null;
    }

    view = onViewCreatedInternal(view, context, attrs);
    for (OnViewCreatedListener listener : otherListeners) {
      if (listener != null) {
        view = listener.onViewCreated(view, context, attrs);
      }
    }
    return view;
  }

public View onViewCreated ( View view , Context context , AttributeSet attrs ) { if ( view == null ) { return null ; } view = onViewCreatedInternal ( view , context , attrs ) ; for ( OnViewCreatedListener listener : otherListeners ) { if ( listener != null ) { view = listener . onViewCreated ( view , context , attrs ) ; } } return view ; }

Handle the created view

@param view nullable.
@param context shouldn't be null.
@param attrs shouldn't be null.
@return null if null is passed in.


private void addParallaxView(View view, int pageIndex) {
    if (view instanceof ViewGroup) {
      // recurse children
      ViewGroup viewGroup = (ViewGroup) view;
      for (int i = 0, childCount = viewGroup.getChildCount(); i < childCount; i++) {
        addParallaxView(viewGroup.getChildAt(i), pageIndex);
      }
    }

    ParallaxViewTag tag = (ParallaxViewTag) view.getTag(R.id.parallax_view_tag);
    if (tag != null) {
      // only track view if it has a parallax tag
      tag.index = pageIndex;
      parallaxViews.add(view);
    }
  }


@Override
  protected View onCreateView(String name, AttributeSet attrs) throws ClassNotFoundException {
    // This mimics the {@code PhoneLayoutInflater} in the way it tries to inflate the base
    // classes, if this fails its pretty certain the app will fail at this point.
    View view = null;
    for (String prefix : sClassPrefixList) {
      try {
        view = createView(name, prefix, attrs);
      } catch (ClassNotFoundException ignored) {
      }
    }
    // In this case we want to let the base class take a crack
    // at it.
    if (view == null) { view = super.onCreateView(name, attrs); }

    return mParallaxFactory.onViewCreated(view, view.getContext(), attrs);
  }

The LayoutInflater onCreateView is the fourth port of call for LayoutInflation.
BUT only for none CustomViews.
Basically if this method doesn't inflate the View nothing probably will.

The LayoutInflater onCreateView is the fourth port of call for LayoutInflation . BUT only for none CustomViews . Basically if this method doesn t inflate the View nothing probably will .


private View createCustomViewInternal(View parent, View view, String name, Context context,
      AttributeSet attrs) {
    // I by no means advise anyone to do this normally, but Google have locked down access to
    // the createView() method, so we never get a callback with attributes at the end of the
    // createViewFromTag chain (which would solve all this unnecessary rubbish).
    // We at the very least try to optimise this as much as possible.
    // We only call for customViews (As they are the ones that never go through onCreateView(...)).
    // We also maintain the Field reference and make it accessible which will make a pretty
    // significant difference to performance on Android 4.0+.

    // If CustomViewCreation is off skip this.
    if (view == null && name.indexOf('.') > -1) {
      if (mConstructorArgs == null) {
        mConstructorArgs = ReflectionUtils.getField(LayoutInflater.class, "mConstructorArgs");
      }

      final Object[] mConstructorArgsArr =
          (Object[]) ReflectionUtils.getValue(mConstructorArgs, this);
      final Object lastContext = mConstructorArgsArr[0];
      mConstructorArgsArr[0] = parent != null ? parent.getContext() : context;
      ReflectionUtils.setValue(mConstructorArgs, this, mConstructorArgsArr);
      try {
        view = createView(name, null, attrs);
      } catch (ClassNotFoundException ignored) {
      } finally {
        mConstructorArgsArr[0] = lastContext;
        ReflectionUtils.setValue(mConstructorArgs, this, mConstructorArgsArr);
      }
    }
    return view;
  }

Nasty method to inflate custom layouts that haven't been handled else where. If this fails it
will fall back through to the PhoneLayoutInflater method of inflating custom views where
Calligraphy will NOT have a hook into.

@param parent parent view
@param view view if it has been inflated by this point, if this is not null this method
just returns this value.
@param name name of the thing to inflate.
@param context Context to inflate by if parent is null
@param attrs Attr for this view which we can steal fontPath from too.
@return view or the View we inflate in here.

Nasty method to inflate custom layouts that haven t been handled else where . If this fails it will fall back through to the PhoneLayoutInflater method of inflating custom views where Calligraphy will NOT have a hook into .


protected void subAppend(CyclicBuffer<ILoggingEvent> cb, ILoggingEvent event) {
    if(includeCallerData) {
      event.getCallerData();
    }
    event.prepareForDeferredProcessing();
    cb.add(event);
  }

protected void subAppend ( CyclicBuffer < ILoggingEvent > cb , ILoggingEvent event ) { if ( includeCallerData ) { event . getCallerData ( ) ; } event . prepareForDeferredProcessing ( ) ; cb . add ( event ) ; }

Perform SMTPAppender specific appending actions, mainly adding the event to
a cyclic buffer.

Perform SMTPAppender specific appending actions mainly adding the event to a cyclic buffer .


private URL findConfigFileFromSystemProperties(boolean updateStatus) {
    String logbackConfigFile = OptionHelper.getSystemProperty(CONFIG_FILE_PROPERTY);
    if (logbackConfigFile != null) {
      URL result = null;
      try {
        File file = new File(logbackConfigFile);
        if (file.exists() && file.isFile()) {
          if (updateStatus) {
            statusOnResourceSearch(logbackConfigFile, this.classLoader, logbackConfigFile);
          }
          result = file.toURI().toURL();
        } else {
          result = new URL(logbackConfigFile);
        }
        return result;
      } catch (MalformedURLException e) {
        // so, resource is not a URL:
        // attempt to get the resource from the class path
        result = Loader.getResource(logbackConfigFile, this.classLoader);
        if (result != null) {
          return result;
        }
      } finally {
        if (updateStatus) {
          statusOnResourceSearch(logbackConfigFile, this.classLoader, result != null ? result.toString() : null);
        }
      }
    }
    return null;
  }

Finds a configuration file by system property
@return the file; or {@code null} if not found


private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
    URL url = myClassLoader.getResource(filename);
    if (updateStatus) {
      String resourcePath = null;
      if (url != null) {
        resourcePath = filename;
      }
      statusOnResourceSearch(filename, myClassLoader, resourcePath);
    }
    return url;
  }

private URL getResource ( String filename , ClassLoader myClassLoader , boolean updateStatus ) { URL url = myClassLoader . getResource ( filename ) ; if ( updateStatus ) { String resourcePath = null ; if ( url != null ) { resourcePath = filename ; } statusOnResourceSearch ( filename , myClassLoader , resourcePath ) ; } return url ; }

Uses the given classloader to search for a resource
@return the URL to the resource; or {@code null} if not found


public void autoConfig() throws JoranException {
    StatusListenerConfigHelper.installIfAsked(loggerContext);

    new AndroidContextUtil().setupProperties(loggerContext);

    boolean verbose = true;
    boolean configured = false;

    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(loggerContext);

    // search system property
    if (!configured) {
      URL url = findConfigFileFromSystemProperties(verbose);
      if (url != null) {
        configurator.doConfigure(url);
        configured = true;
      }
    }

    // search assets
    if (!configured) {
      URL assetsConfigUrl = findConfigFileURLFromAssets(verbose);
      if (assetsConfigUrl != null) {
        configurator.doConfigure(assetsConfigUrl);
        configured = true;
      }
    }
  }

public
void
autoConfig
(
)
throws
JoranException
{
StatusListenerConfigHelper
.
installIfAsked
(
loggerContext
)
;
new
AndroidContextUtil
(
)
.
setupProperties
(
loggerContext
)
;
boolean
verbose
=
true
;
boolean
configured
=
false
;
JoranConfigurator
configurator
=
new
JoranConfigurator
(
)
;
configurator
.
setContext
(
loggerContext
)
;
// search system property
if
(
!
configured
)
{
URL
url
=
findConfigFileFromSystemProperties
(
verbose
)
;
if
(
url
!=
)
{
configurator
.
doConfigure
(
url
)
;
configured
=
true
;
}
}
// search assets
if
(
!
configured
)
{
URL
assetsConfigUrl
=
findConfigFileURLFromAssets
(
verbose
)
;
if
(
assetsConfigUrl
!=
)
{
configurator
.
doConfigure
(
assetsConfigUrl
)
;
configured
=
true
;
}
}
}

Configures logback with the first configuration found in the following search path.
If no configuration found, nothing is done and logging is disabled.

${logback.configurationFile} (a system property)

jar:file://assets/logback.xml

Configures logback with the first configuration found in the following search path . If no configuration found nothing is done and logging is disabled .


private void statusOnResourceSearch(String resourceName, ClassLoader classLoader, String path) {
    StatusManager sm = loggerContext.getStatusManager();
    if (path == null) {
      sm.add(new InfoStatus("Could NOT find resource [" + resourceName + "]",
              loggerContext));
    } else {
      sm.add(new InfoStatus("Found resource [" + resourceName + "] at [" + path + "]",
              loggerContext));
    }
  }

private
void
statusOnResourceSearch
(
String
resourceName
,
ClassLoader
classLoader
,
String
path
)
{
StatusManager
sm
=
loggerContext
.
getStatusManager
(
)
;
if
(
path
==
)
{
sm
.
add
(
new
InfoStatus
(
"Could NOT find resource ["
+
resourceName
+
"]"
,
loggerContext
)
)
;
}
else
{
sm
.
add
(
new
InfoStatus
(
"Found resource ["
+
resourceName
+
"] at ["
+
path
+
"]"
,
loggerContext
)
)
;
}
}

Adds a status message for the result of the resource search


private String socketAddressToString(SocketAddress address) {
    String addr = address.toString();
    int i = addr.indexOf("/");
    if (i >= 0) {
      addr = addr.substring(i + 1);
    }
    return addr;
  }

private String socketAddressToString ( SocketAddress address ) { String addr = address . toString ( ) ; int i = addr . indexOf ( "/" ) ; if ( i >= 0 ) { addr = addr . substring ( i + 1 ) ; } return addr ; }

Converts a socket address to a reasonable display string.
@param address the subject socket address
@return display string

Converts a socket address to a reasonable display string .


static public ExecutorService newExecutorService() {
    return new ThreadPoolExecutor(CoreConstants.CORE_POOL_SIZE,
        CoreConstants.MAX_POOL_SIZE,
        0L, TimeUnit.MILLISECONDS,
        new SynchronousQueue<Runnable>(),
        THREAD_FACTORY);
  }

static public ExecutorService newExecutorService ( ) { return new ThreadPoolExecutor ( CoreConstants . CORE_POOL_SIZE , CoreConstants . MAX_POOL_SIZE , 0L , TimeUnit . MILLISECONDS , new SynchronousQueue < Runnable > ( ) , THREAD_FACTORY ) ; }

Creates an executor service suitable for use by logback components.
@return executor service

Creates an executor service suitable for use by logback components .


public static <E> void startConverters(Converter<E> head) {
    Converter<E> c = head;
    while (c != null) {
      // CompositeConverter is a subclass of  DynamicConverter
      if (c instanceof CompositeConverter) {
        CompositeConverter<E> cc = (CompositeConverter<E>) c;
        Converter<E> childConverter = cc.childConverter;
        startConverters(childConverter);
        cc.start();
      } else if (c instanceof DynamicConverter) {
        DynamicConverter<E> dc = (DynamicConverter<E>) c;
        dc.start();
      }
      c = c.getNext();
    }
  }

Start converters in the chain of converters.

@param head head node of converter chain
@param <E> type of log event object

Start converters in the chain of converters .


@Override
  protected void subAppend(E event) {
    // The roll-over check must precede actual writing. This is the
    // only correct behavior for time driven triggers.

    // We need to synchronize on triggeringPolicy so that only one rollover
    // occurs at a time
    synchronized (triggeringPolicy) {
      if (triggeringPolicy.isTriggeringEvent(currentlyActiveFile, event)) {
        rollover();
      }
    }

    super.subAppend(event);
  }

This method differentiates RollingFileAppender from its super class.

This method differentiates RollingFileAppender from its super class .


public void addSubstitutionProperty(String key, String value) {
    if (key == null || value == null) {
      return;
    }
    // values with leading or trailing spaces are bad. We remove them now.
    value = value.trim();
    propertiesMap.put(key, value);
  }

Add a property to the properties of this execution context. If the property
exists already, it is overwritten.
@param key the property's key
@param value the value associated with the key

Add a property to the properties of this execution context . If the property exists already it is overwritten .


public String getProperty(String key) {
    String v = propertiesMap.get(key);
    if (v != null) {
      return v;
    } else {
      return context.getProperty(key);
    }
  }

public String getProperty ( String key ) { String v = propertiesMap . get ( key ) ; if ( v != null ) { return v ; } else { return context . getProperty ( key ) ; } }

If a key is found in propertiesMap then return it. Otherwise, delegate to
the context.

If a key is found in propertiesMap then return it . Otherwise delegate to the context .


public Converter<E> compile(final Node top, Map<String, String> converterMap) {
    Compiler<E> compiler = new Compiler<E>(top, converterMap);
    compiler.setContext(context);
    //compiler.setStatusManager(statusManager);
    return compiler.compile();
  }

When the parsing step is done, the Node list can be transformed into a
converter chain.

@param top the top node
@param converterMap converter map
@return the converter chain

When the parsing step is done the Node list can be transformed into a converter chain .


Node E() throws ScanException {
    Node t = T();
    if (t == null) {
      return null;
    }
    Node eOpt = Eopt();
    if (eOpt != null) {
      t.setNext(eOpt);
    }
    return t;
  }

Node E ( ) throws ScanException { Node t = T ( ) ; if ( t == null ) { return null ; } Node eOpt = Eopt ( ) ; if ( eOpt != null ) { t . setNext ( eOpt ) ; } return t ; }


Node T() throws ScanException {
    Token t = getCurentToken();
    expectNotNull(t, "a LITERAL or '%'");

    switch (t.getType()) {
    case Token.LITERAL:
      advanceTokenPointer();
      return new Node(Node.LITERAL, t.getValue());
    case Token.PERCENT:
      advanceTokenPointer();
      // System.out.println("% token found");
      FormatInfo fi;
      Token u = getCurentToken();
      FormattingNode c;
      expectNotNull(u, "a FORMAT_MODIFIER, SIMPLE_KEYWORD or COMPOUND_KEYWORD");
      if (u.getType() == Token.FORMAT_MODIFIER) {
        fi = FormatInfo.valueOf((String) u.getValue());
        advanceTokenPointer();
        c = C();
        c.setFormatInfo(fi);
      } else {
        c = C();
      }
      return c;

    default:
      return null;

    }

  }

T = LITERAL | '%' C | '%' FORMAT_MODIFIER C


public void escape(String escapeChars, StringBuffer buf, char next,
      int pointer) {
    super.escape(""+CoreConstants.PERCENT_CHAR+CoreConstants.RIGHT_PARENTHESIS_CHAR, buf, next, pointer);
  }

public void escape ( String escapeChars , StringBuffer buf , char next , int pointer ) { super . escape ( "" + CoreConstants . PERCENT_CHAR + CoreConstants . RIGHT_PARENTHESIS_CHAR , buf , next , pointer ) ; }

Do not perform any character escaping, except for '%', and ')'.

Here is the rationale. First, filename patterns do not include escape
combinations such as \r or \n. Moreover, characters which have special
meaning in logback parsers, such as '{', or '}' cannot be part of file
names (so me thinks). The left parenthesis character has special meaning
only if it is preceded by %. Thus, the only characters that needs escaping
are '%' and ')'.

Note that this method assumes that it is called after the escape character
has been consumed.

Do not perform any character escaping except for % and ) .


public String toRegexForFixedDate(Date date) {
    StringBuilder buf = new StringBuilder();
    Converter<Object> p = headTokenConverter;
    while (p != null) {
      if (p instanceof LiteralConverter) {
        buf.append(p.convert(null));
      } else if (p instanceof IntegerTokenConverter) {
        buf.append(FileFinder.regexEscapePath("(\\d+)"));
      } else if (p instanceof DateTokenConverter) {
        DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p;
        if (dtc.isPrimary()) {
          buf.append(p.convert(date));
        } else {
          buf.append(FileFinder.regexEscapePath(dtc.toRegex()));
        }
      }
      p = p.getNext();
    }
    return buf.toString();
  }

public String toRegexForFixedDate ( Date date ) { StringBuilder buf = new StringBuilder ( ) ; Converter < Object > p = headTokenConverter ; while ( p != null ) { if ( p instanceof LiteralConverter ) { buf . append ( p . convert ( null ) ) ; } else if ( p instanceof IntegerTokenConverter ) { buf . append ( FileFinder . regexEscapePath ( "(\\d+)" ) ) ; } else if ( p instanceof DateTokenConverter ) { DateTokenConverter < Object > dtc = ( DateTokenConverter < Object > ) p ; if ( dtc . isPrimary ( ) ) { buf . append ( p . convert ( date ) ) ; } else { buf . append ( FileFinder . regexEscapePath ( dtc . toRegex ( ) ) ) ; } } p = p . getNext ( ) ; } return buf . toString ( ) ; }

Given date, convert this instance to a regular expression.

Used to compute sub-regex when the pattern has both %d and %i, and the
date is known.

@param date - date to be converted

Given date convert this instance to a regular expression .


public void begin(InterpretationContext ec, String name, Attributes attributes) {
    // Let us forget about previous errors (in this instance)
    inError = false;
    evaluator = null;

    String className = attributes.getValue(CLASS_ATTRIBUTE);
    if (OptionHelper.isEmpty(className)) {
      className = defaultClassName();
      addInfo("Assuming default evaluator class [" + className + "]");
    }

    if (OptionHelper.isEmpty(className)) {
      className = defaultClassName();
      inError = true;
      addError("Mandatory \"" + CLASS_ATTRIBUTE
          + "\" attribute not set for <evaluator>");
      return;
    }

    String evaluatorName = attributes.getValue(Action.NAME_ATTRIBUTE);
    if (OptionHelper.isEmpty(evaluatorName)) {
      inError = true;
      addError("Mandatory \"" + NAME_ATTRIBUTE
          + "\" attribute not set for <evaluator>");
      return;
    }
    try {
      evaluator = (EventEvaluator<?>) OptionHelper.instantiateByClassName(
          className, ch.qos.logback.core.boolex.EventEvaluator.class, context);

      evaluator.setContext(this.context);
      evaluator.setName(evaluatorName);

      ec.pushObject(evaluator);
      addInfo("Adding evaluator named [" + evaluatorName
          + "] to the object stack");

    } catch (Exception oops) {
      inError = true;
      addError("Could not create evaluator of type " + className + "].", oops);
    }
  }

Instantiates an evaluator of the given class and sets its name.

Instantiates an evaluator of the given class and sets its name .