You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/26 20:20:52 UTC
[05/13] Put queryindex classes all under one top-level "index"
package to eliminate conflict with old persistence classes.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java
deleted file mode 100644
index 518e39f..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/FloatLiteral.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class FloatLiteral extends Literal<Float> implements NumericLiteral {
-
- private float value;
-
-
- /**
- * @param t
- */
- public FloatLiteral( Token t ) {
- super( t );
- value = Float.valueOf( t.getText() );
- }
-
-
- public FloatLiteral( float f ) {
- super( new ClassicToken( 0, String.valueOf( f ) ) );
- value = f;
- }
-
-
- /** @return the value */
- public Float getValue() {
- return value;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
- */
- @Override
- public float getFloatValue() {
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java
deleted file mode 100644
index 966fbb2..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThan.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class GreaterThan extends EqualityOperand {
-
- /**
- * @param property
- * @param literal
- */
- public GreaterThan( Token t ) {
- super( t );
- }
-
-
- public GreaterThan() {
- super( new CommonToken( 0, ">" ) );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
- * .query.tree.QueryVisitor)
- */
- @Override
- public void visit( QueryVisitor visitor ) throws NoIndexException {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java
deleted file mode 100644
index d561010..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/GreaterThanEqual.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class GreaterThanEqual extends EqualityOperand {
-
- /**
- * @param property
- * @param literal
- */
- public GreaterThanEqual( Token t ) {
- super( t );
- }
-
-
- /**
- * @param property
- * @param literal
- */
- public GreaterThanEqual() {
- super( new CommonToken( 0, ">=" ) );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
- * .query.tree.QueryVisitor)
- */
- @Override
- public void visit( QueryVisitor visitor ) throws NoIndexException {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java
deleted file mode 100644
index 008abf5..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThan.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class LessThan extends EqualityOperand {
-
- /**
- * @param property
- * @param literal
- */
- public LessThan( Token t ) {
- super( t );
- }
-
-
- public LessThan() {
- super( new CommonToken( 0, "<" ) );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
- * .query.tree.QueryVisitor)
- */
- @Override
- public void visit( QueryVisitor visitor ) throws NoIndexException {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java
deleted file mode 100644
index 1ea5d81..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LessThanEqual.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-
-
-/** @author tnine */
-public class LessThanEqual extends EqualityOperand {
-
- /**
- * @param property
- * @param literal
- */
- public LessThanEqual( Token t ) {
- super( t );
- }
-
-
- /**
- */
- public LessThanEqual() {
- super( new CommonToken( 0, "<=" ) );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
- * .query.tree.QueryVisitor)
- */
- @Override
- public void visit( QueryVisitor visitor ) throws NoIndexException {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java
deleted file mode 100644
index acd9ac4..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Literal.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-import org.antlr.runtime.tree.CommonTree;
-
-
-/**
- * Abstract class for literals
- *
- * @author tnine
- */
-public abstract class Literal<V> extends CommonTree {
-
-
- protected Literal( Token t ) {
- super( t );
- }
-
-
- /** Return the value of the literal the user has passed in */
- public abstract V getValue();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java
deleted file mode 100644
index 2895797..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LiteralFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import java.util.UUID;
-
-
-/**
- * Simple factory for generating literal instance based on the runtime value
- *
- * @author tnine
- */
-public class LiteralFactory {
-
- /** Generate the correct literal subclass based on the runtime instance. */
- public static final Literal<?> getLiteral( Object value ) {
- if ( value instanceof Integer ) {
- return new LongLiteral( ( Integer ) value );
- }
- if ( value instanceof Long ) {
- return new LongLiteral( ( Long ) value );
- }
-
- if ( value instanceof String ) {
- return new StringLiteral( ( String ) value );
- }
-
- if ( value instanceof Float ) {
- return new FloatLiteral( ( Float ) value );
- }
-
- if ( value instanceof UUID ) {
- return new UUIDLiteral( ( UUID ) value );
- }
-
- if ( value instanceof Boolean ) {
- return new BooleanLiteral( ( Boolean ) value );
- }
-
- throw new UnsupportedOperationException(
- String.format( "Unsupported type of %s was passed when trying to construct a literal",
- value.getClass() ) );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java
deleted file mode 100644
index 609e11c..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/LongLiteral.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class LongLiteral extends Literal<Long> implements NumericLiteral {
-
- private long value;
-
-
- /**
- * @param t
- */
- public LongLiteral( Token t ) {
- super( t );
- this.value = Long.valueOf( t.getText() );
- }
-
-
- /**
- *
- * @param value
- */
- public LongLiteral( long value ) {
- super( new ClassicToken( 0, String.valueOf( value ) ) );
- this.value = value;
- }
-
-
- /**
- *
- * @return
- */
- public Long getValue() {
- return this.value;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
- */
- @Override
- public float getFloatValue() {
- return value;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java
deleted file mode 100644
index 8388e5d..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NotOperand.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.
- ******************************************************************************/
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/** @author tnine */
-public class NotOperand extends Operand {
-
-
- public NotOperand( Token t ) {
- super( t );
- }
-
-
- /** get the only child operation */
- public Operand getOperation() {
- return ( Operand ) this.children.get( 0 );
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence.query.tree.QueryVisitor)
- */
- @Override
- public void visit( QueryVisitor visitor ) throws PersistenceException {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java
deleted file mode 100644
index 9ec5b0c..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/NumericLiteral.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-/** @author tnine */
-public interface NumericLiteral {
-
- /** Return the value of this numeric literal as a float */
- public float getFloatValue();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java
deleted file mode 100644
index d3f5791..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Operand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-import org.antlr.runtime.tree.CommonTree;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/**
- * Any logical operation should subclass. Boolean logic, equality, not, contains, within and others are examples of
- * operands
- *
- * @author tnine
- */
-public abstract class Operand extends CommonTree {
-
-
- /** Default constructor to take a token */
- public Operand( Token t ) {
- super( t );
- }
-
-
- /** Get the pointer to the parent node */
- public Operand getParent() {
- return ( Operand ) super.getParent();
- }
-
-
- /** Visitor method */
- public abstract void visit( QueryVisitor visitor ) throws PersistenceException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java
deleted file mode 100644
index 279c0f1..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/OrOperand.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-
-
-/** @author tnine */
-public class OrOperand extends BooleanOperand {
-
- /**
- * @param left
- * @param token
- * @param right
- */
- public OrOperand( Token t ) {
- super( t );
- }
-
-
- public OrOperand() {
- super( new CommonToken( 0, "or" ) );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
- * .query.tree.QueryVisitor)
- */
- @Override
- public void visit( QueryVisitor visitor ) throws PersistenceException {
- visitor.visit( this );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java
deleted file mode 100644
index dee3d91..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/Property.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/**
- * A property
- *
- * @author tnine
- */
-public class Property extends Literal<String> {
-
- private String property;
-
-
- public Property( Token t ) {
- super( t );
- this.property = t.getText();
- }
-
-
- public Property( String property ) {
- this( new ClassicToken( 0, property ) );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.tree.Literal#getValue()
- */
- @Override
- public String getValue() {
- return this.property;
- }
-
-
- /**
- * Subclasses an override. Indexed value could be different when stored internally. By default returns the same
- * property
- */
- public String getIndexedValue() {
- return this.property;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java
deleted file mode 100644
index 888f1cf..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/QueryVisitor.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.apache.usergrid.persistence.exceptions.NoFullTextIndexException;
-import org.apache.usergrid.persistence.exceptions.NoIndexException;
-import org.apache.usergrid.persistence.exceptions.PersistenceException;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-
-
-/**
- * Interface for visiting nodes in our AST as we produce
- *
- * @author tnine
- */
-public interface QueryVisitor {
-
- /**
- *
- * @param op
- * @throws PersistenceException
- */
- public void visit( AndOperand op ) throws PersistenceException;
-
- /**
- * @param op
- * @throws PersistenceException
- */
- public void visit( OrOperand op ) throws PersistenceException;
-
- /**
- * @param op
- * @throws PersistenceException
- */
- public void visit( NotOperand op ) throws PersistenceException;
-
- /**
- * @param op
- * @throws NoIndexException
- */
- public void visit( LessThan op ) throws NoIndexException;
-
- /**
- * @param op
- * @throws NoFullTextIndexException
- */
- public void visit( ContainsOperand op ) throws NoFullTextIndexException;
-
- /**
- * @param op
- */
- public void visit( WithinOperand op );
-
- /**
- * @param op
- * @throws NoIndexException
- */
- public void visit( LessThanEqual op ) throws NoIndexException;
-
- /**
- * @param op
- * @throws NoIndexException
- */
- public void visit( Equal op ) throws NoIndexException;
-
- /**
- * @param op
- * @throws NoIndexException
- */
- public void visit( GreaterThan op ) throws NoIndexException;
-
- /**
- * @param op
- * @throws NoIndexException
- */
- public void visit( GreaterThanEqual op ) throws NoIndexException;
-
- /**
- * Returns resulting query builder.
- */
- public QueryBuilder getQueryBuilder();
-
- public FilterBuilder getFilterBuilder();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java
deleted file mode 100644
index 982cb8a..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/StringLiteral.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-import static org.apache.commons.lang.StringUtils.removeEnd;
-
-
-/** @author tnine */
-public class StringLiteral extends Literal<String> {
-
- private String value;
- private String finishValue;
-
-
- /**
- * @param t
- */
- public StringLiteral( Token t ) {
- super( t );
- String newValue = t.getText();
- newValue = newValue.substring( 1, newValue.length() - 1 );
-
- parseValue( newValue );
- }
-
-
- public StringLiteral( String value ) {
- super( new ClassicToken( 0, value ) );
- parseValue( value );
- }
-
-
- /** Parse the value and set the optional end value */
- private void parseValue( String value ) {
-
- this.value = value.trim().toLowerCase();
-
- if ( "*".equals( value ) ) {
- this.value = null;
- this.finishValue = null;
- return;
- }
-
- if ( value != null && value.endsWith( "*" ) ) {
- this.value = removeEnd( value.toString(), "*" );
-
- finishValue = this.value + "\uFFFF";
- }
- // set the end value to the same as the start value
- else {
- finishValue = value;
- }
- }
-
-
- /** If this were a string literal */
- public String getEndValue() {
- return this.finishValue;
- }
-
-
- public String getValue() {
- return this.value;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java
deleted file mode 100644
index 1b60540..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/UUIDLiteral.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import java.util.UUID;
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class UUIDLiteral extends Literal<UUID> {
-
- private UUID value;
-
-
- /**
- * @param t
- */
- public UUIDLiteral( Token t ) {
- super( t );
- value = UUID.fromString( t.getText() );
- }
-
-
- public UUIDLiteral( UUID value ) {
- super( new ClassicToken( 0, String.valueOf( value ) ) );
- this.value = value;
- }
-
-
- public UUID getValue() {
- return this.value;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java
deleted file mode 100644
index debf07c..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinOperand.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * 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.
- ******************************************************************************/
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.Token;
-
-
-/** @author tnine */
-public class WithinOperand extends Operand {
-
- /**
- * @param property
- * @param literal
- */
- public WithinOperand( Token t ) {
- super( t );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
- * .query.tree.QueryVisitor)
- */
- @Override
- public void visit( QueryVisitor visitor ) {
- visitor.visit( this );
- }
-
-
- /**
- * @param propName
- */
- public void setProperty( String propName ) {
- setChild( 0, new WithinProperty( propName ) );
- }
-
-
- /**
- * @param distance
- */
- public void setDistance( float distance ) {
- setChild( 1, new FloatLiteral( distance ) );
- }
-
-
- /**
- * @param Latitude
- */
- public void setLatitude( float Latitude ) {
- setChild( 2, new FloatLiteral( Latitude ) );
- }
-
-
- /**
- * @param longitude
- */
- public void setLongitude( float longitude ) {
- setChild( 3, new FloatLiteral( longitude ) );
- }
-
-
- /**
- *
- * @return
- */
- public WithinProperty getProperty() {
- return ( WithinProperty ) this.children.get( 0 );
- }
-
-
- /**
- *
- * @return
- */
- public NumericLiteral getDistance() {
- return ( NumericLiteral ) this.children.get( 1 );
- }
-
-
- /**
- * @return
- */
- public NumericLiteral getLatitude() {
- return ( NumericLiteral ) this.children.get( 2 );
- }
-
-
- /**
- * @return
- */
- public NumericLiteral getLongitude() {
- return ( NumericLiteral ) this.children.get( 3 );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java
deleted file mode 100644
index 2707e77..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/tree/WithinProperty.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.query.tree;
-
-
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.Token;
-
-
-/**
- * A property
- *
- * @author tnine
- */
-public class WithinProperty extends Property {
-
- private String indexedName = null;
-
-
- public WithinProperty( Token t ) {
- super( t );
- this.indexedName = String.format( "%s.coordinates", super.getValue() );
- }
-
-
- public WithinProperty( String property ) {
- this( new ClassicToken( 0, property ) );
- }
-
-
- /** Get the */
- public String getIndexedName() {
- return this.indexedName;
- }
-
-
- /** @return the property */
- public WithinProperty getProperty() {
- return ( WithinProperty ) this.children.get( 0 );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.java
deleted file mode 100644
index 6ce847e..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ClassUtils.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.utils;
-
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-
-public class ClassUtils extends org.apache.commons.lang.ClassUtils {
-
- @SuppressWarnings("unchecked")
- public static <A, B> B cast( A a ) {
- return ( B ) a;
- }
-
-
- @SuppressWarnings("unchecked")
- private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>(
- Arrays.asList( Boolean.class, Byte.class, Character.class, Double.class, Float.class, Integer.class,
- Long.class, Short.class, Void.class ) );
-
-
- public static boolean isWrapperType( Class<?> clazz ) {
- return WRAPPER_TYPES.contains( clazz );
- }
-
-
- public static boolean isPrimitiveType( Class<?> clazz ) {
- if ( clazz == null ) {
- return false;
- }
- return clazz.isPrimitive() || isWrapperType( clazz );
- }
-
-
- public static boolean isBasicType( Class<?> clazz ) {
- if ( clazz == null ) {
- return false;
- }
- return ( String.class.isAssignableFrom( clazz ) ) || isPrimitiveType( clazz );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java
deleted file mode 100644
index 567a713..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/ConversionUtils.java
+++ /dev/null
@@ -1,765 +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.utils;
-
-
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.lang.math.NumberUtils;
-
-
-/** Convenience methods for converting to and from formats, primarily between byte arrays and UUIDs, Strings,
- * and Longs. */
-public class ConversionUtils {
-
- private static final Logger logger = LoggerFactory.getLogger( ConversionUtils.class );
-
- /**
- *
- */
- public static final String UTF8_ENCODING = "UTF-8";
-
- /**
- *
- */
- public static final String ASCII_ENCODING = "US-ASCII";
-
- public static final ByteBuffer HOLDER = ByteBuffer.wrap( new byte[] { 0 } );
-
-
- /**
- * @param uuid
- * @return
- */
- public static UUID uuid( byte[] uuid ) {
- return uuid( uuid, 0 );
- }
-
-
- /**
- * @param uuid
- * @param offset
- * @return
- */
- public static UUID uuid( byte[] uuid, int offset ) {
- ByteBuffer bb = ByteBuffer.wrap( uuid, offset, 16 );
- return new UUID( bb.getLong(), bb.getLong() );
- }
-
-
- public static UUID uuid( ByteBuffer bb ) {
- if ( bb == null ) {
- return null;
- }
- if ( bb.remaining() < 16 ) {
- return null;
- }
- bb = bb.slice();
- return new UUID( bb.getLong(), bb.getLong() );
- }
-
-
- /**
- * @param uuid
- * @return
- */
- public static UUID uuid( String uuid ) {
- try {
- return UUID.fromString( uuid );
- }
- catch ( Exception e ) {
- logger.error( "Bad UUID", e );
- }
- return UUIDUtils.ZERO_UUID;
- }
-
-
- /**
- * @param obj
- * @return
- */
- public static UUID uuid( Object obj ) {
- return uuid( obj, UUIDUtils.ZERO_UUID );
- }
-
-
- public static UUID uuid( Object obj, UUID defaultValue ) {
- if ( obj instanceof UUID ) {
- return ( UUID ) obj;
- }
- else if ( obj instanceof byte[] ) {
- return uuid( ( byte[] ) obj );
- }
- else if ( obj instanceof ByteBuffer ) {
- return uuid( ( ByteBuffer ) obj );
- }
- else if ( obj instanceof String ) {
- return uuid( ( String ) obj );
- }
- return defaultValue;
- }
-
-
- /**
- * @param uuid
- * @return
- */
- public static byte[] bytes( UUID uuid ) {
- if ( uuid == null ) {
- return null;
- }
- long msb = uuid.getMostSignificantBits();
- long lsb = uuid.getLeastSignificantBits();
- byte[] buffer = new byte[16];
-
- for ( int i = 0; i < 8; i++ ) {
- buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) );
- }
- for ( int i = 8; i < 16; i++ ) {
- buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) );
- }
-
- return buffer;
- }
-
-
- public static ByteBuffer bytebuffer( UUID uuid ) {
- if ( uuid == null ) {
- return null;
- }
- return ByteBuffer.wrap( bytes( uuid ) );
- }
-
-
- /**
- * @param uuid
- * @return
- */
- public static byte[] uuidToBytesNullOk( UUID uuid ) {
- if ( uuid != null ) {
- return bytes( uuid );
- }
- return new byte[16];
- }
-
-
- /**
- * @param s
- * @return
- */
- public static byte[] bytes( String s ) {
- return bytes( s, UTF8_ENCODING );
- }
-
-
- public static ByteBuffer bytebuffer( String s ) {
- return ByteBuffer.wrap( bytes( s ) );
- }
-
-
- /**
- * @param s
- * @return
- */
- public static byte[] ascii( String s ) {
- if ( s == null ) {
- return new byte[0];
- }
- return bytes( s, ASCII_ENCODING );
- }
-
-
- public ByteBuffer asciibuffer( String s ) {
- return ByteBuffer.wrap( ascii( s ) );
- }
-
-
- /**
- * @param s
- * @param encoding
- * @return
- */
- public static byte[] bytes( String s, String encoding ) {
- try {
- return s.getBytes( encoding );
- }
- catch ( UnsupportedEncodingException e ) {
- // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
- throw new RuntimeException( e );
- }
- }
-
-
- public static byte[] bytes( ByteBuffer bb ) {
- byte[] b = new byte[bb.remaining()];
- bb.duplicate().get( b );
- return b;
- }
-
-
- public static ByteBuffer bytebuffer( String s, String encoding ) {
- return ByteBuffer.wrap( bytes( s, encoding ) );
- }
-
-
- /**
- * @param b
- * @return
- */
- public static byte[] bytes( Boolean b ) {
- byte[] bytes = new byte[1];
- bytes[0] = b ? ( byte ) 1 : 0;
- return bytes;
- }
-
-
- public static ByteBuffer bytebuffer( Boolean b ) {
- return ByteBuffer.wrap( bytes( b ) );
- }
-
-
- /**
- * @param val
- * @return
- */
- public static byte[] bytes( Long val ) {
- ByteBuffer buf = ByteBuffer.allocate( 8 );
- buf.order( ByteOrder.BIG_ENDIAN );
- buf.putLong( val );
- return buf.array();
- }
-
-
- public static ByteBuffer bytebuffer( Long val ) {
- ByteBuffer buf = ByteBuffer.allocate( 8 );
- buf.order( ByteOrder.BIG_ENDIAN );
- buf.putLong( val );
- return ( ByteBuffer ) buf.rewind();
- }
-
-
- /**
- * @param obj
- * @return
- */
- public static byte[] bytes( Object obj ) {
- if ( obj == null ) {
- return new byte[0];
- }
- else if ( obj instanceof byte[] ) {
- return ( byte[] ) obj;
- }
- else if ( obj instanceof Long ) {
- return bytes( ( Long ) obj );
- }
- else if ( obj instanceof String ) {
- return bytes( ( String ) obj );
- }
- else if ( obj instanceof UUID ) {
- return bytes( ( UUID ) obj );
- }
- else if ( obj instanceof Boolean ) {
- return bytes( ( Boolean ) obj );
- }
- else if ( obj instanceof Date ) {
- return bytes( ( ( Date ) obj ).getTime() );
- }
- else {
- return bytes( obj.toString() );
- }
- }
-
-
- public static ByteBuffer bytebuffer( byte[] bytes ) {
- return ByteBuffer.wrap( bytes );
- }
-
-
- public static ByteBuffer bytebuffer( ByteBuffer bytes ) {
- return bytes.duplicate();
- }
-
-
- public static ByteBuffer bytebuffer( Object obj ) {
- if ( obj instanceof ByteBuffer ) {
- return ( ( ByteBuffer ) obj ).duplicate();
- }
- return ByteBuffer.wrap( bytes( obj ) );
- }
-
-
- public static List<ByteBuffer> bytebuffers( List<?> l ) {
- List<ByteBuffer> results = new ArrayList<ByteBuffer>( l.size() );
- for ( Object o : l ) {
- results.add( bytebuffer( o ) );
- }
- return results;
- }
-
-
- /**
- * @param bytes
- * @return
- */
- public static boolean getBoolean( byte[] bytes ) {
- return bytes[0] != 0;
- }
-
-
- public static boolean getBoolean( ByteBuffer bytes ) {
- return bytes.slice().get() != 0;
- }
-
-
- /**
- * @param bytes
- * @param offset
- * @return
- */
- public static boolean getBoolean( byte[] bytes, int offset ) {
- return bytes[offset] != 0;
- }
-
-
- public static boolean getBoolean( Object obj ) {
- if ( obj instanceof Boolean ) {
- return ( Boolean ) obj;
- }
- else if ( obj instanceof String ) {
- return Boolean.parseBoolean( ( String ) obj );
- }
- else if ( obj instanceof Number ) {
- return ( ( Number ) obj ).longValue() > 0;
- }
-
- return false;
- }
-
-
- /**
- * @param obj
- * @return
- */
- public static String string( Object obj ) {
- if ( obj instanceof String ) {
- return ( String ) obj;
- }
- else if ( obj instanceof byte[] ) {
- return string( ( byte[] ) obj );
- }
- else if ( obj instanceof ByteBuffer ) {
- return string( ( ByteBuffer ) obj );
- }
- else if ( obj != null ) {
- return obj.toString();
- }
- return null;
- }
-
-
- /**
- * @param bytes
- * @return
- */
- public static String string( byte[] bytes ) {
- if ( bytes == null ) {
- return null;
- }
- return string( bytes, 0, bytes.length, UTF8_ENCODING );
- }
-
-
- public static String string( ByteBuffer bytes ) {
- if ( bytes == null ) {
- return null;
- }
- return string( bytes.array(), bytes.arrayOffset() + bytes.position(), bytes.remaining(), UTF8_ENCODING );
- }
-
-
- /**
- * @param bytes
- * @param offset
- * @param length
- * @return
- */
- public static String string( byte[] bytes, int offset, int length ) {
- return string( bytes, offset, length, UTF8_ENCODING );
- }
-
-
- /**
- * @param bytes
- * @param offset
- * @param length
- * @param encoding
- * @return
- */
- public static String string( byte[] bytes, int offset, int length, String encoding ) {
-
- if ( length <= 0 ) {
- return "";
- }
-
- if ( bytes == null ) {
- return "";
- }
-
- try {
- return new String( bytes, offset, length, encoding );
- }
- catch ( UnsupportedEncodingException e ) {
- // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
- throw new RuntimeException( e );
- }
- }
-
-
- public static <T> List<String> strings( Collection<T> items ) {
- List<String> strings = new ArrayList<String>();
- for ( T item : items ) {
- strings.add( string( item ) );
- }
- return strings;
- }
-
-
- /**
- * @param bytes
- * @param offset
- * @return
- */
- public static String stringFromLong( byte[] bytes, int offset ) {
- if ( bytes.length == 0 ) {
- return "";
- }
- if ( ( bytes.length - offset ) < 8 ) {
- throw new IllegalArgumentException( "A long is at least 8 bytes" );
- }
- return String.valueOf( ByteBuffer.wrap( bytes, offset, 8 ).getLong() );
- }
-
-
- /**
- * @param bytes
- * @return
- */
- public static long getLong( byte[] bytes ) {
- return ByteBuffer.wrap( bytes, 0, 8 ).getLong();
- }
-
-
- public static long getLong( ByteBuffer bytes ) {
- return bytes.slice().getLong();
- }
-
-
- public static long getLong( Object obj ) {
- if ( obj instanceof Long ) {
- return ( Long ) obj;
- }
- if ( obj instanceof Number ) {
- return ( ( Number ) obj ).longValue();
- }
- if ( obj instanceof String ) {
- return NumberUtils.toLong( ( String ) obj );
- }
- if ( obj instanceof Date ) {
- return ( ( Date ) obj ).getTime();
- }
- if ( obj instanceof byte[] ) {
- return getLong( ( byte[] ) obj );
- }
- if ( obj instanceof ByteBuffer ) {
- return getLong( ( ByteBuffer ) obj );
- }
- return 0;
- }
-
-
- /**
- * @param bytes
- * @return
- */
- public static int getInt( byte[] bytes ) {
- return ByteBuffer.wrap( bytes, 0, 4 ).getInt();
- }
-
-
- public static int getInt( ByteBuffer bytes ) {
- return bytes.slice().getInt();
- }
-
-
- public static int getInt( Object obj ) {
- if ( obj instanceof Integer ) {
- return ( Integer ) obj;
- }
- if ( obj instanceof Number ) {
- return ( ( Number ) obj ).intValue();
- }
- if ( obj instanceof String ) {
- return NumberUtils.toInt( ( String ) obj );
- }
- if ( obj instanceof Date ) {
- return ( int ) ( ( Date ) obj ).getTime();
- }
- if ( obj instanceof byte[] ) {
- return getInt( ( byte[] ) obj );
- }
- if ( obj instanceof ByteBuffer ) {
- return getInt( ( ByteBuffer ) obj );
- }
- return 0;
- }
-
-
- /**
- * @param bytes
- * @return
- */
- public static float getFloat( byte[] bytes ) {
- return ByteBuffer.wrap( bytes, 0, 4 ).getFloat();
- }
-
-
- public static float getFloat( ByteBuffer bytes ) {
- return bytes.slice().getFloat();
- }
-
-
- public static float getFloat( Object obj ) {
- if ( obj instanceof Float ) {
- return ( Float ) obj;
- }
- if ( obj instanceof Number ) {
- return ( ( Number ) obj ).floatValue();
- }
- if ( obj instanceof String ) {
- return NumberUtils.toFloat( ( String ) obj );
- }
- if ( obj instanceof Date ) {
- return ( ( Date ) obj ).getTime();
- }
- if ( obj instanceof byte[] ) {
- return getFloat( ( byte[] ) obj );
- }
- if ( obj instanceof ByteBuffer ) {
- return getFloat( ( ByteBuffer ) obj );
- }
- return 0;
- }
-
-
- public static double getDouble( byte[] bytes ) {
- return ByteBuffer.wrap( bytes, 0, 8 ).getDouble();
- }
-
-
- public static double getDouble( ByteBuffer bytes ) {
- return bytes.slice().getDouble();
- }
-
-
- public static double getDouble( Object obj ) {
- if ( obj instanceof Double ) {
- return ( Double ) obj;
- }
- if ( obj instanceof Number ) {
- return ( ( Number ) obj ).doubleValue();
- }
- if ( obj instanceof String ) {
- return NumberUtils.toDouble( ( String ) obj );
- }
- if ( obj instanceof Date ) {
- return ( ( Date ) obj ).getTime();
- }
- if ( obj instanceof byte[] ) {
- return getDouble( ( byte[] ) obj );
- }
- if ( obj instanceof ByteBuffer ) {
- return getDouble( ( ByteBuffer ) obj );
- }
- return 0;
- }
-
-
- /**
- * @param type
- * @param bytes
- * @return
- */
- public static Object object( Class<?> type, byte[] bytes ) {
-
- try {
- if ( Long.class.isAssignableFrom( type ) ) {
- return getLong( bytes );
- }
- else if ( UUID.class.isAssignableFrom( type ) ) {
- return uuid( bytes );
- }
- else if ( String.class.isAssignableFrom( type ) ) {
- return string( bytes );
- }
- else if ( Boolean.class.isAssignableFrom( type ) ) {
- return getBoolean( bytes );
- }
- else if ( Integer.class.isAssignableFrom( type ) ) {
- return getInt( bytes );
- }
- else if ( Double.class.isAssignableFrom( type ) ) {
- return getDouble( bytes );
- }
- else if ( Float.class.isAssignableFrom( type ) ) {
- return getFloat( bytes );
- }
- else if ( byte[].class.isAssignableFrom( type ) ) {
- return bytes;
- }
- }
- catch ( Exception e ) {
- logger.error( "Unable to get object from bytes for type " + type.getName(), e );
- }
- return null;
- }
-
-
- public static Object object( Class<?> type, ByteBuffer bytes ) {
-
- try {
- if ( Long.class.isAssignableFrom( type ) ) {
- return bytes.slice().getLong();
- }
- else if ( UUID.class.isAssignableFrom( type ) ) {
- return uuid( bytes );
- }
- else if ( String.class.isAssignableFrom( type ) ) {
- return string( bytes );
- }
- else if ( Boolean.class.isAssignableFrom( type ) ) {
- return bytes.slice().get() != 0;
- }
- else if ( Integer.class.isAssignableFrom( type ) ) {
- return bytes.slice().getInt();
- }
- else if ( Double.class.isAssignableFrom( type ) ) {
- return bytes.slice().getDouble();
- }
- else if ( Float.class.isAssignableFrom( type ) ) {
- return bytes.slice().getFloat();
- }
- else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
- return bytes.duplicate();
- }
- else if ( byte[].class.isAssignableFrom( type ) ) {
- byte[] b = new byte[bytes.remaining()];
- bytes.slice().get( b );
- return b;
- }
- }
- catch ( Exception e ) {
- logger.error( "Unable to get object from bytes for type " + type.getName(), e );
- }
- return null;
- }
-
-
- /**
- * @param bb
- * @param bytes
- * @param len
- * @return
- */
- public static ByteBuffer appendToByteBuffer( ByteBuffer bb, byte[] bytes, int len ) {
- if ( len > bytes.length ) {
- int pos = bb.position();
- bb.put( bytes );
- bb.position( pos + len );
- }
- else {
- bb.put( bytes, 0, len );
- }
- return bb;
- }
-
-
- public static Object coerce( Class<?> type, Object obj ) {
-
- if ( obj == null ) {
- return null;
- }
-
- if ( type == null ) {
- return obj;
- }
-
- try {
- if ( Long.class.isAssignableFrom( type ) ) {
- return getLong( obj );
- }
- else if ( UUID.class.isAssignableFrom( type ) ) {
- return uuid( obj );
- }
- else if ( String.class.isAssignableFrom( type ) ) {
- return string( obj );
- }
- else if ( Boolean.class.isAssignableFrom( type ) ) {
- return getBoolean( obj );
- }
- else if ( Integer.class.isAssignableFrom( type ) ) {
- return getInt( obj );
- }
- else if ( Double.class.isAssignableFrom( type ) ) {
- return getDouble( obj );
- }
- else if ( Float.class.isAssignableFrom( type ) ) {
- return getFloat( obj );
- }
- else if ( byte[].class.isAssignableFrom( type ) ) {
- return bytes( obj );
- }
- else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
- return bytebuffer( obj );
- }
- }
- catch ( Exception e ) {
- logger.error( "Unable to get object from bytes for type " + type.getName(), e );
- }
- return null;
- }
-
-
- public static Map<String, Object> coerceMap( Map<String, Class<?>> types, Map<String, Object> values ) {
- for ( Map.Entry<String, Object> entry : values.entrySet() ) {
- if ( types.containsKey( entry.getKey() ) ) {
- values.put( entry.getKey(), coerce( types.get( entry.getKey() ), entry.getValue() ) );
- }
- }
- return values;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java
deleted file mode 100644
index c9e1c84..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/EntityBuilder.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-
-package org.apache.usergrid.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.field.BooleanField;
-import org.apache.usergrid.persistence.model.field.DoubleField;
-import org.apache.usergrid.persistence.model.field.EntityObjectField;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.apache.usergrid.persistence.model.field.FloatField;
-import org.apache.usergrid.persistence.model.field.IntegerField;
-import org.apache.usergrid.persistence.model.field.ListField;
-import org.apache.usergrid.persistence.model.field.LocationField;
-import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.field.value.Location;
-
-
-public class EntityBuilder {
-
- public static Entity fromMap( String scope, Map<String, Object> item ) {
- return fromMap( scope, null, item );
- }
-
- public static Entity fromMap( String scope, Entity entity, Map<String, Object> map ) {
-
- if ( entity == null ) {
- entity = new Entity();
- }
-
- for ( String fieldName : map.keySet() ) {
-
- Object value = map.get( fieldName );
-
- if ( value instanceof String ) {
- entity.setField( new StringField( fieldName, (String)value ));
-
- } else if ( value instanceof Boolean ) {
- entity.setField( new BooleanField( fieldName, (Boolean)value ));
-
- } else if ( value instanceof Integer ) {
- entity.setField( new IntegerField( fieldName, (Integer)value ));
-
- } else if ( value instanceof Double ) {
- entity.setField( new DoubleField( fieldName, (Double)value ));
-
- } else if ( value instanceof Float ) {
- entity.setField( new FloatField( fieldName, (Float)value ));
-
- } else if ( value instanceof Long ) {
- entity.setField( new LongField( fieldName, (Long)value ));
-
- } else if ( value instanceof List) {
- entity.setField( listToListField( scope, fieldName, (List)value ));
-
- } else if ( value instanceof Map ) {
-
- Field field = null;
-
- // is the map really a location element?
- Map<String, Object> m = (Map<String, Object>)value;
- if ( m.size() == 2) {
- Double lat = null;
- Double lon = null;
- try {
- if ( m.get("latitude") != null && m.get("longitude") != null ) {
- lat = Double.parseDouble( m.get("latitude").toString() );
- lon = Double.parseDouble( m.get("longitude").toString() );
-
- } else if ( m.get("lat") != null && m.get("lon") != null ) {
- lat = Double.parseDouble( m.get("lat").toString() );
- lon = Double.parseDouble( m.get("lon").toString() );
- }
- } catch ( NumberFormatException ignored ) {}
-
- if ( lat != null && lon != null ) {
- field = new LocationField( fieldName, new Location( lat, lon ));
- }
- }
-
- if ( field == null ) {
-
- // not a location element, process it as map
- entity.setField( new EntityObjectField( fieldName,
- fromMap( scope, (Map<String, Object>)value ))); // recursion
-
- } else {
- entity.setField( field );
- }
-
- } else {
- throw new RuntimeException("Unknown type " + value.getClass().getName());
- }
- }
-
- return entity;
- }
-
-
- private static ListField listToListField( String scope, String fieldName, List list ) {
-
- if (list.isEmpty()) {
- return new ListField( fieldName );
- }
-
- Object sample = list.get(0);
-
- if ( sample instanceof Map ) {
- return new ListField<Entity>( fieldName, processListForField( scope, list ));
-
- } else if ( sample instanceof List ) {
- return new ListField<List>( fieldName, processListForField( scope, list ));
-
- } else if ( sample instanceof String ) {
- return new ListField<String>( fieldName, (List<String>)list );
-
- } else if ( sample instanceof Boolean ) {
- return new ListField<Boolean>( fieldName, (List<Boolean>)list );
-
- } else if ( sample instanceof Integer ) {
- return new ListField<Integer>( fieldName, (List<Integer>)list );
-
- } else if ( sample instanceof Double ) {
- return new ListField<Double>( fieldName, (List<Double>)list );
-
- } else if ( sample instanceof Long ) {
- return new ListField<Long>( fieldName, (List<Long>)list );
-
- } else {
- throw new RuntimeException("Unknown type " + sample.getClass().getName());
- }
- }
-
-
- private static List processListForField( String scope, List list ) {
- if ( list.isEmpty() ) {
- return list;
- }
- Object sample = list.get(0);
-
- if ( sample instanceof Map ) {
- List<Entity> newList = new ArrayList<Entity>();
- for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
- newList.add( fromMap( scope, map ) );
- }
- return newList;
-
- } else if ( sample instanceof List ) {
- return processListForField( scope, list ); // recursion
-
- } else {
- return list;
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2809a67d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java
deleted file mode 100644
index 4b3e40d..0000000
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/utils/JsonUtils.java
+++ /dev/null
@@ -1,329 +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.utils;
-
-
-import java.io.File;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.exceptions.JsonReadException;
-import org.apache.usergrid.persistence.exceptions.JsonWriteException;
-//import org.apache.usergrid.persistence.Entity;
-
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.io.JsonStringEncoder;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig.Feature;
-import org.codehaus.jackson.smile.SmileFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.commons.lang.StringUtils.substringAfter;
-
-import static org.apache.usergrid.utils.StringUtils.stringOrSubstringBeforeFirst;
-
-
-public class JsonUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger( JsonUtils.class );
-
- static ObjectMapper mapper = new ObjectMapper();
-
- static SmileFactory smile = new SmileFactory();
-
- static ObjectMapper smileMapper = new ObjectMapper( smile );
-
- private static ObjectMapper indentObjectMapper = new ObjectMapper();
-
-
- static {
- indentObjectMapper.getSerializationConfig().set( Feature.INDENT_OUTPUT, true );
- }
-
-
- /** Converts object to JSON string, throws runtime exception JsonWriteException on failure. */
- public static String mapToJsonString( Object obj ) {
- try {
- return mapper.writeValueAsString( obj );
- }
- catch ( Throwable t ) {
- LOG.debug( "Error generating JSON", t );
- throw new JsonWriteException( "Error generating JSON", t );
- }
- }
-
-
- /** Converts object to JSON string, throws runtime exception JsonWriteException on failure. */
- public static String mapToFormattedJsonString( Object obj ) {
- try {
- return indentObjectMapper.writeValueAsString( obj );
- }
- catch ( Throwable t ) {
- LOG.debug( "Error generating JSON", t );
- throw new JsonWriteException( "Error generating JSON", t );
- }
- }
-
-
- /** Parses JSON string and returns object, throws runtime exception JsonReadException on failure. */
- public static Object parse( String json ) {
- try {
- return mapper.readValue( json, Object.class );
- }
- catch ( Throwable t ) {
- LOG.debug( "Error parsing JSON", t );
- throw new JsonReadException( "Error parsing JSON", t );
- }
- }
-
-
- public static String quoteString( String s ) {
- JsonStringEncoder encoder = new JsonStringEncoder();
- return new String( encoder.quoteAsUTF8( s ) );
- }
-
-
- public static ByteBuffer toByteBuffer( Object obj ) {
- if ( obj == null ) {
- return null;
- }
-
- byte[] bytes = null;
- try {
- bytes = smileMapper.writeValueAsBytes( obj );
- }
- catch ( Exception e ) {
- LOG.error( "Error getting SMILE bytes", e );
- }
- if ( bytes != null ) {
- return ByteBuffer.wrap( bytes );
- }
- return null;
- }
-
-
- public static Object fromByteBuffer( ByteBuffer byteBuffer ) {
- return fromByteBuffer( byteBuffer, Object.class );
- }
-
-
- public static Object fromByteBuffer( ByteBuffer byteBuffer, Class<?> clazz ) {
- if ( ( byteBuffer == null ) || !byteBuffer.hasRemaining() ) {
- return null;
- }
- if ( clazz == null ) {
- clazz = Object.class;
- }
-
- Object obj = null;
- try {
- obj = smileMapper.readValue( byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(),
- byteBuffer.remaining(), clazz );
- }
- catch ( Exception e ) {
- LOG.error( "Error parsing SMILE bytes", e );
- }
- return obj;
- }
-
-
- public static JsonNode toJsonNode( Object obj ) {
- if ( obj == null ) {
- return null;
- }
- return mapper.convertValue( obj, JsonNode.class );
- }
-
-
- @SuppressWarnings("unchecked")
- public static Map<String, Object> toJsonMap( Object obj ) {
- if ( obj == null ) {
- return null;
- }
-
- return ( Map<String, Object> ) mapper.convertValue( obj, Map.class );
- }
-
-
- private static UUID tryConvertToUUID( Object o ) {
- if ( o instanceof String ) {
- String s = ( String ) o;
- if ( s.length() == 36 ) {
- try {
- return UUID.fromString( s );
- }
- catch ( IllegalArgumentException e ) {
- LOG.warn( "Argument to UUID.fromString({}) was invalid.", s, e );
- }
- }
- }
- return null;
- }
-
-
- public static Object normalizeJsonTree( Object obj ) {
- if ( obj instanceof Map ) {
- @SuppressWarnings("unchecked") Map<Object, Object> m = ( Map<Object, Object> ) obj;
- Object o;
- UUID uuid;
- for ( Object k : m.keySet() ) {
- if ( k instanceof String && ( ( String ) k ).equalsIgnoreCase( "name" ) ) {
- continue;
- }
-
- o = m.get( k );
- uuid = tryConvertToUUID( o );
- if ( uuid != null ) {
- m.put( k, uuid );
- }
- else if ( o instanceof Integer ) {
- m.put( k, ( ( Integer ) o ).longValue() );
- }
- else if ( o instanceof BigInteger ) {
- m.put( k, ( ( BigInteger ) o ).longValue() );
- }
- }
- }
- else if ( obj instanceof List ) {
- @SuppressWarnings("unchecked") List<Object> l = ( List<Object> ) obj;
- Object o;
- UUID uuid;
- for ( int i = 0; i < l.size(); i++ ) {
- o = l.get( i );
- uuid = tryConvertToUUID( o );
- if ( uuid != null ) {
- l.set( i, uuid );
- }
- else if ( ( o instanceof Map ) || ( o instanceof List ) ) {
- normalizeJsonTree( o );
- }
- else if ( o instanceof Integer ) {
- l.set( i, ( ( Integer ) o ).longValue() );
- }
- else if ( o instanceof BigInteger ) {
- l.set( i, ( ( BigInteger ) o ).longValue() );
- }
- }
- }
- else if ( obj instanceof String ) {
- UUID uuid = tryConvertToUUID( obj );
- if ( uuid != null ) {
- return uuid;
- }
- }
- else if ( obj instanceof Integer ) {
- return ( ( Integer ) obj ).longValue();
- }
- else if ( obj instanceof BigInteger ) {
- return ( ( BigInteger ) obj ).longValue();
- }
- else if ( obj instanceof JsonNode ) {
- return mapper.convertValue( obj, Object.class );
- }
- return obj;
- }
-
-
-// public static Object select( Object obj, String path ) {
-// return select( obj, path, false );
-// }
-//
-//
-// public static Object select( Object obj, String path, boolean buildResultTree ) {
-//
-// if ( obj == null ) {
-// return null;
-// }
-//
-// if ( org.apache.commons.lang.StringUtils.isBlank( path ) ) {
-// return obj;
-// }
-//
-// String segment = stringOrSubstringBeforeFirst( path, '.' );
-// String remaining = substringAfter( path, "." );
-//
-// if ( obj instanceof Map ) {
-// Map<?, ?> map = ( Map<?, ?> ) obj;
-// Object child = map.get( segment );
-// Object result = select( child, remaining, buildResultTree );
-// if ( result != null ) {
-// if ( buildResultTree ) {
-// Map<Object, Object> results = new LinkedHashMap<Object, Object>();
-// results.put( segment, result );
-// return results;
-// }
-// else {
-// return result;
-// }
-// }
-// return null;
-// }
-// if ( obj instanceof List ) {
-// List<Object> results = new ArrayList<Object>();
-// List<?> list = ( List<?> ) obj;
-// for ( Object i : list ) {
-// Object result = select( i, path, buildResultTree );
-// if ( result != null ) {
-// results.add( result );
-// }
-// }
-// if ( !results.isEmpty() ) {
-// return results;
-// }
-// return null;
-// }
-//
-// if ( obj instanceof Entity ) {
-// Object child = ( ( Entity ) obj ).getProperty( segment );
-// Object result = select( child, remaining, buildResultTree );
-// if ( result != null ) {
-// if ( buildResultTree ) {
-// Map<Object, Object> results = new LinkedHashMap<Object, Object>();
-// results.put( segment, result );
-// return results;
-// }
-// else {
-// return result;
-// }
-// }
-// else {
-// return result;
-// }
-// }
-//
-// return obj;
-// }
-
-
- public static Object loadFromFilesystem( String filename ) {
- Object json = null;
- try {
- File file = new File( filename );
- json = mapper.readValue( file, Object.class );
- }
- catch ( Exception e ) {
- LOG.error( "Error loading JSON", e );
- }
- return json;
- }
-}