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

cleaning dependencies, remove apache-commons #79

Merged
merged 13 commits into from
Feb 26, 2019
26 changes: 14 additions & 12 deletions oshdb-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -71,13 +66,6 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -96,6 +84,20 @@
<artifactId>t-digest</artifactId>
<version>3.2</version>
</dependency>

<!-- TEST dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.heigit.bigspatialdata.oshdb.api.db;

import com.google.common.base.Joiner;
import java.io.File;
import java.util.Collection;
import java.util.Optional;

import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.lang.IgniteRunnable;
Expand Down Expand Up @@ -73,7 +72,7 @@ public <X extends OSHDBMapReducible> MapReducer<X> createMapReducer(Class<X> for
.map(t -> t.toString(this.prefix()))
.collect(Collectors.toList());
if (!allCaches.containsAll(expectedCaches)) {
throw new OSHDBTableNotFoundException(StringUtils.join(expectedCaches, ", "));
throw new OSHDBTableNotFoundException(Joiner.on(", ").join(expectedCaches));
}
switch (this.computeMode()) {
case LocalPeek:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.heigit.bigspatialdata.oshdb.api.db;

import com.google.common.base.Joiner;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.heigit.bigspatialdata.oshdb.TableNames;
import org.heigit.bigspatialdata.oshdb.api.mapreducer.MapReducer;
import org.heigit.bigspatialdata.oshdb.api.mapreducer.backend.MapReducerJdbcMultithread;
Expand Down Expand Up @@ -64,7 +63,7 @@ public <X extends OSHDBMapReducible> MapReducer<X> createMapReducer(Class<X> for
allTables.add(rs.getString("TABLE_NAME").toLowerCase());
}
if (!allTables.containsAll(expectedTables)) {
throw new OSHDBTableNotFoundException(StringUtils.join(expectedTables, ", "));
throw new OSHDBTableNotFoundException(Joiner.on(", ").join(expectedTables));
}
} catch (SQLException e) {
throw new RuntimeException(e);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
package org.heigit.bigspatialdata.oshdb.api.generic;

import java.io.Serializable;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.jetbrains.annotations.NotNull;

public class OSHDBCombinedIndex<U, V> extends OSHDBBiIndex<U, V>
implements Comparable<OSHDBCombinedIndex<U, V>> {
public class OSHDBCombinedIndex<
U extends Comparable<U> & Serializable,
V extends Comparable<V> & Serializable>
implements Comparable<OSHDBCombinedIndex<U, V>>, Serializable {

private U index1;
private V index2;

public OSHDBCombinedIndex(U index1, V index2) {
super(index1, index2);
this.index1 = index1;
this.index2 = index2;
}

public U getFirstIndex() {
return this.payload.getLeft();
return this.index1;
}

public V getSecondIndex() {
return this.payload.getRight();
return this.index2;
}

@Override
public int compareTo(@NotNull OSHDBCombinedIndex<U,V> o) {
return this.payload.compareTo(o.payload);
public int compareTo(@NotNull OSHDBCombinedIndex<U,V> other) {
int c = this.index1.compareTo(other.index1);
if (c == 0) {
c = this.index2.compareTo(other.index2);
}
return c;
}

@Override
public boolean equals(Object obj) {
return this == obj || obj instanceof OSHDBCombinedIndex
&& java.util.Objects.equals(this.index1, ((OSHDBCombinedIndex) obj).index1)
&& java.util.Objects.equals(this.index2, ((OSHDBCombinedIndex) obj).index2);
}

@Override
public int hashCode() {
return java.util.Objects.hash(index1, index2);
}

@Override
public String toString() {
return this.getFirstIndex().toString() + "&" + this.getSecondIndex().toString();
Expand All @@ -42,7 +66,8 @@ public String toString() {
* @param <V> an arbitrary data type, used for the index'es key items
* @return a nested data structure: for each index part there is a separate level of nested maps
*/
public static <A, U, V> SortedMap<U, SortedMap<V, A>> nest(
public static <A, U extends Comparable<U> & Serializable, V extends Comparable<V> & Serializable>
SortedMap<U, SortedMap<V, A>> nest(
Map<OSHDBCombinedIndex<U, V>, A> result
) {
TreeMap<U, SortedMap<V, A>> ret = new TreeMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.heigit.bigspatialdata.oshdb.api.object.OSMContribution;
import org.heigit.bigspatialdata.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox;
Expand Down Expand Up @@ -56,13 +53,31 @@ <P extends Geometry & Polygonal> GeometrySplitter(Map<U, P> subregions) {
this.subregions = subregions;
}

private static class IndexData<I,D> {
private final I index;
private final D data;

IndexData(I index, D data) {
this.index = index;
this.data = data;
}

I getIndex() {
return index;
}

D getData() {
return data;
}
}

/**
* Splits osm entity snapshot objects into sub-regions.
*
* @param data the OSMEntitySnapshot to split into the given sub-regions
* @return a list of OSMEntitySnapshot objects
*/
public List<Pair<U, OSMEntitySnapshot>> splitOSMEntitySnapshot(OSMEntitySnapshot data) {
public Map<U,OSMEntitySnapshot> splitOSMEntitySnapshot(OSMEntitySnapshot data) {
OSHDBBoundingBox oshBoundingBox = data.getOSHEntity().getBoundingBox();
//noinspection unchecked – STRtree works with raw types unfortunately :-/
List<U> candidates = (List<U>) spatialIndex.query(
Expand All @@ -74,7 +89,7 @@ public List<Pair<U, OSMEntitySnapshot>> splitOSMEntitySnapshot(OSMEntitySnapshot
.flatMap(index -> {
if (bips.get(index).test(oshBoundingBox)) {
// OSH entity fully inside -> directly return
return Stream.of(new ImmutablePair<>(index, data));
return Stream.of(new IndexData<>(index, data));
}

// now we can check against the actual contribution geometry
Expand All @@ -89,7 +104,7 @@ public List<Pair<U, OSMEntitySnapshot>> splitOSMEntitySnapshot(OSMEntitySnapshot
}
// OSM entity fully inside -> directly return
if (bips.get(index).test(snapshotBbox)) {
return Stream.of(new ImmutablePair<>(index, data));
return Stream.of(new IndexData<>(index, data));
}

FastPolygonOperations poop = poops.get(index);
Expand All @@ -98,15 +113,15 @@ public List<Pair<U, OSMEntitySnapshot>> splitOSMEntitySnapshot(OSMEntitySnapshot
if (intersection == null || intersection.isEmpty()) {
return Stream.empty(); // not actually intersecting -> skip
} else {
return Stream.of(new ImmutablePair<>(
return Stream.of(new IndexData<>(
index,
new OSMEntitySnapshot(data, intersection)
));
}
} catch (TopologyException ignored) {
return Stream.empty(); // JTS cannot handle broken osm geometry -> skip
}
}).collect(Collectors.toCollection(LinkedList::new));
}).collect(Collectors.toMap(IndexData::getIndex, IndexData::getData));
}

/**
Expand All @@ -123,7 +138,7 @@ public List<Pair<U, OSMEntitySnapshot>> splitOSMEntitySnapshot(OSMEntitySnapshot
* @param data the OSMContribution to split into the given sub-regions
* @return a list of OSMContribution objects
*/
public List<Pair<U, OSMContribution>> splitOSMContribution(OSMContribution data) {
public Map<U,OSMContribution> splitOSMContribution(OSMContribution data) {
OSHDBBoundingBox oshBoundingBox = data.getOSHEntity().getBoundingBox();
//noinspection unchecked – STRtree works with raw types unfortunately :-/
List<U> candidates = (List<U>) spatialIndex.query(
Expand All @@ -135,7 +150,7 @@ public List<Pair<U, OSMContribution>> splitOSMContribution(OSMContribution data)
.flatMap(index -> {
// OSH entity fully inside -> directly return
if (bips.get(index).test(oshBoundingBox)) {
return Stream.of(new ImmutablePair<>(index, data));
return Stream.of(new IndexData<>(index, data));
}

// now we can check against the actual contribution geometry
Expand Down Expand Up @@ -165,7 +180,7 @@ public List<Pair<U, OSMContribution>> splitOSMContribution(OSMContribution data)
}
// contribution fully inside -> directly return
if (bips.get(index).test(contributionGeometryBbox)) {
return Stream.of(new ImmutablePair<>(index, data));
return Stream.of(new IndexData<>(index, data));
}

FastPolygonOperations poop = poops.get(index);
Expand All @@ -176,15 +191,15 @@ public List<Pair<U, OSMContribution>> splitOSMContribution(OSMContribution data)
&& (intersectionAfter == null || intersectionAfter.isEmpty())) {
return Stream.empty(); // not actually intersecting -> skip
} else {
return Stream.of(new ImmutablePair<>(
return Stream.of(new IndexData<>(
index,
new OSMContribution(data, intersectionBefore, intersectionAfter)
));
}
} catch (TopologyException ignored) {
return Stream.empty(); // JTS cannot handle broken osm geometry -> skip
}
}).collect(Collectors.toCollection(LinkedList::new));
}).collect(Collectors.toMap(IndexData::getIndex, IndexData::getData));
}

/**
Expand Down Expand Up @@ -229,7 +244,7 @@ private <P extends Geometry & Polygonal> void readObject(ObjectInputStream in)
this.subregions = result;
}

private <P extends Geometry & Polygonal> Object readResolve() throws ObjectStreamException {
protected <P extends Geometry & Polygonal> Object readResolve() throws ObjectStreamException {
//noinspection unchecked - constructor checks that `subregions` only contain `P` entry values
return new GeometrySplitter<>((Map<U, P>) this.subregions);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.bigspatialdata.oshdb.api.mapreducer;

import java.io.Serializable;
import org.heigit.bigspatialdata.oshdb.api.generic.function.SerializableFunction;

/**
Expand All @@ -18,5 +19,5 @@ interface MapAggregatable<M, X> {
* @return a MapAggregator object with the equivalent state (settings, filters, map function,
* etc.) of the current MapReducer object
*/
<U extends Comparable<U>> M aggregateBy(SerializableFunction<X, U> indexer);
<U extends Comparable<U> & Serializable> M aggregateBy(SerializableFunction<X, U> indexer);
}
Loading