REPO-484: Code formatting.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130645 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-09-14 13:27:05 +00:00
parent e05b5d5a0e
commit 5cf090c1f1

View File

@@ -42,57 +42,56 @@ import org.apache.commons.lang.StringUtils;
*/ */
public abstract class QueryHelper public abstract class QueryHelper
{ {
/** /**
* An interface used when walking a query tree. Calls are made to methods when the particular clause is encountered. * An interface used when walking a query tree. Calls are made to methods when the particular clause is encountered.
*/ */
public static interface WalkerCallback public static interface WalkerCallback
{ {
/** /**
* Called any time an EXISTS clause is encountered. * Called any time an EXISTS clause is encountered.
* @param propertyName Name of the property * @param propertyName Name of the property
* @param negated returns true if "NOT EXISTS" was used * @param negated returns true if "NOT EXISTS" was used
*/ */
void exists(String propertyName, boolean negated); void exists(String propertyName, boolean negated);
/** /**
* Called any time a BETWEEN clause is encountered. * Called any time a BETWEEN clause is encountered.
* @param propertyName Name of the property * @param propertyName Name of the property
* @param firstValue String * @param firstValue String
* @param secondValue String * @param secondValue String
* @param negated returns true if "NOT BETWEEN" was used * @param negated returns true if "NOT BETWEEN" was used
*/ */
void between(String propertyName, String firstValue, String secondValue, boolean negated); void between(String propertyName, String firstValue, String secondValue, boolean negated);
/** /**
* One of EQUALS LESSTHAN GREATERTHAN LESSTHANOREQUALS GREATERTHANOREQUALS; * One of EQUALS LESSTHAN GREATERTHAN LESSTHANOREQUALS GREATERTHANOREQUALS;
*/ */
void comparison(int type, String propertyName, String propertyValue, boolean negated); void comparison(int type, String propertyName, String propertyValue, boolean negated);
/** /**
* Called any time an IN clause is encountered. * Called any time an IN clause is encountered.
* @param property Name of the property * @param property Name of the property
* @param negated returns true if "NOT IN" was used * @param negated returns true if "NOT IN" was used
* @param propertyValues the property values * @param propertyValues the property values
*/ */
void in(String property, boolean negated, String... propertyValues); void in(String property, boolean negated, String... propertyValues);
/**
/** * Called any time a MATCHES clause is encountered.
* Called any time a MATCHES clause is encountered. * @param property Name of the property
* @param property Name of the property * @param propertyValue String
* @param propertyValue String
* @param negated returns true if "NOT MATCHES" was used * @param negated returns true if "NOT MATCHES" was used
*/ */
void matches(String property, String propertyValue, boolean negated); void matches(String property, String propertyValue, boolean negated);
/** /**
* Called any time an AND is encountered. * Called any time an AND is encountered.
*/ */
void and(); void and();
/** /**
* Called any time an OR is encountered. * Called any time an OR is encountered.
*/ */
void or(); void or();
} }
/** /**
@@ -104,20 +103,20 @@ public abstract class QueryHelper
public static class WalkerCallbackAdapter implements WalkerCallback public static class WalkerCallbackAdapter implements WalkerCallback
{ {
@Override @Override
public void exists(String propertyName, boolean negated) { throw UNSUPPORTED;} public void exists(String propertyName, boolean negated) { throw UNSUPPORTED;}
@Override @Override
public void between(String propertyName, String firstValue, String secondValue, boolean negated) { throw UNSUPPORTED;} public void between(String propertyName, String firstValue, String secondValue, boolean negated) { throw UNSUPPORTED;}
@Override @Override
public void comparison(int type, String propertyName, String propertyValue, boolean negated) { throw UNSUPPORTED;} public void comparison(int type, String propertyName, String propertyValue, boolean negated) { throw UNSUPPORTED;}
@Override @Override
public void in(String propertyName, boolean negated, String... propertyValues) { throw UNSUPPORTED;} public void in(String propertyName, boolean negated, String... propertyValues) { throw UNSUPPORTED;}
@Override @Override
public void matches(String property, String value, boolean negated) { throw UNSUPPORTED;} public void matches(String property, String value, boolean negated) { throw UNSUPPORTED;}
@Override @Override
public void and() {throw UNSUPPORTED;} public void and() {throw UNSUPPORTED;}
@Override @Override
public void or() {throw UNSUPPORTED;} public void or() {throw UNSUPPORTED;}
} }
/** /**
@@ -127,14 +126,13 @@ public abstract class QueryHelper
*/ */
public static void walk(Query query, WalkerCallback callback) public static void walk(Query query, WalkerCallback callback)
{ {
CommonTree tree = query.getTree();
CommonTree tree = query.getTree(); if (tree != null)
if (tree != null) {
{ LinkedList<Tree> stack = new LinkedList<Tree>();
LinkedList<Tree> stack = new LinkedList<Tree>(); stack.push(tree);
stack.push(tree); callbackTree(tree, callback, false);
callbackTree(tree, callback, false); }
}
} }
/** /**
@@ -145,77 +143,80 @@ public abstract class QueryHelper
*/ */
protected static void callbackTree(Tree tree, WalkerCallback callback, boolean negated) protected static void callbackTree(Tree tree, WalkerCallback callback, boolean negated)
{ {
if (tree != null) if (tree != null)
{ {
switch (tree.getType()) { switch (tree.getType()) {
case WhereClauseParser.EXISTS: case WhereClauseParser.EXISTS:
if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType()) if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType())
{ {
callback.exists(tree.getChild(0).getText(), negated); callback.exists(tree.getChild(0).getText(), negated);
return; return;
} }
break; break;
case WhereClauseParser.MATCHES: case WhereClauseParser.MATCHES:
if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType()) if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType())
{ {
callback.matches(tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()), negated); callback.matches(tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()), negated);
return; return;
} }
break; break;
case WhereClauseParser.IN: case WhereClauseParser.IN:
if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType()) if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType())
{ {
List<Tree> children = getChildren(tree); List<Tree> children = getChildren(tree);
//Don't need the first item because its the property name //Don't need the first item because its the property name
String[] inVals = new String[children.size()-1]; String[] inVals = new String[children.size()-1];
for (int i = 1; i < children.size(); i++) { for (int i = 1; i < children.size(); i++)
inVals[i-1] = stripQuotes(children.get(i).getText()); {
} inVals[i-1] = stripQuotes(children.get(i).getText());
callback.in(tree.getChild(0).getText(), negated, inVals); }
return; callback.in(tree.getChild(0).getText(), negated, inVals);
} return;
break; }
case WhereClauseParser.BETWEEN: break;
if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType()) case WhereClauseParser.BETWEEN:
{ if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType())
callback.between(tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()), stripQuotes(tree.getChild(2).getText()), negated); {
return; callback.between(tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()), stripQuotes(tree.getChild(2).getText()), negated);
} return;
break; }
case WhereClauseParser.EQUALS: //fall through (comparison) break;
case WhereClauseParser.LESSTHAN: //fall through (comparison) case WhereClauseParser.EQUALS: //fall through (comparison)
case WhereClauseParser.GREATERTHAN: //fall through (comparison) case WhereClauseParser.LESSTHAN: //fall through (comparison)
case WhereClauseParser.LESSTHANOREQUALS: //fall through (comparison) case WhereClauseParser.GREATERTHAN: //fall through (comparison)
case WhereClauseParser.GREATERTHANOREQUALS: case WhereClauseParser.LESSTHANOREQUALS: //fall through (comparison)
if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType() && case WhereClauseParser.GREATERTHANOREQUALS:
WhereClauseParser.PROPERTYVALUE == tree.getChild(1).getType()) if (WhereClauseParser.PROPERTYNAME == tree.getChild(0).getType() &&
{ WhereClauseParser.PROPERTYVALUE == tree.getChild(1).getType())
callback.comparison(tree.getType(), tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()), negated); {
return; callback.comparison(tree.getType(), tree.getChild(0).getText(), stripQuotes(tree.getChild(1).getText()), negated);
} return;
break; }
case WhereClauseParser.NEGATION: break;
//Negate the next element case WhereClauseParser.NEGATION:
callbackTree(tree.getChild(0), callback, true); //Negate the next element
return; callbackTree(tree.getChild(0), callback, true);
case WhereClauseParser.OR: return;
callback.or(); case WhereClauseParser.OR:
List<Tree> children = getChildren(tree); callback.or();
for (Tree child : children) { List<Tree> children = getChildren(tree);
callbackTree(child, callback, negated); for (Tree child : children)
} {
return; callbackTree(child, callback, negated);
case WhereClauseParser.AND: }
callback.and(); return;
List<Tree> childrenOfAnd = getChildren(tree); case WhereClauseParser.AND:
for (Tree child : childrenOfAnd) { callback.and();
callbackTree(child, callback, negated); List<Tree> childrenOfAnd = getChildren(tree);
} for (Tree child : childrenOfAnd)
return; {
default: callbackTree(child, callback, negated);
} }
callbackTree(tree.getChild(0), callback, negated); //Callback on the next node return;
} default:
}
callbackTree(tree.getChild(0), callback, negated); //Callback on the next node
}
} }
/** /**
@@ -224,30 +225,30 @@ public abstract class QueryHelper
* @param tree the current tree * @param tree the current tree
* @return siblings - all the elements at the same level in the tree * @return siblings - all the elements at the same level in the tree
*/ */
// public static List<Tree> getYoungerSiblings(Tree tree) // public static List<Tree> getYoungerSiblings(Tree tree)
// { // {
// Tree parent = tree.getParent(); // Tree parent = tree.getParent();
// //
// if (parent!=null && parent.getChildCount() > 0) // if (parent!=null && parent.getChildCount() > 0)
// { // {
// List<Tree> sibs = new ArrayList<Tree>(parent.getChildCount()-1); // List<Tree> sibs = new ArrayList<Tree>(parent.getChildCount()-1);
// boolean laterChildren = false; // boolean laterChildren = false;
// for (int i = 0; i < parent.getChildCount(); i++) { // for (int i = 0; i < parent.getChildCount(); i++) {
// Tree child = parent.getChild(i); // Tree child = parent.getChild(i);
// if (tree.equals(child)) // if (tree.equals(child))
// { // {
// laterChildren = true; // laterChildren = true;
// } // }
// else // else
// { // {
// if (laterChildren) sibs.add(child); // if (laterChildren) sibs.add(child);
// } // }
// } // }
// return sibs; // return sibs;
// } // }
// //
// //
// } // }
/** /**
* Gets the children as a List * Gets the children as a List
@@ -256,33 +257,33 @@ public abstract class QueryHelper
*/ */
public static List<Tree> getChildren(Tree tree) public static List<Tree> getChildren(Tree tree)
{ {
if (tree!=null && tree.getChildCount() > 0) if (tree!=null && tree.getChildCount() > 0)
{ {
List<Tree> children = new ArrayList<Tree>(tree.getChildCount()); List<Tree> children = new ArrayList<Tree>(tree.getChildCount());
for (int i = 0; i < tree.getChildCount(); i++) { for (int i = 0; i < tree.getChildCount(); i++) {
Tree child = tree.getChild(i); Tree child = tree.getChild(i);
children.add(child); children.add(child);
} }
return children; return children;
} }
//Default //Default
return Collections.emptyList(); return Collections.emptyList();
} }
private static final String SINGLE_QUOTE = "'"; private static final String SINGLE_QUOTE = "'";
/** /**
* Strips off any leading or trailing single quotes. * Strips off any leading or trailing single quotes.
* @param toBeStripped String * @param toBeStripped String
* @return the String that has been stripped * @return the String that has been stripped
*/ */
public static String stripQuotes(String toBeStripped) public static String stripQuotes(String toBeStripped)
{ {
if (StringUtils.isNotEmpty(toBeStripped) && toBeStripped.startsWith(SINGLE_QUOTE) && toBeStripped.endsWith(SINGLE_QUOTE)) if (StringUtils.isNotEmpty(toBeStripped) && toBeStripped.startsWith(SINGLE_QUOTE) && toBeStripped.endsWith(SINGLE_QUOTE))
{ {
return toBeStripped.substring(1,toBeStripped.length()-1); return toBeStripped.substring(1,toBeStripped.length()-1);
} }
return toBeStripped; //default to return the String unchanged. return toBeStripped; //default to return the String unchanged.
} }
} }