repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | return GeometryUtil.intersects(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
}
private boolean intersects(RectangleDouble rd) {
return GeometryUtil.intersects(x1, y1, x2, y2, rd.x1, rd.y1, rd.x2, rd.y2);
}
@Override
public double distance(Rectangle r) {
return GeometryUtil.distance(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
@Override
public Rectangle mbr() {
return this;
}
@Override
public String toString() {
return "Rectangle [x1=" + x1 + ", y1=" + y1 + ", x2=" + x2 + ", y2=" + y2 + "]";
}
@Override
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleDouble.java
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
return GeometryUtil.intersects(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
}
private boolean intersects(RectangleDouble rd) {
return GeometryUtil.intersects(x1, y1, x2, y2, rd.x1, rd.y1, rd.x2, rd.y2);
}
@Override
public double distance(Rectangle r) {
return GeometryUtil.distance(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
@Override
public Rectangle mbr() {
return this;
}
@Override
public String toString() {
return "Rectangle [x1=" + x1 + ", y1=" + y1 + ", x2=" + x2 + ", y2=" + y2 + "]";
}
@Override
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) { | Optional<RectangleDouble> other = ObjectsHelper.asClass(obj, RectangleDouble.class); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | public String toString() {
return "Rectangle [x1=" + x1 + ", y1=" + y1 + ", x2=" + x2 + ", y2=" + y2 + "]";
}
@Override
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) {
Optional<RectangleDouble> other = ObjectsHelper.asClass(obj, RectangleDouble.class);
if (other.isPresent()) {
return Objects.equals(x1, other.get().x1) && Objects.equals(x2, other.get().x2)
&& Objects.equals(y1, other.get().y1) && Objects.equals(y2, other.get().y2);
} else
return false;
}
@Override
public double intersectionArea(Rectangle r) {
if (!intersects(r))
return 0;
else {
return create(max(x1, r.x1()), max(y1, r.y1()), min(x2, r.x2()), min(y2, r.y2()))
.area();
}
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleDouble.java
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
public String toString() {
return "Rectangle [x1=" + x1 + ", y1=" + y1 + ", x2=" + x2 + ", y2=" + y2 + "]";
}
@Override
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) {
Optional<RectangleDouble> other = ObjectsHelper.asClass(obj, RectangleDouble.class);
if (other.isPresent()) {
return Objects.equals(x1, other.get().x1) && Objects.equals(x2, other.get().x2)
&& Objects.equals(y1, other.get().y1) && Objects.equals(y2, other.get().y2);
} else
return false;
}
@Override
public double intersectionArea(Rectangle r) {
if (!intersects(r))
return 0;
else {
return create(max(x1, r.x1()), max(y1, r.y1()), min(x2, r.x2()), min(y2, r.y2()))
.area();
}
}
@Override | public Geometry geometry() { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | package com.github.davidmoten.rtree.geometry.internal;
public final class CircleFloat implements Circle {
private final float x, y, radius; | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
package com.github.davidmoten.rtree.geometry.internal;
public final class CircleFloat implements Circle {
private final float x, y, radius; | private final Rectangle mbr; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | }
@Override
public Rectangle mbr() {
return mbr;
}
@Override
public double distance(Rectangle r) {
return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
}
@Override
public Rectangle mbr() {
return mbr;
}
@Override
public double distance(Rectangle r) {
return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) { | Optional<CircleFloat> other = ObjectsHelper.asClass(obj, CircleFloat.class); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleFloat> other = ObjectsHelper.asClass(obj, CircleFloat.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleFloat> other = ObjectsHelper.asClass(obj, CircleFloat.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override | public boolean intersects(Point point) { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleFloat> other = ObjectsHelper.asClass(obj, CircleFloat.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override
public boolean intersects(Point point) {
return Math.sqrt(sqr(x - point.x()) + sqr(y - point.y())) <= radius;
}
private double sqr(double x) {
return x * x;
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleFloat.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleFloat> other = ObjectsHelper.asClass(obj, CircleFloat.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override
public boolean intersects(Point point) {
return Math.sqrt(sqr(x - point.x()) + sqr(y - point.y())) <= radius;
}
private double sqr(double x) {
return x * x;
}
@Override | public boolean intersects(Line line) { |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/BackpressureTest.java | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
| import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class); | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/BackpressureTest.java
import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class); | ImmutableStack<NodePosition<Object, Geometry>> stack = ImmutableStack.empty(); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/BackpressureTest.java | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
| import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class); | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/BackpressureTest.java
import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class); | ImmutableStack<NodePosition<Object, Geometry>> stack = ImmutableStack.empty(); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/BackpressureTest.java | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
| import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class);
ImmutableStack<NodePosition<Object, Geometry>> stack = ImmutableStack.empty();
Func1<Geometry, Boolean> condition = Mockito.mock(Func1.class);
Backpressure.search(condition, sub, stack, 1);
Mockito.verify(sub, Mockito.never()).onNext(Mockito.any());
}
@Test
public void testBackpressureSearchNodeWithConditionThatAlwaysReturnsFalse() { | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/BackpressureTest.java
import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class);
ImmutableStack<NodePosition<Object, Geometry>> stack = ImmutableStack.empty();
Func1<Geometry, Boolean> condition = Mockito.mock(Func1.class);
Backpressure.search(condition, sub, stack, 1);
Mockito.verify(sub, Mockito.never()).onNext(Mockito.any());
}
@Test
public void testBackpressureSearchNodeWithConditionThatAlwaysReturnsFalse() { | RTree<Object, Rectangle> tree = RTree.maxChildren(3).<Object, Rectangle> create() |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/BackpressureTest.java | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
| import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class);
ImmutableStack<NodePosition<Object, Geometry>> stack = ImmutableStack.empty();
Func1<Geometry, Boolean> condition = Mockito.mock(Func1.class);
Backpressure.search(condition, sub, stack, 1);
Mockito.verify(sub, Mockito.never()).onNext(Mockito.any());
}
@Test
public void testBackpressureSearchNodeWithConditionThatAlwaysReturnsFalse() {
RTree<Object, Rectangle> tree = RTree.maxChildren(3).<Object, Rectangle> create() | // Path: src/test/java/com/github/davidmoten/rtree/RTreeTest.java
// static Entry<Object, Rectangle> e(int n) {
// return Entries.<Object, Rectangle>entry(n, r(n));
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/BackpressureTest.java
import static com.github.davidmoten.rtree.RTreeTest.e;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
public class BackpressureTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Backpressure.class);
}
@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Subscriber<Object> sub = Mockito.mock(Subscriber.class);
ImmutableStack<NodePosition<Object, Geometry>> stack = ImmutableStack.empty();
Func1<Geometry, Boolean> condition = Mockito.mock(Func1.class);
Backpressure.search(condition, sub, stack, 1);
Mockito.verify(sub, Mockito.never()).onNext(Mockito.any());
}
@Test
public void testBackpressureSearchNodeWithConditionThatAlwaysReturnsFalse() {
RTree<Object, Rectangle> tree = RTree.maxChildren(3).<Object, Rectangle> create() | .add(e(1)).add(e(3)).add(e(5)).add(e(7)); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/SelectorMinimalOverlapArea.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
| import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators; | package com.github.davidmoten.rtree;
public final class SelectorMinimalOverlapArea implements Selector {
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/SelectorMinimalOverlapArea.java
import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators;
package com.github.davidmoten.rtree;
public final class SelectorMinimalOverlapArea implements Selector {
@Override | public <T, S extends Geometry> Node<T, S> select(Geometry g, List<? extends Node<T, S>> nodes) { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/SelectorMinimalOverlapArea.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
| import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators; | package com.github.davidmoten.rtree;
public final class SelectorMinimalOverlapArea implements Selector {
@Override
public <T, S extends Geometry> Node<T, S> select(Geometry g, List<? extends Node<T, S>> nodes) {
return min(nodes, | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/SelectorMinimalOverlapArea.java
import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators;
package com.github.davidmoten.rtree;
public final class SelectorMinimalOverlapArea implements Selector {
@Override
public <T, S extends Geometry> Node<T, S> select(Geometry g, List<? extends Node<T, S>> nodes) {
return min(nodes, | Comparators.overlapAreaThenAreaIncreaseThenAreaComparator(g.mbr(), nodes)); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/GreekEarthquakes.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
| import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.zip.GZIPInputStream;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func0;
import rx.functions.Func1;
import rx.observables.StringObservable; | } catch (IOException e) {
throw new RuntimeException(e);
}
}
}, new Func1<InputStream, Observable<String>>() {
@Override
public Observable<String> call(InputStream is) {
return StringObservable.from(new InputStreamReader(is));
}
}, new Action1<InputStream>() {
@Override
public void call(InputStream is) {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
return StringObservable.split(source, "\n")
.flatMap(new Func1<String, Observable<Entry<Object, Point>>>() {
@Override
public Observable<Entry<Object, Point>> call(String line) {
if (line.trim().length() > 0) {
String[] items = line.split(" ");
double lat = Double.parseDouble(items[0]);
double lon = Double.parseDouble(items[1]);
Entry<Object, Point> entry;
if (precision == Precision.DOUBLE) | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/GreekEarthquakes.java
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.zip.GZIPInputStream;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func0;
import rx.functions.Func1;
import rx.observables.StringObservable;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}, new Func1<InputStream, Observable<String>>() {
@Override
public Observable<String> call(InputStream is) {
return StringObservable.from(new InputStreamReader(is));
}
}, new Action1<InputStream>() {
@Override
public void call(InputStream is) {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
return StringObservable.split(source, "\n")
.flatMap(new Func1<String, Observable<Entry<Object, Point>>>() {
@Override
public Observable<Entry<Object, Point>> call(String line) {
if (line.trim().length() > 0) {
String[] items = line.split(" ");
double lat = Double.parseDouble(items[0]);
double lon = Double.parseDouble(items[1]);
Entry<Object, Point> entry;
if (precision == Precision.DOUBLE) | entry = Entries.entry(new Object(), Geometries.point(lat, lon)); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/SelectorMinimalAreaIncrease.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
| import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators; | package com.github.davidmoten.rtree;
/**
* Uses minimal area increase to select a node from a list.
*
*/
public final class SelectorMinimalAreaIncrease implements Selector {
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/SelectorMinimalAreaIncrease.java
import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators;
package com.github.davidmoten.rtree;
/**
* Uses minimal area increase to select a node from a list.
*
*/
public final class SelectorMinimalAreaIncrease implements Selector {
@Override | public <T, S extends Geometry> Node<T, S> select(Geometry g, List<? extends Node<T, S>> nodes) { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/SelectorMinimalAreaIncrease.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
| import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators; | package com.github.davidmoten.rtree;
/**
* Uses minimal area increase to select a node from a list.
*
*/
public final class SelectorMinimalAreaIncrease implements Selector {
@Override
public <T, S extends Geometry> Node<T, S> select(Geometry g, List<? extends Node<T, S>> nodes) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/SelectorMinimalAreaIncrease.java
import static java.util.Collections.min;
import java.util.List;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.Comparators;
package com.github.davidmoten.rtree;
/**
* Uses minimal area increase to select a node from a list.
*
*/
public final class SelectorMinimalAreaIncrease implements Selector {
@Override
public <T, S extends Geometry> Node<T, S> select(Geometry g, List<? extends Node<T, S>> nodes) { | return min(nodes, Comparators.areaIncreaseThenAreaComparator(g.mbr())); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/Visualizer.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.*;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle; | package com.github.davidmoten.rtree;
public final class Visualizer {
private final RTree<?, Geometry> tree;
private final int width;
private final int height; | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/Visualizer.java
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.*;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
package com.github.davidmoten.rtree;
public final class Visualizer {
private final RTree<?, Geometry> tree;
private final int width;
private final int height; | private final Rectangle view; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/EntryDefault.java | // Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; |
/**
* Returns the value wrapped by this {@link EntryDefault}.
*
* @return the entry value
*/
@Override
public T value() {
return value;
}
@Override
public S geometry() {
return geometry;
}
@Override
public String toString() {
String builder = "Entry [value=" + value + ", geometry=" + geometry + "]";
return builder;
}
@Override
public int hashCode() {
return Objects.hash(value, geometry);
}
@Override
public boolean equals(Object obj) {
@SuppressWarnings("rawtypes") | // Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/EntryDefault.java
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
/**
* Returns the value wrapped by this {@link EntryDefault}.
*
* @return the entry value
*/
@Override
public T value() {
return value;
}
@Override
public S geometry() {
return geometry;
}
@Override
public String toString() {
String builder = "Entry [value=" + value + ", geometry=" + geometry + "]";
return builder;
}
@Override
public int hashCode() {
return Objects.hash(value, geometry);
}
@Override
public boolean equals(Object obj) {
@SuppressWarnings("rawtypes") | Optional<EntryDefault> other = ObjectsHelper.asClass(obj, EntryDefault.class); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/Group.java | // Path: src/main/java/com/github/davidmoten/rtree/internal/Util.java
// public final class Util {
//
// private Util() {
// // prevent instantiation
// }
//
// /**
// * Returns the minimum bounding rectangle of a number of items. Benchmarks below
// * indicate that when the number of items is >1 this method is more
// * performant than one using {@link Rectangle#add(Rectangle)}.
// *
// * <pre>
// * Benchmark Mode Samples Score Score error Units
// * c.g.d.r.BenchmarksMbr.mbrList1 thrpt 10 48450492.301 436127.960 ops/s
// * c.g.d.r.BenchmarksMbr.mbrList2 thrpt 10 46658242.728 987901.581 ops/s
// * c.g.d.r.BenchmarksMbr.mbrList3 thrpt 10 40357809.306 937827.660 ops/s
// * c.g.d.r.BenchmarksMbr.mbrList4 thrpt 10 35930532.557 605535.237 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList1 thrpt 10 55848118.198 1342997.309 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList2 thrpt 10 25171873.903 395127.918 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList3 thrpt 10 19222116.139 246965.178 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList4 thrpt 10 14891862.638 198765.157 ops/s
// * </pre>
// *
// * @param items
// * items to bound
// * @return the minimum bounding rectangle containings items
// */
// public static Rectangle mbr(Collection<? extends HasGeometry> items) {
// Preconditions.checkArgument(!items.isEmpty());
// double minX1 = Double.MAX_VALUE;
// double minY1 = Double.MAX_VALUE;
// double maxX2 = -Double.MAX_VALUE;
// double maxY2 = -Double.MAX_VALUE;
// boolean isDoublePrecision = false;
// for (final HasGeometry item : items) {
// Rectangle r = item.geometry().mbr();
// if (r.isDoublePrecision()) {
// isDoublePrecision = true;
// }
// if (r.x1() < minX1)
// minX1 = r.x1();
// if (r.y1() < minY1)
// minY1 = r.y1();
// if (r.x2() > maxX2)
// maxX2 = r.x2();
// if (r.y2() > maxY2)
// maxY2 = r.y2();
// }
// if (isDoublePrecision) {
// return Geometries.rectangle(minX1, minY1, maxX2, maxY2);
// } else {
// return Geometries.rectangle((float) minX1, (float) minY1, (float) maxX2, (float) maxY2);
// }
// }
//
// public static <T> List<T> add(List<T> list, T element) {
// final ArrayList<T> result = new ArrayList<T>(list.size() + 2);
// result.addAll(list);
// result.add(element);
// return result;
// }
//
// public static <T> List<T> remove(List<? extends T> list, List<? extends T> elements) {
// final ArrayList<T> result = new ArrayList<T>(list);
// result.removeAll(elements);
// return result;
// }
//
// public static <T> List<? extends T> replace(List<? extends T> list, T element,
// List<T> replacements) {
// List<T> list2 = new ArrayList<T>(list.size() + replacements.size());
// for (T node : list)
// if (node != element)
// list2.add(node);
// list2.addAll(replacements);
// return list2;
// }
//
// }
| import java.util.List;
import com.github.davidmoten.rtree.internal.Util; | package com.github.davidmoten.rtree.geometry;
public class Group<T extends HasGeometry> implements HasGeometry {
private final List<T> list;
private final Rectangle mbr;
public Group(List<T> list) {
this.list = list; | // Path: src/main/java/com/github/davidmoten/rtree/internal/Util.java
// public final class Util {
//
// private Util() {
// // prevent instantiation
// }
//
// /**
// * Returns the minimum bounding rectangle of a number of items. Benchmarks below
// * indicate that when the number of items is >1 this method is more
// * performant than one using {@link Rectangle#add(Rectangle)}.
// *
// * <pre>
// * Benchmark Mode Samples Score Score error Units
// * c.g.d.r.BenchmarksMbr.mbrList1 thrpt 10 48450492.301 436127.960 ops/s
// * c.g.d.r.BenchmarksMbr.mbrList2 thrpt 10 46658242.728 987901.581 ops/s
// * c.g.d.r.BenchmarksMbr.mbrList3 thrpt 10 40357809.306 937827.660 ops/s
// * c.g.d.r.BenchmarksMbr.mbrList4 thrpt 10 35930532.557 605535.237 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList1 thrpt 10 55848118.198 1342997.309 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList2 thrpt 10 25171873.903 395127.918 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList3 thrpt 10 19222116.139 246965.178 ops/s
// * c.g.d.r.BenchmarksMbr.mbrOldList4 thrpt 10 14891862.638 198765.157 ops/s
// * </pre>
// *
// * @param items
// * items to bound
// * @return the minimum bounding rectangle containings items
// */
// public static Rectangle mbr(Collection<? extends HasGeometry> items) {
// Preconditions.checkArgument(!items.isEmpty());
// double minX1 = Double.MAX_VALUE;
// double minY1 = Double.MAX_VALUE;
// double maxX2 = -Double.MAX_VALUE;
// double maxY2 = -Double.MAX_VALUE;
// boolean isDoublePrecision = false;
// for (final HasGeometry item : items) {
// Rectangle r = item.geometry().mbr();
// if (r.isDoublePrecision()) {
// isDoublePrecision = true;
// }
// if (r.x1() < minX1)
// minX1 = r.x1();
// if (r.y1() < minY1)
// minY1 = r.y1();
// if (r.x2() > maxX2)
// maxX2 = r.x2();
// if (r.y2() > maxY2)
// maxY2 = r.y2();
// }
// if (isDoublePrecision) {
// return Geometries.rectangle(minX1, minY1, maxX2, maxY2);
// } else {
// return Geometries.rectangle((float) minX1, (float) minY1, (float) maxX2, (float) maxY2);
// }
// }
//
// public static <T> List<T> add(List<T> list, T element) {
// final ArrayList<T> result = new ArrayList<T>(list.size() + 2);
// result.addAll(list);
// result.add(element);
// return result;
// }
//
// public static <T> List<T> remove(List<? extends T> list, List<? extends T> elements) {
// final ArrayList<T> result = new ArrayList<T>(list);
// result.removeAll(elements);
// return result;
// }
//
// public static <T> List<? extends T> replace(List<? extends T> list, T element,
// List<T> replacements) {
// List<T> list2 = new ArrayList<T>(list.size() + replacements.size());
// for (T node : list)
// if (node != element)
// list2.add(node);
// list2.addAll(replacements);
// return list2;
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Group.java
import java.util.List;
import com.github.davidmoten.rtree.internal.Util;
package com.github.davidmoten.rtree.geometry;
public class Group<T extends HasGeometry> implements HasGeometry {
private final List<T> list;
private final Rectangle mbr;
public Group(List<T> list) {
this.list = list; | this.mbr = Util.mbr(list); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/NodePositionTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.rtree.geometry.Rectangle; | package com.github.davidmoten.rtree;
public class NodePositionTest {
@Test
public void testToString() {
@SuppressWarnings("unchecked") | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/NodePositionTest.java
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.mockito.Mockito;
import com.github.davidmoten.rtree.geometry.Rectangle;
package com.github.davidmoten.rtree;
public class NodePositionTest {
@Test
public void testToString() {
@SuppressWarnings("unchecked") | Node<Object, Rectangle> node = Mockito.mock(Node.class); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/operators/OperatorBoundedPriorityQueue.java | // Path: src/main/java/com/github/davidmoten/rtree/internal/util/BoundedPriorityQueue.java
// public final class BoundedPriorityQueue<T> {
//
// private final PriorityQueue<T> queue; /* backing data structure */
// private final Comparator<? super T> comparator;
// private final int maxSize;
//
// /**
// * Constructs a {@link BoundedPriorityQueue} with the specified
// * {@code maxSize} and {@code comparator}.
// *
// * @param maxSize
// * - The maximum size the queue can reach, must be a positive
// * integer.
// * @param comparator
// * - The comparator to be used to compare the elements in the
// * queue, must be non-null.
// */
// public BoundedPriorityQueue(final int maxSize, final Comparator<? super T> comparator) {
// Preconditions.checkArgument(maxSize > 0, "maxSize must be > 0");
// Preconditions.checkNotNull(comparator, "comparator cannot be null");
// this.queue = new PriorityQueue<T>(reverse(comparator));
// this.comparator = comparator;
// this.maxSize = maxSize;
// }
//
// private static <T> Comparator<T> reverse(final Comparator<T> comparator) {
// return (o1, o2) -> comparator.compare(o2, o1);
// }
//
// public static <T> BoundedPriorityQueue<T> create(final int maxSize,
// final Comparator<? super T> comparator) {
// return new BoundedPriorityQueue<T>(maxSize, comparator);
// }
//
// /**
// * Adds an element to the queue. If the queue contains {@code maxSize}
// * elements, {@code e} will be compared to the lowest element in the queue
// * using {@code comparator}. If {@code e} is greater than or equal to the
// * lowest element, that element will be removed and {@code e} will be added
// * instead. Otherwise, the queue will not be modified and {@code e} will not
// * be added.
// *
// * @param t
// * - Element to be added, must be non-null.
// */
// public void add(final T t) {
// if (t == null) {
// throw new NullPointerException("cannot add null to the queue");
// }
// if (queue.size() >= maxSize) {
// final T maxElement = queue.peek();
// if (comparator.compare(maxElement, t) < 1) {
// return;
// } else {
// queue.poll();
// }
// }
// queue.add(t);
// }
//
// /**
// * @return Returns a view of the queue as a
// * {@link Collections#unmodifiableList(java.util.List)}
// * unmodifiableList sorted in reverse order.
// */
// public List<T> asList() {
// return Collections.unmodifiableList(new ArrayList<>(queue));
// }
//
// public List<T> asOrderedList() {
// List<T> list = new ArrayList<>(queue);
// list.sort(comparator);
// return list;
// }
//
// }
| import java.util.Comparator;
import java.util.List;
import com.github.davidmoten.rtree.internal.util.BoundedPriorityQueue;
import rx.Observable.Operator;
import rx.Subscriber; | package com.github.davidmoten.rtree.internal.operators;
public final class OperatorBoundedPriorityQueue<T> implements Operator<T, T> {
private final int maximumSize;
private final Comparator<? super T> comparator;
public OperatorBoundedPriorityQueue(int maximumSize, Comparator<? super T> comparator) {
this.maximumSize = maximumSize;
this.comparator = comparator;
}
@Override
public Subscriber<? super T> call(final Subscriber<? super T> child) { | // Path: src/main/java/com/github/davidmoten/rtree/internal/util/BoundedPriorityQueue.java
// public final class BoundedPriorityQueue<T> {
//
// private final PriorityQueue<T> queue; /* backing data structure */
// private final Comparator<? super T> comparator;
// private final int maxSize;
//
// /**
// * Constructs a {@link BoundedPriorityQueue} with the specified
// * {@code maxSize} and {@code comparator}.
// *
// * @param maxSize
// * - The maximum size the queue can reach, must be a positive
// * integer.
// * @param comparator
// * - The comparator to be used to compare the elements in the
// * queue, must be non-null.
// */
// public BoundedPriorityQueue(final int maxSize, final Comparator<? super T> comparator) {
// Preconditions.checkArgument(maxSize > 0, "maxSize must be > 0");
// Preconditions.checkNotNull(comparator, "comparator cannot be null");
// this.queue = new PriorityQueue<T>(reverse(comparator));
// this.comparator = comparator;
// this.maxSize = maxSize;
// }
//
// private static <T> Comparator<T> reverse(final Comparator<T> comparator) {
// return (o1, o2) -> comparator.compare(o2, o1);
// }
//
// public static <T> BoundedPriorityQueue<T> create(final int maxSize,
// final Comparator<? super T> comparator) {
// return new BoundedPriorityQueue<T>(maxSize, comparator);
// }
//
// /**
// * Adds an element to the queue. If the queue contains {@code maxSize}
// * elements, {@code e} will be compared to the lowest element in the queue
// * using {@code comparator}. If {@code e} is greater than or equal to the
// * lowest element, that element will be removed and {@code e} will be added
// * instead. Otherwise, the queue will not be modified and {@code e} will not
// * be added.
// *
// * @param t
// * - Element to be added, must be non-null.
// */
// public void add(final T t) {
// if (t == null) {
// throw new NullPointerException("cannot add null to the queue");
// }
// if (queue.size() >= maxSize) {
// final T maxElement = queue.peek();
// if (comparator.compare(maxElement, t) < 1) {
// return;
// } else {
// queue.poll();
// }
// }
// queue.add(t);
// }
//
// /**
// * @return Returns a view of the queue as a
// * {@link Collections#unmodifiableList(java.util.List)}
// * unmodifiableList sorted in reverse order.
// */
// public List<T> asList() {
// return Collections.unmodifiableList(new ArrayList<>(queue));
// }
//
// public List<T> asOrderedList() {
// List<T> list = new ArrayList<>(queue);
// list.sort(comparator);
// return list;
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/operators/OperatorBoundedPriorityQueue.java
import java.util.Comparator;
import java.util.List;
import com.github.davidmoten.rtree.internal.util.BoundedPriorityQueue;
import rx.Observable.Operator;
import rx.Subscriber;
package com.github.davidmoten.rtree.internal.operators;
public final class OperatorBoundedPriorityQueue<T> implements Operator<T, T> {
private final int maximumSize;
private final Comparator<? super T> comparator;
public OperatorBoundedPriorityQueue(int maximumSize, Comparator<? super T> comparator) {
this.maximumSize = maximumSize;
this.comparator = comparator;
}
@Override
public Subscriber<? super T> call(final Subscriber<? super T> child) { | final BoundedPriorityQueue<T> q = new BoundedPriorityQueue<T>(maximumSize, comparator); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/NodeAndEntries.java | // Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
| import java.util.List;
import java.util.Optional;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.geometry.Geometry; | package com.github.davidmoten.rtree.internal;
/**
* Used for tracking deletions through recursive calls.
*
* @param <T>
* value type
* @param <S> geometry type
*/
public final class NodeAndEntries<T, S extends Geometry> {
private final Optional<? extends Node<T, S>> node; | // Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/NodeAndEntries.java
import java.util.List;
import java.util.Optional;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.geometry.Geometry;
package com.github.davidmoten.rtree.internal;
/**
* Used for tracking deletions through recursive calls.
*
* @param <T>
* value type
* @param <S> geometry type
*/
public final class NodeAndEntries<T, S extends Geometry> {
private final Optional<? extends Node<T, S>> node; | private final List<Entry<T, S>> entries; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/Backpressure.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
/**
* Utility methods for controlling backpressure of the tree search.
*/
final class Backpressure {
private Backpressure() {
// prevent instantiation
}
| // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/Backpressure.java
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
/**
* Utility methods for controlling backpressure of the tree search.
*/
final class Backpressure {
private Backpressure() {
// prevent instantiation
}
| static <T, S extends Geometry> ImmutableStack<NodePosition<T, S>> search( |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/Backpressure.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
/**
* Utility methods for controlling backpressure of the tree search.
*/
final class Backpressure {
private Backpressure() {
// prevent instantiation
}
| // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/Backpressure.java
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Subscriber;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
/**
* Utility methods for controlling backpressure of the tree search.
*/
final class Backpressure {
private Backpressure() {
// prevent instantiation
}
| static <T, S extends Geometry> ImmutableStack<NodePosition<T, S>> search( |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | }
@Override
public double x1() {
return x1;
}
@Override
public double y1() {
return y1;
}
@Override
public double x2() {
return x2;
}
@Override
public double y2() {
return y2;
}
@Override
public double area() {
return (x2 - x1) * (y2 - y1);
}
@Override
public Rectangle add(Rectangle r) {
if (r.isDoublePrecision()) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
}
@Override
public double x1() {
return x1;
}
@Override
public double y1() {
return y1;
}
@Override
public double x2() {
return x2;
}
@Override
public double y2() {
return y2;
}
@Override
public double area() {
return (x2 - x1) * (y2 - y1);
}
@Override
public Rectangle add(Rectangle r) {
if (r.isDoublePrecision()) { | return RectangleDouble.create(min(x1, r.x1()), min(y1, r.y1()), max(x2, r.x2()), |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | }
@Override
public double x1() {
return x1;
}
@Override
public double y1() {
return y1;
}
@Override
public double x2() {
return x2;
}
@Override
public double y2() {
return y2;
}
@Override
public double area() {
return (x2 - x1) * (y2 - y1);
}
@Override
public Rectangle add(Rectangle r) {
if (r.isDoublePrecision()) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
}
@Override
public double x1() {
return x1;
}
@Override
public double y1() {
return y1;
}
@Override
public double x2() {
return x2;
}
@Override
public double y2() {
return y2;
}
@Override
public double area() {
return (x2 - x1) * (y2 - y1);
}
@Override
public Rectangle add(Rectangle r) {
if (r.isDoublePrecision()) { | return RectangleDouble.create(min(x1, r.x1()), min(y1, r.y1()), max(x2, r.x2()), |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | }
}
@Override
public boolean contains(double x, double y) {
return x >= x1 && x <= x2 && y >= y1 && y <= y2;
}
@Override
public boolean intersects(Rectangle r) {
return GeometryUtil.intersects(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
@Override
public double distance(Rectangle r) {
return GeometryUtil.distance(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
@Override
public Rectangle mbr() {
return this;
}
@Override
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
}
}
@Override
public boolean contains(double x, double y) {
return x >= x1 && x <= x2 && y >= y1 && y <= y2;
}
@Override
public boolean intersects(Rectangle r) {
return GeometryUtil.intersects(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
@Override
public double distance(Rectangle r) {
return GeometryUtil.distance(x1, y1, x2, y2, r.x1(), r.y1(), r.x2(), r.y2());
}
@Override
public Rectangle mbr() {
return this;
}
@Override
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) { | Optional<RectangleFloat> other = ObjectsHelper.asClass(obj, RectangleFloat.class); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) {
Optional<RectangleFloat> other = ObjectsHelper.asClass(obj, RectangleFloat.class);
if (other.isPresent()) {
return Objects.equals(x1, other.get().x1) && Objects.equals(x2, other.get().x2)
&& Objects.equals(y1, other.get().y1) && Objects.equals(y2, other.get().y2);
} else
return false;
}
@Override
public double intersectionArea(Rectangle r) {
if (!intersects(r))
return 0;
else
return RectangleDouble
.create(max(x1, r.x1()), max(y1, r.y1()), min(x2, r.x2()), min(y2, r.y2()))
.area();
}
@Override
public double perimeter() {
return 2 * (x2 - x1) + 2 * (y2 - y1);
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double max(double a, double b) {
// if (a < b)
// return b;
// else
// return a;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
// public static double min(double a, double b) {
// if (a < b)
// return a;
// else
// return b;
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/RectangleFloat.java
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.max;
import static com.github.davidmoten.rtree.geometry.internal.GeometryUtil.min;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
public int hashCode() {
return Objects.hash(x1, y1, x2, y2);
}
@Override
public boolean equals(Object obj) {
Optional<RectangleFloat> other = ObjectsHelper.asClass(obj, RectangleFloat.class);
if (other.isPresent()) {
return Objects.equals(x1, other.get().x1) && Objects.equals(x2, other.get().x2)
&& Objects.equals(y1, other.get().y1) && Objects.equals(y2, other.get().y2);
} else
return false;
}
@Override
public double intersectionArea(Rectangle r) {
if (!intersects(r))
return 0;
else
return RectangleDouble
.create(max(x1, r.x1()), max(y1, r.y1()), min(x2, r.x2()), min(y2, r.y2()))
.area();
}
@Override
public double perimeter() {
return 2 * (x2 - x1) + 2 * (y2 - y1);
}
@Override | public Geometry geometry() { |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/internal/util/BoundedPriorityQueueTest.java | // Path: src/main/java/com/github/davidmoten/rtree/internal/util/BoundedPriorityQueue.java
// public static <T> BoundedPriorityQueue<T> create(final int maxSize,
// final Comparator<? super T> comparator) {
// return new BoundedPriorityQueue<T>(maxSize, comparator);
// }
| import static com.github.davidmoten.rtree.internal.util.BoundedPriorityQueue.create;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Comparator;
import org.junit.Test;
import com.github.davidmoten.guavamini.Sets; | package com.github.davidmoten.rtree.internal.util;
public class BoundedPriorityQueueTest {
private static final Comparator<Integer> comparator = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1.compareTo(o2);
}
};
@Test
public void emptyQueueAsListIsEmpty() { | // Path: src/main/java/com/github/davidmoten/rtree/internal/util/BoundedPriorityQueue.java
// public static <T> BoundedPriorityQueue<T> create(final int maxSize,
// final Comparator<? super T> comparator) {
// return new BoundedPriorityQueue<T>(maxSize, comparator);
// }
// Path: src/test/java/com/github/davidmoten/rtree/internal/util/BoundedPriorityQueueTest.java
import static com.github.davidmoten.rtree.internal.util.BoundedPriorityQueue.create;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Comparator;
import org.junit.Test;
import com.github.davidmoten.guavamini.Sets;
package com.github.davidmoten.rtree.internal.util;
public class BoundedPriorityQueueTest {
private static final Comparator<Integer> comparator = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1.compareTo(o2);
}
};
@Test
public void emptyQueueAsListIsEmpty() { | BoundedPriorityQueue<Integer> q = create(2, comparator); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/ComparatorsTest.java | // Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
| import org.junit.Test;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.internal.Comparators; | package com.github.davidmoten.rtree;
public class ComparatorsTest {
@Test
public void testConstructorIsPrivate() { | // Path: src/main/java/com/github/davidmoten/rtree/internal/Comparators.java
// public final class Comparators {
//
// private Comparators() {
// // prevent instantiation
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> overlapAreaThenAreaIncreaseThenAreaComparator(
// final Rectangle r, final List<T> list) {
// return new Comparator<HasGeometry>() {
//
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(overlapArea(r, list, g1), overlapArea(r, list, g2));
// if (value == 0) {
// value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// }
// return value;
// }
// };
// }
//
// private static double area(final Rectangle r, HasGeometry g1) {
// return g1.geometry().mbr().add(r).area();
// }
//
// public static <T extends HasGeometry> Comparator<HasGeometry> areaIncreaseThenAreaComparator(
// final Rectangle r) {
// return new Comparator<HasGeometry>() {
// @Override
// public int compare(HasGeometry g1, HasGeometry g2) {
// int value = Double.compare(areaIncrease(r, g1), areaIncrease(r, g2));
// if (value == 0) {
// value = Double.compare(area(r, g1), area(r, g2));
// }
// return value;
// }
// };
// }
//
// private static float overlapArea(Rectangle r, List<? extends HasGeometry> list, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// float m = 0;
// for (HasGeometry other : list) {
// if (other != g) {
// m += gPlusR.intersectionArea(other.geometry().mbr());
// }
// }
// return m;
// }
//
// private static double areaIncrease(Rectangle r, HasGeometry g) {
// Rectangle gPlusR = g.geometry().mbr().add(r);
// return gPlusR.area() - g.geometry().mbr().area();
// }
//
// /**
// * <p>
// * Returns a comparator that can be used to sort entries returned by search
// * methods. For example:
// * </p>
// * <p>
// * <code>search(100).toSortedList(ascendingDistance(r))</code>
// * </p>
// *
// * @param <T>
// * the value type
// * @param <S>
// * the entry type
// * @param r
// * rectangle to measure distance to
// * @return a comparator to sort by ascending distance from the rectangle
// */
// public static <T, S extends Geometry> Comparator<Entry<T, S>> ascendingDistance(
// final Rectangle r) {
// return new Comparator<Entry<T, S>>() {
// @Override
// public int compare(Entry<T, S> e1, Entry<T, S> e2) {
// return Double.compare(e1.geometry().distance(r), e2.geometry().distance(r));
// }
// };
// }
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/ComparatorsTest.java
import org.junit.Test;
import com.github.davidmoten.junit.Asserts;
import com.github.davidmoten.rtree.internal.Comparators;
package com.github.davidmoten.rtree;
public class ComparatorsTest {
@Test
public void testConstructorIsPrivate() { | Asserts.assertIsUtilityClass(Comparators.class); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/PointDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle; | package com.github.davidmoten.rtree.geometry.internal;
public final class PointDouble implements Point {
private final double x;
private final double y;
private PointDouble(double x, double y) {
this.x = x;
this.y = y;
}
public static PointDouble create(double x, double y) {
return new PointDouble(x, y);
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/PointDouble.java
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
package com.github.davidmoten.rtree.geometry.internal;
public final class PointDouble implements Point {
private final double x;
private final double y;
private PointDouble(double x, double y) {
this.x = x;
this.y = y;
}
public static PointDouble create(double x, double y) {
return new PointDouble(x, y);
}
@Override | public Rectangle mbr() { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/PointDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle; | return this;
}
@Override
public double x1() {
return x;
}
@Override
public double y1() {
return y;
}
@Override
public double x2() {
return x;
}
@Override
public double y2() {
return y;
}
@Override
public double area() {
return 0;
}
@Override
public Rectangle add(Rectangle r) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/PointDouble.java
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
return this;
}
@Override
public double x1() {
return x;
}
@Override
public double y1() {
return y;
}
@Override
public double x2() {
return x;
}
@Override
public double y2() {
return y;
}
@Override
public double area() {
return 0;
}
@Override
public Rectangle add(Rectangle r) { | return Geometries.rectangle(Math.min(x, r.x1()), Math.min(y, r.y1()), Math.max(x, r.x2()), |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/OnSubscribeSearch.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
| import java.util.concurrent.atomic.AtomicLong;
import com.github.davidmoten.guavamini.annotations.VisibleForTesting;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Observable.OnSubscribe;
import rx.Producer;
import rx.Subscriber;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
final class OnSubscribeSearch<T, S extends Geometry> implements OnSubscribe<Entry<T, S>> {
private final Node<T, S> node;
private final Func1<? super Geometry, Boolean> condition;
OnSubscribeSearch(Node<T, S> node, Func1<? super Geometry, Boolean> condition) {
this.node = node;
this.condition = condition;
}
@Override
public void call(Subscriber<? super Entry<T, S>> subscriber) {
subscriber.setProducer(new SearchProducer<T, S>(node, condition, subscriber));
}
@VisibleForTesting
static class SearchProducer<T, S extends Geometry> implements Producer {
private final Subscriber<? super Entry<T, S>> subscriber;
private final Node<T, S> node;
private final Func1<? super Geometry, Boolean> condition; | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ImmutableStack.java
// public final class ImmutableStack<T> implements Iterable<T> {
// private final Optional<T> head;
// private final Optional<ImmutableStack<T>> tail;
//
// private static ImmutableStack<?> EMPTY = new ImmutableStack<>();
//
// public ImmutableStack(final T head, final ImmutableStack<T> tail) {
// this(of(head), of(tail));
// }
//
// private ImmutableStack(Optional<T> head, Optional<ImmutableStack<T>> tail) {
// this.head = head;
// this.tail = tail;
// }
//
// public static <T> ImmutableStack<T> create(T t) {
// return new ImmutableStack<>(of(t), of(ImmutableStack.empty()));
// }
//
// public ImmutableStack() {
// this(Optional.empty(), Optional.empty());
// }
//
// @SuppressWarnings("unchecked")
// public static <S> ImmutableStack<S> empty() {
// return (ImmutableStack<S>) EMPTY;
// }
//
// public boolean isEmpty() {
// return !head.isPresent();
// }
//
// public T peek() {
// // if (isEmpty())
// // throw new RuntimeException("cannot peek on empty stack");
// // else
// return this.head.get();
// }
//
// public ImmutableStack<T> pop() {
// // if (isEmpty())
// // throw new RuntimeException("cannot pop on empty stack");
// // else
// return this.tail.get();
// }
//
// public ImmutableStack<T> push(T value) {
// return new ImmutableStack<T>(value, this);
// }
//
// @Override
// public Iterator<T> iterator() {
// return new StackIterator<T>(this);
// }
//
// private static class StackIterator<U> implements Iterator<U> {
// private ImmutableStack<U> stack;
//
// public StackIterator(final ImmutableStack<U> stack) {
// this.stack = stack;
// }
//
// @Override
// public boolean hasNext() {
// return !this.stack.isEmpty();
// }
//
// @Override
// public U next() {
// final U result = this.stack.peek();
// this.stack = this.stack.pop();
// return result;
// }
//
// @Override
// public void remove() {
// throw new RuntimeException("not supported");
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/OnSubscribeSearch.java
import java.util.concurrent.atomic.AtomicLong;
import com.github.davidmoten.guavamini.annotations.VisibleForTesting;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.util.ImmutableStack;
import rx.Observable.OnSubscribe;
import rx.Producer;
import rx.Subscriber;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
final class OnSubscribeSearch<T, S extends Geometry> implements OnSubscribe<Entry<T, S>> {
private final Node<T, S> node;
private final Func1<? super Geometry, Boolean> condition;
OnSubscribeSearch(Node<T, S> node, Func1<? super Geometry, Boolean> condition) {
this.node = node;
this.condition = condition;
}
@Override
public void call(Subscriber<? super Entry<T, S>> subscriber) {
subscriber.setProducer(new SearchProducer<T, S>(node, condition, subscriber));
}
@VisibleForTesting
static class SearchProducer<T, S extends Geometry> implements Producer {
private final Subscriber<? super Entry<T, S>> subscriber;
private final Node<T, S> node;
private final Func1<? super Geometry, Boolean> condition; | private volatile ImmutableStack<NodePosition<T, S>> stack; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/Util.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.HasGeometry;
import com.github.davidmoten.rtree.geometry.Rectangle; | package com.github.davidmoten.rtree.internal;
/**
* @author dxm
*
*/
public final class Util {
private Util() {
// prevent instantiation
}
/**
* Returns the minimum bounding rectangle of a number of items. Benchmarks below
* indicate that when the number of items is >1 this method is more
* performant than one using {@link Rectangle#add(Rectangle)}.
*
* <pre>
* Benchmark Mode Samples Score Score error Units
* c.g.d.r.BenchmarksMbr.mbrList1 thrpt 10 48450492.301 436127.960 ops/s
* c.g.d.r.BenchmarksMbr.mbrList2 thrpt 10 46658242.728 987901.581 ops/s
* c.g.d.r.BenchmarksMbr.mbrList3 thrpt 10 40357809.306 937827.660 ops/s
* c.g.d.r.BenchmarksMbr.mbrList4 thrpt 10 35930532.557 605535.237 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList1 thrpt 10 55848118.198 1342997.309 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList2 thrpt 10 25171873.903 395127.918 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList3 thrpt 10 19222116.139 246965.178 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList4 thrpt 10 14891862.638 198765.157 ops/s
* </pre>
*
* @param items
* items to bound
* @return the minimum bounding rectangle containings items
*/ | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/Util.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.HasGeometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
package com.github.davidmoten.rtree.internal;
/**
* @author dxm
*
*/
public final class Util {
private Util() {
// prevent instantiation
}
/**
* Returns the minimum bounding rectangle of a number of items. Benchmarks below
* indicate that when the number of items is >1 this method is more
* performant than one using {@link Rectangle#add(Rectangle)}.
*
* <pre>
* Benchmark Mode Samples Score Score error Units
* c.g.d.r.BenchmarksMbr.mbrList1 thrpt 10 48450492.301 436127.960 ops/s
* c.g.d.r.BenchmarksMbr.mbrList2 thrpt 10 46658242.728 987901.581 ops/s
* c.g.d.r.BenchmarksMbr.mbrList3 thrpt 10 40357809.306 937827.660 ops/s
* c.g.d.r.BenchmarksMbr.mbrList4 thrpt 10 35930532.557 605535.237 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList1 thrpt 10 55848118.198 1342997.309 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList2 thrpt 10 25171873.903 395127.918 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList3 thrpt 10 19222116.139 246965.178 ops/s
* c.g.d.r.BenchmarksMbr.mbrOldList4 thrpt 10 14891862.638 198765.157 ops/s
* </pre>
*
* @param items
* items to bound
* @return the minimum bounding rectangle containings items
*/ | public static Rectangle mbr(Collection<? extends HasGeometry> items) { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/NonLeaf.java
// public interface NonLeaf<T, S extends Geometry> extends Node<T, S> {
//
// Node<T, S> child(int i);
//
// /**
// * Returns a list of children nodes. For accessing individual children the
// * child(int) method should be used to ensure good performance. To avoid
// * copying an existing list though this method can be used.
// *
// * @return list of children nodes
// */
// List<Node<T, S>> children();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.util.List;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.NonLeaf;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1; | package com.github.davidmoten.rtree.internal;
public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
private final List<? extends Node<T, S>> children; | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/NonLeaf.java
// public interface NonLeaf<T, S extends Geometry> extends Node<T, S> {
//
// Node<T, S> child(int i);
//
// /**
// * Returns a list of children nodes. For accessing individual children the
// * child(int) method should be used to ensure good performance. To avoid
// * copying an existing list though this method can be used.
// *
// * @return list of children nodes
// */
// List<Node<T, S>> children();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java
import java.util.List;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.NonLeaf;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1;
package com.github.davidmoten.rtree.internal;
public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
private final List<? extends Node<T, S>> children; | private final Rectangle mbr; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/NonLeaf.java
// public interface NonLeaf<T, S extends Geometry> extends Node<T, S> {
//
// Node<T, S> child(int i);
//
// /**
// * Returns a list of children nodes. For accessing individual children the
// * child(int) method should be used to ensure good performance. To avoid
// * copying an existing list though this method can be used.
// *
// * @return list of children nodes
// */
// List<Node<T, S>> children();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.util.List;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.NonLeaf;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1; | package com.github.davidmoten.rtree.internal;
public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
private final List<? extends Node<T, S>> children;
private final Rectangle mbr; | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/NonLeaf.java
// public interface NonLeaf<T, S extends Geometry> extends Node<T, S> {
//
// Node<T, S> child(int i);
//
// /**
// * Returns a list of children nodes. For accessing individual children the
// * child(int) method should be used to ensure good performance. To avoid
// * copying an existing list though this method can be used.
// *
// * @return list of children nodes
// */
// List<Node<T, S>> children();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java
import java.util.List;
import com.github.davidmoten.guavamini.Preconditions;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.NonLeaf;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1;
package com.github.davidmoten.rtree.internal;
public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
private final List<? extends Node<T, S>> children;
private final Rectangle mbr; | private final Context<T, S> context; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/Factories.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/FactoryDefault.java
// public final class FactoryDefault<T, S extends Geometry> implements Factory<T, S> {
//
// private static class Holder {
// private static final Factory<Object, Geometry> INSTANCE = new FactoryDefault<>();
// }
//
// @SuppressWarnings("unchecked")
// public static <T, S extends Geometry> Factory<T, S> instance() {
// return (Factory<T, S>) Holder.INSTANCE;
// }
//
// @Override
// public Leaf<T, S> createLeaf(List<Entry<T, S>> entries, Context<T, S> context) {
// return new LeafDefault<>(entries, context);
// }
//
// @Override
// public NonLeaf<T, S> createNonLeaf(List<? extends Node<T, S>> children, Context<T, S> context) {
// return new NonLeafDefault<>(children, context);
// }
//
// @Override
// public Entry<T, S> createEntry(T value, S geometry) {
// return Entries.entry(value, geometry);
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.FactoryDefault; | package com.github.davidmoten.rtree;
public final class Factories {
private Factories() {
// prevent instantiation
}
| // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/FactoryDefault.java
// public final class FactoryDefault<T, S extends Geometry> implements Factory<T, S> {
//
// private static class Holder {
// private static final Factory<Object, Geometry> INSTANCE = new FactoryDefault<>();
// }
//
// @SuppressWarnings("unchecked")
// public static <T, S extends Geometry> Factory<T, S> instance() {
// return (Factory<T, S>) Holder.INSTANCE;
// }
//
// @Override
// public Leaf<T, S> createLeaf(List<Entry<T, S>> entries, Context<T, S> context) {
// return new LeafDefault<>(entries, context);
// }
//
// @Override
// public NonLeaf<T, S> createNonLeaf(List<? extends Node<T, S>> children, Context<T, S> context) {
// return new NonLeafDefault<>(children, context);
// }
//
// @Override
// public Entry<T, S> createEntry(T value, S geometry) {
// return Entries.entry(value, geometry);
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/Factories.java
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.FactoryDefault;
package com.github.davidmoten.rtree;
public final class Factories {
private Factories() {
// prevent instantiation
}
| public static <T, S extends Geometry> Factory<T, S> defaultFactory() { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/Factories.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/FactoryDefault.java
// public final class FactoryDefault<T, S extends Geometry> implements Factory<T, S> {
//
// private static class Holder {
// private static final Factory<Object, Geometry> INSTANCE = new FactoryDefault<>();
// }
//
// @SuppressWarnings("unchecked")
// public static <T, S extends Geometry> Factory<T, S> instance() {
// return (Factory<T, S>) Holder.INSTANCE;
// }
//
// @Override
// public Leaf<T, S> createLeaf(List<Entry<T, S>> entries, Context<T, S> context) {
// return new LeafDefault<>(entries, context);
// }
//
// @Override
// public NonLeaf<T, S> createNonLeaf(List<? extends Node<T, S>> children, Context<T, S> context) {
// return new NonLeafDefault<>(children, context);
// }
//
// @Override
// public Entry<T, S> createEntry(T value, S geometry) {
// return Entries.entry(value, geometry);
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.FactoryDefault; | package com.github.davidmoten.rtree;
public final class Factories {
private Factories() {
// prevent instantiation
}
public static <T, S extends Geometry> Factory<T, S> defaultFactory() { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/FactoryDefault.java
// public final class FactoryDefault<T, S extends Geometry> implements Factory<T, S> {
//
// private static class Holder {
// private static final Factory<Object, Geometry> INSTANCE = new FactoryDefault<>();
// }
//
// @SuppressWarnings("unchecked")
// public static <T, S extends Geometry> Factory<T, S> instance() {
// return (Factory<T, S>) Holder.INSTANCE;
// }
//
// @Override
// public Leaf<T, S> createLeaf(List<Entry<T, S>> entries, Context<T, S> context) {
// return new LeafDefault<>(entries, context);
// }
//
// @Override
// public NonLeaf<T, S> createNonLeaf(List<? extends Node<T, S>> children, Context<T, S> context) {
// return new NonLeafDefault<>(children, context);
// }
//
// @Override
// public Entry<T, S> createEntry(T value, S geometry) {
// return Entries.entry(value, geometry);
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/Factories.java
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.FactoryDefault;
package com.github.davidmoten.rtree;
public final class Factories {
private Factories() {
// prevent instantiation
}
public static <T, S extends Geometry> Factory<T, S> defaultFactory() { | return FactoryDefault.instance(); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/geometry/IntersectsTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
| import static com.github.davidmoten.rtree.geometry.Geometries.circle;
import static com.github.davidmoten.rtree.geometry.Geometries.rectangle;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.github.davidmoten.junit.Asserts; | package com.github.davidmoten.rtree.geometry;
public class IntersectsTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Intersects.class);
}
@Test
public void testRectangleIntersectsCircle() {
assertTrue( | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
// Path: src/test/java/com/github/davidmoten/rtree/geometry/IntersectsTest.java
import static com.github.davidmoten.rtree.geometry.Geometries.circle;
import static com.github.davidmoten.rtree.geometry.Geometries.rectangle;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.github.davidmoten.junit.Asserts;
package com.github.davidmoten.rtree.geometry;
public class IntersectsTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Intersects.class);
}
@Test
public void testRectangleIntersectsCircle() {
assertTrue( | Intersects.rectangleIntersectsCircle.call(rectangle(0, 0, 0, 0), circle(0, 0, 1))); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/geometry/IntersectsTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
| import static com.github.davidmoten.rtree.geometry.Geometries.circle;
import static com.github.davidmoten.rtree.geometry.Geometries.rectangle;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.github.davidmoten.junit.Asserts; | package com.github.davidmoten.rtree.geometry;
public class IntersectsTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Intersects.class);
}
@Test
public void testRectangleIntersectsCircle() {
assertTrue( | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
// Path: src/test/java/com/github/davidmoten/rtree/geometry/IntersectsTest.java
import static com.github.davidmoten.rtree.geometry.Geometries.circle;
import static com.github.davidmoten.rtree.geometry.Geometries.rectangle;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.github.davidmoten.junit.Asserts;
package com.github.davidmoten.rtree.geometry;
public class IntersectsTest {
@Test
public void testConstructorIsPrivate() {
Asserts.assertIsUtilityClass(Intersects.class);
}
@Test
public void testRectangleIntersectsCircle() {
assertTrue( | Intersects.rectangleIntersectsCircle.call(rectangle(0, 0, 0, 0), circle(0, 0, 1))); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | package com.github.davidmoten.rtree.geometry.internal;
public final class CircleDouble implements Circle {
private final double x, y, radius; | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
package com.github.davidmoten.rtree.geometry.internal;
public final class CircleDouble implements Circle {
private final double x, y, radius; | private final Rectangle mbr; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | }
@Override
public Rectangle mbr() {
return mbr;
}
@Override
public double distance(Rectangle r) {
return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
}
@Override
public Rectangle mbr() {
return mbr;
}
@Override
public double distance(Rectangle r) {
return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) { | Optional<CircleDouble> other = ObjectsHelper.asClass(obj, CircleDouble.class); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleDouble> other = ObjectsHelper.asClass(obj, CircleDouble.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
return Math.max(0, GeometryUtil.distance(x, y, r) - radius);
}
@Override
public boolean intersects(Rectangle r) {
return distance(r) == 0;
}
@Override
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleDouble> other = ObjectsHelper.asClass(obj, CircleDouble.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override | public boolean intersects(Point point) { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional; | public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleDouble> other = ObjectsHelper.asClass(obj, CircleDouble.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override
public boolean intersects(Point point) {
return Math.sqrt(sqr(x - point.x()) + sqr(y - point.y())) <= radius;
}
private double sqr(double x) {
return x * x;
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Line.java
// public interface Line extends Geometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// boolean intersects(Line b);
//
// boolean intersects(Point point);
//
// boolean intersects(Circle circle);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/util/ObjectsHelper.java
// public final class ObjectsHelper {
//
// private ObjectsHelper() {
// // prevent instantiation
// }
//
// @VisibleForTesting
// static void instantiateForTestCoveragePurposesOnly() {
// new ObjectsHelper();
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Optional<T> asClass(Object object, Class<T> cls) {
// if (object == null) {
// return Optional.empty();
// } else if (object.getClass() != cls) {
// return Optional.empty();
// } else {
// return Optional.of((T) object);
// }
// }
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/CircleDouble.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Line;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import com.github.davidmoten.rtree.internal.util.ObjectsHelper;
import java.util.Objects;
import java.util.Optional;
public boolean intersects(Circle c) {
double total = radius + c.radius();
return GeometryUtil.distanceSquared(x, y, c.x(), c.y()) <= total * total;
}
@Override
public int hashCode() {
return Objects.hash(x, y, radius);
}
@Override
public boolean equals(Object obj) {
Optional<CircleDouble> other = ObjectsHelper.asClass(obj, CircleDouble.class);
if (other.isPresent()) {
return Objects.equals(x, other.get().x) && Objects.equals(y, other.get().y)
&& Objects.equals(radius, other.get().radius);
} else
return false;
}
@Override
public boolean intersects(Point point) {
return Math.sqrt(sqr(x - point.x()) + sqr(y - point.y())) <= radius;
}
private double sqr(double x) {
return x * x;
}
@Override | public boolean intersects(Line line) { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/PointFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle; | package com.github.davidmoten.rtree.geometry.internal;
public final class PointFloat implements Point {
private final float x;
private final float y;
private PointFloat(float x, float y) {
this.x = x;
this.y = y;
}
public static PointFloat create(float x, float y) {
return new PointFloat(x, y);
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/PointFloat.java
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
package com.github.davidmoten.rtree.geometry.internal;
public final class PointFloat implements Point {
private final float x;
private final float y;
private PointFloat(float x, float y) {
this.x = x;
this.y = y;
}
public static PointFloat create(float x, float y) {
return new PointFloat(x, y);
}
@Override | public Rectangle mbr() { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/PointFloat.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle; | public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Float.floatToIntBits(x);
result = prime * result + Float.floatToIntBits(y);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PointFloat other = (PointFloat) obj;
if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
return false;
if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
return false;
return true;
}
@Override
public String toString() {
return "Point [x=" + x() + ", y=" + y() + "]";
}
@Override | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/PointFloat.java
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Float.floatToIntBits(x);
result = prime * result + Float.floatToIntBits(y);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PointFloat other = (PointFloat) obj;
if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
return false;
if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
return false;
return true;
}
@Override
public String toString() {
return "Point [x=" + x() + ", y=" + y() + "]";
}
@Override | public Geometry geometry() { |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/geometry/CircleTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
| import static com.github.davidmoten.rtree.geometry.Geometries.circle;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test; | package com.github.davidmoten.rtree.geometry;
public class CircleTest {
private static final double PRECISION = 0.000001;
@Test
public void testCoordinates() { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
// Path: src/test/java/com/github/davidmoten/rtree/geometry/CircleTest.java
import static com.github.davidmoten.rtree.geometry.Geometries.circle;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
package com.github.davidmoten.rtree.geometry;
public class CircleTest {
private static final double PRECISION = 0.000001;
@Test
public void testCoordinates() { | Circle circle = circle(1, 2, 3); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/geometry/RectangleTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
| import static com.github.davidmoten.rtree.geometry.Geometries.rectangle;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test; | package com.github.davidmoten.rtree.geometry;
public class RectangleTest {
private static final double PRECISION = 0.00001;
@Test
public void testDistanceToSelfIsZero() { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
// Path: src/test/java/com/github/davidmoten/rtree/geometry/RectangleTest.java
import static com.github.davidmoten.rtree.geometry.Geometries.rectangle;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
package com.github.davidmoten.rtree.geometry;
public class RectangleTest {
private static final double PRECISION = 0.00001;
@Test
public void testDistanceToSelfIsZero() { | Rectangle r = rectangle(0, 0, 1, 1); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/LatLongExampleTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import com.github.davidmoten.grumpy.core.Position;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Observable;
import rx.functions.Func1; | package com.github.davidmoten.rtree;
public class LatLongExampleTest {
private static final Point sydney = Geometries.point(151.2094, -33.86);
private static final Point canberra = Geometries.point(149.1244, -35.3075);
private static final Point brisbane = Geometries.point(153.0278, -27.4679);
private static final Point bungendore = Geometries.point(149.4500, -35.2500);
@Test
public void testLatLongExample() {
// This is to demonstrate how to use rtree to to do distance searches
// with Lat Long points
// Let's find all cities within 300km of Canberra
RTree<String, Point> tree = RTree.star().create();
tree = tree.add("Sydney", sydney);
tree = tree.add("Brisbane", brisbane);
// Now search for all locations within 300km of Canberra
final double distanceKm = 300;
List<Entry<String, Point>> list = search(tree, canberra, distanceKm)
// get the result
.toList().toBlocking().single();
// should have returned Sydney only
assertEquals(1, list.size());
assertEquals("Sydney", list.get(0).value());
}
public static <T> Observable<Entry<T, Point>> search(RTree<T, Point> tree, Point lonLat,
final double distanceKm) {
// First we need to calculate an enclosing lat long rectangle for this
// distance then we refine on the exact distance
final Position from = Position.create(lonLat.y(), lonLat.x()); | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/LatLongExampleTest.java
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import com.github.davidmoten.grumpy.core.Position;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Observable;
import rx.functions.Func1;
package com.github.davidmoten.rtree;
public class LatLongExampleTest {
private static final Point sydney = Geometries.point(151.2094, -33.86);
private static final Point canberra = Geometries.point(149.1244, -35.3075);
private static final Point brisbane = Geometries.point(153.0278, -27.4679);
private static final Point bungendore = Geometries.point(149.4500, -35.2500);
@Test
public void testLatLongExample() {
// This is to demonstrate how to use rtree to to do distance searches
// with Lat Long points
// Let's find all cities within 300km of Canberra
RTree<String, Point> tree = RTree.star().create();
tree = tree.add("Sydney", sydney);
tree = tree.add("Brisbane", brisbane);
// Now search for all locations within 300km of Canberra
final double distanceKm = 300;
List<Entry<String, Point>> list = search(tree, canberra, distanceKm)
// get the result
.toList().toBlocking().single();
// should have returned Sydney only
assertEquals(1, list.size());
assertEquals("Sydney", list.get(0).value());
}
public static <T> Observable<Entry<T, Point>> search(RTree<T, Point> tree, Point lonLat,
final double distanceKm) {
// First we need to calculate an enclosing lat long rectangle for this
// distance then we refine on the exact distance
final Position from = Position.create(lonLat.y(), lonLat.x()); | Rectangle bounds = createBounds(from, distanceKm); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/LeafDefault.java | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Leaf.java
// public interface Leaf<T, S extends Geometry> extends Node<T, S> {
//
// List<Entry<T, S>> entries();
//
// /**
// * Returns the ith entry (0-based). This method should be preferred for
// * performance reasons when only one entry is required (in comparison to
// * {@code entries().get(i)}).
// *
// * @param i
// * 0-based index
// * @return ith entry
// */
// Entry<T, S> entry(int i);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.util.List;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Leaf;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1; | package com.github.davidmoten.rtree.internal;
public final class LeafDefault<T, S extends Geometry> implements Leaf<T, S> {
private final List<Entry<T, S>> entries; | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Leaf.java
// public interface Leaf<T, S extends Geometry> extends Node<T, S> {
//
// List<Entry<T, S>> entries();
//
// /**
// * Returns the ith entry (0-based). This method should be preferred for
// * performance reasons when only one entry is required (in comparison to
// * {@code entries().get(i)}).
// *
// * @param i
// * 0-based index
// * @return ith entry
// */
// Entry<T, S> entry(int i);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/LeafDefault.java
import java.util.List;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Leaf;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1;
package com.github.davidmoten.rtree.internal;
public final class LeafDefault<T, S extends Geometry> implements Leaf<T, S> {
private final List<Entry<T, S>> entries; | private final Rectangle mbr; |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/internal/LeafDefault.java | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Leaf.java
// public interface Leaf<T, S extends Geometry> extends Node<T, S> {
//
// List<Entry<T, S>> entries();
//
// /**
// * Returns the ith entry (0-based). This method should be preferred for
// * performance reasons when only one entry is required (in comparison to
// * {@code entries().get(i)}).
// *
// * @param i
// * 0-based index
// * @return ith entry
// */
// Entry<T, S> entry(int i);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.util.List;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Leaf;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1; | package com.github.davidmoten.rtree.internal;
public final class LeafDefault<T, S extends Geometry> implements Leaf<T, S> {
private final List<Entry<T, S>> entries;
private final Rectangle mbr; | // Path: src/main/java/com/github/davidmoten/rtree/Context.java
// public final class Context<T, S extends Geometry> {
//
// private final int maxChildren;
// private final int minChildren;
// private final Splitter splitter;
// private final Selector selector;
// private final Factory<T, S> factory;
//
// /**
// * Constructor.
// *
// * @param minChildren
// * minimum number of children per node (at least 1)
// * @param maxChildren
// * max number of children per node (minimum is 3)
// * @param selector
// * algorithm to select search path
// * @param splitter
// * algorithm to split the children across two new nodes
// * @param factory
// * node creation factory
// */
// public Context(int minChildren, int maxChildren, Selector selector, Splitter splitter,
// Factory<T, S> factory) {
// Preconditions.checkNotNull(splitter);
// Preconditions.checkNotNull(selector);
// Preconditions.checkArgument(maxChildren > 2);
// Preconditions.checkArgument(minChildren >= 1);
// Preconditions.checkArgument(minChildren < maxChildren);
// Preconditions.checkNotNull(factory);
// this.selector = selector;
// this.maxChildren = maxChildren;
// this.minChildren = minChildren;
// this.splitter = splitter;
// this.factory = factory;
// }
//
// public int maxChildren() {
// return maxChildren;
// }
//
// public int minChildren() {
// return minChildren;
// }
//
// public Splitter splitter() {
// return splitter;
// }
//
// public Selector selector() {
// return selector;
// }
//
// public Factory<T, S> factory() {
// return factory;
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Entry.java
// public interface Entry<T, S extends Geometry> extends HasGeometry {
//
// T value();
//
// @Override
// S geometry();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Leaf.java
// public interface Leaf<T, S extends Geometry> extends Node<T, S> {
//
// List<Entry<T, S>> entries();
//
// /**
// * Returns the ith entry (0-based). This method should be preferred for
// * performance reasons when only one entry is required (in comparison to
// * {@code entries().get(i)}).
// *
// * @param i
// * 0-based index
// * @return ith entry
// */
// Entry<T, S> entry(int i);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/Node.java
// public interface Node<T, S extends Geometry> extends HasGeometry {
//
// List<Node<T, S>> add(Entry<? extends T, ? extends S> entry);
//
// NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all);
//
// /**
// * Run when a search requests Long.MAX_VALUE results. This is the
// * no-backpressure fast path.
// *
// * @param criterion
// * function that returns true if the geometry is a search match
// * @param subscriber
// * the subscriber to report search findings to
// */
// void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber);
//
// int count();
//
// Context<T, S> context();
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/internal/LeafDefault.java
import java.util.List;
import com.github.davidmoten.rtree.Context;
import com.github.davidmoten.rtree.Entry;
import com.github.davidmoten.rtree.Leaf;
import com.github.davidmoten.rtree.Node;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.Rectangle;
import rx.Subscriber;
import rx.functions.Func1;
package com.github.davidmoten.rtree.internal;
public final class LeafDefault<T, S extends Geometry> implements Leaf<T, S> {
private final List<Entry<T, S>> entries;
private final Rectangle mbr; | private final Context<T, S> context; |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/NonLeafTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java
// public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
//
// private final List<? extends Node<T, S>> children;
// private final Rectangle mbr;
// private final Context<T, S> context;
//
// public NonLeafDefault(List<? extends Node<T, S>> children, Context<T, S> context) {
// Preconditions.checkArgument(!children.isEmpty());
// this.context = context;
// this.children = children;
// this.mbr = Util.mbr(children);
// }
//
// @Override
// public Geometry geometry() {
// return mbr;
// }
//
// @Override
// public void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber) {
// NonLeafHelper.search(criterion, subscriber, this);
// }
//
// @Override
// public int count() {
// return children.size();
// }
//
// @Override
// public List<Node<T, S>> add(Entry<? extends T, ? extends S> entry) {
// return NonLeafHelper.add(entry, this);
// }
//
// @Override
// public NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all) {
// return NonLeafHelper.delete(entry, all, this);
// }
//
// @Override
// public Context<T, S> context() {
// return context;
// }
//
// @Override
// public Node<T, S> child(int i) {
// return children.get(i);
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<Node<T, S>> children() {
// return (List<Node<T, S>>) children;
// }
// }
| import java.util.Collections;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.NonLeafDefault; | package com.github.davidmoten.rtree;
public class NonLeafTest {
@Test(expected=IllegalArgumentException.class)
public void testNonLeafPrecondition() { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java
// public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
//
// private final List<? extends Node<T, S>> children;
// private final Rectangle mbr;
// private final Context<T, S> context;
//
// public NonLeafDefault(List<? extends Node<T, S>> children, Context<T, S> context) {
// Preconditions.checkArgument(!children.isEmpty());
// this.context = context;
// this.children = children;
// this.mbr = Util.mbr(children);
// }
//
// @Override
// public Geometry geometry() {
// return mbr;
// }
//
// @Override
// public void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber) {
// NonLeafHelper.search(criterion, subscriber, this);
// }
//
// @Override
// public int count() {
// return children.size();
// }
//
// @Override
// public List<Node<T, S>> add(Entry<? extends T, ? extends S> entry) {
// return NonLeafHelper.add(entry, this);
// }
//
// @Override
// public NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all) {
// return NonLeafHelper.delete(entry, all, this);
// }
//
// @Override
// public Context<T, S> context() {
// return context;
// }
//
// @Override
// public Node<T, S> child(int i) {
// return children.get(i);
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<Node<T, S>> children() {
// return (List<Node<T, S>>) children;
// }
// }
// Path: src/test/java/com/github/davidmoten/rtree/NonLeafTest.java
import java.util.Collections;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.NonLeafDefault;
package com.github.davidmoten.rtree;
public class NonLeafTest {
@Test(expected=IllegalArgumentException.class)
public void testNonLeafPrecondition() { | new NonLeafDefault<Object,Geometry>(Collections.<Node<Object,Geometry>>emptyList(), null); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/NonLeafTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java
// public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
//
// private final List<? extends Node<T, S>> children;
// private final Rectangle mbr;
// private final Context<T, S> context;
//
// public NonLeafDefault(List<? extends Node<T, S>> children, Context<T, S> context) {
// Preconditions.checkArgument(!children.isEmpty());
// this.context = context;
// this.children = children;
// this.mbr = Util.mbr(children);
// }
//
// @Override
// public Geometry geometry() {
// return mbr;
// }
//
// @Override
// public void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber) {
// NonLeafHelper.search(criterion, subscriber, this);
// }
//
// @Override
// public int count() {
// return children.size();
// }
//
// @Override
// public List<Node<T, S>> add(Entry<? extends T, ? extends S> entry) {
// return NonLeafHelper.add(entry, this);
// }
//
// @Override
// public NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all) {
// return NonLeafHelper.delete(entry, all, this);
// }
//
// @Override
// public Context<T, S> context() {
// return context;
// }
//
// @Override
// public Node<T, S> child(int i) {
// return children.get(i);
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<Node<T, S>> children() {
// return (List<Node<T, S>>) children;
// }
// }
| import java.util.Collections;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.NonLeafDefault; | package com.github.davidmoten.rtree;
public class NonLeafTest {
@Test(expected=IllegalArgumentException.class)
public void testNonLeafPrecondition() { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometry.java
// public interface Geometry {
//
// /**
// * <p>
// * Returns the distance to the given {@link Rectangle}. For a {@link Rectangle}
// * this might be Euclidean distance but for an EPSG4326 lat-long Rectangle might
// * be great-circle distance. The distance function should satisfy the following
// * properties:
// * </p>
// *
// * <p>
// * <code>distance(r) >= 0</code>
// * </p>
// *
// * <p>
// * <code>if r1 contains r2 then distance(r1)<=distance(r2)</code>
// * </p>
// *
// *
// * @param r
// * rectangle to measure distance to
// * @return distance to the rectangle r from the geometry
// */
// double distance(Rectangle r);
//
// /**
// * Returns the minimum bounding rectangle of this geometry.
// *
// * @return minimum bounding rectangle
// */
// Rectangle mbr();
//
// boolean intersects(Rectangle r);
//
// boolean isDoublePrecision();
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/internal/NonLeafDefault.java
// public final class NonLeafDefault<T, S extends Geometry> implements NonLeaf<T, S> {
//
// private final List<? extends Node<T, S>> children;
// private final Rectangle mbr;
// private final Context<T, S> context;
//
// public NonLeafDefault(List<? extends Node<T, S>> children, Context<T, S> context) {
// Preconditions.checkArgument(!children.isEmpty());
// this.context = context;
// this.children = children;
// this.mbr = Util.mbr(children);
// }
//
// @Override
// public Geometry geometry() {
// return mbr;
// }
//
// @Override
// public void searchWithoutBackpressure(Func1<? super Geometry, Boolean> criterion,
// Subscriber<? super Entry<T, S>> subscriber) {
// NonLeafHelper.search(criterion, subscriber, this);
// }
//
// @Override
// public int count() {
// return children.size();
// }
//
// @Override
// public List<Node<T, S>> add(Entry<? extends T, ? extends S> entry) {
// return NonLeafHelper.add(entry, this);
// }
//
// @Override
// public NodeAndEntries<T, S> delete(Entry<? extends T, ? extends S> entry, boolean all) {
// return NonLeafHelper.delete(entry, all, this);
// }
//
// @Override
// public Context<T, S> context() {
// return context;
// }
//
// @Override
// public Node<T, S> child(int i) {
// return children.get(i);
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<Node<T, S>> children() {
// return (List<Node<T, S>>) children;
// }
// }
// Path: src/test/java/com/github/davidmoten/rtree/NonLeafTest.java
import java.util.Collections;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.internal.NonLeafDefault;
package com.github.davidmoten.rtree;
public class NonLeafTest {
@Test(expected=IllegalArgumentException.class)
public void testNonLeafPrecondition() { | new NonLeafDefault<Object,Geometry>(Collections.<Node<Object,Geometry>>emptyList(), null); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/HighPrecisionTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Rectangle; | package com.github.davidmoten.rtree;
public class HighPrecisionTest {
@Test
public void testForIssue72() {
long x = 123456789L;
System.out.println(new BigDecimal(x).floatValue());
BigDecimal b = new BigDecimal(x);
System.out.println(b.round(FLOOR).floatValue());
System.out.println(b.round(CEILING).floatValue());
}
@Test
public void testHighPrecision() { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/HighPrecisionTest.java
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Rectangle;
package com.github.davidmoten.rtree;
public class HighPrecisionTest {
@Test
public void testForIssue72() {
long x = 123456789L;
System.out.println(new BigDecimal(x).floatValue());
BigDecimal b = new BigDecimal(x);
System.out.println(b.round(FLOOR).floatValue());
System.out.println(b.round(CEILING).floatValue());
}
@Test
public void testHighPrecision() { | RTree<Integer, Rectangle> tree = RTree.create(); |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/HighPrecisionTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Rectangle; | package com.github.davidmoten.rtree;
public class HighPrecisionTest {
@Test
public void testForIssue72() {
long x = 123456789L;
System.out.println(new BigDecimal(x).floatValue());
BigDecimal b = new BigDecimal(x);
System.out.println(b.round(FLOOR).floatValue());
System.out.println(b.round(CEILING).floatValue());
}
@Test
public void testHighPrecision() {
RTree<Integer, Rectangle> tree = RTree.create(); | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/HighPrecisionTest.java
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import org.junit.Test;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Rectangle;
package com.github.davidmoten.rtree;
public class HighPrecisionTest {
@Test
public void testForIssue72() {
long x = 123456789L;
System.out.println(new BigDecimal(x).floatValue());
BigDecimal b = new BigDecimal(x);
System.out.println(b.round(FLOOR).floatValue());
System.out.println(b.round(CEILING).floatValue());
}
@Test
public void testHighPrecision() {
RTree<Integer, Rectangle> tree = RTree.create(); | tree = tree.add(1, Geometries.rectangle(0, 0, 1, 1)); |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Rectangle; | }
public static double max(double a, double b) {
if (a < b)
return b;
else
return a;
}
public static float max(float a, float b) {
if (a < b)
return b;
else
return a;
}
public static double min(double a, double b) {
if (a < b)
return a;
else
return b;
}
public static float min(float a, float b) {
if (a < b)
return a;
else
return b;
}
| // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Rectangle;
}
public static double max(double a, double b) {
if (a < b)
return b;
else
return a;
}
public static float max(float a, float b) {
if (a < b)
return b;
else
return a;
}
public static double min(double a, double b) {
if (a < b)
return a;
else
return b;
}
public static float min(float a, float b) {
if (a < b)
return a;
else
return b;
}
| public static double distance(double x, double y, Rectangle r) { |
davidmoten/rtree | src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
| import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Rectangle; | public static double distance(double x, double y, double a1, double b1, double a2, double b2) {
return distance(x, y, x, y, a1, b1, a2, b2);
}
public static double distance(double x1, double y1, double x2, double y2, double a1, double b1,
double a2, double b2) {
if (intersects(x1, y1, x2, y2, a1, b1, a2, b2)) {
return 0;
}
boolean xyMostLeft = x1 < a1;
double mostLeftX1 = xyMostLeft ? x1 : a1;
double mostRightX1 = xyMostLeft ? a1 : x1;
double mostLeftX2 = xyMostLeft ? x2 : a2;
double xDifference = max(0, mostLeftX1 == mostRightX1 ? 0 : mostRightX1 - mostLeftX2);
boolean xyMostDown = y1 < b1;
double mostDownY1 = xyMostDown ? y1 : b1;
double mostUpY1 = xyMostDown ? b1 : y1;
double mostDownY2 = xyMostDown ? y2 : b2;
double yDifference = max(0, mostDownY1 == mostUpY1 ? 0 : mostUpY1 - mostDownY2);
return Math.sqrt(xDifference * xDifference + yDifference * yDifference);
}
public static boolean intersects(double x1, double y1, double x2, double y2, double a1,
double b1, double a2, double b2) {
return x1 <= a2 && a1 <= x2 && y1 <= b2 && b1 <= y2;
}
| // Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
//
// double x();
//
// double y();
//
// double radius();
//
// boolean intersects(Circle c);
//
// boolean intersects(Point point);
//
// boolean intersects(Line line);
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
//
// double x1();
//
// double y1();
//
// double x2();
//
// double y2();
//
// double area();
//
// double intersectionArea(Rectangle r);
//
// double perimeter();
//
// Rectangle add(Rectangle r);
//
// boolean contains(double x, double y);
//
// boolean isDoublePrecision();
//
// }
// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Rectangle;
public static double distance(double x, double y, double a1, double b1, double a2, double b2) {
return distance(x, y, x, y, a1, b1, a2, b2);
}
public static double distance(double x1, double y1, double x2, double y2, double a1, double b1,
double a2, double b2) {
if (intersects(x1, y1, x2, y2, a1, b1, a2, b2)) {
return 0;
}
boolean xyMostLeft = x1 < a1;
double mostLeftX1 = xyMostLeft ? x1 : a1;
double mostRightX1 = xyMostLeft ? a1 : x1;
double mostLeftX2 = xyMostLeft ? x2 : a2;
double xDifference = max(0, mostLeftX1 == mostRightX1 ? 0 : mostRightX1 - mostLeftX2);
boolean xyMostDown = y1 < b1;
double mostDownY1 = xyMostDown ? y1 : b1;
double mostUpY1 = xyMostDown ? b1 : y1;
double mostDownY2 = xyMostDown ? y2 : b2;
double yDifference = max(0, mostDownY1 == mostUpY1 ? 0 : mostUpY1 - mostDownY2);
return Math.sqrt(xDifference * xDifference + yDifference * yDifference);
}
public static boolean intersects(double x1, double y1, double x2, double y2, double a1,
double b1, double a2, double b2) {
return x1 <= a2 && a1 <= x2 && y1 <= b2 && b1 <= y2;
}
| public static boolean lineIntersects(double x1, double y1, double x2, double y2, Circle circle) { |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/KryoSerializationTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
| import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.junit.Ignore;
import org.junit.Test;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point; | package com.github.davidmoten.rtree;
public class KryoSerializationTest {
@Test
@Ignore
public void testRTree() {
Kryo kryo = new Kryo();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Output output = new Output(bytes); | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/KryoSerializationTest.java
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.junit.Ignore;
import org.junit.Test;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point;
package com.github.davidmoten.rtree;
public class KryoSerializationTest {
@Test
@Ignore
public void testRTree() {
Kryo kryo = new Kryo();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Output output = new Output(bytes); | RTree<String, Point> tree = RTree.<String, Point> create() |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/KryoSerializationTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
| import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.junit.Ignore;
import org.junit.Test;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point; | package com.github.davidmoten.rtree;
public class KryoSerializationTest {
@Test
@Ignore
public void testRTree() {
Kryo kryo = new Kryo();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Output output = new Output(bytes);
RTree<String, Point> tree = RTree.<String, Point> create() | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public final class Geometries {
//
// private Geometries() {
// // prevent instantiation
// }
//
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
//
// public static Point point(float x, float y) {
// return PointFloat.create(x, y);
// }
//
// public static Point pointGeographic(double lon, double lat) {
// return point(normalizeLongitudeDouble(lon), lat);
// }
//
// public static Point pointGeographic(float lon, float lat) {
// return point(normalizeLongitude(lon), lat);
// }
//
// public static Rectangle rectangle(double x1, double y1, double x2, double y2) {
// return rectangleDouble(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangle(float x1, float y1, float x2, float y2) {
// return RectangleFloat.create(x1, y1, x2, y2);
// }
//
// public static Rectangle rectangleGeographic(double lon1, double lat1, double lon2,
// double lat2) {
// return rectangleGeographic((float) lon1, (float) lat1, (float) lon2, (float) lat2);
// }
//
// public static Rectangle rectangleGeographic(float lon1, float lat1, float lon2, float lat2) {
// float x1 = normalizeLongitude(lon1);
// float x2 = normalizeLongitude(lon2);
// if (x2 < x1) {
// x2 += 360;
// }
// return rectangle(x1, lat1, x2, lat2);
// }
//
// private static Rectangle rectangleDouble(double x1, double y1, double x2, double y2) {
// return RectangleDouble.create(x1, y1, x2, y2);
// }
//
// public static Circle circle(double x, double y, double radius) {
// return CircleDouble.create(x, y, radius);
// }
//
// public static Circle circle(float x, float y, float radius) {
// return CircleFloat.create(x, y, radius);
// }
//
// public static Line line(double x1, double y1, double x2, double y2) {
// return LineDouble.create(x1, y1, x2, y2);
// }
//
// public static Line line(float x1, float y1, float x2, float y2) {
// return LineFloat.create(x1, y1, x2, y2);
// }
//
// @VisibleForTesting
// static double normalizeLongitude(double d) {
// return normalizeLongitude((float) d);
// }
//
// private static float normalizeLongitude(float d) {
// if (d == -180.0f)
// return -180.0f;
// else {
// float sign = Math.signum(d);
// float x = Math.abs(d) / 360;
// float x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// private static double normalizeLongitudeDouble(double d) {
// if (d == -180.0f)
// return -180.0d;
// else {
// double sign = Math.signum(d);
// double x = Math.abs(d) / 360;
// double x2 = (x - (float) Math.floor(x)) * 360;
// if (x2 >= 180)
// x2 -= 360;
// return x2 * sign;
// }
// }
//
// }
//
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Point.java
// public interface Point extends Rectangle {
//
// double x();
//
// double y();
//
// }
// Path: src/test/java/com/github/davidmoten/rtree/KryoSerializationTest.java
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.junit.Ignore;
import org.junit.Test;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.github.davidmoten.rtree.geometry.Geometries;
import com.github.davidmoten.rtree.geometry.Point;
package com.github.davidmoten.rtree;
public class KryoSerializationTest {
@Test
@Ignore
public void testRTree() {
Kryo kryo = new Kryo();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Output output = new Output(bytes);
RTree<String, Point> tree = RTree.<String, Point> create() | .add(Entries.entry("thing", Geometries.point(10, 20))) |
davidmoten/rtree | src/test/java/com/github/davidmoten/rtree/geometry/LineTest.java | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
| import static com.github.davidmoten.rtree.geometry.Geometries.point;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.awt.geom.Line2D;
import org.junit.Test; | @Test
public void testLineDistanceToRectangleIsZeroWhenContainsWestEdge() {
Line a = Geometries.line(3, 1, 3, 10);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDistanceToRectangleIsZeroWhenContainsNorthEdge() {
Line a = Geometries.line(2, 7, 10, 7);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDistanceToRectangleIsZeroWhenContainsSouthEdge() {
Line a = Geometries.line(2, 3, 10, 3);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDistanceToRectangleIsZeroWhenContainsEastEdge() {
Line a = Geometries.line(7, 1, 7, 10);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDoesNotIntersectsPoint() { | // Path: src/main/java/com/github/davidmoten/rtree/geometry/Geometries.java
// public static Point point(double x, double y) {
// return PointDouble.create(x, y);
// }
// Path: src/test/java/com/github/davidmoten/rtree/geometry/LineTest.java
import static com.github.davidmoten.rtree.geometry.Geometries.point;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.awt.geom.Line2D;
import org.junit.Test;
@Test
public void testLineDistanceToRectangleIsZeroWhenContainsWestEdge() {
Line a = Geometries.line(3, 1, 3, 10);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDistanceToRectangleIsZeroWhenContainsNorthEdge() {
Line a = Geometries.line(2, 7, 10, 7);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDistanceToRectangleIsZeroWhenContainsSouthEdge() {
Line a = Geometries.line(2, 3, 10, 3);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDistanceToRectangleIsZeroWhenContainsEastEdge() {
Line a = Geometries.line(7, 1, 7, 10);
Rectangle r = Geometries.rectangle(3, 3, 7, 7);
assertEquals(0, a.distance(r), PRECISION);
}
@Test
public void testLineDoesNotIntersectsPoint() { | assertFalse(Geometries.line(1.5, 1.5, 2.6, 2.5).intersects(point(2, 2))); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/spring/ShiZiQiuConfPlaceholderConfigurer.java | // Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
//
// private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// private static Cache cache;
//
// static {
// CacheManager manager = CacheManager.create();
// cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// manager.addCache(cache);
// }
//
// public static void set(String key, String value) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
//
// public static void update(String key, String value) {
// if (cache != null) {
// if (cache.get(key)!=null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
// }
//
// public static String get(String key, String defaultVal) {
// if (localProp!=null && localProp.containsKey(key)) {
// return localProp.getProperty(key);
// }
// if (cache != null) {
// Element element = cache.get(key);
// if (element != null) {
// return (String) element.getObjectValue();
// }
// }
// String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// if (zkData!=null) {
// set(key, zkData);
// return zkData;
// }
//
// return defaultVal;
// }
//
// public static boolean remove(String key) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置:key ", key);
// return cache.remove(key);
// }
// return false;
// }
//
// public static void main(String[] args) {
// String key = "key";
// String value = "hello";
// set(key, value);
// System.out.println(get(key, "-1"));
// }
//
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
| import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionVisitor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.Ordered;
import org.springframework.util.StringValueResolver;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient;
import com.shiziqiu.configuration.util.Constant; | package com.shiziqiu.configuration.core.spring;
/**
* @title : ShiZiQiuConfPlaceholderConfigurer
* @author : crazy
* @date : 2017年9月6日 下午5:11:04
* @Fun :
*/
public class ShiZiQiuConfPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfPlaceholderConfigurer.class);
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
StringValueResolver valueResolver = new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
StringBuffer sb = new StringBuffer(strVal);
/**
* 给变量加上${XXXXXXX}
*/ | // Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
//
// private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// private static Cache cache;
//
// static {
// CacheManager manager = CacheManager.create();
// cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// manager.addCache(cache);
// }
//
// public static void set(String key, String value) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
//
// public static void update(String key, String value) {
// if (cache != null) {
// if (cache.get(key)!=null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
// }
//
// public static String get(String key, String defaultVal) {
// if (localProp!=null && localProp.containsKey(key)) {
// return localProp.getProperty(key);
// }
// if (cache != null) {
// Element element = cache.get(key);
// if (element != null) {
// return (String) element.getObjectValue();
// }
// }
// String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// if (zkData!=null) {
// set(key, zkData);
// return zkData;
// }
//
// return defaultVal;
// }
//
// public static boolean remove(String key) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置:key ", key);
// return cache.remove(key);
// }
// return false;
// }
//
// public static void main(String[] args) {
// String key = "key";
// String value = "hello";
// set(key, value);
// System.out.println(get(key, "-1"));
// }
//
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/spring/ShiZiQiuConfPlaceholderConfigurer.java
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionVisitor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.Ordered;
import org.springframework.util.StringValueResolver;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient;
import com.shiziqiu.configuration.util.Constant;
package com.shiziqiu.configuration.core.spring;
/**
* @title : ShiZiQiuConfPlaceholderConfigurer
* @author : crazy
* @date : 2017年9月6日 下午5:11:04
* @Fun :
*/
public class ShiZiQiuConfPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfPlaceholderConfigurer.class);
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
StringValueResolver valueResolver = new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
StringBuffer sb = new StringBuffer(strVal);
/**
* 给变量加上${XXXXXXX}
*/ | boolean start = strVal.startsWith(Constant.PLACEHOLDER_PREFIX); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/spring/ShiZiQiuConfPlaceholderConfigurer.java | // Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
//
// private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// private static Cache cache;
//
// static {
// CacheManager manager = CacheManager.create();
// cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// manager.addCache(cache);
// }
//
// public static void set(String key, String value) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
//
// public static void update(String key, String value) {
// if (cache != null) {
// if (cache.get(key)!=null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
// }
//
// public static String get(String key, String defaultVal) {
// if (localProp!=null && localProp.containsKey(key)) {
// return localProp.getProperty(key);
// }
// if (cache != null) {
// Element element = cache.get(key);
// if (element != null) {
// return (String) element.getObjectValue();
// }
// }
// String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// if (zkData!=null) {
// set(key, zkData);
// return zkData;
// }
//
// return defaultVal;
// }
//
// public static boolean remove(String key) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置:key ", key);
// return cache.remove(key);
// }
// return false;
// }
//
// public static void main(String[] args) {
// String key = "key";
// String value = "hello";
// set(key, value);
// System.out.println(get(key, "-1"));
// }
//
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
| import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionVisitor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.Ordered;
import org.springframework.util.StringValueResolver;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient;
import com.shiziqiu.configuration.util.Constant; | package com.shiziqiu.configuration.core.spring;
/**
* @title : ShiZiQiuConfPlaceholderConfigurer
* @author : crazy
* @date : 2017年9月6日 下午5:11:04
* @Fun :
*/
public class ShiZiQiuConfPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfPlaceholderConfigurer.class);
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
StringValueResolver valueResolver = new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
StringBuffer sb = new StringBuffer(strVal);
/**
* 给变量加上${XXXXXXX}
*/
boolean start = strVal.startsWith(Constant.PLACEHOLDER_PREFIX);
boolean end = strVal.endsWith(Constant.PLACEHOLDER_SUFFIX);
while(start && end) {
String key = sb.substring(placeholderPrefix.length(), sb.length() - placeholderSuffix.length()); | // Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
//
// private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// private static Cache cache;
//
// static {
// CacheManager manager = CacheManager.create();
// cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// manager.addCache(cache);
// }
//
// public static void set(String key, String value) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
//
// public static void update(String key, String value) {
// if (cache != null) {
// if (cache.get(key)!=null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
// }
//
// public static String get(String key, String defaultVal) {
// if (localProp!=null && localProp.containsKey(key)) {
// return localProp.getProperty(key);
// }
// if (cache != null) {
// Element element = cache.get(key);
// if (element != null) {
// return (String) element.getObjectValue();
// }
// }
// String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// if (zkData!=null) {
// set(key, zkData);
// return zkData;
// }
//
// return defaultVal;
// }
//
// public static boolean remove(String key) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置:key ", key);
// return cache.remove(key);
// }
// return false;
// }
//
// public static void main(String[] args) {
// String key = "key";
// String value = "hello";
// set(key, value);
// System.out.println(get(key, "-1"));
// }
//
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/spring/ShiZiQiuConfPlaceholderConfigurer.java
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionVisitor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.Ordered;
import org.springframework.util.StringValueResolver;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient;
import com.shiziqiu.configuration.util.Constant;
package com.shiziqiu.configuration.core.spring;
/**
* @title : ShiZiQiuConfPlaceholderConfigurer
* @author : crazy
* @date : 2017年9月6日 下午5:11:04
* @Fun :
*/
public class ShiZiQiuConfPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfPlaceholderConfigurer.class);
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
StringValueResolver valueResolver = new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
StringBuffer sb = new StringBuffer(strVal);
/**
* 给变量加上${XXXXXXX}
*/
boolean start = strVal.startsWith(Constant.PLACEHOLDER_PREFIX);
boolean end = strVal.endsWith(Constant.PLACEHOLDER_SUFFIX);
while(start && end) {
String key = sb.substring(placeholderPrefix.length(), sb.length() - placeholderSuffix.length()); | String zkValue = ShiZiQiuConfClient.get(key, ""); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfNode.java
// public class ShiZiQiuConfNode implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 132434523L;
//
// private String nodeGroup;
// private String nodeKey;
// private String nodeValue;
// private String nodeDesc;
//
// private String groupKey;
// private String nodeValueReal;
//
// public ShiZiQiuConfNode() {
// super();
// }
//
// public ShiZiQiuConfNode(String nodeGroup, String nodeKey, String nodeValue,
// String nodeDesc, String groupKey, String nodeValueReal) {
// super();
// this.nodeGroup = nodeGroup;
// this.nodeKey = nodeKey;
// this.nodeValue = nodeValue;
// this.nodeDesc = nodeDesc;
// this.groupKey = groupKey;
// this.nodeValueReal = nodeValueReal;
// }
//
// public String getNodeGroup() {
// return nodeGroup;
// }
// public void setNodeGroup(String nodeGroup) {
// this.nodeGroup = nodeGroup;
// }
// public String getNodeKey() {
// return nodeKey;
// }
// public void setNodeKey(String nodeKey) {
// this.nodeKey = nodeKey;
// }
// public String getNodeValue() {
// return nodeValue;
// }
// public void setNodeValue(String nodeValue) {
// this.nodeValue = nodeValue;
// }
// public String getNodeDesc() {
// return nodeDesc;
// }
// public void setNodeDesc(String nodeDesc) {
// this.nodeDesc = nodeDesc;
// }
// public String getGroupKey() {
// return ShiZiQiuZkConfClient.generateGroupKey(nodeGroup, nodeKey);
// }
// public void setGroupKey(String groupKey) {
// this.groupKey = groupKey;
// }
// public String getNodeValueReal() {
// return nodeValueReal;
// }
// public void setNodeValueReal(String nodeValueReal) {
// this.nodeValueReal = nodeValueReal;
// }
//
// }
| import java.util.Map;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfNode; | package com.shiziqiu.configuration.console.service;
/**
* @title : ShiZiQiuConfNodeService
* @author : crazy
* @date : 2017年9月6日 下午8:07:04
* @Fun :
*/
public interface ShiZiQiuConfNodeService {
public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
| // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfNode.java
// public class ShiZiQiuConfNode implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 132434523L;
//
// private String nodeGroup;
// private String nodeKey;
// private String nodeValue;
// private String nodeDesc;
//
// private String groupKey;
// private String nodeValueReal;
//
// public ShiZiQiuConfNode() {
// super();
// }
//
// public ShiZiQiuConfNode(String nodeGroup, String nodeKey, String nodeValue,
// String nodeDesc, String groupKey, String nodeValueReal) {
// super();
// this.nodeGroup = nodeGroup;
// this.nodeKey = nodeKey;
// this.nodeValue = nodeValue;
// this.nodeDesc = nodeDesc;
// this.groupKey = groupKey;
// this.nodeValueReal = nodeValueReal;
// }
//
// public String getNodeGroup() {
// return nodeGroup;
// }
// public void setNodeGroup(String nodeGroup) {
// this.nodeGroup = nodeGroup;
// }
// public String getNodeKey() {
// return nodeKey;
// }
// public void setNodeKey(String nodeKey) {
// this.nodeKey = nodeKey;
// }
// public String getNodeValue() {
// return nodeValue;
// }
// public void setNodeValue(String nodeValue) {
// this.nodeValue = nodeValue;
// }
// public String getNodeDesc() {
// return nodeDesc;
// }
// public void setNodeDesc(String nodeDesc) {
// this.nodeDesc = nodeDesc;
// }
// public String getGroupKey() {
// return ShiZiQiuZkConfClient.generateGroupKey(nodeGroup, nodeKey);
// }
// public void setGroupKey(String groupKey) {
// this.groupKey = groupKey;
// }
// public String getNodeValueReal() {
// return nodeValueReal;
// }
// public void setNodeValueReal(String nodeValueReal) {
// this.nodeValueReal = nodeValueReal;
// }
//
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
import java.util.Map;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfNode;
package com.shiziqiu.configuration.console.service;
/**
* @title : ShiZiQiuConfNodeService
* @author : crazy
* @date : 2017年9月6日 下午8:07:04
* @Fun :
*/
public interface ShiZiQiuConfNodeService {
public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
| public ResultT<String> deleteByKey(String nodeGroup, String nodeKey); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfNode.java
// public class ShiZiQiuConfNode implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 132434523L;
//
// private String nodeGroup;
// private String nodeKey;
// private String nodeValue;
// private String nodeDesc;
//
// private String groupKey;
// private String nodeValueReal;
//
// public ShiZiQiuConfNode() {
// super();
// }
//
// public ShiZiQiuConfNode(String nodeGroup, String nodeKey, String nodeValue,
// String nodeDesc, String groupKey, String nodeValueReal) {
// super();
// this.nodeGroup = nodeGroup;
// this.nodeKey = nodeKey;
// this.nodeValue = nodeValue;
// this.nodeDesc = nodeDesc;
// this.groupKey = groupKey;
// this.nodeValueReal = nodeValueReal;
// }
//
// public String getNodeGroup() {
// return nodeGroup;
// }
// public void setNodeGroup(String nodeGroup) {
// this.nodeGroup = nodeGroup;
// }
// public String getNodeKey() {
// return nodeKey;
// }
// public void setNodeKey(String nodeKey) {
// this.nodeKey = nodeKey;
// }
// public String getNodeValue() {
// return nodeValue;
// }
// public void setNodeValue(String nodeValue) {
// this.nodeValue = nodeValue;
// }
// public String getNodeDesc() {
// return nodeDesc;
// }
// public void setNodeDesc(String nodeDesc) {
// this.nodeDesc = nodeDesc;
// }
// public String getGroupKey() {
// return ShiZiQiuZkConfClient.generateGroupKey(nodeGroup, nodeKey);
// }
// public void setGroupKey(String groupKey) {
// this.groupKey = groupKey;
// }
// public String getNodeValueReal() {
// return nodeValueReal;
// }
// public void setNodeValueReal(String nodeValueReal) {
// this.nodeValueReal = nodeValueReal;
// }
//
// }
| import java.util.Map;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfNode; | package com.shiziqiu.configuration.console.service;
/**
* @title : ShiZiQiuConfNodeService
* @author : crazy
* @date : 2017年9月6日 下午8:07:04
* @Fun :
*/
public interface ShiZiQiuConfNodeService {
public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
| // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfNode.java
// public class ShiZiQiuConfNode implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 132434523L;
//
// private String nodeGroup;
// private String nodeKey;
// private String nodeValue;
// private String nodeDesc;
//
// private String groupKey;
// private String nodeValueReal;
//
// public ShiZiQiuConfNode() {
// super();
// }
//
// public ShiZiQiuConfNode(String nodeGroup, String nodeKey, String nodeValue,
// String nodeDesc, String groupKey, String nodeValueReal) {
// super();
// this.nodeGroup = nodeGroup;
// this.nodeKey = nodeKey;
// this.nodeValue = nodeValue;
// this.nodeDesc = nodeDesc;
// this.groupKey = groupKey;
// this.nodeValueReal = nodeValueReal;
// }
//
// public String getNodeGroup() {
// return nodeGroup;
// }
// public void setNodeGroup(String nodeGroup) {
// this.nodeGroup = nodeGroup;
// }
// public String getNodeKey() {
// return nodeKey;
// }
// public void setNodeKey(String nodeKey) {
// this.nodeKey = nodeKey;
// }
// public String getNodeValue() {
// return nodeValue;
// }
// public void setNodeValue(String nodeValue) {
// this.nodeValue = nodeValue;
// }
// public String getNodeDesc() {
// return nodeDesc;
// }
// public void setNodeDesc(String nodeDesc) {
// this.nodeDesc = nodeDesc;
// }
// public String getGroupKey() {
// return ShiZiQiuZkConfClient.generateGroupKey(nodeGroup, nodeKey);
// }
// public void setGroupKey(String groupKey) {
// this.groupKey = groupKey;
// }
// public String getNodeValueReal() {
// return nodeValueReal;
// }
// public void setNodeValueReal(String nodeValueReal) {
// this.nodeValueReal = nodeValueReal;
// }
//
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
import java.util.Map;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfNode;
package com.shiziqiu.configuration.console.service;
/**
* @title : ShiZiQiuConfNodeService
* @author : crazy
* @date : 2017年9月6日 下午8:07:04
* @Fun :
*/
public interface ShiZiQiuConfNodeService {
public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
| public ResultT<String> add(ShiZiQiuConfNode node); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
| import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils; | package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils;
package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource | private ShiZiQiuConfNodeService shiZiQiuConfNodeService; |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
| import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils; | package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils;
package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource | private ShiZiQiuConfGroupService shiZiQiuConfGroupService; |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
| import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils; | package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource
private ShiZiQiuConfGroupService shiZiQiuConfGroupService;
@RequestMapping
public String index(Model model) { | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils;
package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource
private ShiZiQiuConfGroupService shiZiQiuConfGroupService;
@RequestMapping
public String index(Model model) { | List<ShiZiQiuConfGroup> list = shiZiQiuConfGroupService.findAll(); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
| import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils; | package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource
private ShiZiQiuConfGroupService shiZiQiuConfGroupService;
@RequestMapping
public String index(Model model) {
List<ShiZiQiuConfGroup> list = shiZiQiuConfGroupService.findAll();
model.addAttribute("list", list);
return "group/index";
}
@RequestMapping("/save")
@ResponseBody | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils;
package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource
private ShiZiQiuConfGroupService shiZiQiuConfGroupService;
@RequestMapping
public String index(Model model) {
List<ShiZiQiuConfGroup> list = shiZiQiuConfGroupService.findAll();
model.addAttribute("list", list);
return "group/index";
}
@RequestMapping("/save")
@ResponseBody | public ResultT<String> save(ShiZiQiuConfGroup shiZiQiuConfGroup){ |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
| import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils; | package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource
private ShiZiQiuConfGroupService shiZiQiuConfGroupService;
@RequestMapping
public String index(Model model) {
List<ShiZiQiuConfGroup> list = shiZiQiuConfGroupService.findAll();
model.addAttribute("list", list);
return "group/index";
}
@RequestMapping("/save")
@ResponseBody
public ResultT<String> save(ShiZiQiuConfGroup shiZiQiuConfGroup){
| // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ResultT.java
// public class ResultT<T> {
//
// public static final ResultT<String> SUCCESS = new ResultT<String>(null);
// public static final ResultT<String> FAIL = new ResultT<String>(500, null);
//
// private int code;
// private String msg;
// private T content;
//
// public ResultT(){}
//
// public ResultT(int code, String msg) {
// this.code = code;
// this.msg = msg;
// }
// public ResultT(T content) {
// this.code = 200;
// this.content = content;
// }
//
// public int getCode() {
// return code;
// }
//
// public void setCode(int code) {
// this.code = code;
// }
//
// public String getMsg() {
// return msg;
// }
//
// public void setMsg(String msg) {
// this.msg = msg;
// }
//
// public T getContent() {
// return content;
// }
//
// public void setContent(T content) {
// this.content = content;
// }
//
// @Override
// public String toString() {
// return "ResultT [code=" + code + ", msg=" + msg + ", content="
// + content + "]";
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfNodeService.java
// public interface ShiZiQiuConfNodeService {
//
// public Map<String,Object> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public ResultT<String> deleteByKey(String nodeGroup, String nodeKey);
//
// public ResultT<String> add(ShiZiQiuConfNode node);
//
// public ResultT<String> update(ShiZiQiuConfNode node);
//
// public int pageListCount(int offset, int pagesize, String groupName, String nodeKey);
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/StringUtils.java
// public class StringUtils {
//
// public static boolean isNotBlank(String str) {
// return !StringUtils.isBlank(str);
// }
//
// public static boolean isBlank(String str) {
// int strLen;
// if (str == null || (strLen = str.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if ((Character.isWhitespace(str.charAt(i)) == false)) {
// return false;
// }
// }
// return true;
// }
//
// public static String trim(String str) {
// return str == null ? null : str.trim();
// }
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/controller/GroupController.java
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shiziqiu.configuration.console.model.ResultT;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfNodeService;
import com.shiziqiu.configuration.util.StringUtils;
package com.shiziqiu.configuration.console.web.controller;
/**
* @title : GroupController
* @author : crazy
* @date : 2017年9月7日 上午9:57:18
* @Fun :
*/
@Controller
@RequestMapping("/group")
public class GroupController {
@Resource
private ShiZiQiuConfNodeService shiZiQiuConfNodeService;
@Resource
private ShiZiQiuConfGroupService shiZiQiuConfGroupService;
@RequestMapping
public String index(Model model) {
List<ShiZiQiuConfGroup> list = shiZiQiuConfGroupService.findAll();
model.addAttribute("list", list);
return "group/index";
}
@RequestMapping("/save")
@ResponseBody
public ResultT<String> save(ShiZiQiuConfGroup shiZiQiuConfGroup){
| if (null == shiZiQiuConfGroup.getGroupName() || StringUtils.isBlank(shiZiQiuConfGroup.getGroupName())) { |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuZkConfClient.java | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
//
// public static final String CONF_DATA_PATH = "/shziiqiu-conf";
//
// private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
//
// private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
//
// /**
// * zk地址
// * 例:zk地址:格式 ip1:port,ip2:port,ip3:port
// */
// public static final String ZK_ADDRESS;
//
// static {
// /**
// * loadFileProperties 根据路径加载文件
// * loadProperties 当前路径下加载文件
// */
// Properties props = System.getProperties(); //获得系统属性集
// String osName = props.getProperty("os.name"); //操作系统名称
// Properties prop = null;
// try {
// if(StringUtils.isNotBlank(osName)) {
// if((osName.substring(0, 7)).equals("Windows")) {
// prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// } else {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
// }
// } catch (Exception e) {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
//
// ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// }
//
// public static void main(String[] args) {
// System.out.println(ZK_ADDRESS);
//
// }
//
// }
| import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure; | package com.shiziqiu.configuration.core.zk;
/**
* @title : ShiZiQiuZkConfClient
* @author : crazy
* @date : 2017年9月6日 下午5:29:33
* @Fun :
*/
public class ShiZiQiuZkConfClient implements Watcher{
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuZkConfClient.class);
private static ZooKeeper zooKeeper;
/**
* 常用的lock ,tryLock ,其中有个lockInterruptibly 。
*/
private static ReentrantLock INSTANCE_INIT_LOCK = new ReentrantLock(true);
private static ZooKeeper getInstance() {
if (null == zooKeeper) {
try {
/**
* 如果 lock 不可用,则以下代码将在 2秒后超时:
*/
if (INSTANCE_INIT_LOCK.tryLock(2, TimeUnit.SECONDS)) {
try { | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
//
// public static final String CONF_DATA_PATH = "/shziiqiu-conf";
//
// private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
//
// private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
//
// /**
// * zk地址
// * 例:zk地址:格式 ip1:port,ip2:port,ip3:port
// */
// public static final String ZK_ADDRESS;
//
// static {
// /**
// * loadFileProperties 根据路径加载文件
// * loadProperties 当前路径下加载文件
// */
// Properties props = System.getProperties(); //获得系统属性集
// String osName = props.getProperty("os.name"); //操作系统名称
// Properties prop = null;
// try {
// if(StringUtils.isNotBlank(osName)) {
// if((osName.substring(0, 7)).equals("Windows")) {
// prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// } else {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
// }
// } catch (Exception e) {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
//
// ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// }
//
// public static void main(String[] args) {
// System.out.println(ZK_ADDRESS);
//
// }
//
// }
// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuZkConfClient.java
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure;
package com.shiziqiu.configuration.core.zk;
/**
* @title : ShiZiQiuZkConfClient
* @author : crazy
* @date : 2017年9月6日 下午5:29:33
* @Fun :
*/
public class ShiZiQiuZkConfClient implements Watcher{
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuZkConfClient.class);
private static ZooKeeper zooKeeper;
/**
* 常用的lock ,tryLock ,其中有个lockInterruptibly 。
*/
private static ReentrantLock INSTANCE_INIT_LOCK = new ReentrantLock(true);
private static ZooKeeper getInstance() {
if (null == zooKeeper) {
try {
/**
* 如果 lock 不可用,则以下代码将在 2秒后超时:
*/
if (INSTANCE_INIT_LOCK.tryLock(2, TimeUnit.SECONDS)) {
try { | zooKeeper = new ZooKeeper(Configure.ZK_ADDRESS, 20000, new Watcher() { |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/impl/ShiZiQiuConfGroupServiceImpl.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfGroupDao.java
// public interface ShiZiQiuConfGroupDao {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup load(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
| import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfGroupDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService; | package com.shiziqiu.configuration.console.service.impl;
/**
* @title : ShiZiQiuConfGroupServiceImpl
* @author : crazy
* @date : 2017年9月7日 上午9:43:06
* @Fun : 分组
*/
@Service("shiZiQiuConfGroupService")
public class ShiZiQiuConfGroupServiceImpl implements ShiZiQiuConfGroupService{
@Autowired | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfGroupDao.java
// public interface ShiZiQiuConfGroupDao {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup load(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/impl/ShiZiQiuConfGroupServiceImpl.java
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfGroupDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
package com.shiziqiu.configuration.console.service.impl;
/**
* @title : ShiZiQiuConfGroupServiceImpl
* @author : crazy
* @date : 2017年9月7日 上午9:43:06
* @Fun : 分组
*/
@Service("shiZiQiuConfGroupService")
public class ShiZiQiuConfGroupServiceImpl implements ShiZiQiuConfGroupService{
@Autowired | private ShiZiQiuConfGroupDao shiZiQiuConfGroupDao; |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/impl/ShiZiQiuConfGroupServiceImpl.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfGroupDao.java
// public interface ShiZiQiuConfGroupDao {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup load(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
| import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfGroupDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService; | package com.shiziqiu.configuration.console.service.impl;
/**
* @title : ShiZiQiuConfGroupServiceImpl
* @author : crazy
* @date : 2017年9月7日 上午9:43:06
* @Fun : 分组
*/
@Service("shiZiQiuConfGroupService")
public class ShiZiQiuConfGroupServiceImpl implements ShiZiQiuConfGroupService{
@Autowired
private ShiZiQiuConfGroupDao shiZiQiuConfGroupDao;
@Override | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfGroupDao.java
// public interface ShiZiQiuConfGroupDao {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup load(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/ShiZiQiuConfGroupService.java
// public interface ShiZiQiuConfGroupService {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup get(String groupName);
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/service/impl/ShiZiQiuConfGroupServiceImpl.java
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfGroupDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
import com.shiziqiu.configuration.console.service.ShiZiQiuConfGroupService;
package com.shiziqiu.configuration.console.service.impl;
/**
* @title : ShiZiQiuConfGroupServiceImpl
* @author : crazy
* @date : 2017年9月7日 上午9:43:06
* @Fun : 分组
*/
@Service("shiZiQiuConfGroupService")
public class ShiZiQiuConfGroupServiceImpl implements ShiZiQiuConfGroupService{
@Autowired
private ShiZiQiuConfGroupDao shiZiQiuConfGroupDao;
@Override | public List<ShiZiQiuConfGroup> findAll() { |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/impl/ShiZiQiuConfNodeDaoImpl.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfNodeDao.java
// public interface ShiZiQiuConfNodeDao {
//
// public List<ShiZiQiuConfNode> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public int pageListCount(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public int deleteByKey(String nodeGroup, String nodeKey);
//
// public void insert(ShiZiQiuConfNode xxlConfNode);
//
// public ShiZiQiuConfNode selectByKey(String nodeGroup, String nodeKey);
//
// public int update(ShiZiQiuConfNode xxlConfNode);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfNode.java
// public class ShiZiQiuConfNode implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 132434523L;
//
// private String nodeGroup;
// private String nodeKey;
// private String nodeValue;
// private String nodeDesc;
//
// private String groupKey;
// private String nodeValueReal;
//
// public ShiZiQiuConfNode() {
// super();
// }
//
// public ShiZiQiuConfNode(String nodeGroup, String nodeKey, String nodeValue,
// String nodeDesc, String groupKey, String nodeValueReal) {
// super();
// this.nodeGroup = nodeGroup;
// this.nodeKey = nodeKey;
// this.nodeValue = nodeValue;
// this.nodeDesc = nodeDesc;
// this.groupKey = groupKey;
// this.nodeValueReal = nodeValueReal;
// }
//
// public String getNodeGroup() {
// return nodeGroup;
// }
// public void setNodeGroup(String nodeGroup) {
// this.nodeGroup = nodeGroup;
// }
// public String getNodeKey() {
// return nodeKey;
// }
// public void setNodeKey(String nodeKey) {
// this.nodeKey = nodeKey;
// }
// public String getNodeValue() {
// return nodeValue;
// }
// public void setNodeValue(String nodeValue) {
// this.nodeValue = nodeValue;
// }
// public String getNodeDesc() {
// return nodeDesc;
// }
// public void setNodeDesc(String nodeDesc) {
// this.nodeDesc = nodeDesc;
// }
// public String getGroupKey() {
// return ShiZiQiuZkConfClient.generateGroupKey(nodeGroup, nodeKey);
// }
// public void setGroupKey(String groupKey) {
// this.groupKey = groupKey;
// }
// public String getNodeValueReal() {
// return nodeValueReal;
// }
// public void setNodeValueReal(String nodeValueReal) {
// this.nodeValueReal = nodeValueReal;
// }
//
// }
| import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfNodeDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfNode; | package com.shiziqiu.configuration.console.dao.impl;
/**
* @title : ShiZiQiuConfNodeDaoImpl
* @author : crazy
* @date : 2017年9月6日 下午7:46:24
* @Fun :
*/
@Repository
public class ShiZiQiuConfNodeDaoImpl implements ShiZiQiuConfNodeDao{
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
@Override | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfNodeDao.java
// public interface ShiZiQiuConfNodeDao {
//
// public List<ShiZiQiuConfNode> pageList(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public int pageListCount(int offset, int pagesize, String nodeGroup, String nodeKey);
//
// public int deleteByKey(String nodeGroup, String nodeKey);
//
// public void insert(ShiZiQiuConfNode xxlConfNode);
//
// public ShiZiQiuConfNode selectByKey(String nodeGroup, String nodeKey);
//
// public int update(ShiZiQiuConfNode xxlConfNode);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfNode.java
// public class ShiZiQiuConfNode implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 132434523L;
//
// private String nodeGroup;
// private String nodeKey;
// private String nodeValue;
// private String nodeDesc;
//
// private String groupKey;
// private String nodeValueReal;
//
// public ShiZiQiuConfNode() {
// super();
// }
//
// public ShiZiQiuConfNode(String nodeGroup, String nodeKey, String nodeValue,
// String nodeDesc, String groupKey, String nodeValueReal) {
// super();
// this.nodeGroup = nodeGroup;
// this.nodeKey = nodeKey;
// this.nodeValue = nodeValue;
// this.nodeDesc = nodeDesc;
// this.groupKey = groupKey;
// this.nodeValueReal = nodeValueReal;
// }
//
// public String getNodeGroup() {
// return nodeGroup;
// }
// public void setNodeGroup(String nodeGroup) {
// this.nodeGroup = nodeGroup;
// }
// public String getNodeKey() {
// return nodeKey;
// }
// public void setNodeKey(String nodeKey) {
// this.nodeKey = nodeKey;
// }
// public String getNodeValue() {
// return nodeValue;
// }
// public void setNodeValue(String nodeValue) {
// this.nodeValue = nodeValue;
// }
// public String getNodeDesc() {
// return nodeDesc;
// }
// public void setNodeDesc(String nodeDesc) {
// this.nodeDesc = nodeDesc;
// }
// public String getGroupKey() {
// return ShiZiQiuZkConfClient.generateGroupKey(nodeGroup, nodeKey);
// }
// public void setGroupKey(String groupKey) {
// this.groupKey = groupKey;
// }
// public String getNodeValueReal() {
// return nodeValueReal;
// }
// public void setNodeValueReal(String nodeValueReal) {
// this.nodeValueReal = nodeValueReal;
// }
//
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/impl/ShiZiQiuConfNodeDaoImpl.java
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfNodeDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfNode;
package com.shiziqiu.configuration.console.dao.impl;
/**
* @title : ShiZiQiuConfNodeDaoImpl
* @author : crazy
* @date : 2017年9月6日 下午7:46:24
* @Fun :
*/
@Repository
public class ShiZiQiuConfNodeDaoImpl implements ShiZiQiuConfNodeDao{
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
@Override | public List<ShiZiQiuConfNode> pageList(int offset, int pagesize, String nodeGroup, String nodeKey) { |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-example/src/test/java/com/shiziqiu/example/TestShiZiQiuConfClient.java | // Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
//
// private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// private static Cache cache;
//
// static {
// CacheManager manager = CacheManager.create();
// cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// manager.addCache(cache);
// }
//
// public static void set(String key, String value) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
//
// public static void update(String key, String value) {
// if (cache != null) {
// if (cache.get(key)!=null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
// }
//
// public static String get(String key, String defaultVal) {
// if (localProp!=null && localProp.containsKey(key)) {
// return localProp.getProperty(key);
// }
// if (cache != null) {
// Element element = cache.get(key);
// if (element != null) {
// return (String) element.getObjectValue();
// }
// }
// String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// if (zkData!=null) {
// set(key, zkData);
// return zkData;
// }
//
// return defaultVal;
// }
//
// public static boolean remove(String key) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置:key ", key);
// return cache.remove(key);
// }
// return false;
// }
//
// public static void main(String[] args) {
// String key = "key";
// String value = "hello";
// set(key, value);
// System.out.println(get(key, "-1"));
// }
//
//
// }
| import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient; | package com.shiziqiu.example;
/**
* ²âÊÔ°¸Àý
* @title : TestShiZiQiuConfClient
* @author : crazy
* @date : 2017Äê9ÔÂ7ÈÕ ÏÂÎç2:21:41
* @Fun :
* ÔÚ×Ô¼ºµÄxml×îÉÏÃæÌí¼ÓÏÂÃæÅäÖÃ
* <bean id="shiziqiuConfPropertyPlaceholderConfigurer" class="com.shiziqiu.configuration.core.spring.ShiZiQiuConfPlaceholderConfigurer" />
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationcontext-shiziqiu-conf.xml")
public class TestShiZiQiuConfClient {
@Test
public void TestShiZiQiuConfClientGet(){
/**
* ´ÓÅäÖÃÎļþÀï»ñÈ¡ÅäÖõÄÊý¾Ý
*/ | // Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
// public class ShiZiQiuConfClient {
//
// private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
// public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
// private static Cache cache;
//
// static {
// CacheManager manager = CacheManager.create();
// cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800);
// manager.addCache(cache);
// }
//
// public static void set(String key, String value) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 初始化配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
//
// public static void update(String key, String value) {
// if (cache != null) {
// if (cache.get(key)!=null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 更新配置: [{}:{}]", new Object[]{key, value});
// cache.put(new Element(key, value));
// }
// }
// }
//
// public static String get(String key, String defaultVal) {
// if (localProp!=null && localProp.containsKey(key)) {
// return localProp.getProperty(key);
// }
// if (cache != null) {
// Element element = cache.get(key);
// if (element != null) {
// return (String) element.getObjectValue();
// }
// }
// String zkData = ShiZiQiuZkConfClient.getPathDataByKey(key);
// if (zkData!=null) {
// set(key, zkData);
// return zkData;
// }
//
// return defaultVal;
// }
//
// public static boolean remove(String key) {
// if (cache != null) {
// logger.info(">>>>>>>>>> shiziqiu-conf: 删除配置:key ", key);
// return cache.remove(key);
// }
// return false;
// }
//
// public static void main(String[] args) {
// String key = "key";
// String value = "hello";
// set(key, value);
// System.out.println(get(key, "-1"));
// }
//
//
// }
// Path: shiziqiu-configuration-example/src/test/java/com/shiziqiu/example/TestShiZiQiuConfClient.java
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.shiziqiu.configuration.core.zk.ShiZiQiuConfClient;
package com.shiziqiu.example;
/**
* ²âÊÔ°¸Àý
* @title : TestShiZiQiuConfClient
* @author : crazy
* @date : 2017Äê9ÔÂ7ÈÕ ÏÂÎç2:21:41
* @Fun :
* ÔÚ×Ô¼ºµÄxml×îÉÏÃæÌí¼ÓÏÂÃæÅäÖÃ
* <bean id="shiziqiuConfPropertyPlaceholderConfigurer" class="com.shiziqiu.configuration.core.spring.ShiZiQiuConfPlaceholderConfigurer" />
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationcontext-shiziqiu-conf.xml")
public class TestShiZiQiuConfClient {
@Test
public void TestShiZiQiuConfClientGet(){
/**
* ´ÓÅäÖÃÎļþÀï»ñÈ¡ÅäÖõÄÊý¾Ý
*/ | String redis = ShiZiQiuConfClient.get("redis.port", null); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/impl/ShiZiQiuConfGroupDaoImpl.java | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfGroupDao.java
// public interface ShiZiQiuConfGroupDao {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup load(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
| import java.util.List;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfGroupDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup; | package com.shiziqiu.configuration.console.dao.impl;
/**
* @title : ShiZiQiuConfGroupDaoImpl
* @author : crazy
* @date : 2017年9月6日 下午7:57:58
* @Fun :
*/
@Repository
public class ShiZiQiuConfGroupDaoImpl implements ShiZiQiuConfGroupDao {
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
@Override | // Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/ShiZiQiuConfGroupDao.java
// public interface ShiZiQiuConfGroupDao {
//
// public List<ShiZiQiuConfGroup> findAll();
//
// public int save(ShiZiQiuConfGroup group);
//
// public int update(ShiZiQiuConfGroup group);
//
// public int remove(String groupName);
//
// public ShiZiQiuConfGroup load(String groupName);
// }
//
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/model/ShiZiQiuConfGroup.java
// public class ShiZiQiuConfGroup implements Serializable{
//
// /**
// *
// */
// private static final long serialVersionUID = 112412412412412L;
//
// private String groupName;
// private String groupTitle;
//
// public ShiZiQiuConfGroup() {
// super();
// }
//
// public ShiZiQiuConfGroup(String groupName, String groupTitle) {
// super();
// this.groupName = groupName;
// this.groupTitle = groupTitle;
// }
//
// public String getGroupName() {
// return groupName;
// }
// public void setGroupName(String groupName) {
// this.groupName = groupName;
// }
// public String getGroupTitle() {
// return groupTitle;
// }
// public void setGroupTitle(String groupTitle) {
// this.groupTitle = groupTitle;
// }
//
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/dao/impl/ShiZiQiuConfGroupDaoImpl.java
import java.util.List;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.shiziqiu.configuration.console.dao.ShiZiQiuConfGroupDao;
import com.shiziqiu.configuration.console.model.ShiZiQiuConfGroup;
package com.shiziqiu.configuration.console.dao.impl;
/**
* @title : ShiZiQiuConfGroupDaoImpl
* @author : crazy
* @date : 2017年9月6日 下午7:57:58
* @Fun :
*/
@Repository
public class ShiZiQiuConfGroupDaoImpl implements ShiZiQiuConfGroupDao {
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
@Override | public List<ShiZiQiuConfGroup> findAll() { |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
//
// public static final String CONF_DATA_PATH = "/shziiqiu-conf";
//
// private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
//
// private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
//
// /**
// * zk地址
// * 例:zk地址:格式 ip1:port,ip2:port,ip3:port
// */
// public static final String ZK_ADDRESS;
//
// static {
// /**
// * loadFileProperties 根据路径加载文件
// * loadProperties 当前路径下加载文件
// */
// Properties props = System.getProperties(); //获得系统属性集
// String osName = props.getProperty("os.name"); //操作系统名称
// Properties prop = null;
// try {
// if(StringUtils.isNotBlank(osName)) {
// if((osName.substring(0, 7)).equals("Windows")) {
// prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// } else {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
// }
// } catch (Exception e) {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
//
// ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// }
//
// public static void main(String[] args) {
// System.out.println(ZK_ADDRESS);
//
// }
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/PropertiesUtil.java
// public class PropertiesUtil {
//
// private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
//
// /**
// * 根据文件名加载文件
// * @param fileName
// * @return
// *
// */
// public static Properties loadProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = loder.getResource(fileName); // 方式1:配置更新不需要重启JVM
// if(null != url) {
// in = new FileInputStream(url.getPath());
// if(null != in) {
// prop.load(in);
// }
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (null != in) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
// /**
// * @param fileName
// * @return
// */
// public static Properties loadFileProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = url = new File(fileName).toURI().toURL();
// in = new FileInputStream(url.getPath());
// if (in != null) {
// prop.load(in);
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (in != null) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
//
// /**
// * @param key
// * @return
// */
// public static String getString(Properties prop, String key) {
// return prop.getProperty(key);
// }
//
// /**
// * @param key
// * @return
// */
// public static int getInt(Properties prop, String key) {
// return Integer.parseInt(getString(prop, key));
// }
//
// /**
// * @param prop
// * @param key
// * @return
// */
// public static boolean getBoolean(Properties prop, String key) {
// return Boolean.valueOf(getString(prop, key));
// }
//
// public static void main(String[] args) {
// Properties prop = loadProperties("shiziqiu-conf.properties");
// System.out.println(prop);
// logger.info("==========");
// }
//
// }
| import java.util.Properties;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure;
import com.shiziqiu.configuration.util.PropertiesUtil; | package com.shiziqiu.configuration.core.zk;
/**
* @title : ShiZiQiuConfClient
* @author : crazy
* @date : 2017年9月6日 下午5:23:16
* @Fun :
*/
public class ShiZiQiuConfClient {
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class); | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
//
// public static final String CONF_DATA_PATH = "/shziiqiu-conf";
//
// private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
//
// private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
//
// /**
// * zk地址
// * 例:zk地址:格式 ip1:port,ip2:port,ip3:port
// */
// public static final String ZK_ADDRESS;
//
// static {
// /**
// * loadFileProperties 根据路径加载文件
// * loadProperties 当前路径下加载文件
// */
// Properties props = System.getProperties(); //获得系统属性集
// String osName = props.getProperty("os.name"); //操作系统名称
// Properties prop = null;
// try {
// if(StringUtils.isNotBlank(osName)) {
// if((osName.substring(0, 7)).equals("Windows")) {
// prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// } else {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
// }
// } catch (Exception e) {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
//
// ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// }
//
// public static void main(String[] args) {
// System.out.println(ZK_ADDRESS);
//
// }
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/PropertiesUtil.java
// public class PropertiesUtil {
//
// private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
//
// /**
// * 根据文件名加载文件
// * @param fileName
// * @return
// *
// */
// public static Properties loadProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = loder.getResource(fileName); // 方式1:配置更新不需要重启JVM
// if(null != url) {
// in = new FileInputStream(url.getPath());
// if(null != in) {
// prop.load(in);
// }
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (null != in) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
// /**
// * @param fileName
// * @return
// */
// public static Properties loadFileProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = url = new File(fileName).toURI().toURL();
// in = new FileInputStream(url.getPath());
// if (in != null) {
// prop.load(in);
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (in != null) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
//
// /**
// * @param key
// * @return
// */
// public static String getString(Properties prop, String key) {
// return prop.getProperty(key);
// }
//
// /**
// * @param key
// * @return
// */
// public static int getInt(Properties prop, String key) {
// return Integer.parseInt(getString(prop, key));
// }
//
// /**
// * @param prop
// * @param key
// * @return
// */
// public static boolean getBoolean(Properties prop, String key) {
// return Boolean.valueOf(getString(prop, key));
// }
//
// public static void main(String[] args) {
// Properties prop = loadProperties("shiziqiu-conf.properties");
// System.out.println(prop);
// logger.info("==========");
// }
//
// }
// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
import java.util.Properties;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure;
import com.shiziqiu.configuration.util.PropertiesUtil;
package com.shiziqiu.configuration.core.zk;
/**
* @title : ShiZiQiuConfClient
* @author : crazy
* @date : 2017年9月6日 下午5:23:16
* @Fun :
*/
public class ShiZiQiuConfClient {
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class); | public static Properties localProp = PropertiesUtil.loadProperties("local.properties"); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
//
// public static final String CONF_DATA_PATH = "/shziiqiu-conf";
//
// private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
//
// private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
//
// /**
// * zk地址
// * 例:zk地址:格式 ip1:port,ip2:port,ip3:port
// */
// public static final String ZK_ADDRESS;
//
// static {
// /**
// * loadFileProperties 根据路径加载文件
// * loadProperties 当前路径下加载文件
// */
// Properties props = System.getProperties(); //获得系统属性集
// String osName = props.getProperty("os.name"); //操作系统名称
// Properties prop = null;
// try {
// if(StringUtils.isNotBlank(osName)) {
// if((osName.substring(0, 7)).equals("Windows")) {
// prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// } else {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
// }
// } catch (Exception e) {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
//
// ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// }
//
// public static void main(String[] args) {
// System.out.println(ZK_ADDRESS);
//
// }
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/PropertiesUtil.java
// public class PropertiesUtil {
//
// private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
//
// /**
// * 根据文件名加载文件
// * @param fileName
// * @return
// *
// */
// public static Properties loadProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = loder.getResource(fileName); // 方式1:配置更新不需要重启JVM
// if(null != url) {
// in = new FileInputStream(url.getPath());
// if(null != in) {
// prop.load(in);
// }
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (null != in) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
// /**
// * @param fileName
// * @return
// */
// public static Properties loadFileProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = url = new File(fileName).toURI().toURL();
// in = new FileInputStream(url.getPath());
// if (in != null) {
// prop.load(in);
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (in != null) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
//
// /**
// * @param key
// * @return
// */
// public static String getString(Properties prop, String key) {
// return prop.getProperty(key);
// }
//
// /**
// * @param key
// * @return
// */
// public static int getInt(Properties prop, String key) {
// return Integer.parseInt(getString(prop, key));
// }
//
// /**
// * @param prop
// * @param key
// * @return
// */
// public static boolean getBoolean(Properties prop, String key) {
// return Boolean.valueOf(getString(prop, key));
// }
//
// public static void main(String[] args) {
// Properties prop = loadProperties("shiziqiu-conf.properties");
// System.out.println(prop);
// logger.info("==========");
// }
//
// }
| import java.util.Properties;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure;
import com.shiziqiu.configuration.util.PropertiesUtil; | package com.shiziqiu.configuration.core.zk;
/**
* @title : ShiZiQiuConfClient
* @author : crazy
* @date : 2017年9月6日 下午5:23:16
* @Fun :
*/
public class ShiZiQiuConfClient {
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
private static Cache cache;
static {
CacheManager manager = CacheManager.create(); | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Configure.java
// public class Configure {
//
// public static final String CONF_DATA_PATH = "/shziiqiu-conf";
//
// private static final String ZK_LINUX_ADDRESS_FILE = "/home/appConfig/shiziqiu-conf.properties";
//
// private static final String ZK_WINDOWS_ADDRESS_FILE = "c:/shiziqiu-conf.properties";
//
// /**
// * zk地址
// * 例:zk地址:格式 ip1:port,ip2:port,ip3:port
// */
// public static final String ZK_ADDRESS;
//
// static {
// /**
// * loadFileProperties 根据路径加载文件
// * loadProperties 当前路径下加载文件
// */
// Properties props = System.getProperties(); //获得系统属性集
// String osName = props.getProperty("os.name"); //操作系统名称
// Properties prop = null;
// try {
// if(StringUtils.isNotBlank(osName)) {
// if((osName.substring(0, 7)).equals("Windows")) {
// prop = PropertiesUtil.loadFileProperties(ZK_WINDOWS_ADDRESS_FILE);
// } else {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
// }
// } catch (Exception e) {
// prop = PropertiesUtil.loadFileProperties(ZK_LINUX_ADDRESS_FILE);
// }
//
// ZK_ADDRESS = PropertiesUtil.getString(prop, "zkserver");
// }
//
// public static void main(String[] args) {
// System.out.println(ZK_ADDRESS);
//
// }
//
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/PropertiesUtil.java
// public class PropertiesUtil {
//
// private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
//
// /**
// * 根据文件名加载文件
// * @param fileName
// * @return
// *
// */
// public static Properties loadProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = loder.getResource(fileName); // 方式1:配置更新不需要重启JVM
// if(null != url) {
// in = new FileInputStream(url.getPath());
// if(null != in) {
// prop.load(in);
// }
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (null != in) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
// /**
// * @param fileName
// * @return
// */
// public static Properties loadFileProperties(String fileName) {
// Properties prop = new Properties();
// InputStream in = null;
// try {
// ClassLoader loder = Thread.currentThread().getContextClassLoader();
// URL url = url = new File(fileName).toURI().toURL();
// in = new FileInputStream(url.getPath());
// if (in != null) {
// prop.load(in);
// }
// } catch (Exception e) {
// logger.error("load {} error!", fileName);
// } finally {
// if (in != null) {
// try {
// in.close();
// } catch (IOException e) {
// logger.error("close {} error!", fileName);
// }
// }
// }
// return prop;
// }
//
//
// /**
// * @param key
// * @return
// */
// public static String getString(Properties prop, String key) {
// return prop.getProperty(key);
// }
//
// /**
// * @param key
// * @return
// */
// public static int getInt(Properties prop, String key) {
// return Integer.parseInt(getString(prop, key));
// }
//
// /**
// * @param prop
// * @param key
// * @return
// */
// public static boolean getBoolean(Properties prop, String key) {
// return Boolean.valueOf(getString(prop, key));
// }
//
// public static void main(String[] args) {
// Properties prop = loadProperties("shiziqiu-conf.properties");
// System.out.println(prop);
// logger.info("==========");
// }
//
// }
// Path: shiziqiu-configuration-core/src/main/java/com/shiziqiu/configuration/core/zk/ShiZiQiuConfClient.java
import java.util.Properties;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.shiziqiu.configuration.util.Configure;
import com.shiziqiu.configuration.util.PropertiesUtil;
package com.shiziqiu.configuration.core.zk;
/**
* @title : ShiZiQiuConfClient
* @author : crazy
* @date : 2017年9月6日 下午5:23:16
* @Fun :
*/
public class ShiZiQiuConfClient {
private static Logger logger = LoggerFactory.getLogger(ShiZiQiuConfClient.class);
public static Properties localProp = PropertiesUtil.loadProperties("local.properties");
private static Cache cache;
static {
CacheManager manager = CacheManager.create(); | cache = new Cache(Configure.CONF_DATA_PATH, 10000, false, true, 1800, 1800); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/interceptor/PermissionInterceptor.java | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/CookieUtil.java
// public class CookieUtil {
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param ifRemember
// * true = age设置-1,不缓存;否则 age设置俩小时;
// */
// public static void set(HttpServletResponse response, String key,
// String value, boolean ifRemember) {
//
// int age = Constant.COOKIE_MAX_AGE;
// if (ifRemember) {
// age = Constant.COOKIE_MAX_AGE;
// } else {
// age = -1;
// }
//
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(age); // Cookie过期时间,单位/秒
// cookie.setPath(Constant.COOKIE_PATH); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param maxAge
// */
// @SuppressWarnings("unused")
// private static void set(HttpServletResponse response, String key, String value, int maxAge, String path) {
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(maxAge); // Cookie过期时间,单位/秒
// cookie.setPath(path); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 查询value
// *
// * @param request
// * @param key
// * @return
// */
// public static String getValue(HttpServletRequest request, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// return cookie.getValue();
// }
// return null;
// }
//
// /**
// * 查询Cookie
// *
// * @param request
// * @param key
// */
// private static Cookie get(HttpServletRequest request, String key) {
// Cookie[] arr_cookie = request.getCookies();
// if (arr_cookie != null && arr_cookie.length > 0) {
// for (Cookie cookie : arr_cookie) {
// if (cookie.getName().equals(key)) {
// return cookie;
// }
// }
// }
// return null;
// }
//
// /**
// * 删除Cookie
// *
// * @param request
// * @param response
// * @param key
// */
// public static void remove(HttpServletRequest request, HttpServletResponse response, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// set(response, key, "", 0, Constant.COOKIE_PATH);
// }
// }
// }
| import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.shiziqiu.configuration.console.web.annotation.Permession;
import com.shiziqiu.configuration.util.Constant;
import com.shiziqiu.configuration.util.CookieUtil; | package com.shiziqiu.configuration.console.web.interceptor;
/**
* @title : PermissionInterceptor
* @author : crazy
* @date : 2017年9月6日 下午8:32:07
* @Fun :
*/
public class PermissionInterceptor extends HandlerInterceptorAdapter{
public static boolean login(HttpServletResponse response, boolean ifRemember){ | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/CookieUtil.java
// public class CookieUtil {
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param ifRemember
// * true = age设置-1,不缓存;否则 age设置俩小时;
// */
// public static void set(HttpServletResponse response, String key,
// String value, boolean ifRemember) {
//
// int age = Constant.COOKIE_MAX_AGE;
// if (ifRemember) {
// age = Constant.COOKIE_MAX_AGE;
// } else {
// age = -1;
// }
//
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(age); // Cookie过期时间,单位/秒
// cookie.setPath(Constant.COOKIE_PATH); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param maxAge
// */
// @SuppressWarnings("unused")
// private static void set(HttpServletResponse response, String key, String value, int maxAge, String path) {
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(maxAge); // Cookie过期时间,单位/秒
// cookie.setPath(path); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 查询value
// *
// * @param request
// * @param key
// * @return
// */
// public static String getValue(HttpServletRequest request, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// return cookie.getValue();
// }
// return null;
// }
//
// /**
// * 查询Cookie
// *
// * @param request
// * @param key
// */
// private static Cookie get(HttpServletRequest request, String key) {
// Cookie[] arr_cookie = request.getCookies();
// if (arr_cookie != null && arr_cookie.length > 0) {
// for (Cookie cookie : arr_cookie) {
// if (cookie.getName().equals(key)) {
// return cookie;
// }
// }
// }
// return null;
// }
//
// /**
// * 删除Cookie
// *
// * @param request
// * @param response
// * @param key
// */
// public static void remove(HttpServletRequest request, HttpServletResponse response, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// set(response, key, "", 0, Constant.COOKIE_PATH);
// }
// }
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/interceptor/PermissionInterceptor.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.shiziqiu.configuration.console.web.annotation.Permession;
import com.shiziqiu.configuration.util.Constant;
import com.shiziqiu.configuration.util.CookieUtil;
package com.shiziqiu.configuration.console.web.interceptor;
/**
* @title : PermissionInterceptor
* @author : crazy
* @date : 2017年9月6日 下午8:32:07
* @Fun :
*/
public class PermissionInterceptor extends HandlerInterceptorAdapter{
public static boolean login(HttpServletResponse response, boolean ifRemember){ | CookieUtil.set(response, Constant.LOGIN_PERM_KEY, Constant.LOGIN_PERM_VAL, ifRemember); |
shiziqiu/shiziqiu-configuration | shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/interceptor/PermissionInterceptor.java | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/CookieUtil.java
// public class CookieUtil {
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param ifRemember
// * true = age设置-1,不缓存;否则 age设置俩小时;
// */
// public static void set(HttpServletResponse response, String key,
// String value, boolean ifRemember) {
//
// int age = Constant.COOKIE_MAX_AGE;
// if (ifRemember) {
// age = Constant.COOKIE_MAX_AGE;
// } else {
// age = -1;
// }
//
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(age); // Cookie过期时间,单位/秒
// cookie.setPath(Constant.COOKIE_PATH); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param maxAge
// */
// @SuppressWarnings("unused")
// private static void set(HttpServletResponse response, String key, String value, int maxAge, String path) {
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(maxAge); // Cookie过期时间,单位/秒
// cookie.setPath(path); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 查询value
// *
// * @param request
// * @param key
// * @return
// */
// public static String getValue(HttpServletRequest request, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// return cookie.getValue();
// }
// return null;
// }
//
// /**
// * 查询Cookie
// *
// * @param request
// * @param key
// */
// private static Cookie get(HttpServletRequest request, String key) {
// Cookie[] arr_cookie = request.getCookies();
// if (arr_cookie != null && arr_cookie.length > 0) {
// for (Cookie cookie : arr_cookie) {
// if (cookie.getName().equals(key)) {
// return cookie;
// }
// }
// }
// return null;
// }
//
// /**
// * 删除Cookie
// *
// * @param request
// * @param response
// * @param key
// */
// public static void remove(HttpServletRequest request, HttpServletResponse response, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// set(response, key, "", 0, Constant.COOKIE_PATH);
// }
// }
// }
| import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.shiziqiu.configuration.console.web.annotation.Permession;
import com.shiziqiu.configuration.util.Constant;
import com.shiziqiu.configuration.util.CookieUtil; | package com.shiziqiu.configuration.console.web.interceptor;
/**
* @title : PermissionInterceptor
* @author : crazy
* @date : 2017年9月6日 下午8:32:07
* @Fun :
*/
public class PermissionInterceptor extends HandlerInterceptorAdapter{
public static boolean login(HttpServletResponse response, boolean ifRemember){ | // Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/Constant.java
// public class Constant {
//
// public static final String PLACEHOLDER_PREFIX = "${";
// public static final String PLACEHOLDER_SUFFIX = "}";
// public static final String LOGIN_PERM_KEY = "LOGIN_PERM";
// public static final String LOGIN_PERM_VAL = "1234567890";
//
// // 默认缓存时间,单位/秒, 2H
// public static final int COOKIE_MAX_AGE = 60 * 60 * 2;
//
// // 保存路径,根路径
// public static final String COOKIE_PATH = "/";
// }
//
// Path: shiziqiu-configuration-util/src/main/java/com/shiziqiu/configuration/util/CookieUtil.java
// public class CookieUtil {
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param ifRemember
// * true = age设置-1,不缓存;否则 age设置俩小时;
// */
// public static void set(HttpServletResponse response, String key,
// String value, boolean ifRemember) {
//
// int age = Constant.COOKIE_MAX_AGE;
// if (ifRemember) {
// age = Constant.COOKIE_MAX_AGE;
// } else {
// age = -1;
// }
//
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(age); // Cookie过期时间,单位/秒
// cookie.setPath(Constant.COOKIE_PATH); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 保存
// *
// * @param response
// * @param key
// * @param value
// * @param maxAge
// */
// @SuppressWarnings("unused")
// private static void set(HttpServletResponse response, String key, String value, int maxAge, String path) {
// Cookie cookie = new Cookie(key, value);
// cookie.setMaxAge(maxAge); // Cookie过期时间,单位/秒
// cookie.setPath(path); // Cookie适用的路径
// response.addCookie(cookie);
// }
//
// /**
// * 查询value
// *
// * @param request
// * @param key
// * @return
// */
// public static String getValue(HttpServletRequest request, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// return cookie.getValue();
// }
// return null;
// }
//
// /**
// * 查询Cookie
// *
// * @param request
// * @param key
// */
// private static Cookie get(HttpServletRequest request, String key) {
// Cookie[] arr_cookie = request.getCookies();
// if (arr_cookie != null && arr_cookie.length > 0) {
// for (Cookie cookie : arr_cookie) {
// if (cookie.getName().equals(key)) {
// return cookie;
// }
// }
// }
// return null;
// }
//
// /**
// * 删除Cookie
// *
// * @param request
// * @param response
// * @param key
// */
// public static void remove(HttpServletRequest request, HttpServletResponse response, String key) {
// Cookie cookie = get(request, key);
// if (cookie != null) {
// set(response, key, "", 0, Constant.COOKIE_PATH);
// }
// }
// }
// Path: shiziqiu-configuration-console/src/main/java/com/shiziqiu/configuration/console/web/interceptor/PermissionInterceptor.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.shiziqiu.configuration.console.web.annotation.Permession;
import com.shiziqiu.configuration.util.Constant;
import com.shiziqiu.configuration.util.CookieUtil;
package com.shiziqiu.configuration.console.web.interceptor;
/**
* @title : PermissionInterceptor
* @author : crazy
* @date : 2017年9月6日 下午8:32:07
* @Fun :
*/
public class PermissionInterceptor extends HandlerInterceptorAdapter{
public static boolean login(HttpServletResponse response, boolean ifRemember){ | CookieUtil.set(response, Constant.LOGIN_PERM_KEY, Constant.LOGIN_PERM_VAL, ifRemember); |
marioluan/java-data-structures | src/main/java/io/github/marioluan/datastructures/queue/Deque.java | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/Node.java
// public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {
//
// /**
// * The value of the node.
// */
// public T data;
//
// /**
// * A link to the next node.
// */
// public Node<T> next;
//
// /**
// * A link to the previous node.
// */
// public Node<T> prev;
//
// /**
// * Construct a new node with the given data.
// *
// * @param data
// */
// public Node(T data) {
// this.data = data;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public int compareTo(Node<T> that) {
// return this.data.compareTo(that.data);
// }
//
// /**
// * Checks whether there is a link to next node.
// *
// * @return whether the next field is not null
// */
// public boolean hasNext() {
// return this.next != null;
// }
//
// /**
// * Checks whether there is a link to previous node.
// *
// * @return whether the prev field is not null
// */
// public boolean hasPrev() {
// return this.prev != null;
// }
//
// }
| import java.util.Iterator;
import java.util.NoSuchElementException;
import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import io.github.marioluan.datastructures.Node; | * <strong>Time complexity:</strong> O(1)<br>
*
* @return returns the last data
*/
public T removeLast() {
if (this.isEmpty())
throw new NoSuchElementException();
Node<T> oldTail = this.tail;
this.tail = this.tail.prev;
if (this.tail != null)
this.tail.next = null;
this.size--;
// when the dequeue becomes empty, head == tail
if (this.isEmpty())
this.head = null;
return oldTail.data;
}
/**
* Return the iterator over items in order from front to end.
*
* @return returns a new instance
*/
@Override
public Iterator<T> iterator() { | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/Node.java
// public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {
//
// /**
// * The value of the node.
// */
// public T data;
//
// /**
// * A link to the next node.
// */
// public Node<T> next;
//
// /**
// * A link to the previous node.
// */
// public Node<T> prev;
//
// /**
// * Construct a new node with the given data.
// *
// * @param data
// */
// public Node(T data) {
// this.data = data;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public int compareTo(Node<T> that) {
// return this.data.compareTo(that.data);
// }
//
// /**
// * Checks whether there is a link to next node.
// *
// * @return whether the next field is not null
// */
// public boolean hasNext() {
// return this.next != null;
// }
//
// /**
// * Checks whether there is a link to previous node.
// *
// * @return whether the prev field is not null
// */
// public boolean hasPrev() {
// return this.prev != null;
// }
//
// }
// Path: src/main/java/io/github/marioluan/datastructures/queue/Deque.java
import java.util.Iterator;
import java.util.NoSuchElementException;
import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import io.github.marioluan.datastructures.Node;
* <strong>Time complexity:</strong> O(1)<br>
*
* @return returns the last data
*/
public T removeLast() {
if (this.isEmpty())
throw new NoSuchElementException();
Node<T> oldTail = this.tail;
this.tail = this.tail.prev;
if (this.tail != null)
this.tail.next = null;
this.size--;
// when the dequeue becomes empty, head == tail
if (this.isEmpty())
this.head = null;
return oldTail.data;
}
/**
* Return the iterator over items in order from front to end.
*
* @return returns a new instance
*/
@Override
public Iterator<T> iterator() { | return new LinkedListIterator<T>(this.head); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/graph/search/BreadthFirstSearchTest.java | // Path: src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java
// public final class DigraphGraphFactory {
// private DigraphGraphFactory() {
// }
//
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Digraph build() {
// Digraph graph = new Digraph(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 5);
//
// graph.addEdge(2, 0);
// graph.addEdge(2, 3);
//
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
//
// graph.addEdge(4, 2);
// graph.addEdge(4, 3);
//
// graph.addEdge(5, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 9);
// graph.addEdge(6, 4);
// graph.addEdge(6, 8);
//
// graph.addEdge(7, 6);
// graph.addEdge(7, 9);
//
// graph.addEdge(8, 6);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
//
// graph.addEdge(10, 12);
//
// graph.addEdge(11, 12);
// graph.addEdge(11, 4);
//
// graph.addEdge(12, 9);
//
// return graph;
// }
// }
//
// Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
| import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.DigraphGraphFactory;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*; | package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class BreadthFirstSearchTest { | // Path: src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java
// public final class DigraphGraphFactory {
// private DigraphGraphFactory() {
// }
//
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Digraph build() {
// Digraph graph = new Digraph(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 5);
//
// graph.addEdge(2, 0);
// graph.addEdge(2, 3);
//
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
//
// graph.addEdge(4, 2);
// graph.addEdge(4, 3);
//
// graph.addEdge(5, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 9);
// graph.addEdge(6, 4);
// graph.addEdge(6, 8);
//
// graph.addEdge(7, 6);
// graph.addEdge(7, 9);
//
// graph.addEdge(8, 6);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
//
// graph.addEdge(10, 12);
//
// graph.addEdge(11, 12);
// graph.addEdge(11, 4);
//
// graph.addEdge(12, 9);
//
// return graph;
// }
// }
//
// Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
// Path: src/test/java/io/github/marioluan/datastructures/graph/search/BreadthFirstSearchTest.java
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.DigraphGraphFactory;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*;
package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class BreadthFirstSearchTest { | private Graph graph; |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/graph/search/BreadthFirstSearchTest.java | // Path: src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java
// public final class DigraphGraphFactory {
// private DigraphGraphFactory() {
// }
//
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Digraph build() {
// Digraph graph = new Digraph(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 5);
//
// graph.addEdge(2, 0);
// graph.addEdge(2, 3);
//
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
//
// graph.addEdge(4, 2);
// graph.addEdge(4, 3);
//
// graph.addEdge(5, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 9);
// graph.addEdge(6, 4);
// graph.addEdge(6, 8);
//
// graph.addEdge(7, 6);
// graph.addEdge(7, 9);
//
// graph.addEdge(8, 6);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
//
// graph.addEdge(10, 12);
//
// graph.addEdge(11, 12);
// graph.addEdge(11, 4);
//
// graph.addEdge(12, 9);
//
// return graph;
// }
// }
//
// Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
| import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.DigraphGraphFactory;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*; | package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class BreadthFirstSearchTest {
private Graph graph;
private BreadthFirstSearch subject;
{
describe("BreadthFirstSearch", () -> {
beforeEach(() -> { | // Path: src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java
// public final class DigraphGraphFactory {
// private DigraphGraphFactory() {
// }
//
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Digraph build() {
// Digraph graph = new Digraph(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 5);
//
// graph.addEdge(2, 0);
// graph.addEdge(2, 3);
//
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
//
// graph.addEdge(4, 2);
// graph.addEdge(4, 3);
//
// graph.addEdge(5, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 9);
// graph.addEdge(6, 4);
// graph.addEdge(6, 8);
//
// graph.addEdge(7, 6);
// graph.addEdge(7, 9);
//
// graph.addEdge(8, 6);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
//
// graph.addEdge(10, 12);
//
// graph.addEdge(11, 12);
// graph.addEdge(11, 4);
//
// graph.addEdge(12, 9);
//
// return graph;
// }
// }
//
// Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
// Path: src/test/java/io/github/marioluan/datastructures/graph/search/BreadthFirstSearchTest.java
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.DigraphGraphFactory;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*;
package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class BreadthFirstSearchTest {
private Graph graph;
private BreadthFirstSearch subject;
{
describe("BreadthFirstSearch", () -> {
beforeEach(() -> { | graph = new Undirected(6); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/graph/sort/TopologicalSortTest.java | // Path: src/test/java/io/github/marioluan/datastructures/factory/DirectedAcyclicGraphFactory.java
// public final class DirectedAcyclicGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Graph build() {
// Graph graph = new Digraph(7);
//
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 1);
//
// graph.addEdge(1, 4);
//
// graph.addEdge(5, 2);
//
// graph.addEdge(3, 6);
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
// graph.addEdge(3, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 4);
//
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
| import com.greghaskins.spectrum.Spectrum;
import static com.greghaskins.spectrum.Spectrum.*;
import io.github.marioluan.datastructures.factory.DirectedAcyclicGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import org.junit.Assert;
import org.junit.runner.RunWith; | package io.github.marioluan.datastructures.graph.sort;
@RunWith(Spectrum.class)
public class TopologicalSortTest { | // Path: src/test/java/io/github/marioluan/datastructures/factory/DirectedAcyclicGraphFactory.java
// public final class DirectedAcyclicGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Graph build() {
// Graph graph = new Digraph(7);
//
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 1);
//
// graph.addEdge(1, 4);
//
// graph.addEdge(5, 2);
//
// graph.addEdge(3, 6);
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
// graph.addEdge(3, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 4);
//
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
// Path: src/test/java/io/github/marioluan/datastructures/graph/sort/TopologicalSortTest.java
import com.greghaskins.spectrum.Spectrum;
import static com.greghaskins.spectrum.Spectrum.*;
import io.github.marioluan.datastructures.factory.DirectedAcyclicGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import org.junit.Assert;
import org.junit.runner.RunWith;
package io.github.marioluan.datastructures.graph.sort;
@RunWith(Spectrum.class)
public class TopologicalSortTest { | private Graph graph; |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/graph/sort/TopologicalSortTest.java | // Path: src/test/java/io/github/marioluan/datastructures/factory/DirectedAcyclicGraphFactory.java
// public final class DirectedAcyclicGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Graph build() {
// Graph graph = new Digraph(7);
//
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 1);
//
// graph.addEdge(1, 4);
//
// graph.addEdge(5, 2);
//
// graph.addEdge(3, 6);
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
// graph.addEdge(3, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 4);
//
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
| import com.greghaskins.spectrum.Spectrum;
import static com.greghaskins.spectrum.Spectrum.*;
import io.github.marioluan.datastructures.factory.DirectedAcyclicGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import org.junit.Assert;
import org.junit.runner.RunWith; | package io.github.marioluan.datastructures.graph.sort;
@RunWith(Spectrum.class)
public class TopologicalSortTest {
private Graph graph;
private TopologicalSort subject;
{
describe("TopologicalSort", () -> {
beforeEach(() -> { | // Path: src/test/java/io/github/marioluan/datastructures/factory/DirectedAcyclicGraphFactory.java
// public final class DirectedAcyclicGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Graph build() {
// Graph graph = new Digraph(7);
//
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 1);
//
// graph.addEdge(1, 4);
//
// graph.addEdge(5, 2);
//
// graph.addEdge(3, 6);
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
// graph.addEdge(3, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 4);
//
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
// Path: src/test/java/io/github/marioluan/datastructures/graph/sort/TopologicalSortTest.java
import com.greghaskins.spectrum.Spectrum;
import static com.greghaskins.spectrum.Spectrum.*;
import io.github.marioluan.datastructures.factory.DirectedAcyclicGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import org.junit.Assert;
import org.junit.runner.RunWith;
package io.github.marioluan.datastructures.graph.sort;
@RunWith(Spectrum.class)
public class TopologicalSortTest {
private Graph graph;
private TopologicalSort subject;
{
describe("TopologicalSort", () -> {
beforeEach(() -> { | graph = DirectedAcyclicGraphFactory.build(); |
marioluan/java-data-structures | src/main/java/io/github/marioluan/datastructures/priority/queue/MaxBinaryHeap.java | // Path: src/main/java/io/github/marioluan/datastructures/Util.java
// public final class Util {
//
// private Util() {
// }
//
// /**
// * Check whether {@link Comparable a} is lesser than {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean less(Comparable a, Comparable b) {
// return a.compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link a} is lesser than {@link b}.
// *
// * @param <T>
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings("unchecked")
// public static <T> boolean less(T a, T b) {
// return ((Comparable<T>) a).compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link Comparable a} is lesser or equal to
// * {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser or equal to b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean lessOrEqual(Comparable a, Comparable b) {
// return a.compareTo(b) < 1;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param a
// * @param i
// * @param j
// */
// @SuppressWarnings("rawtypes")
// public static void swap(Comparable[] a, int i, int j) {
// Comparable copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param <T>
// * @param a
// * @param i
// * @param j
// */
// public static <T> void swap(T[] a, int i, int j) {
// T copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Find and return the index from the minimum item from array a within
// * lowerBound and upperBound.
// *
// * @param a
// * @param lowerBound
// * @param upperBound
// * @return returns the index from the element with the minimum value
// */
// @SuppressWarnings("rawtypes")
// public static int findMin(Comparable[] a, int lowerBound, int upperBound) {
// int min = lowerBound;
// for (int i = lowerBound + 1; i < upperBound; i++)
// if (less(a[i], a[min]))
// min = i;
//
// return min;
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// @SuppressWarnings("rawtypes")
// public static void copy(Comparable[] a, Comparable[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param <T>
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// public static <T> void copy(T[] a, T[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
// }
| import java.util.Iterator;
import java.util.NoSuchElementException;
import io.github.marioluan.datastructures.Util; | package io.github.marioluan.datastructures.priority.queue;
/**
* Complete binary tree implementation using a max-heap data structure.<br>
* TODO: implement resizable functionality.
*
* @author marioluan
* @param <Key>
* the class type of the key being handled
*/
public class MaxBinaryHeap<Key> implements Iterable<Key> {
private static final int LARGEST_KEY_INDEX = 1;
private int n;
private Key[] keys;
/**
* Construct an empty priority queue.
*
* @param capacity
*/
@SuppressWarnings("unchecked")
public MaxBinaryHeap(int capacity) {
this.keys = (Key[]) new Object[capacity + 1];
this.n = 0;
}
/**
* Is the heap empty?
*
* @return returns whether it is empty or not
*/
public boolean isEmpty() {
return this.n == 0;
}
/**
* Returns the size of the heap.
*
* @return the size
*/
public int size() {
return this.n;
}
/**
* Returns (but does not remove) the largest key from the heap.
*
* @return the largest key
*/
public Key max() {
return this.keys[LARGEST_KEY_INDEX];
}
/**
* Add the key to the heap by performing an up-heap operation.<br>
* <strong>Time complexity:</strong> O(log n)
*
* @param key
*/
public void insert(Key key) {
if (key == null)
throw new NullPointerException();
this.keys[++this.n] = key;
this.swim(this.n);
}
/**
* Remove and return the max key from the heap by performing a down-heap
* operation.<br>
* <strong>Time complexity:</strong> O(log n)
*
* @return the largest key
*/
public Key delMax() {
if (this.isEmpty())
throw new NoSuchElementException();
Key max = this.keys[LARGEST_KEY_INDEX]; | // Path: src/main/java/io/github/marioluan/datastructures/Util.java
// public final class Util {
//
// private Util() {
// }
//
// /**
// * Check whether {@link Comparable a} is lesser than {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean less(Comparable a, Comparable b) {
// return a.compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link a} is lesser than {@link b}.
// *
// * @param <T>
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings("unchecked")
// public static <T> boolean less(T a, T b) {
// return ((Comparable<T>) a).compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link Comparable a} is lesser or equal to
// * {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser or equal to b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean lessOrEqual(Comparable a, Comparable b) {
// return a.compareTo(b) < 1;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param a
// * @param i
// * @param j
// */
// @SuppressWarnings("rawtypes")
// public static void swap(Comparable[] a, int i, int j) {
// Comparable copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param <T>
// * @param a
// * @param i
// * @param j
// */
// public static <T> void swap(T[] a, int i, int j) {
// T copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Find and return the index from the minimum item from array a within
// * lowerBound and upperBound.
// *
// * @param a
// * @param lowerBound
// * @param upperBound
// * @return returns the index from the element with the minimum value
// */
// @SuppressWarnings("rawtypes")
// public static int findMin(Comparable[] a, int lowerBound, int upperBound) {
// int min = lowerBound;
// for (int i = lowerBound + 1; i < upperBound; i++)
// if (less(a[i], a[min]))
// min = i;
//
// return min;
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// @SuppressWarnings("rawtypes")
// public static void copy(Comparable[] a, Comparable[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param <T>
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// public static <T> void copy(T[] a, T[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
// }
// Path: src/main/java/io/github/marioluan/datastructures/priority/queue/MaxBinaryHeap.java
import java.util.Iterator;
import java.util.NoSuchElementException;
import io.github.marioluan.datastructures.Util;
package io.github.marioluan.datastructures.priority.queue;
/**
* Complete binary tree implementation using a max-heap data structure.<br>
* TODO: implement resizable functionality.
*
* @author marioluan
* @param <Key>
* the class type of the key being handled
*/
public class MaxBinaryHeap<Key> implements Iterable<Key> {
private static final int LARGEST_KEY_INDEX = 1;
private int n;
private Key[] keys;
/**
* Construct an empty priority queue.
*
* @param capacity
*/
@SuppressWarnings("unchecked")
public MaxBinaryHeap(int capacity) {
this.keys = (Key[]) new Object[capacity + 1];
this.n = 0;
}
/**
* Is the heap empty?
*
* @return returns whether it is empty or not
*/
public boolean isEmpty() {
return this.n == 0;
}
/**
* Returns the size of the heap.
*
* @return the size
*/
public int size() {
return this.n;
}
/**
* Returns (but does not remove) the largest key from the heap.
*
* @return the largest key
*/
public Key max() {
return this.keys[LARGEST_KEY_INDEX];
}
/**
* Add the key to the heap by performing an up-heap operation.<br>
* <strong>Time complexity:</strong> O(log n)
*
* @param key
*/
public void insert(Key key) {
if (key == null)
throw new NullPointerException();
this.keys[++this.n] = key;
this.swim(this.n);
}
/**
* Remove and return the max key from the heap by performing a down-heap
* operation.<br>
* <strong>Time complexity:</strong> O(log n)
*
* @return the largest key
*/
public Key delMax() {
if (this.isEmpty())
throw new NoSuchElementException();
Key max = this.keys[LARGEST_KEY_INDEX]; | Util.swap(this.keys, LARGEST_KEY_INDEX, this.n--); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/queue/RandomizedQueueTest.java | // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
| import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.Assert;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable; | package io.github.marioluan.datastructures.queue;
@SuppressWarnings({ "unchecked", "rawtypes" })
@RunWith(Spectrum.class)
public class RandomizedQueueTest {
| // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
// Path: src/test/java/io/github/marioluan/datastructures/queue/RandomizedQueueTest.java
import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.Assert;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable;
package io.github.marioluan.datastructures.queue;
@SuppressWarnings({ "unchecked", "rawtypes" })
@RunWith(Spectrum.class)
public class RandomizedQueueTest {
| private Resizable<Integer[]> rs; |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/queue/RandomizedQueueTest.java | // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
| import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.Assert;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable; | package io.github.marioluan.datastructures.queue;
@SuppressWarnings({ "unchecked", "rawtypes" })
@RunWith(Spectrum.class)
public class RandomizedQueueTest {
private Resizable<Integer[]> rs;
private RandomizedQueue<Integer> subject;
{
describe("RandomizedQueue", () -> {
beforeEach(() -> { | // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
// Path: src/test/java/io/github/marioluan/datastructures/queue/RandomizedQueueTest.java
import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.Assert;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable;
package io.github.marioluan.datastructures.queue;
@SuppressWarnings({ "unchecked", "rawtypes" })
@RunWith(Spectrum.class)
public class RandomizedQueueTest {
private Resizable<Integer[]> rs;
private RandomizedQueue<Integer> subject;
{
describe("RandomizedQueue", () -> {
beforeEach(() -> { | this.rs = mock(ArrayResizable.class); |
marioluan/java-data-structures | src/main/java/io/github/marioluan/datastructures/multiset/Bag.java | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/Node.java
// public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {
//
// /**
// * The value of the node.
// */
// public T data;
//
// /**
// * A link to the next node.
// */
// public Node<T> next;
//
// /**
// * A link to the previous node.
// */
// public Node<T> prev;
//
// /**
// * Construct a new node with the given data.
// *
// * @param data
// */
// public Node(T data) {
// this.data = data;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public int compareTo(Node<T> that) {
// return this.data.compareTo(that.data);
// }
//
// /**
// * Checks whether there is a link to next node.
// *
// * @return whether the next field is not null
// */
// public boolean hasNext() {
// return this.next != null;
// }
//
// /**
// * Checks whether there is a link to previous node.
// *
// * @return whether the prev field is not null
// */
// public boolean hasPrev() {
// return this.prev != null;
// }
//
// }
| import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import io.github.marioluan.datastructures.Node;
import java.util.Iterator; | package io.github.marioluan.datastructures.multiset;
/**
* Implementation of a multiset using a LinkedList.
*
* @param <T> class type of the items contained in the bag
*/
public class Bag<T extends Comparable<T>> implements Iterable<T> {
private static final String CANNOT_BE_NULL_MSG = "item cannot be null"; | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/Node.java
// public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {
//
// /**
// * The value of the node.
// */
// public T data;
//
// /**
// * A link to the next node.
// */
// public Node<T> next;
//
// /**
// * A link to the previous node.
// */
// public Node<T> prev;
//
// /**
// * Construct a new node with the given data.
// *
// * @param data
// */
// public Node(T data) {
// this.data = data;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public int compareTo(Node<T> that) {
// return this.data.compareTo(that.data);
// }
//
// /**
// * Checks whether there is a link to next node.
// *
// * @return whether the next field is not null
// */
// public boolean hasNext() {
// return this.next != null;
// }
//
// /**
// * Checks whether there is a link to previous node.
// *
// * @return whether the prev field is not null
// */
// public boolean hasPrev() {
// return this.prev != null;
// }
//
// }
// Path: src/main/java/io/github/marioluan/datastructures/multiset/Bag.java
import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import io.github.marioluan.datastructures.Node;
import java.util.Iterator;
package io.github.marioluan.datastructures.multiset;
/**
* Implementation of a multiset using a LinkedList.
*
* @param <T> class type of the items contained in the bag
*/
public class Bag<T extends Comparable<T>> implements Iterable<T> {
private static final String CANNOT_BE_NULL_MSG = "item cannot be null"; | private Node<T> head; |
marioluan/java-data-structures | src/main/java/io/github/marioluan/datastructures/multiset/Bag.java | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/Node.java
// public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {
//
// /**
// * The value of the node.
// */
// public T data;
//
// /**
// * A link to the next node.
// */
// public Node<T> next;
//
// /**
// * A link to the previous node.
// */
// public Node<T> prev;
//
// /**
// * Construct a new node with the given data.
// *
// * @param data
// */
// public Node(T data) {
// this.data = data;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public int compareTo(Node<T> that) {
// return this.data.compareTo(that.data);
// }
//
// /**
// * Checks whether there is a link to next node.
// *
// * @return whether the next field is not null
// */
// public boolean hasNext() {
// return this.next != null;
// }
//
// /**
// * Checks whether there is a link to previous node.
// *
// * @return whether the prev field is not null
// */
// public boolean hasPrev() {
// return this.prev != null;
// }
//
// }
| import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import io.github.marioluan.datastructures.Node;
import java.util.Iterator; | package io.github.marioluan.datastructures.multiset;
/**
* Implementation of a multiset using a LinkedList.
*
* @param <T> class type of the items contained in the bag
*/
public class Bag<T extends Comparable<T>> implements Iterable<T> {
private static final String CANNOT_BE_NULL_MSG = "item cannot be null";
private Node<T> head;
private int size;
/**
* Adds the item to the bag.
*
* @param item to be added
* @throws IllegalArgumentException when item is null
*/
public void add(T item) throws IllegalArgumentException {
if (item == null)
throw new IllegalArgumentException(CANNOT_BE_NULL_MSG);
Node<T> node = new Node<>(item);
Node<T> next = head;
head = node;
head.next = next;
if (next != null)
next.prev = head;
size++;
}
/**
* Returns whether the bag is empty or not.
*
* @return whether the bag is empty or not
*/
public boolean isEmpty() {
return size == 0;
}
/**
* Returns the number of items in the bag.
*
* @return number of items in the bag
*/
public int size() {
return size;
}
@Override
public Iterator<T> iterator() { | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/Node.java
// public class Node<T extends Comparable<T>> implements Comparable<Node<T>> {
//
// /**
// * The value of the node.
// */
// public T data;
//
// /**
// * A link to the next node.
// */
// public Node<T> next;
//
// /**
// * A link to the previous node.
// */
// public Node<T> prev;
//
// /**
// * Construct a new node with the given data.
// *
// * @param data
// */
// public Node(T data) {
// this.data = data;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public int compareTo(Node<T> that) {
// return this.data.compareTo(that.data);
// }
//
// /**
// * Checks whether there is a link to next node.
// *
// * @return whether the next field is not null
// */
// public boolean hasNext() {
// return this.next != null;
// }
//
// /**
// * Checks whether there is a link to previous node.
// *
// * @return whether the prev field is not null
// */
// public boolean hasPrev() {
// return this.prev != null;
// }
//
// }
// Path: src/main/java/io/github/marioluan/datastructures/multiset/Bag.java
import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import io.github.marioluan.datastructures.Node;
import java.util.Iterator;
package io.github.marioluan.datastructures.multiset;
/**
* Implementation of a multiset using a LinkedList.
*
* @param <T> class type of the items contained in the bag
*/
public class Bag<T extends Comparable<T>> implements Iterable<T> {
private static final String CANNOT_BE_NULL_MSG = "item cannot be null";
private Node<T> head;
private int size;
/**
* Adds the item to the bag.
*
* @param item to be added
* @throws IllegalArgumentException when item is null
*/
public void add(T item) throws IllegalArgumentException {
if (item == null)
throw new IllegalArgumentException(CANNOT_BE_NULL_MSG);
Node<T> node = new Node<>(item);
Node<T> next = head;
head = node;
head.next = next;
if (next != null)
next.prev = head;
size++;
}
/**
* Returns whether the bag is empty or not.
*
* @return whether the bag is empty or not
*/
public boolean isEmpty() {
return size == 0;
}
/**
* Returns the number of items in the bag.
*
* @return number of items in the bag
*/
public int size() {
return size;
}
@Override
public Iterator<T> iterator() { | return new LinkedListIterator(head); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/factory/DirectedAcyclicGraphFactory.java | // Path: src/main/java/io/github/marioluan/datastructures/graph/Digraph.java
// public class Digraph implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Digraph(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// E++;
// }
//
// // time complexity: outdegree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// Digraph reversed = new Digraph(V);
//
// for (int i = 0; i < V; i++)
// for (int s : adj(i))
// reversed.addEdge(s, i);
//
// return reversed;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
| import io.github.marioluan.datastructures.graph.Digraph;
import io.github.marioluan.datastructures.graph.Graph; | package io.github.marioluan.datastructures.factory;
public final class DirectedAcyclicGraphFactory {
/**
* Builds a graph with the same vertices and edges from lecture slides. <br>
* <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
*/
public static Graph build() { | // Path: src/main/java/io/github/marioluan/datastructures/graph/Digraph.java
// public class Digraph implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Digraph(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// E++;
// }
//
// // time complexity: outdegree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// Digraph reversed = new Digraph(V);
//
// for (int i = 0; i < V; i++)
// for (int s : adj(i))
// reversed.addEdge(s, i);
//
// return reversed;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
// Path: src/test/java/io/github/marioluan/datastructures/factory/DirectedAcyclicGraphFactory.java
import io.github.marioluan.datastructures.graph.Digraph;
import io.github.marioluan.datastructures.graph.Graph;
package io.github.marioluan.datastructures.factory;
public final class DirectedAcyclicGraphFactory {
/**
* Builds a graph with the same vertices and edges from lecture slides. <br>
* <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
*/
public static Graph build() { | Graph graph = new Digraph(7); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/multiset/BagTest.java | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
| import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.*;
import java.util.Random;
import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import org.hamcrest.CoreMatchers;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum; | subject.add(item);
});
it("returns false", () -> {
assertFalse(subject.isEmpty());
});
});
});
describe("#size", () -> {
describe("when it is empty", () -> {
it("returns zero", () -> {
assertEquals(0, subject.size());
});
});
describe("when it is not empty", () -> {
beforeEach(() -> {
item = new Random().nextInt();
subject.add(item);
});
it("returns greater than zero", () -> {
assertTrue(subject.size() > 0);
});
});
});
describe("#iterator", () -> {
it("returns an instance of LinkedListIterator", () -> { | // Path: src/main/java/io/github/marioluan/datastructures/priority/queue/LinkedListIterator.java
// public class LinkedListIterator<T extends Comparable<T>>
// implements Iterator<T> {
// private Node<T> cursor;
//
// /**
// * Constructs the iterator by pointing its cursor to the head.
// */
// public LinkedListIterator(Node<T> head) {
// this.cursor = head;
// }
//
// /**
// * {@inheritDoc}
// */
// public boolean hasNext() {
// return this.cursor != null;
// }
//
// /**
// * Operation not permitted.
// *
// * @throws UnsupportedOperationException
// */
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// /**
// * {@inheritDoc}
// */
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T oldItem = this.cursor.data;
// this.cursor = this.cursor.next;
//
// return oldItem;
// }
// }
// Path: src/test/java/io/github/marioluan/datastructures/multiset/BagTest.java
import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.*;
import java.util.Random;
import io.github.marioluan.datastructures.priority.queue.LinkedListIterator;
import org.hamcrest.CoreMatchers;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
subject.add(item);
});
it("returns false", () -> {
assertFalse(subject.isEmpty());
});
});
});
describe("#size", () -> {
describe("when it is empty", () -> {
it("returns zero", () -> {
assertEquals(0, subject.size());
});
});
describe("when it is not empty", () -> {
beforeEach(() -> {
item = new Random().nextInt();
subject.add(item);
});
it("returns greater than zero", () -> {
assertTrue(subject.size() > 0);
});
});
});
describe("#iterator", () -> {
it("returns an instance of LinkedListIterator", () -> { | assertThat(subject.iterator(), CoreMatchers.instanceOf(LinkedListIterator.class)); |
marioluan/java-data-structures | src/main/java/io/github/marioluan/datastructures/graph/sort/TopologicalSort.java | // Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/stack/LinkedList.java
// public class LinkedList<T> implements Stack<T> {
//
// private final class Node {
// private T data;
// private Node next;
//
// private Node(T data, Node next) {
// this.data = data;
// this.next = next;
// }
// }
//
// private Node head;
// private int n;
//
// /**
// * Constructs an empty stack.
// */
// public LinkedList() {
// this.head = null;
// this.n = 0;
// }
//
// @Override
// public boolean isEmpty() {
// return n == 0;
// }
//
// @Override
// public int size() {
// return n;
// }
//
// @Override
// public void push(T item) throws IllegalArgumentException {
// if (item == null)
// throw new IllegalArgumentException("item must not be null");
//
// head = new Node(item, head);
// n++;
// }
//
// @Override
// public T pop() throws NoSuchElementException {
// if (isEmpty())
// throw new NoSuchElementException();
//
// T data = head.data;
// head = head.next;
// n--;
//
// return data;
// }
//
// @Override
// public T peek() throws NoSuchElementException {
// if (isEmpty())
// throw new NoSuchElementException();
//
// return head.data;
// }
//
// @Override
// public Iterator<T> iterator() {
// return new LinkedListIterator(head);
// }
//
// private final class LinkedListIterator implements Iterator<T> {
//
// private Node cursor;
//
// LinkedListIterator(Node cursor) {
// this.cursor = cursor;
// }
//
// @Override
// public boolean hasNext() {
// return cursor != null;
// }
//
// @Override
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// @Override
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T data = cursor.data;
// cursor = cursor.next;
//
// return data;
// }
//
// }
// }
| import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.stack.LinkedList; | package io.github.marioluan.datastructures.graph.sort;
/**
* Implementation of Topological Sort algorithm using {@link io.github.marioluan.datastructures.graph.search.DepthFirstSearch}. <br>
* Constraint: graph MUST be a DAG (Directed Acyclic Graph).
* Category: topoligical sort in a DAG.
*/
public class TopologicalSort {
private Graph graph; | // Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/stack/LinkedList.java
// public class LinkedList<T> implements Stack<T> {
//
// private final class Node {
// private T data;
// private Node next;
//
// private Node(T data, Node next) {
// this.data = data;
// this.next = next;
// }
// }
//
// private Node head;
// private int n;
//
// /**
// * Constructs an empty stack.
// */
// public LinkedList() {
// this.head = null;
// this.n = 0;
// }
//
// @Override
// public boolean isEmpty() {
// return n == 0;
// }
//
// @Override
// public int size() {
// return n;
// }
//
// @Override
// public void push(T item) throws IllegalArgumentException {
// if (item == null)
// throw new IllegalArgumentException("item must not be null");
//
// head = new Node(item, head);
// n++;
// }
//
// @Override
// public T pop() throws NoSuchElementException {
// if (isEmpty())
// throw new NoSuchElementException();
//
// T data = head.data;
// head = head.next;
// n--;
//
// return data;
// }
//
// @Override
// public T peek() throws NoSuchElementException {
// if (isEmpty())
// throw new NoSuchElementException();
//
// return head.data;
// }
//
// @Override
// public Iterator<T> iterator() {
// return new LinkedListIterator(head);
// }
//
// private final class LinkedListIterator implements Iterator<T> {
//
// private Node cursor;
//
// LinkedListIterator(Node cursor) {
// this.cursor = cursor;
// }
//
// @Override
// public boolean hasNext() {
// return cursor != null;
// }
//
// @Override
// public void remove() {
// throw new UnsupportedOperationException();
// }
//
// @Override
// public T next() {
// if (!hasNext())
// throw new NoSuchElementException();
//
// T data = cursor.data;
// cursor = cursor.next;
//
// return data;
// }
//
// }
// }
// Path: src/main/java/io/github/marioluan/datastructures/graph/sort/TopologicalSort.java
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.stack.LinkedList;
package io.github.marioluan.datastructures.graph.sort;
/**
* Implementation of Topological Sort algorithm using {@link io.github.marioluan.datastructures.graph.search.DepthFirstSearch}. <br>
* Constraint: graph MUST be a DAG (Directed Acyclic Graph).
* Category: topoligical sort in a DAG.
*/
public class TopologicalSort {
private Graph graph; | private LinkedList<Integer> reversePost; |
marioluan/java-data-structures | src/main/java/io/github/marioluan/datastructures/graph/Digraph.java | // Path: src/main/java/io/github/marioluan/datastructures/multiset/Bag.java
// public class Bag<T extends Comparable<T>> implements Iterable<T> {
// private static final String CANNOT_BE_NULL_MSG = "item cannot be null";
// private Node<T> head;
// private int size;
//
// /**
// * Adds the item to the bag.
// *
// * @param item to be added
// * @throws IllegalArgumentException when item is null
// */
// public void add(T item) throws IllegalArgumentException {
// if (item == null)
// throw new IllegalArgumentException(CANNOT_BE_NULL_MSG);
//
// Node<T> node = new Node<>(item);
// Node<T> next = head;
// head = node;
// head.next = next;
//
// if (next != null)
// next.prev = head;
//
// size++;
// }
//
// /**
// * Returns whether the bag is empty or not.
// *
// * @return whether the bag is empty or not
// */
// public boolean isEmpty() {
// return size == 0;
// }
//
// /**
// * Returns the number of items in the bag.
// *
// * @return number of items in the bag
// */
// public int size() {
// return size;
// }
//
// @Override
// public Iterator<T> iterator() {
// return new LinkedListIterator(head);
// }
// }
| import io.github.marioluan.datastructures.multiset.Bag;
import java.util.stream.IntStream; | package io.github.marioluan.datastructures.graph;
/**
* Undirected {@link Graph} implementation using an adjacency-list.<br>
* Maintain vertex-indexed array of lists.<br>
* <b>Space complexity: E + V</b>
*/
public class Digraph implements Graph {
private final int V;
private int E; | // Path: src/main/java/io/github/marioluan/datastructures/multiset/Bag.java
// public class Bag<T extends Comparable<T>> implements Iterable<T> {
// private static final String CANNOT_BE_NULL_MSG = "item cannot be null";
// private Node<T> head;
// private int size;
//
// /**
// * Adds the item to the bag.
// *
// * @param item to be added
// * @throws IllegalArgumentException when item is null
// */
// public void add(T item) throws IllegalArgumentException {
// if (item == null)
// throw new IllegalArgumentException(CANNOT_BE_NULL_MSG);
//
// Node<T> node = new Node<>(item);
// Node<T> next = head;
// head = node;
// head.next = next;
//
// if (next != null)
// next.prev = head;
//
// size++;
// }
//
// /**
// * Returns whether the bag is empty or not.
// *
// * @return whether the bag is empty or not
// */
// public boolean isEmpty() {
// return size == 0;
// }
//
// /**
// * Returns the number of items in the bag.
// *
// * @return number of items in the bag
// */
// public int size() {
// return size;
// }
//
// @Override
// public Iterator<T> iterator() {
// return new LinkedListIterator(head);
// }
// }
// Path: src/main/java/io/github/marioluan/datastructures/graph/Digraph.java
import io.github.marioluan.datastructures.multiset.Bag;
import java.util.stream.IntStream;
package io.github.marioluan.datastructures.graph;
/**
* Undirected {@link Graph} implementation using an adjacency-list.<br>
* Maintain vertex-indexed array of lists.<br>
* <b>Space complexity: E + V</b>
*/
public class Digraph implements Graph {
private final int V;
private int E; | private Bag<Integer>[] adj; |
marioluan/java-data-structures | src/main/java/io/github/marioluan/datastructures/symboltable/ArraySymbolTable.java | // Path: src/main/java/io/github/marioluan/datastructures/Util.java
// public final class Util {
//
// private Util() {
// }
//
// /**
// * Check whether {@link Comparable a} is lesser than {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean less(Comparable a, Comparable b) {
// return a.compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link a} is lesser than {@link b}.
// *
// * @param <T>
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings("unchecked")
// public static <T> boolean less(T a, T b) {
// return ((Comparable<T>) a).compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link Comparable a} is lesser or equal to
// * {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser or equal to b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean lessOrEqual(Comparable a, Comparable b) {
// return a.compareTo(b) < 1;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param a
// * @param i
// * @param j
// */
// @SuppressWarnings("rawtypes")
// public static void swap(Comparable[] a, int i, int j) {
// Comparable copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param <T>
// * @param a
// * @param i
// * @param j
// */
// public static <T> void swap(T[] a, int i, int j) {
// T copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Find and return the index from the minimum item from array a within
// * lowerBound and upperBound.
// *
// * @param a
// * @param lowerBound
// * @param upperBound
// * @return returns the index from the element with the minimum value
// */
// @SuppressWarnings("rawtypes")
// public static int findMin(Comparable[] a, int lowerBound, int upperBound) {
// int min = lowerBound;
// for (int i = lowerBound + 1; i < upperBound; i++)
// if (less(a[i], a[min]))
// min = i;
//
// return min;
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// @SuppressWarnings("rawtypes")
// public static void copy(Comparable[] a, Comparable[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param <T>
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// public static <T> void copy(T[] a, T[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
// }
| import edu.princeton.cs.algs4.Stack;
import io.github.marioluan.datastructures.Util; |
@Override
public boolean isEmpty() {
return n == 0;
}
@Override
public int size() {
return n;
}
// Time complexity: O(n)
@Override
public Iterable<Key> keys() {
Stack<Key> stack = new Stack<>();
for (int i = n - 1; i > -1; i--)
stack.push(keys[i]);
return stack;
}
/**
* Shifts all keys greater than the key at the last position of the table.
*
* @param i
* starting index
*/
private void shift(int lo, int hi) {
while (keys[lo].compareTo(keys[hi]) > 0) { | // Path: src/main/java/io/github/marioluan/datastructures/Util.java
// public final class Util {
//
// private Util() {
// }
//
// /**
// * Check whether {@link Comparable a} is lesser than {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean less(Comparable a, Comparable b) {
// return a.compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link a} is lesser than {@link b}.
// *
// * @param <T>
// * @param a
// * @param b
// * @return returns whether a is lesser than b
// */
// @SuppressWarnings("unchecked")
// public static <T> boolean less(T a, T b) {
// return ((Comparable<T>) a).compareTo(b) < 0;
// }
//
// /**
// * Check whether {@link Comparable a} is lesser or equal to
// * {@link Comparable b}.
// *
// * @param a
// * @param b
// * @return returns whether a is lesser or equal to b
// */
// @SuppressWarnings({ "rawtypes", "unchecked" })
// public static boolean lessOrEqual(Comparable a, Comparable b) {
// return a.compareTo(b) < 1;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param a
// * @param i
// * @param j
// */
// @SuppressWarnings("rawtypes")
// public static void swap(Comparable[] a, int i, int j) {
// Comparable copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Swap item in position i by item in position j from array {@link a}.
// *
// * @param <T>
// * @param a
// * @param i
// * @param j
// */
// public static <T> void swap(T[] a, int i, int j) {
// T copy = a[i];
// a[i] = a[j];
// a[j] = copy;
// }
//
// /**
// * Find and return the index from the minimum item from array a within
// * lowerBound and upperBound.
// *
// * @param a
// * @param lowerBound
// * @param upperBound
// * @return returns the index from the element with the minimum value
// */
// @SuppressWarnings("rawtypes")
// public static int findMin(Comparable[] a, int lowerBound, int upperBound) {
// int min = lowerBound;
// for (int i = lowerBound + 1; i < upperBound; i++)
// if (less(a[i], a[min]))
// min = i;
//
// return min;
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// @SuppressWarnings("rawtypes")
// public static void copy(Comparable[] a, Comparable[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
//
// /**
// * Make a copy of items from array a within lo and hi bounds into array aux.
// *
// * @param <T>
// * @param a
// * @param aux
// * @param lo
// * @param hi
// */
// public static <T> void copy(T[] a, T[] aux, int lo, int hi) {
// for (int i = lo; i <= hi; i++)
// aux[i] = a[i];
// }
// }
// Path: src/main/java/io/github/marioluan/datastructures/symboltable/ArraySymbolTable.java
import edu.princeton.cs.algs4.Stack;
import io.github.marioluan.datastructures.Util;
@Override
public boolean isEmpty() {
return n == 0;
}
@Override
public int size() {
return n;
}
// Time complexity: O(n)
@Override
public Iterable<Key> keys() {
Stack<Key> stack = new Stack<>();
for (int i = n - 1; i > -1; i--)
stack.push(keys[i]);
return stack;
}
/**
* Shifts all keys greater than the key at the last position of the table.
*
* @param i
* starting index
*/
private void shift(int lo, int hi) {
while (keys[lo].compareTo(keys[hi]) > 0) { | Util.swap(keys, lo, hi); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/graph/search/ConnectedComponentsTest.java | // Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
| import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*; | package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class ConnectedComponentsTest { | // Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
// Path: src/test/java/io/github/marioluan/datastructures/graph/search/ConnectedComponentsTest.java
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*;
package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class ConnectedComponentsTest { | private Undirected graph; |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/graph/search/ConnectedComponentsTest.java | // Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
| import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*; | package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class ConnectedComponentsTest {
private Undirected graph;
private ConnectedComponents subject;
{
describe("ConnectedComponents", () -> {
beforeEach(() -> { | // Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Undirected.java
// public class Undirected implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Undirected(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// adj[w].add(v);
// E++;
// }
//
// // time complexity: degree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// return this;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
// Path: src/test/java/io/github/marioluan/datastructures/graph/search/ConnectedComponentsTest.java
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import io.github.marioluan.datastructures.graph.Graph;
import io.github.marioluan.datastructures.graph.Undirected;
import org.junit.Assert;
import org.junit.runner.RunWith;
import static com.greghaskins.spectrum.Spectrum.*;
package io.github.marioluan.datastructures.graph.search;
@RunWith(Spectrum.class)
public class ConnectedComponentsTest {
private Undirected graph;
private ConnectedComponents subject;
{
describe("ConnectedComponents", () -> {
beforeEach(() -> { | graph = UndirectedGraphFactory.build(); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/stack/DynamicArrayTest.java | // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
| import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable; | package io.github.marioluan.datastructures.stack;
@SuppressWarnings("unchecked")
@RunWith(Spectrum.class)
public class DynamicArrayTest {
| // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
// Path: src/test/java/io/github/marioluan/datastructures/stack/DynamicArrayTest.java
import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable;
package io.github.marioluan.datastructures.stack;
@SuppressWarnings("unchecked")
@RunWith(Spectrum.class)
public class DynamicArrayTest {
| private Resizable<Integer[]> rs; |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/stack/DynamicArrayTest.java | // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
| import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable; | package io.github.marioluan.datastructures.stack;
@SuppressWarnings("unchecked")
@RunWith(Spectrum.class)
public class DynamicArrayTest {
private Resizable<Integer[]> rs;
private Stack<Integer> subject;
{
describe("DynamicArray", () -> {
beforeEach(() -> { | // Path: src/main/java/io/github/marioluan/datastructures/wrappers/ArrayResizable.java
// public class ArrayResizable<T> implements Resizable<T[]> {
//
// /**
// * {@inheritDoc}
// */
// @SuppressWarnings("unchecked")
// public T[] resize(T[] a, int n, int capacity) {
// assert capacity >= n;
//
// T[] temp = (T[]) new Object[capacity];
// for (int i = 0; i < n; i++)
// temp[i] = a[i];
//
// return temp;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
// Path: src/test/java/io/github/marioluan/datastructures/stack/DynamicArrayTest.java
import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.ArrayResizable;
import io.github.marioluan.datastructures.wrappers.Resizable;
package io.github.marioluan.datastructures.stack;
@SuppressWarnings("unchecked")
@RunWith(Spectrum.class)
public class DynamicArrayTest {
private Resizable<Integer[]> rs;
private Stack<Integer> subject;
{
describe("DynamicArray", () -> {
beforeEach(() -> { | this.rs = mock(ArrayResizable.class); |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java | // Path: src/main/java/io/github/marioluan/datastructures/graph/Digraph.java
// public class Digraph implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Digraph(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// E++;
// }
//
// // time complexity: outdegree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// Digraph reversed = new Digraph(V);
//
// for (int i = 0; i < V; i++)
// for (int s : adj(i))
// reversed.addEdge(s, i);
//
// return reversed;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
| import io.github.marioluan.datastructures.graph.Digraph;
import io.github.marioluan.datastructures.graph.Graph; | package io.github.marioluan.datastructures.factory;
public final class DigraphGraphFactory {
private DigraphGraphFactory() {
}
/**
* Builds a graph with the same vertices and edges from lecture slides. <br>
* <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
*/ | // Path: src/main/java/io/github/marioluan/datastructures/graph/Digraph.java
// public class Digraph implements Graph {
// private final int V;
// private int E;
// private Bag<Integer>[] adj;
//
// /**
// * Creates an empty {@link Digraph}.<br>
// * time complexity: O(V)
// *
// * @param V number of vertices
// */
// public Digraph(int V) {
// this.V = V;
// adj = (Bag<Integer>[]) new Bag[V];
// IntStream.range(0, V).forEach(v -> adj[v] = new Bag<>());
// E = 0;
// }
//
// // time complexity: O(1)
// @Override
// public void addEdge(int v, int w) {
// adj[v].add(w);
// E++;
// }
//
// // time complexity: outdegree(v)
// @Override
// public Iterable<Integer> adj(int v) {
// return adj[v];
// }
//
// // time complexity: O(1)
// @Override
// public int V() {
// return V;
// }
//
// // time complexity: O(1)
// @Override
// public int E() {
// return E;
// }
//
// @Override
// public Graph reverse() {
// Digraph reversed = new Digraph(V);
//
// for (int i = 0; i < V; i++)
// for (int s : adj(i))
// reversed.addEdge(s, i);
//
// return reversed;
// }
//
// // TODO: implement me!
// @Override
// public String toString() {
// return null;
// }
// }
//
// Path: src/main/java/io/github/marioluan/datastructures/graph/Graph.java
// public interface Graph {
//
// /**
// * Adds an edge v-w.
// *
// * @param v vertex v
// * @param w vertex w
// */
// void addEdge(int v, int w);
//
// /**
// * Returns the vertices adjacent to v.
// *
// * @param v vertex v
// * @return vertices adjacent to v
// */
// Iterable<Integer> adj(int v);
//
// /**
// * Returns the number of vertices.
// *
// * @return number of vertices
// */
// int V();
//
// /**
// * Returns the number of edges.
// *
// * @return number of edges
// */
// int E();
//
// /**
// * Returns its reverse order.
// *
// * @return its reverse order
// */
// Graph reverse();
//
// /**
// * Returns its string representation.
// *
// * @return string representation
// */
// String toString();
// }
// Path: src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java
import io.github.marioluan.datastructures.graph.Digraph;
import io.github.marioluan.datastructures.graph.Graph;
package io.github.marioluan.datastructures.factory;
public final class DigraphGraphFactory {
private DigraphGraphFactory() {
}
/**
* Builds a graph with the same vertices and edges from lecture slides. <br>
* <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
*/ | public static Digraph build() { |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/priority/queue/MaxBinaryHeapTest.java | // Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
| import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static com.greghaskins.spectrum.Spectrum.xdescribe;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.Resizable; | package io.github.marioluan.datastructures.priority.queue;
@RunWith(Spectrum.class)
public class MaxBinaryHeapTest {
| // Path: src/main/java/io/github/marioluan/datastructures/wrappers/Resizable.java
// public interface Resizable<T> {
//
// /**
// * Resize the underlying object T holding the elements and returns a copy of
// * it.
// * <strong>Time complexity:</strong> O(n)<br>
// *
// * @param a
// * the array to be resized
// * @param n
// * the number of elements on the array
// * @param capacity
// * the new capacity of the array
// * @return the resized copy of a
// */
// T resize(T a, int n, int capacity);
// }
// Path: src/test/java/io/github/marioluan/datastructures/priority/queue/MaxBinaryHeapTest.java
import static com.greghaskins.spectrum.Spectrum.afterEach;
import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static com.greghaskins.spectrum.Spectrum.xdescribe;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.NoSuchElementException;
import java.util.Random;
import org.junit.runner.RunWith;
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.wrappers.Resizable;
package io.github.marioluan.datastructures.priority.queue;
@RunWith(Spectrum.class)
public class MaxBinaryHeapTest {
| private Resizable<Integer[]> rs; |
marioluan/java-data-structures | src/test/java/io/github/marioluan/datastructures/graph/UndirectedTest.java | // Path: src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java
// public final class DigraphGraphFactory {
// private DigraphGraphFactory() {
// }
//
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Digraph build() {
// Digraph graph = new Digraph(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 5);
//
// graph.addEdge(2, 0);
// graph.addEdge(2, 3);
//
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
//
// graph.addEdge(4, 2);
// graph.addEdge(4, 3);
//
// graph.addEdge(5, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 9);
// graph.addEdge(6, 4);
// graph.addEdge(6, 8);
//
// graph.addEdge(7, 6);
// graph.addEdge(7, 9);
//
// graph.addEdge(8, 6);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
//
// graph.addEdge(10, 12);
//
// graph.addEdge(11, 12);
// graph.addEdge(11, 4);
//
// graph.addEdge(12, 9);
//
// return graph;
// }
// }
//
// Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
| import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.DigraphGraphFactory;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import org.junit.Assert;
import org.junit.runner.RunWith;
import java.util.Random;
import java.util.stream.IntStream;
import static com.greghaskins.spectrum.Spectrum.*; | Assert.assertSame(w, subject.adj(v).iterator().next());
});
});
describe("#V", () -> {
beforeEach(() -> {
V = 2;
subject = new Undirected(V);
});
it("returns the number of vertices", () -> {
Assert.assertEquals(V, subject.V());
});
});
describe("#E", () -> {
beforeEach(() -> {
w = new Random().nextInt(V);
v = new Random().nextInt(V);
subject.addEdge(v, w);
});
it("returns the number of edges", () -> {
Assert.assertEquals(1, subject.E());
});
});
describe("#reverse", () -> {
it("returns itself", () -> { | // Path: src/test/java/io/github/marioluan/datastructures/factory/DigraphGraphFactory.java
// public final class DigraphGraphFactory {
// private DigraphGraphFactory() {
// }
//
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://algs4.cs.princeton.edu/lectures/42DirectedGraphs.pdf</strong>
// */
// public static Digraph build() {
// Digraph graph = new Digraph(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 5);
//
// graph.addEdge(2, 0);
// graph.addEdge(2, 3);
//
// graph.addEdge(3, 2);
// graph.addEdge(3, 5);
//
// graph.addEdge(4, 2);
// graph.addEdge(4, 3);
//
// graph.addEdge(5, 4);
//
// graph.addEdge(6, 0);
// graph.addEdge(6, 9);
// graph.addEdge(6, 4);
// graph.addEdge(6, 8);
//
// graph.addEdge(7, 6);
// graph.addEdge(7, 9);
//
// graph.addEdge(8, 6);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
//
// graph.addEdge(10, 12);
//
// graph.addEdge(11, 12);
// graph.addEdge(11, 4);
//
// graph.addEdge(12, 9);
//
// return graph;
// }
// }
//
// Path: src/test/java/io/github/marioluan/datastructures/factory/UndirectedGraphFactory.java
// public final class UndirectedGraphFactory {
// /**
// * Builds a graph with the same vertices and edges from lecture slides. <br>
// * <strong>https://www.coursera.org/learn/algorithms-part2/lecture/mW9aG/depth-first-search</strong>
// */
// public static Undirected build() {
// Undirected graph = new Undirected(13);
//
// graph.addEdge(0, 1);
// graph.addEdge(0, 2);
// graph.addEdge(0, 5);
// graph.addEdge(0, 6);
// graph.addEdge(6, 4);
// graph.addEdge(4, 3);
// graph.addEdge(4, 5);
// graph.addEdge(3, 5);
//
// graph.addEdge(7, 8);
//
// graph.addEdge(9, 10);
// graph.addEdge(9, 11);
// graph.addEdge(9, 12);
// graph.addEdge(11, 12);
//
// return graph;
// }
// }
// Path: src/test/java/io/github/marioluan/datastructures/graph/UndirectedTest.java
import com.greghaskins.spectrum.Spectrum;
import io.github.marioluan.datastructures.factory.DigraphGraphFactory;
import io.github.marioluan.datastructures.factory.UndirectedGraphFactory;
import org.junit.Assert;
import org.junit.runner.RunWith;
import java.util.Random;
import java.util.stream.IntStream;
import static com.greghaskins.spectrum.Spectrum.*;
Assert.assertSame(w, subject.adj(v).iterator().next());
});
});
describe("#V", () -> {
beforeEach(() -> {
V = 2;
subject = new Undirected(V);
});
it("returns the number of vertices", () -> {
Assert.assertEquals(V, subject.V());
});
});
describe("#E", () -> {
beforeEach(() -> {
w = new Random().nextInt(V);
v = new Random().nextInt(V);
subject.addEdge(v, w);
});
it("returns the number of edges", () -> {
Assert.assertEquals(1, subject.E());
});
});
describe("#reverse", () -> {
it("returns itself", () -> { | subject = UndirectedGraphFactory.build(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.