You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/02/13 00:15:59 UTC
[04/10] incubator-usergrid git commit: First pass at removing
unnecessary 1.0 files.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/geo/GeocellUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/GeocellUtils.java b/stack/core/src/main/java/org/apache/usergrid/persistence/geo/GeocellUtils.java
deleted file mode 100644
index ffc3d72..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/GeocellUtils.java
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.geo;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.usergrid.persistence.geo.comparator.DoubleTupleComparator;
-import org.apache.usergrid.persistence.geo.model.BoundingBox;
-import org.apache.usergrid.persistence.geo.model.Point;
-import org.apache.usergrid.persistence.geo.model.Tuple;
-
-/**
- #
- # Copyright 2010 Alexandre Gellibert
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- */
-
-
-/**
- * Utils class to compute geocells.
- *
- * @author api.roman.public@gmail.com (Roman Nurik)
- * @author (java portage) Alexandre Gellibert
- */
-public final class GeocellUtils {
-
- public static final float MIN_LONGITUDE = -180.0f;
- public static final float MAX_LONGITUDE = 180.0f;
- public static final float MIN_LATITUDE = -90.0f;
- public static final float MAX_LATITUDE = 90.0f;
- // Geocell algorithm constants.
- public static final int GEOCELL_GRID_SIZE = 4;
- private static final String GEOCELL_ALPHABET = "0123456789abcdef";
-
- // Direction enumerations.
- private static final int[] NORTHWEST = new int[] { -1, 1 };
- private static final int[] NORTH = new int[] { 0, 1 };
- private static final int[] NORTHEAST = new int[] { 1, 1 };
- private static final int[] EAST = new int[] { 1, 0 };
- private static final int[] SOUTHEAST = new int[] { 1, -1 };
- private static final int[] SOUTH = new int[] { 0, -1 };
- private static final int[] SOUTHWEST = new int[] { -1, -1 };
- private static final int[] WEST = new int[] { -1, 0 };
-
- private static final int RADIUS = 6378135;
-
-
- private GeocellUtils() {
- // no instantiation allowed
- }
-
-
- /**
- * Determines whether the given cells are collinear along a dimension.
- * <p/>
- * Returns True if the given cells are in the same row (columnTest=False) or in the same column (columnTest=True).
- *
- * @param cell1 : The first geocell string.
- * @param cell2 : The second geocell string.
- * @param columnTest : A boolean, where False invokes a row collinearity test and 1 invokes a column collinearity
- * test.
- *
- * @return A bool indicating whether or not the given cells are collinear in the given dimension.
- */
- public static boolean collinear( String cell1, String cell2, boolean columnTest ) {
-
- for ( int i = 0; i < Math.min( cell1.length(), cell2.length() ); i++ ) {
- int l1[] = subdivXY( cell1.charAt( i ) );
- int x1 = l1[0];
- int y1 = l1[1];
- int l2[] = subdivXY( cell2.charAt( i ) );
- int x2 = l2[0];
- int y2 = l2[1];
-
- // Check row collinearity (assure y's are always the same).
- if ( !columnTest && y1 != y2 ) {
- return false;
- }
-
- // Check column collinearity (assure x's are always the same).
- if ( columnTest && x1 != x2 ) {
- return false;
- }
- }
- return true;
- }
-
-
- /**
- * Calculates the grid of cells formed between the two given cells.
- * <p/>
- * Generates the set of cells in the grid created by interpolating from the given Northeast geocell to the given
- * Southwest geocell.
- * <p/>
- * Assumes the Northeast geocell is actually Northeast of Southwest geocell.
- *
- * @param cellNE : The Northeast geocell string.
- * @param cellSW : The Southwest geocell string.
- *
- * @return A list of geocell strings in the interpolation.
- */
- public static List<String> interpolate( String cellNE, String cellSW ) {
- // 2D array, will later be flattened.
- LinkedList<LinkedList<String>> cellSet = new LinkedList<LinkedList<String>>();
- LinkedList<String> cellFirst = new LinkedList<String>();
- cellFirst.add( cellSW );
- cellSet.add( cellFirst );
-
- // First get adjacent geocells across until Southeast--collinearity with
- // Northeast in vertical direction (0) means we're at Southeast.
- while ( !collinear( cellFirst.getLast(), cellNE, true ) ) {
- String cellTmp = adjacent( cellFirst.getLast(), EAST );
- if ( cellTmp == null ) {
- break;
- }
- cellFirst.add( cellTmp );
- }
-
- // Then get adjacent geocells upwards.
- while ( !cellSet.getLast().getLast().equalsIgnoreCase( cellNE ) ) {
-
- LinkedList<String> cellTmpRow = new LinkedList<String>();
- for ( String g : cellSet.getLast() ) {
- cellTmpRow.add( adjacent( g, NORTH ) );
- }
- if ( cellTmpRow.getFirst() == null ) {
- break;
- }
- cellSet.add( cellTmpRow );
- }
-
- // Flatten cellSet, since it's currently a 2D array.
- List<String> result = new ArrayList<String>();
- for ( LinkedList<String> list : cellSet ) {
- result.addAll( list );
- }
- return result;
- }
-
-
- /**
- * Computes the number of cells in the grid formed between two given cells.
- * <p/>
- * Computes the number of cells in the grid created by interpolating from the given Northeast geocell to the given
- * Southwest geocell. Assumes the Northeast geocell is actually Northeast of Southwest geocell.
- *
- * @param cellNE : The Northeast geocell string.
- * @param cellSW : The Southwest geocell string.
- *
- * @return An int, indicating the number of geocells in the interpolation.
- */
- public static int interpolationCount( String cellNE, String cellSW ) {
-
- BoundingBox bboxNE = computeBox( cellNE );
- BoundingBox bboxSW = computeBox( cellSW );
-
- double cellLatSpan = bboxSW.getNorth() - bboxSW.getSouth();
- double cellLonSpan = bboxSW.getEast() - bboxSW.getWest();
-
- double numCols = ( ( bboxNE.getEast() - bboxSW.getWest() ) / cellLonSpan );
- double numRows = ( ( bboxNE.getNorth() - bboxSW.getSouth() ) / cellLatSpan );
-
- double totalCols = numCols * numRows * 1.0;
- if ( totalCols > Integer.MAX_VALUE ) {
- return Integer.MAX_VALUE;
- }
- return ( int ) totalCols;
- }
-
-
- /**
- * Calculates all of the given geocell's adjacent geocells.
- *
- * @param cell : The geocell string for which to calculate adjacent/neighboring cells.
- *
- * @return A list of 8 geocell strings and/or None values indicating adjacent cells.
- */
-
- public static List<String> allAdjacents( String cell ) {
- List<String> result = new ArrayList<String>();
- for ( int[] d : Arrays.asList( NORTHWEST, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST ) ) {
- result.add( adjacent( cell, d ) );
- }
- return result;
- }
-
-
- /**
- * Calculates the geocell adjacent to the given cell in the given direction.
- *
- * @param cell : The geocell string whose neighbor is being calculated.
- * @param dir : An (x, y) tuple indicating direction, where x and y can be -1, 0, or 1. -1 corresponds to West for x
- * and South for y, and 1 corresponds to East for x and North for y. Available helper constants are NORTH, EAST,
- * SOUTH, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, and SOUTHWEST.
- *
- * @return The geocell adjacent to the given cell in the given direction, or None if there is no such cell.
- */
- public static String adjacent( String cell, int[] dir ) {
- if ( cell == null ) {
- return null;
- }
- int dx = dir[0];
- int dy = dir[1];
- char[] cellAdjArr = cell.toCharArray(); // Split the geocell string
- // characters into a list.
- int i = cellAdjArr.length - 1;
-
- while ( i >= 0 && ( dx != 0 || dy != 0 ) ) {
- int l[] = subdivXY( cellAdjArr[i] );
- int x = l[0];
- int y = l[1];
-
- // Horizontal adjacency.
- if ( dx == -1 ) { // Asking for left.
- if ( x == 0 ) { // At left of parent cell.
- x = GEOCELL_GRID_SIZE - 1; // Becomes right edge of adjacent parent.
- }
- else {
- x--; // Adjacent, same parent.
- dx = 0; // Done with x.
- }
- }
- else if ( dx == 1 ) { // Asking for right.
- if ( x == GEOCELL_GRID_SIZE - 1 ) { // At right of parent cell.
- x = 0; // Becomes left edge of adjacent parent.
- }
- else {
- x++; // Adjacent, same parent.
- dx = 0; // Done with x.
- }
- }
-
- // Vertical adjacency.
- if ( dy == 1 ) { // Asking for above.
- if ( y == GEOCELL_GRID_SIZE - 1 ) { // At top of parent cell.
- y = 0; // Becomes bottom edge of adjacent parent.
- }
- else {
- y++; // Adjacent, same parent.
- dy = 0; // Done with y.
- }
- }
- else if ( dy == -1 ) { // Asking for below.
- if ( y == 0 ) { // At bottom of parent cell.
- y = GEOCELL_GRID_SIZE - 1; // Becomes top edge of adjacent parent.
- }
- else {
- y--; // Adjacent, same parent.
- dy = 0; // Done with y.
- }
- }
-
- int l2[] = { x, y };
- cellAdjArr[i] = subdivChar( l2 );
- i--;
- }
- // If we're not done with y then it's trying to wrap vertically,
- // which is a failure.
- if ( dy != 0 ) {
- return null;
- }
-
- // At this point, horizontal wrapping is done inherently.
- return new String( cellAdjArr );
- }
-
-
- /**
- * Returns whether or not the given cell contains the given point.
- *
- * @return Returns whether or not the given cell contains the given point.
- */
- public static boolean containsPoint( String cell, Point point ) {
- return compute( point, cell.length() ).equalsIgnoreCase( cell );
- }
-
-
- /**
- * Returns the shortest distance between a point and a geocell bounding box.
- * <p/>
- * If the point is inside the cell, the shortest distance is always to a 'edge' of the cell rectangle. If the point
- * is outside the cell, the shortest distance will be to either a 'edge' or 'corner' of the cell rectangle.
- *
- * @return The shortest distance from the point to the geocell's rectangle, in meters.
- */
- public static double pointDistance( String cell, Point point ) {
- BoundingBox bbox = computeBox( cell );
-
- boolean betweenWE = bbox.getWest() <= point.getLon() && point.getLon() <= bbox.getEast();
- boolean betweenNS = bbox.getSouth() <= point.getLat() && point.getLat() <= bbox.getNorth();
-
- if ( betweenWE ) {
- if ( betweenNS ) {
- // Inside the geocell.
- return Math.min( Math.min( distance( point, new Point( bbox.getSouth(), point.getLon() ) ),
- distance( point, new Point( bbox.getNorth(), point.getLon() ) ) ),
- Math.min( distance( point, new Point( point.getLat(), bbox.getEast() ) ),
- distance( point, new Point( point.getLat(), bbox.getWest() ) ) ) );
- }
- else {
- return Math.min( distance( point, new Point( bbox.getSouth(), point.getLon() ) ),
- distance( point, new Point( bbox.getNorth(), point.getLon() ) ) );
- }
- }
- else {
- if ( betweenNS ) {
- return Math.min( distance( point, new Point( point.getLat(), bbox.getEast() ) ),
- distance( point, new Point( point.getLat(), bbox.getWest() ) ) );
- }
- else {
- // TODO(romannurik): optimize
- return Math.min( Math.min( distance( point, new Point( bbox.getSouth(), bbox.getEast() ) ),
- distance( point, new Point( bbox.getNorth(), bbox.getEast() ) ) ),
- Math.min( distance( point, new Point( bbox.getSouth(), bbox.getWest() ) ),
- distance( point, new Point( bbox.getNorth(), bbox.getWest() ) ) ) );
- }
- }
- }
-
-
- /**
- * Computes the geocell containing the given point to the given resolution.
- * <p/>
- * This is a simple 16-tree lookup to an arbitrary depth (resolution).
- *
- * @param point : The geotypes.Point to compute the cell for.
- * @param resolution : An int indicating the resolution of the cell to compute.
- *
- * @return The geocell string containing the given point, of length resolution.
- */
- public static String compute( Point point, int resolution ) {
- float north = MAX_LATITUDE;
- float south = MIN_LATITUDE;
- float east = MAX_LONGITUDE;
- float west = MIN_LONGITUDE;
-
- StringBuilder cell = new StringBuilder();
- while ( cell.length() < resolution ) {
- float subcellLonSpan = ( east - west ) / GEOCELL_GRID_SIZE;
- float subcellLatSpan = ( north - south ) / GEOCELL_GRID_SIZE;
-
- int x = Math.min( ( int ) ( GEOCELL_GRID_SIZE * ( point.getLon() - west ) / ( east - west ) ),
- GEOCELL_GRID_SIZE - 1 );
- int y = Math.min( ( int ) ( GEOCELL_GRID_SIZE * ( point.getLat() - south ) / ( north - south ) ),
- GEOCELL_GRID_SIZE - 1 );
-
- int l[] = { x, y };
- cell.append( subdivChar( l ) );
-
- south += subcellLatSpan * y;
- north = south + subcellLatSpan;
-
- west += subcellLonSpan * x;
- east = west + subcellLonSpan;
- }
- return cell.toString();
- }
-
-
- /**
- * Computes the rectangular boundaries (bounding box) of the given geocell.
- *
- * @param cell_ : The geocell string whose boundaries are to be computed.
- *
- * @return A geotypes.Box corresponding to the rectangular boundaries of the geocell.
- */
- public static BoundingBox computeBox( String cell_ ) {
- if ( cell_ == null ) {
- return null;
- }
-
- BoundingBox bbox = new BoundingBox( 90.0, 180.0, -90.0, -180.0 );
- StringBuilder cell = new StringBuilder( cell_ );
- while ( cell.length() > 0 ) {
- double subcellLonSpan = ( bbox.getEast() - bbox.getWest() ) / GEOCELL_GRID_SIZE;
- double subcellLatSpan = ( bbox.getNorth() - bbox.getSouth() ) / GEOCELL_GRID_SIZE;
-
- int l[] = subdivXY( cell.charAt( 0 ) );
- int x = l[0];
- int y = l[1];
-
- bbox = new BoundingBox( bbox.getSouth() + subcellLatSpan * ( y + 1 ),
- bbox.getWest() + subcellLonSpan * ( x + 1 ), bbox.getSouth() + subcellLatSpan * y,
- bbox.getWest() + subcellLonSpan * x );
-
- cell.deleteCharAt( 0 );
- }
-
- return bbox;
- }
-
-
- /**
- * Returns whether or not the given geocell string defines a valid geocell.
- *
- * @return Returns whether or not the given geocell string defines a valid geocell.
- */
- public static boolean isValid( String cell ) {
- if ( cell == null || cell.trim().length() == 0 ) {
- return false;
- }
- for ( char c : cell.toCharArray() ) {
- if ( GEOCELL_ALPHABET.indexOf( c ) < 0 ) {
- return false;
- }
- }
- return true;
- }
-
-
- /**
- * Returns the (x, y) of the geocell character in the 4x4 alphabet grid.
- *
- * @return Returns the (x, y) of the geocell character in the 4x4 alphabet grid.
- */
- public static int[] subdivXY( char char_ ) {
- // NOTE: This only works for grid size 4.
- int charI = GEOCELL_ALPHABET.indexOf( char_ );
- return new int[] {
- ( charI & 4 ) >> 1 | (charI & 1), ( charI & 8 ) >> 2 | ( charI & 2 ) >> 1
- };
- }
-
-
- /**
- * Returns the geocell character in the 4x4 alphabet grid at pos. (x, y).
- *
- * @return Returns the geocell character in the 4x4 alphabet grid at pos. (x, y).
- */
- public static char subdivChar( int[] pos ) {
- // NOTE: This only works for grid size 4.
- return GEOCELL_ALPHABET.charAt( ( pos[1] & 2 ) << 2 |
- ( pos[0] & 2 ) << 1 |
- ( pos[1] & 1 ) << 1 |
- (pos[0] & 1));
- }
-
-
- /**
- * Calculates the great circle distance between two points (law of cosines).
- *
- * @param p1 : indicating the first point.
- * @param p2 : indicating the second point.
- *
- * @return The 2D great-circle distance between the two given points, in meters.
- */
- public static double distance( Point p1, Point p2 ) {
- double p1lat = Math.toRadians( p1.getLat() );
- double p1lon = Math.toRadians( p1.getLon() );
- double p2lat = Math.toRadians( p2.getLat() );
- double p2lon = Math.toRadians( p2.getLon() );
- return RADIUS * Math.acos( makeDoubleInRange(
- Math.sin( p1lat ) * Math.sin( p2lat ) + Math.cos( p1lat ) * Math.cos( p2lat ) * Math
- .cos( p2lon - p1lon ) ) );
- }
-
-
- /**
- * This function is used to fix issue 10: GeocellUtils.distance(...) uses Math.acos(arg) method. In some cases arg >
- * 1 (i.e 1.0000000002), so acos cannot be calculated and the method returns NaN.
- *
- * @return a double between -1 and 1
- */
- public static double makeDoubleInRange( double d ) {
- double result = d;
- if ( d > 1 ) {
- result = 1;
- }
- else if ( d < -1 ) {
- result = -1;
- }
- return result;
- }
-
-
- /**
- * Returns the edges of the rectangular region containing all of the given geocells, sorted by distance from the
- * given point, along with the actual distances from the point to these edges.
- *
- * @param cells : The cells (should be adjacent) defining the rectangular region whose edge distances are
- * requested.
- * @param point : The point that should determine the edge sort order.
- *
- * @return A list of (direction, distance) tuples, where direction is the edge and distance is the distance from the
- * point to that edge. A direction value of (0,-1), for example, corresponds to the South edge of the
- * rectangular region containing all of the given geocells.
- * <p/>
- * TODO(romannurik): Assert that lat,lon are actually inside the geocell.
- */
- public static List<Tuple<int[], Double>> distanceSortedEdges( List<String> cells, Point point ) {
- List<BoundingBox> boxes = new ArrayList<BoundingBox>();
- for ( String cell : cells ) {
- boxes.add( computeBox( cell ) );
- }
- double maxNorth = Double.NEGATIVE_INFINITY;
- double maxEast = Double.NEGATIVE_INFINITY;
- double maxSouth = Double.POSITIVE_INFINITY;
- double maxWest = Double.POSITIVE_INFINITY;
- for ( BoundingBox box : boxes ) {
- maxNorth = Math.max( maxNorth, box.getNorth() );
- maxEast = Math.max( maxEast, box.getEast() );
- maxSouth = Math.min( maxSouth, box.getSouth() );
- maxWest = Math.min( maxWest, box.getWest() );
- }
- List<Tuple<int[], Double>> result = new ArrayList<Tuple<int[], Double>>();
- result.add( new Tuple<int[], Double>( SOUTH, distance( new Point( maxSouth, point.getLon() ), point ) ) );
- result.add( new Tuple<int[], Double>( NORTH, distance( new Point( maxNorth, point.getLon() ), point ) ) );
- result.add( new Tuple<int[], Double>( WEST, distance( new Point( point.getLat(), maxWest ), point ) ) );
- result.add( new Tuple<int[], Double>( EAST, distance( new Point( point.getLat(), maxEast ), point ) ) );
- Collections.sort( result, new DoubleTupleComparator() );
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/geo/comparator/DoubleTupleComparator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/comparator/DoubleTupleComparator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/geo/comparator/DoubleTupleComparator.java
deleted file mode 100644
index 92aca74..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/comparator/DoubleTupleComparator.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.geo.comparator;
-
-
-import java.util.Comparator;
-
-import org.apache.usergrid.persistence.geo.model.Tuple;
-
-
-public class DoubleTupleComparator implements Comparator<Tuple<int[], Double>> {
-
- public int compare( Tuple<int[], Double> o1, Tuple<int[], Double> o2 ) {
- if ( o1 == null && o2 == null ) {
- return 0;
- }
- if ( o1 == null ) {
- return -1;
- }
- if ( o2 == null ) {
- return 1;
- }
- return o1.getSecond().compareTo( o2.getSecond() );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/BoundingBox.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/BoundingBox.java b/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/BoundingBox.java
deleted file mode 100644
index 587bfd8..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/BoundingBox.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.geo.model;
-
-
-/** @author Alexandre Gellibert */
-public class BoundingBox {
-
- private Point northEast;
- private Point southWest;
-
-
- public BoundingBox( double north, double east, double south, double west ) {
- double north_, south_;
- if ( south > north ) {
- south_ = north;
- north_ = south;
- }
- else {
- south_ = south;
- north_ = north;
- }
-
- // Don't swap east and west to allow disambiguation of
- // antimeridian crossing.
-
- northEast = new Point( north_, east );
- southWest = new Point( south_, west );
- }
-
-
- public double getNorth() {
- return northEast.getLat();
- }
-
-
- public double getSouth() {
- return southWest.getLat();
- }
-
-
- public double getWest() {
- return southWest.getLon();
- }
-
-
- public double getEast() {
- return northEast.getLon();
- }
-
-
- public Point getNorthEast() {
- return northEast;
- }
-
-
- public Point getSouthWest() {
- return southWest;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/CostFunction.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/CostFunction.java b/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/CostFunction.java
deleted file mode 100644
index 5ae4759..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/CostFunction.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.geo.model;
-
-
-/**
- * Interface to create a cost function used in geocells algorithm. This function will determine the cost of an operation
- * depending of number of cells and resolution. When the cost is going higher, the algorithm stops. The cost depends on
- * application use of geocells.
- *
- * @author Alexandre Gellibert
- */
-public interface CostFunction {
-
- /**
- * @param numCells number of cells found
- * @param resolution resolution of those cells
- *
- * @return the cost of the operation
- */
- public double defaultCostFunction( int numCells, int resolution );
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/DefaultCostFunction.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/DefaultCostFunction.java b/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/DefaultCostFunction.java
deleted file mode 100644
index 0d34ad5..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/DefaultCostFunction.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.geo.model;
-
-
-import org.apache.usergrid.persistence.geo.GeocellUtils;
-
-
-/**
- * Default cost function used if no cost function is specified in Geocell.bestBboxSearchCells method.
- *
- * @author Alexandre Gellibert
- */
-public class DefaultCostFunction implements CostFunction {
-
- /*
- * (non-Javadoc)
- * @see com.beoui.utils.CostFunction#defaultCostFunction(int, int)
- */
- public double defaultCostFunction( int numCells, int resolution ) {
- return numCells > Math.pow( GeocellUtils.GEOCELL_GRID_SIZE, 2 ) ? Double.MAX_VALUE : 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/Tuple.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/Tuple.java b/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/Tuple.java
deleted file mode 100644
index 753233a..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/geo/model/Tuple.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.geo.model;
-
-
-public class Tuple<A, B> {
-
- private A first;
- private B second;
-
-
- public Tuple( A first, B second ) {
- this.first = first;
- this.second = second;
- }
-
-
- public A getFirst() {
- return first;
- }
-
-
- public B getSecond() {
- return second;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AllNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AllNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AllNode.java
deleted file mode 100644
index 11c39c9..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AllNode.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/**
- * Used to represent a "select all". This will iterate over the entities by UUID
- *
- * @author tnine
- */
-public class AllNode extends QueryNode {
-
-
- private final QuerySlice slice;
- private final boolean forceKeepFirst;
-
-
- /**
- * Note that the slice isn't used on select, but is used when creating cursors
- *
- * @param id. The unique numeric id for this node
- * @param forceKeepFirst True if we don't allow the iterator to skip the first result, regardless of cursor state.
- * Used for startUUID paging
- */
- public AllNode( int id, boolean forceKeepFirst ) {
- this.slice = new QuerySlice( "uuid", id );
- this.forceKeepFirst = forceKeepFirst;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.QueryNode#visit(org.apache.usergrid.persistence.query.ir.NodeVisitor)
- */
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- @Override
- public int getCount() {
- return 1;
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- @Override
- public String toString() {
- return "AllNode";
- }
-
-
- /** @return the slice */
- public QuerySlice getSlice() {
- return slice;
- }
-
-
- /** @return the skipFirstMatch */
- public boolean isForceKeepFirst() {
- return forceKeepFirst;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AndNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AndNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AndNode.java
deleted file mode 100644
index c2dea1f..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/AndNode.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/**
- * Node where the results need intersected. Used instead of a SliceNode when one of the children is an operation other
- * than slices. I.E OR, NOT etc
- *
- * @author tnine
- */
-public class AndNode extends BooleanNode {
-
- /**
- * @param left
- * @param right
- */
- public AndNode( QueryNode left, QueryNode right ) {
- super( left, right );
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.QueryNode#visit(org.apache.usergrid.persistence.query.ir.NodeVisitor)
- */
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/BooleanNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/BooleanNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/BooleanNode.java
deleted file mode 100644
index ee47946..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/BooleanNode.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/** @author tnine */
-public abstract class BooleanNode extends QueryNode {
-
- protected QueryNode left;
- protected QueryNode right;
-
-
- public BooleanNode( QueryNode left, QueryNode right ) {
- this.left = left;
- this.right = right;
- }
-
-
- /** @return the left */
- public QueryNode getLeft() {
- return left;
- }
-
-
- /** @return the right */
- public QueryNode getRight() {
- return right;
- }
-
-
- @Override
- public int getCount() {
- return left.getCount()+ right.getCount();
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- @Override
- public String toString() {
- return "BooleanNode [left=" + left + ", right=" + right + "]";
- }
-
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/EmailIdentifierNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/EmailIdentifierNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/EmailIdentifierNode.java
deleted file mode 100644
index 2fb1dcb..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/EmailIdentifierNode.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-import org.apache.usergrid.persistence.index.query.Identifier;
-
-
-/**
- * Class to represent a UUID based Identifier query
- *
- * @author tnine
- */
-public class EmailIdentifierNode extends QueryNode {
-
- private final Identifier identifier;
-
-
- public EmailIdentifierNode( Identifier identifier ) {
- this.identifier = identifier;
- }
-
-
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- @Override
- public int getCount() {
- return 1;
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- public Identifier getIdentifier() {
- return identifier;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NameIdentifierNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NameIdentifierNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NameIdentifierNode.java
deleted file mode 100644
index 75ba111..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NameIdentifierNode.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/**
- * Class to represent a UUID based Identifier query
- *
- * @author tnine
- */
-public class NameIdentifierNode extends QueryNode {
-
- private final String name;
-
-
- public NameIdentifierNode( String name ) {
- this.name = name;
- }
-
-
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- @Override
- public int getCount() {
- return 1;
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- public String getName() {
- return name;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NodeVisitor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NodeVisitor.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NodeVisitor.java
deleted file mode 100644
index bfaeee3..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NodeVisitor.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/** @author tnine */
-public interface NodeVisitor {
-
- /**
- *
- * @param node
- * @throws Exception
- */
- public void visit( AndNode node ) throws Exception;
-
- /**
- *
- * @param node
- * @throws Exception
- */
- public void visit( NotNode node ) throws Exception;
-
- /**
- *
- * @param node
- * @throws Exception
- */
- public void visit( OrNode node ) throws Exception;
-
- /**
- *
- * @param node
- * @throws Exception
- */
- public void visit( SliceNode node ) throws Exception;
-
- /**
- *
- * @param node
- * @throws Exception
- */
- public void visit( WithinNode node ) throws Exception;
-
- /**
- *
- * @param node
- * @throws Exception
- */
- public void visit( AllNode node ) throws Exception;
-
- /** Visit the name identifier node */
- public void visit( NameIdentifierNode nameIdentifierNode ) throws Exception;
-
- /** Visit the uuid identifier node */
- public void visit( UuidIdentifierNode uuidIdentifierNode );
-
- /**
- * @param orderByNode
- * @throws Exception
- */
- public void visit( OrderByNode orderByNode ) throws Exception;
-
- /** Visit the email id node */
- public void visit( EmailIdentifierNode emailIdentifierNode ) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NotNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NotNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NotNode.java
deleted file mode 100644
index 306eff3..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/NotNode.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/** @author tnine */
-public class NotNode extends QueryNode {
-
- protected QueryNode subtractNode, keepNode;
-
-
- /** @param keepNode may be null if there are parents to this */
- public NotNode( QueryNode subtractNode, QueryNode keepNode ) {
- this.subtractNode = subtractNode;
- this.keepNode = keepNode;
-// throw new RuntimeException( "I'm a not node" );
- }
-
-
- /** @return the child */
- public QueryNode getSubtractNode() {
- return subtractNode;
- }
-
-
- /** @return the all */
- public QueryNode getKeepNode() {
- return keepNode;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.QueryNode#visit(org.apache.usergrid.persistence
- * .query.ir.NodeVisitor)
- */
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- @Override
- public int getCount() {
- return subtractNode.getCount() + keepNode.getCount();
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- @Override
- public String toString() {
- return "NotNode [child=" + subtractNode + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrNode.java
deleted file mode 100644
index 2735f9b..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrNode.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/**
- * @author tnine
- */
-public class OrNode extends BooleanNode {
-
- private final int id;
-
-
- /**
- * @param left
- * @param right
- */
- public OrNode( QueryNode left, QueryNode right, int id ) {
- super( left, right );
- this.id = id;
- }
-
-
- /**
- * Get the context id
- */
- public int getId() {
- return this.id;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.QueryNode#visit(org.apache.usergrid.persistence.query.ir.NodeVisitor)
- */
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrderByNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrderByNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrderByNode.java
deleted file mode 100644
index 6364337..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/OrderByNode.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-import java.util.List;
-
-import org.apache.usergrid.persistence.index.query.Query.SortPredicate;
-
-
-/**
- * Intermediate representation of ordering operations
- *
- * @author tnine
- */
-public class OrderByNode extends QueryNode {
-
-
- private final SliceNode firstPredicate;
- private final List<SortPredicate> secondarySorts;
- private final QueryNode queryOperations;
-
-
- /**
- * @param firstPredicate The first predicate that is in the order by statement
- * @param secondarySorts Any subsequent terms
- * @param queryOperations The subtree for boolean evaluation
- */
- public OrderByNode( SliceNode firstPredicate, List<SortPredicate> secondarySorts, QueryNode queryOperations ) {
- this.firstPredicate = firstPredicate;
- this.secondarySorts = secondarySorts;
- this.queryOperations = queryOperations;
- }
-
-
- /** @return the sorts */
- public List<SortPredicate> getSecondarySorts() {
- return secondarySorts;
- }
-
-
- /** @return the firstPredicate */
- public SliceNode getFirstPredicate() {
- return firstPredicate;
- }
-
-
- public QueryNode getQueryOperations() {
- return queryOperations;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.QueryNode#visit(org.apache.usergrid.persistence
- * .query.ir.NodeVisitor)
- */
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- /** Return true if this order has secondary sorts */
- public boolean hasSecondarySorts() {
- return secondarySorts != null && secondarySorts.size() > 0;
- }
-
-
- @Override
- public int getCount() {
- return firstPredicate.getCount() + secondarySorts.size();
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OrderByNode [sorts=" + secondarySorts + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QueryNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QueryNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QueryNode.java
deleted file mode 100644
index 954c13f..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QueryNode.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-/**
- * The visit the node
- *
- * @author tnine
- */
-public abstract class QueryNode {
-
- /** Visit this node */
- public abstract void visit( NodeVisitor visitor ) throws Exception;
-
-
- /**
- * Get the count of the total number of slices in our tree from this node and it's children
- */
- public abstract int getCount();
-
- /**
- * True if this node should not be used in it's context in the AST, and should ignore it's hint size and always select the max
- * @return
- */
- public abstract boolean ignoreHintSize();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QuerySlice.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QuerySlice.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QuerySlice.java
deleted file mode 100644
index 77c0a6b..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/QuerySlice.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-import java.nio.ByteBuffer;
-
-import org.apache.usergrid.utils.NumberUtils;
-
-import me.prettyprint.hector.api.beans.AbstractComposite.ComponentEquality;
-import me.prettyprint.hector.api.beans.DynamicComposite;
-
-import static org.apache.usergrid.utils.CompositeUtils.setEqualityFlag;
-
-
-/**
- * Node that represents a query slice operation
- *
- * @author tnine
- */
-public class QuerySlice {
-
- private final String propertyName;
- private final int nodeId;
- // Object value;
- private RangeValue start;
- private RangeValue finish;
- private ByteBuffer cursor;
- private boolean reversed;
-
-
- /**
- * @param propertyName
- * @param nodeId
- */
- public QuerySlice( String propertyName, int nodeId ) {
- this.propertyName = propertyName;
- this.nodeId = nodeId;
- }
-
-
- /** Reverse this slice. Flips the reversed switch and correctly changes the start and finish */
- public void reverse() {
- reversed = !reversed;
-
- RangeValue oldStart = start;
-
- start = finish;
-
- finish = oldStart;
- }
-
-
- public String getPropertyName() {
- return propertyName;
- }
-
-
- public RangeValue getStart() {
- return start;
- }
-
-
- public void setStart( RangeValue start ) {
- this.start = start;
- }
-
-
- public RangeValue getFinish() {
- return finish;
- }
-
-
- public void setFinish( RangeValue finish ) {
- this.finish = finish;
- }
-
-
- public ByteBuffer getCursor() {
- return hasCursor() ? cursor.duplicate() : null;
- }
-
-
- public void setCursor( ByteBuffer cursor ) {
- this.cursor = cursor;
- }
-
-
- /** True if a cursor has been set */
- public boolean hasCursor() {
- return this.cursor != null;
- }
-
-
- public boolean isReversed() {
- return reversed;
- }
-
-
- /**
- * Return true if we have a cursor and it's empty. This means that we've already returned all possible values from
- * this slice range with our existing data in a previous invocation of search
- */
- public boolean isComplete() {
- return cursor != null && cursor.remaining() == 0;
- }
-
-
- /**
- * Get the slice range to be used during querying
- *
- * @return An array of dynamic composites to use. Index 0 is the start, index 1 is the finish. One or more could be
- * null
- */
- public DynamicComposite[] getRange() {
- DynamicComposite startComposite = null;
- DynamicComposite finishComposite = null;
-
- // calc
- if ( hasCursor() ) {
- startComposite = DynamicComposite.fromByteBuffer( cursor.duplicate() );
- }
-
- else if ( start != null ) {
- startComposite = new DynamicComposite( start.getCode(), start.getValue() );
-
- // forward scanning from a >= 100 OR //reverse scanning from MAX to >= 100
- if ( ( !reversed && !start.isInclusive() ) || ( reversed && start.isInclusive() ) ) {
- setEqualityFlag( startComposite, ComponentEquality.GREATER_THAN_EQUAL );
- }
- }
-
- if ( finish != null ) {
- finishComposite = new DynamicComposite( finish.getCode(), finish.getValue() );
-
- // forward scan to <= 100 OR reverse scan ININITY to > 100
- if ( ( !reversed && finish.isInclusive() ) || reversed && !finish.isInclusive() ) {
- setEqualityFlag( finishComposite, ComponentEquality.GREATER_THAN_EQUAL );
- }
- }
-
- return new DynamicComposite[] { startComposite, finishComposite };
- }
-
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ( ( finish == null ) ? 0 : finish.hashCode() );
- result = prime * result + ( ( propertyName == null ) ? 0 : propertyName.hashCode() );
- result = prime * result + ( reversed ? 1231 : 1237 );
- result = prime * result + ( ( start == null ) ? 0 : start.hashCode() );
- result = prime * result + nodeId;
- return result;
- }
-
-
- @Override
- public boolean equals( Object obj ) {
- if ( this == obj ) {
- return true;
- }
- if ( obj == null ) {
- return false;
- }
- if ( getClass() != obj.getClass() ) {
- return false;
- }
- QuerySlice other = ( QuerySlice ) obj;
- if ( finish == null ) {
- if ( other.finish != null ) {
- return false;
- }
- }
- else if ( !finish.equals( other.finish ) ) {
- return false;
- }
- if ( propertyName == null ) {
- if ( other.propertyName != null ) {
- return false;
- }
- }
- else if ( !propertyName.equals( other.propertyName ) ) {
- return false;
- }
- if ( reversed != other.reversed ) {
- return false;
- }
- if ( start == null ) {
- if ( other.start != null ) {
- return false;
- }
- }
- else if ( !start.equals( other.start ) ) {
- return false;
- }
- return true;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "QuerySlice [propertyName=" + propertyName + ", start=" + start + ", finish=" + finish + ", cursor="
- + cursor + ", reversed=" + reversed + ", nodeId=" + nodeId + "]";
- }
-
-
- public static class RangeValue {
- final byte code;
- final Object value;
- final boolean inclusive;
-
-
- public RangeValue( byte code, Object value, boolean inclusive ) {
- this.code = code;
- this.value = value;
- this.inclusive = inclusive;
- }
-
-
- public byte getCode() {
- return code;
- }
-
-
- public Object getValue() {
- return value;
- }
-
-
- public boolean isInclusive() {
- return inclusive;
- }
-
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + code;
- result = prime * result + ( inclusive ? 1231 : 1237 );
- result = prime * result + ( ( value == null ) ? 0 : value.hashCode() );
- return result;
- }
-
-
- @Override
- public boolean equals( Object obj ) {
- if ( this == obj ) {
- return true;
- }
- if ( obj == null ) {
- return false;
- }
- if ( getClass() != obj.getClass() ) {
- return false;
- }
- RangeValue other = ( RangeValue ) obj;
- if ( code != other.code ) {
- return false;
- }
- if ( inclusive != other.inclusive ) {
- return false;
- }
- if ( value == null ) {
- if ( other.value != null ) {
- return false;
- }
- }
- else if ( !value.equals( other.value ) ) {
- return false;
- }
- return true;
- }
-
-
- public int compareTo( RangeValue other, boolean finish ) {
- if ( other == null ) {
- return 1;
- }
- if ( code != other.code ) {
- return NumberUtils.sign( code - other.code );
- }
- @SuppressWarnings({ "unchecked", "rawtypes" }) int c = ( ( Comparable ) value ).compareTo( other.value );
- if ( c != 0 ) {
- return c;
- }
- if ( finish ) {
- // for finish values, inclusive means <= which is greater than <
- if ( inclusive != other.inclusive ) {
- return inclusive ? 1 : -1;
- }
- }
- else {
- // for start values, inclusive means >= which is lest than >
- if ( inclusive != other.inclusive ) {
- return inclusive ? -1 : 1;
- }
- }
- return 0;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "RangeValue [code=" + code + ", value=" + value + ", inclusive=" + inclusive + "]";
- }
-
-
- public static int compare( RangeValue v1, RangeValue v2, boolean finish ) {
- if ( v1 == null ) {
- if ( v2 == null ) {
- return 0;
- }
- return -1;
- }
- return v1.compareTo( v2, finish );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SearchVisitor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SearchVisitor.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SearchVisitor.java
deleted file mode 100644
index f938e24..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SearchVisitor.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-import java.util.Stack;
-
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.cassandra.QueryProcessorImpl;
-import org.apache.usergrid.persistence.cassandra.index.IndexScanner;
-import org.apache.usergrid.persistence.cassandra.index.NoOpIndexScanner;
-import org.apache.usergrid.persistence.query.ir.result.EmptyIterator;
-import org.apache.usergrid.persistence.query.ir.result.IntersectionIterator;
-import org.apache.usergrid.persistence.query.ir.result.OrderByIterator;
-import org.apache.usergrid.persistence.query.ir.result.ResultIterator;
-import org.apache.usergrid.persistence.query.ir.result.SecondaryIndexSliceParser;
-import org.apache.usergrid.persistence.query.ir.result.SliceIterator;
-import org.apache.usergrid.persistence.query.ir.result.StaticIdIterator;
-import org.apache.usergrid.persistence.query.ir.result.SubtractionIterator;
-import org.apache.usergrid.persistence.query.ir.result.UnionIterator;
-
-
-/**
- * Simple search visitor that performs all the joining in memory for results.
- * <p/>
- * Subclasses will want to implement visiting SliceNode and WithinNode to actually perform the search on the Cassandra
- * indexes. This class can perform joins on all index entries that conform to the Results object
- *
- * @author tnine
- */
-public abstract class SearchVisitor implements NodeVisitor {
-
- private static final SecondaryIndexSliceParser COLLECTION_PARSER = new SecondaryIndexSliceParser();
-
- protected final Query query;
-
- protected final QueryProcessorImpl queryProcessor;
-
- protected final EntityManager em;
-
- protected final Stack<ResultIterator> results = new Stack<ResultIterator>();
-
-
- /**
- * @param queryProcessor
- */
- public SearchVisitor( QueryProcessorImpl queryProcessor ) {
- this.query = queryProcessor.getQuery();
- this.queryProcessor = queryProcessor;
- this.em = queryProcessor.getEntityManager();
- }
-
-
- /** Return the results if they exist, null otherwise */
- public ResultIterator getResults() {
- return results.isEmpty() ? null : results.pop();
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.NodeVisitor#visit(org.apache.usergrid.
- * persistence.query.ir.AndNode)
- */
- @Override
- public void visit( AndNode node ) throws Exception {
- node.getLeft().visit( this );
- node.getRight().visit( this );
-
- ResultIterator right = results.pop();
- ResultIterator left = results.pop();
-
- /**
- * NOTE: TN We should always maintain post order traversal of the tree. It
- * is required for sorting to work correctly
- */
- IntersectionIterator intersection = new IntersectionIterator( queryProcessor.getPageSizeHint( node ) );
- intersection.addIterator( left );
- intersection.addIterator( right );
-
- results.push( intersection );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.NodeVisitor#visit(org.apache.usergrid.
- * persistence.query.ir.NotNode)
- */
- @Override
- public void visit( NotNode node ) throws Exception {
- node.getSubtractNode().visit( this );
- ResultIterator not = results.pop();
-
- node.getKeepNode().visit( this );
- ResultIterator keep = results.pop();
-
- SubtractionIterator subtraction = new SubtractionIterator( queryProcessor.getPageSizeHint( node ) );
- subtraction.setSubtractIterator( not );
- subtraction.setKeepIterator( keep );
-
- results.push( subtraction );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.NodeVisitor#visit(org.apache.usergrid.
- * persistence.query.ir.OrNode)
- */
- @Override
- public void visit( OrNode node ) throws Exception {
- node.getLeft().visit( this );
- node.getRight().visit( this );
-
- ResultIterator right = results.pop();
- ResultIterator left = results.pop();
-
- final int nodeId = node.getId();
-
- UnionIterator union = new UnionIterator( queryProcessor.getPageSizeHint( node ), nodeId, queryProcessor.getCursorCache(nodeId ) );
-
- if ( left != null ) {
- union.addIterator( left );
- }
- if ( right != null ) {
- union.addIterator( right );
- }
-
- results.push( union );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.NodeVisitor#visit(org.apache.usergrid.persistence
- * .query.ir.OrderByNode)
- */
- @Override
- public void visit( OrderByNode orderByNode ) throws Exception {
-
- QuerySlice slice = orderByNode.getFirstPredicate().getAllSlices().iterator().next();
-
- queryProcessor.applyCursorAndSort( slice );
-
- QueryNode subOperations = orderByNode.getQueryOperations();
-
- ResultIterator subResults = null;
-
- if ( subOperations != null ) {
- //visit our sub operation
- subOperations.visit( this );
-
- subResults = results.pop();
- }
-
- ResultIterator orderIterator;
-
- /**
- * We have secondary sorts, we need to evaluate the candidate results and sort them in memory
- */
- if ( orderByNode.hasSecondarySorts() ) {
-
- //only order by with no query, start scanning the first field
- if ( subResults == null ) {
- QuerySlice firstFieldSlice = new QuerySlice( slice.getPropertyName(), -1 );
- subResults =
- new SliceIterator( slice, secondaryIndexScan( orderByNode, firstFieldSlice ), COLLECTION_PARSER );
- }
-
- orderIterator = new OrderByIterator( slice, orderByNode.getSecondarySorts(), subResults, em,
- queryProcessor.getPageSizeHint( orderByNode ) );
- }
-
- //we don't have multi field sorting, we can simply do intersection with a single scan range
- else {
-
- IndexScanner scanner;
-
- if ( slice.isComplete() ) {
- scanner = new NoOpIndexScanner();
- }
- else {
- scanner = secondaryIndexScan( orderByNode, slice );
- }
-
- SliceIterator joinSlice = new SliceIterator( slice, scanner, COLLECTION_PARSER);
-
- IntersectionIterator union = new IntersectionIterator( queryProcessor.getPageSizeHint( orderByNode ) );
- union.addIterator( joinSlice );
-
- if ( subResults != null ) {
- union.addIterator( subResults );
- }
-
- orderIterator = union;
- }
-
- // now create our intermediate iterator with our real results
- results.push( orderIterator );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.NodeVisitor#visit(org.apache.usergrid.persistence
- * .query.ir.SliceNode)
- */
- @Override
- public void visit( SliceNode node ) throws Exception {
- IntersectionIterator intersections = new IntersectionIterator( queryProcessor.getPageSizeHint( node ) );
-
- for ( QuerySlice slice : node.getAllSlices() ) {
- IndexScanner scanner = secondaryIndexScan( node, slice );
-
- intersections.addIterator( new SliceIterator( slice, scanner, COLLECTION_PARSER) );
- }
-
- results.push( intersections );
- }
-
-
- /**
- * Create a secondary index scan for the given slice node. DOES NOT apply to the "all" case. This should only
- * generate a slice for secondary property scanning
- */
- protected abstract IndexScanner secondaryIndexScan( QueryNode node, QuerySlice slice ) throws Exception;
-
-
- @Override
- public void visit( UuidIdentifierNode uuidIdentifierNode ) {
- this.results.push( new StaticIdIterator( uuidIdentifierNode.getUuid() ) );
- }
-
-
- @Override
- public void visit( EmailIdentifierNode emailIdentifierNode ) throws Exception {
- EntityRef user = queryProcessor.getEntityManager().getUserByIdentifier( emailIdentifierNode.getIdentifier() );
-
- if ( user == null ) {
- this.results.push( new EmptyIterator() );
- return;
- }
-
- this.results.push( new StaticIdIterator( user.getUuid() ) );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SliceNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SliceNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SliceNode.java
deleted file mode 100644
index fc6f53b..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/SliceNode.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.usergrid.persistence.query.ir.QuerySlice.RangeValue;
-import static org.apache.usergrid.persistence.cassandra.IndexUpdate.indexValueCode;
-import static org.apache.usergrid.persistence.cassandra.IndexUpdate.toIndexableValue;
-
-
-/**
- * A node which has 1 or more query Slices that can be unioned together. I.E and && operation with either 1 or more
- * children
- *
- * @author tnine
- */
-public class SliceNode extends QueryNode {
-
- /**
- * A context within a tree to allow for operand and range scan optimizations. In the event that the user enters a
- * query in the following way
- * <p/>
- * (x > 5 and x < 15 and z > 10 and z < 20) or (y > 10 and y < 20)
- * <p/>
- * You will have 2 contexts. The first is for (x > 5 and x < 15 and z > 10 and z < 20), the second is for (y > 10
- * and y < 20). This allows us to compress these operations into a single range scan per context.
- */
- // private class TreeContext {
-
- private Map<String, QuerySlice> pairs = new LinkedHashMap<String, QuerySlice>();
-
- private int id;
-
-
- /**
- * Set the id for construction. Just a counter. Used for creating tokens and things like tokens where the same
- * property can be used in 2 different subtrees
- */
- public SliceNode( int id ) {
- this.id = id;
- }
-
-
- @Override
- public int getCount() {
- return pairs.size();
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return pairs.size() > 1;
- }
-
-
- /**
- * Set the start value. If the range pair doesn't exist, it's created
- *
- * @param start The start value. this will be processed and turned into an indexed value
- */
- public void setStart( String fieldName, Object start, boolean inclusive ) {
- QuerySlice slice = getOrCreateSlice( fieldName );
-
- // if the value is null don't set the range on the slice
- if ( start == null ) {
- return;
- }
-
- RangeValue existingStart = slice.getStart();
-
- Object indexedValue = toIndexableValue( start );
- byte code = indexValueCode( indexedValue );
-
- RangeValue newStart = new RangeValue( code, indexedValue, inclusive );
-
- if ( existingStart == null ) {
- slice.setStart( newStart );
- return;
- }
-
- // check if we're before the currently set start in this
- // context. If so set the value to increase the range scan size;
- if ( existingStart != null && newStart == null || ( existingStart != null
- && existingStart.compareTo( newStart, false ) < 0 ) ) {
- slice.setStart( newStart );
- }
- }
-
-
- /** Set the finish. If finish value is greater than the existing, I.E. null or higher comparison, then */
- public void setFinish( String fieldName, Object finish, boolean inclusive ) {
- QuerySlice slice = getOrCreateSlice( fieldName );
-
- // if the value is null don't set the range on the slice
- if ( finish == null ) {
- return;
- }
-
- RangeValue existingFinish = slice.getFinish();
-
- Object indexedValue = toIndexableValue( finish );
- byte code = indexValueCode( indexedValue );
-
- RangeValue newFinish = new RangeValue( code, indexedValue, inclusive );
-
- if ( existingFinish == null ) {
- slice.setFinish( newFinish );
- return;
- }
-
- // check if we're before the currently set start in this
- // context. If so set the value to increase the range scan size;
- if ( existingFinish != null && newFinish == null || ( existingFinish != null
- && existingFinish.compareTo( newFinish, false ) < 0 ) ) {
- slice.setFinish( newFinish );
- }
- }
-
-
- /** Lazy instanciate a field pair if required. Otherwise return the existing pair */
- private QuerySlice getOrCreateSlice( String fieldName ) {
- QuerySlice pair = this.pairs.get( fieldName );
-
- if ( pair == null ) {
- pair = new QuerySlice( fieldName, id );
- this.pairs.put( fieldName, pair );
- }
-
- return pair;
- }
-
-
- /** Get the slice by field name if it exists. Null otherwise */
- public QuerySlice getSlice( String fieldName ) {
- return this.pairs.get( fieldName );
- }
-
-
- /** Get all slices in our context */
- public Collection<QuerySlice> getAllSlices() {
- return this.pairs.values();
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.QueryNode#visit(org.apache.usergrid.persistence
- * .query.ir.NodeVisitor)
- */
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- @Override
- public String toString() {
- return "SliceNode [pairs=" + pairs + ", id=" + id + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/UuidIdentifierNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/UuidIdentifierNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/UuidIdentifierNode.java
deleted file mode 100644
index 79a6217..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/UuidIdentifierNode.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.query.ir;
-
-
-import java.util.UUID;
-
-
-/**
- * Class to represent a UUID based Identifier query
- *
- * @author tnine
- */
-public class UuidIdentifierNode extends QueryNode {
-
-
- private final UUID uuid;
-
-
- public UuidIdentifierNode( UUID uuid ) {
- this.uuid = uuid;
- }
-
-
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- @Override
- public int getCount() {
- return 1;
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- public UUID getUuid() {
- return uuid;
- }
-}