Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve modularization #852

Merged
merged 19 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 10 additions & 2 deletions baremaps-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ limitations under the License.
<artifactId>ipresource</artifactId>
</dependency>
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-data</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-openstreetmap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apache.baremaps.openstreetmap.OsmReader;

/**
* A reader for the Geonames database.
*/
public class GeonamesReader implements OsmReader<GeonamesRecord> {
public class GeonamesReader {

@Override
public Stream<GeonamesRecord> stream(InputStream inputStream) throws IOException {
CsvMapper mapper = new CsvMapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.List;
import java.util.stream.Stream;
import javax.sql.DataSource;
import org.apache.baremaps.stream.StreamUtils;
import org.apache.baremaps.openstreetmap.stream.StreamUtils;
import org.locationtech.jts.geom.Coordinate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,25 @@

package org.apache.baremaps.openstreetmap;

import static org.apache.baremaps.stream.ConsumerUtils.consumeThenReturn;

import java.io.BufferedInputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.List;
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.GZIPInputStream;
import org.apache.baremaps.database.collection.DataMap;
import org.apache.baremaps.openstreetmap.function.EntityGeometryBuilder;
import org.apache.baremaps.openstreetmap.function.EntityToGeometryMapper;
import org.apache.baremaps.openstreetmap.function.ProjectionTransformer;
import org.apache.baremaps.openstreetmap.model.*;
import org.apache.baremaps.openstreetmap.repository.HeaderRepository;
import org.apache.baremaps.openstreetmap.repository.Repository;
import org.apache.baremaps.openstreetmap.stream.ConsumerUtils;
import org.apache.baremaps.openstreetmap.stream.StreamException;
import org.apache.baremaps.openstreetmap.xml.XmlChangeReader;
import org.apache.baremaps.stream.StreamException;
import org.apache.baremaps.tilestore.TileCoord;
import org.apache.baremaps.utils.ProjectionTransformer;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.slf4j.Logger;
Expand All @@ -50,17 +45,17 @@ public class DiffService implements Callable<List<TileCoord>> {

private static final Logger logger = LoggerFactory.getLogger(DiffService.class);

private final DataMap<Long, Coordinate> coordinateMap;
private final DataMap<Long, List<Long>> referenceMap;
private final Map<Long, Coordinate> coordinateMap;
private final Map<Long, List<Long>> referenceMap;
private final HeaderRepository headerRepository;
private final Repository<Long, Node> nodeRepository;
private final Repository<Long, Way> wayRepository;
private final Repository<Long, Relation> relationRepository;
private final int srid;
private final int zoom;

public DiffService(DataMap<Long, Coordinate> coordinateMap,
DataMap<Long, List<Long>> referenceMap,
public DiffService(Map<Long, Coordinate> coordinateMap,
Map<Long, List<Long>> referenceMap,
HeaderRepository headerRepository, Repository<Long, Node> nodeRepository,
Repository<Long, Way> wayRepository, Repository<Long, Relation> relationRepository, int srid,
int zoom) {
Expand Down Expand Up @@ -139,7 +134,8 @@ private Optional<Geometry> geometriesForPreviousVersion(Entity entity) {

private Stream<Geometry> geometriesForNextVersion(Change change) {
return change.getEntities().stream()
.map(consumeThenReturn(new EntityGeometryBuilder(coordinateMap, referenceMap)))
.map(
ConsumerUtils.consumeThenReturn(new EntityGeometryBuilder(coordinateMap, referenceMap)))
.flatMap(new EntityToGeometryMapper().andThen(Optional::stream));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import java.sql.*;
import java.util.*;
import javax.sql.DataSource;
import org.apache.baremaps.database.collection.DataCollectionException;
import org.apache.baremaps.database.collection.DataMap;
import org.apache.baremaps.data.collection.DataCollectionException;
import org.apache.baremaps.data.collection.DataMap;
import org.locationtech.jts.geom.Coordinate;

/**
* A read-only {@link DataMap} for coordinates baked by OpenStreetMap nodes stored in PostgreSQL.
*/
public class PostgresCoordinateMap extends DataMap<Long, Coordinate> {
public class PostgresCoordinateMap extends PostgresMap<Long, Coordinate> {

private final DataSource dataSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Function;
import org.apache.baremaps.database.collection.DataCollectionException;
import org.apache.baremaps.data.collection.DataCollectionException;

class PostgresIterator<T> implements Iterator<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
* limitations under the License.
*/

package org.apache.baremaps.database.collection;


package org.apache.baremaps.openstreetmap.postgres;

import com.google.common.collect.Streams;
import java.util.*;

/**
* An abstract map of data elements that can hold a large number of elements.
*
* @param <V> The type of the elements.
* An abstract map of data elements backed by a Postgres database.
*/
public abstract class DataMap<K, V> implements Map<K, V> {
public abstract class PostgresMap<K, V> implements Map<K, V> {

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -73,7 +69,7 @@ public int size() {
/** {@inheritDoc} */
@Override
public Set<K> keySet() {
return new KeySet();
return new PostgresMap.KeySet();
}

private class KeySet extends AbstractSet<K> {
Expand All @@ -84,7 +80,7 @@ public Iterator<K> iterator() {

@Override
public int size() {
return DataMap.this.size();
return PostgresMap.this.size();
}
}

Expand All @@ -98,7 +94,7 @@ public int size() {
/** {@inheritDoc} */
@Override
public Collection<V> values() {
return new ValueCollection();
return new PostgresMap.ValueCollection();
}

private class ValueCollection extends AbstractCollection<V> {
Expand All @@ -109,7 +105,7 @@ public Iterator<V> iterator() {

@Override
public int size() {
return DataMap.this.size();
return PostgresMap.this.size();
}
}

Expand All @@ -123,7 +119,7 @@ public int size() {
/** {@inheritDoc} */
@Override
public Set<Entry<K, V>> entrySet() {
return new EntrySet();
return new PostgresMap.EntrySet();
}

private class EntrySet extends AbstractSet<Entry<K, V>> {
Expand All @@ -134,7 +130,7 @@ public Iterator<Entry<K, V>> iterator() {

@Override
public int size() {
return DataMap.this.size();
return PostgresMap.this.size();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.apache.baremaps.openstreetmap.model.Node;
import org.apache.baremaps.openstreetmap.repository.NodeRepository;
import org.apache.baremaps.openstreetmap.repository.RepositoryException;
import org.apache.baremaps.openstreetmap.utils.GeometryUtils;
import org.apache.baremaps.postgres.copy.CopyWriter;
import org.apache.baremaps.utils.GeometryUtils;
import org.locationtech.jts.geom.Geometry;
import org.postgresql.PGConnection;
import org.postgresql.copy.PGCopyOutputStream;
Expand Down
Loading
Loading